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
|
---|---|---|---|---|---|---|
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))
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
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
| have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _) | /-- 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
| 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))
h' : β β β := fun x => (lgb - lga) * f' x - (lfb - lfa) * g' x
β’ β x β Ioo a b, HasDerivAt h (h' 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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
| intro x hx | /-- 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := 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))
hhb : Tendsto h (π[<] b) (π (lgb * lfa - lfb * lga))
h' : β β β := fun x => (lgb - lga) * f' x - (lfb - lfa) * g' x
x : β
hx : x β Ioo a b
β’ HasDerivAt h (h' 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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
| exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _) | /-- 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
| 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))
h' : β β β := fun x => (lgb - lga) * f' x - (lfb - lfa) * g' x
hhh' : β x β Ioo a b, HasDerivAt h (h' x) 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
| rcases exists_hasDerivAt_eq_zero' hab hha hhb hhh' with β¨c, cmem, hcβ© | /-- 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
| 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 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)
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))
h' : β β β := fun x => (lgb - lga) * f' x - (lfb - lfa) * g' x
hhh' : β x β Ioo a b, HasDerivAt h (h' x) x
c : β
cmem : c β Ioo a b
hc : h' c = 0
β’ β 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb hhh' with β¨c, cmem, hcβ©
| exact β¨c, cmem, sub_eq_zero.1 hcβ© | /-- 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb hhh' with β¨c, cmem, hcβ©
| 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)
β’ β c β Ioo a b, f' c = (f b - f 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; 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
| obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x | /-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
| Mathlib.Analysis.Calculus.MeanValue.767_0.ReDurB0qNQAwk9I | /-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) | 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)
c : β
cmem : c β Ioo a b
hc : (b - a) * f' c = (f b - f a) * 1
β’ β c β Ioo a b, f' c = (f b - f 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; 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
| use c, cmem | /-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
| Mathlib.Analysis.Calculus.MeanValue.767_0.ReDurB0qNQAwk9I | /-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) | Mathlib_Analysis_Calculus_MeanValue |
case right
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 : β
cmem : c β Ioo a b
hc : (b - a) * f' c = (f b - f a) * 1
β’ f' c = (f b - f 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; 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
| rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc | /-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
| Mathlib.Analysis.Calculus.MeanValue.767_0.ReDurB0qNQAwk9I | /-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_gt : β x β interior D, C < deriv f x
β’ β x β D, β y β D, x < y β C * (y - x) < f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
| intro x hx y hy hxy | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
| Mathlib.Analysis.Calculus.MeanValue.804_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_gt : β x β interior D, C < deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x < y
β’ C * (y - x) < f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
| have hxyD : Icc x y β D := hD.ordConnected.out hx hy | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
| Mathlib.Analysis.Calculus.MeanValue.804_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_gt : β x β interior D, C < deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x < y
hxyD : Icc x y β D
β’ C * (y - x) < f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
| have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ© | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
| Mathlib.Analysis.Calculus.MeanValue.804_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_gt : β x β interior D, C < deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x < y
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
β’ C * (y - x) < f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
| obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD') | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
| Mathlib.Analysis.Calculus.MeanValue.804_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x | 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_gt : β x β interior D, C < deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x < y
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
a : β
a_mem : a β Ioo x y
ha : deriv f a = (f y - f x) / (y - x)
β’ C * (y - x) < f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
| have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem) | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
| Mathlib.Analysis.Calculus.MeanValue.804_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x | 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_gt : β x β interior D, C < deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x < y
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
a : β
a_mem : a β Ioo x y
ha : deriv f a = (f y - f x) / (y - x)
this : C < (f y - f x) / (y - x)
β’ C * (y - x) < f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
| exact (lt_div_iff (sub_pos.2 hxy)).1 this | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
| Mathlib.Analysis.Calculus.MeanValue.804_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_ge : β x β interior D, C β€ deriv f x
β’ β x β D, β y β D, x β€ y β C * (y - x) β€ f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
| intro x hx y hy hxy | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
| Mathlib.Analysis.Calculus.MeanValue.830_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_ge : β x β interior D, C β€ deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
β’ C * (y - x) β€ f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
| cases' eq_or_lt_of_le hxy with hxy' hxy' | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
| Mathlib.Analysis.Calculus.MeanValue.830_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x | Mathlib_Analysis_Calculus_MeanValue |
case inl
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_ge : β x β interior D, C β€ deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
hxy' : x = y
β’ C * (y - x) β€ f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· | rw [hxy', sub_self, sub_self, mul_zero] | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· | Mathlib.Analysis.Calculus.MeanValue.830_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x | Mathlib_Analysis_Calculus_MeanValue |
case inr
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_ge : β x β interior D, C β€ deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
hxy' : x < y
β’ C * (y - x) β€ f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
| have hxyD : Icc x y β D := hD.ordConnected.out hx hy | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
| Mathlib.Analysis.Calculus.MeanValue.830_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x | Mathlib_Analysis_Calculus_MeanValue |
case inr
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_ge : β x β interior D, C β€ deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
hxy' : x < y
hxyD : Icc x y β D
β’ C * (y - x) β€ f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
| have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ© | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
| Mathlib.Analysis.Calculus.MeanValue.830_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x | Mathlib_Analysis_Calculus_MeanValue |
case inr
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_ge : β x β interior D, C β€ deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
hxy' : x < y
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
β’ C * (y - x) β€ f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
| obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
| Mathlib.Analysis.Calculus.MeanValue.830_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_ge : β x β interior D, C β€ deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
hxy' : x < y
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
β’ β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
case inr.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_ge : β x β interior D, C β€ deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
hxy' : x < y
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
a : β
a_mem : a β Ioo x y
ha : deriv f a = (f y - f x) / (y - x)
β’ C * (y - x) β€ f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
| exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD') | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
| Mathlib.Analysis.Calculus.MeanValue.830_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x | Mathlib_Analysis_Calculus_MeanValue |
case inr.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_ge : β x β interior D, C β€ deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
hxy' : x < y
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
a : β
a_mem : a β Ioo x y
ha : deriv f a = (f y - f x) / (y - x)
β’ C * (y - x) β€ f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
| have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem) | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
| Mathlib.Analysis.Calculus.MeanValue.830_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x | Mathlib_Analysis_Calculus_MeanValue |
case inr.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
hf'_ge : β x β interior D, C β€ deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
hxy' : x < y
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
a : β
a_mem : a β Ioo x y
ha : deriv f a = (f y - f x) / (y - x)
this : C β€ (f y - f x) / (y - x)
β’ C * (y - x) β€ f y - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
| exact (le_div_iff (sub_pos.2 hxy')).1 this | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
| Mathlib.Analysis.Calculus.MeanValue.830_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
lt_hf' : β x β interior D, deriv f x < C
xβ : β
hxβ : xβ β D
y : β
hy : y β D
hxy : xβ < y
x : β
hx : x β interior D
β’ -C < deriv (fun y => -f 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
| rw [deriv.neg, neg_lt_neg_iff] | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
| Mathlib.Analysis.Calculus.MeanValue.858_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
lt_hf' : β x β interior D, deriv f x < C
xβ : β
hxβ : xβ β D
y : β
hy : y β D
hxy : xβ < y
x : β
hx : x β interior D
β’ deriv (fun y => f y) x < 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
| exact lt_hf' x hx | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
| Mathlib.Analysis.Calculus.MeanValue.858_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
lt_hf' : β x β interior D, deriv f x < C
x : β
hx : x β D
y : β
hy : y β D
hxy : x < y
hf'_gt : β x β interior D, -C < deriv (fun y => -f 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by | linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy] | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by | Mathlib.Analysis.Calculus.MeanValue.858_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
le_hf' : β x β interior D, deriv f x β€ C
xβ : β
hxβ : xβ β D
y : β
hy : y β D
hxy : xβ β€ y
x : β
hx : x β interior D
β’ -C β€ deriv (fun y => -f 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
| rw [deriv.neg, neg_le_neg_iff] | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
| Mathlib.Analysis.Calculus.MeanValue.880_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
le_hf' : β x β interior D, deriv f x β€ C
xβ : β
hxβ : xβ β D
y : β
hy : y β D
hxy : xβ β€ y
x : β
hx : x β interior D
β’ deriv (fun y => f y) x β€ 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
| exact le_hf' x hx | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
| Mathlib.Analysis.Calculus.MeanValue.880_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
C : β
le_hf' : β x β interior D, deriv f x β€ C
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
hf'_ge : β x β interior D, -C β€ deriv (fun y => -f 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by | linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy] | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by | Mathlib.Analysis.Calculus.MeanValue.880_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : β x β interior D, 0 < deriv f x
β’ StrictMonoOn f D | /-
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
| intro x hx y hy | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
| Mathlib.Analysis.Calculus.MeanValue.902_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D | Mathlib_Analysis_Calculus_MeanValue |
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : β x β interior D, 0 < deriv f x
x : β
hx : x β D
y : β
hy : y β D
β’ x < y β 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
| have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
| Mathlib.Analysis.Calculus.MeanValue.902_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D | Mathlib_Analysis_Calculus_MeanValue |
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : β x β interior D, 0 < deriv f x
x : β
hx : x β D
y : β
hy : y β D
this : DifferentiableOn β f (interior D)
β’ x < y β 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
| simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
| Mathlib.Analysis.Calculus.MeanValue.902_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D | Mathlib_Analysis_Calculus_MeanValue |
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_nonneg : β x β interior D, 0 β€ deriv f x
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
β’ 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
| simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
| Mathlib.Analysis.Calculus.MeanValue.926_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D | Mathlib_Analysis_Calculus_MeanValue |
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : β x β interior D, deriv f x < 0
x : β
hx : x β D
y : β
β’ y β D β x < y β f y < 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
| simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
| Mathlib.Analysis.Calculus.MeanValue.945_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D | Mathlib_Analysis_Calculus_MeanValue |
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_nonpos : β x β interior D, deriv f x β€ 0
x : β
hx : x β D
y : β
hy : y β D
hxy : x β€ y
β’ f y β€ 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
| simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
| Mathlib.Analysis.Calculus.MeanValue.969_0.ReDurB0qNQAwk9I | /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D | Mathlib_Analysis_Calculus_MeanValue |
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
β’ β {x y z : β}, x β D β z β D β x < y β y < z β (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
| intro x y z hx hz hxy hyz | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
β’ (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
| have hxzD : Icc x z β D := hD.ordConnected.out hx hz | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
β’ (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
| have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
β’ (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
| have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ© | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
β’ (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
| have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
hyzD : Icc y z β D
β’ (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
| have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ© | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
hyzD : Icc y z β D
hyzD' : Ioo y z β interior D
β’ (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
| obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
hyzD : Icc y z β D
hyzD' : Ioo y z β interior D
β’ β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
case intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
hyzD : Icc y z β D
hyzD' : Ioo y z β interior D
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
β’ (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
| exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD') | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
hyzD : Icc y z β D
hyzD' : Ioo y z β interior D
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
β’ (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
| obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y) | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
hyzD : Icc y z β D
hyzD' : Ioo y z β interior D
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
β’ β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
case intro.intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
hyzD : Icc y z β D
hyzD' : Ioo y z β interior D
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
b : β
hb : deriv f b = (f z - f y) / (z - y)
hyb : y < b
hbz : b < z
β’ (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
| exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD') | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
hyzD : Icc y z β D
hyzD' : Ioo y z β interior D
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
b : β
hb : deriv f b = (f z - f y) / (z - y)
hyb : y < b
hbz : b < z
β’ (f y - f x) / (y - x) β€ (f z - f y) / (z - 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
| rw [β ha, β hb] | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
hf'_mono : MonotoneOn (deriv f) (interior D)
x y z : β
hx : x β D
hz : z β D
hxy : x < y
hyz : y < z
hxzD : Icc x z β D
hxyD : Icc x y β D
hxyD' : Ioo x y β interior D
hyzD : Icc y z β D
hyzD' : Ioo y z β interior D
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
b : β
hb : deriv f b = (f z - f y) / (z - y)
hyb : y < b
hbz : b < z
β’ deriv f a β€ deriv f 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
| exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
| Mathlib.Analysis.Calculus.MeanValue.988_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D 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
D : Set β
hD : Convex β D
f : β β β
hf : ContinuousOn f D
hf' : DifferentiableOn β f (interior D)
h_anti : AntitoneOn (deriv f) (interior D)
β’ MonotoneOn (deriv (-f)) (interior D) | /-
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
| simpa only [β deriv.neg] using h_anti.neg | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
| Mathlib.Analysis.Calculus.MeanValue.1013_0.ReDurB0qNQAwk9I | /-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
| have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
| Mathlib.Analysis.Calculus.MeanValue.1023_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
| obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
| Mathlib.Analysis.Calculus.MeanValue.1023_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
β’ β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
case intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
| exact exists_deriv_eq_slope f hxy hf A | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
| Mathlib.Analysis.Calculus.MeanValue.1023_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
| rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β© | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
| Mathlib.Analysis.Calculus.MeanValue.1023_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
b : β
hab : a < b
hby : b < y
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
| refine' β¨b, β¨hxa.trans hab, hbyβ©, _β© | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
| Mathlib.Analysis.Calculus.MeanValue.1023_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
b : β
hab : a < b
hby : b < y
β’ (f y - f x) / (y - x) < deriv f 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
| rw [β ha] | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
| Mathlib.Analysis.Calculus.MeanValue.1023_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
b : β
hab : a < b
hby : b < y
β’ deriv f a < deriv f 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
| exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
| Mathlib.Analysis.Calculus.MeanValue.1023_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
| by_cases h : β w β Ioo x y, deriv f w β 0 | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case pos
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· | apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· | Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case neg
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : Β¬β w β Ioo x y, deriv f w β 0
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· | push_neg at h | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· | Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case neg
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w = 0
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
| rcases h with β¨w, β¨hxw, hwyβ©, hwβ© | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case neg.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
| obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2 | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
β’ β a β Ioo x w, (f w - f x) / (w - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
| apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _ | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
β’ ContinuousOn (fun w => f w) (Icc x w) | /-
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· | exact hf.mono (Icc_subset_Icc le_rfl hwy.le) | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· | Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
β’ StrictMonoOn (deriv fun w => f w) (Ioo x w) | /-
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· | exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· | Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
β’ β w_1 β Ioo x w, deriv (fun w => f w) w_1 β 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; 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· | intro z hz | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· | Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
z : β
hz : z β Ioo x w
β’ deriv (fun w => f w) 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; 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
| rw [β hw] | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
z : β
hz : z β Ioo x w
β’ deriv (fun w => f w) z β deriv f w | /-
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
| apply ne_of_lt | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
z : β
hz : z β Ioo x w
β’ deriv (fun w => f w) z < deriv f w | /-
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
| exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2 | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case neg.intro.intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
ha : (f w - f x) / (w - x) < deriv f a
hxa : x < a
haw : a < w
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
| obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1 | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
ha : (f w - f x) / (w - x) < deriv f a
hxa : x < a
haw : a < w
β’ β b β Ioo w y, (f y - f w) / (y - w) < deriv f 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
| apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _ | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
ha : (f w - f x) / (w - x) < deriv f a
hxa : x < a
haw : a < w
β’ ContinuousOn (fun {y} => f y) (Icc w 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· | refine' hf.mono (Icc_subset_Icc hxw.le le_rfl) | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· | Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
ha : (f w - f x) / (w - x) < deriv f a
hxa : x < a
haw : a < w
β’ StrictMonoOn (deriv fun {y} => f y) (Ioo w 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· | exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl) | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· | Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
ha : (f w - f x) / (w - x) < deriv f a
hxa : x < a
haw : a < w
β’ β w_1 β Ioo w y, deriv (fun {y} => f y) w_1 β 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; 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· | intro z hz | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· | Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
ha : (f w - f x) / (w - x) < deriv f a
hxa : x < a
haw : a < w
z : β
hz : z β Ioo w y
β’ deriv (fun {y} => f y) 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; 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
| rw [β hw] | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
ha : (f w - f x) / (w - x) < deriv f a
hxa : x < a
haw : a < w
z : β
hz : z β Ioo w y
β’ deriv (fun {y} => f y) z β deriv f w | /-
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
| apply ne_of_gt | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
ha : (f w - f x) / (w - x) < deriv f a
hxa : x < a
haw : a < w
z : β
hz : z β Ioo w y
β’ deriv f w < deriv (fun {y} => f y) z | /-
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
| exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1 | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case neg.intro.intro.intro.intro.intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
ha : (f w - f x) / (w - x) < deriv f a
hxa : x < a
haw : a < w
b : β
hb : (f y - f w) / (y - w) < deriv f b
hwb : w < b
hby : b < y
β’ β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
| refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β© | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case neg.intro.intro.intro.intro.intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
ha : (f w - f x) / (w - x) < deriv f a
hxa : x < a
haw : a < w
b : β
hb : (f y - f w) / (y - w) < deriv f b
hwb : w < b
hby : b < y
β’ (f y - f x) / (y - x) < deriv f 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
| simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’ | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case neg.intro.intro.intro.intro.intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
hxa : x < a
haw : a < w
b : β
hwb : w < b
hby : b < y
ha : f w - f x < deriv f a * (w - x)
hb : f y - f w < deriv f b * (y - w)
β’ f y - f x < deriv f b * (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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
| have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
hxa : x < a
haw : a < w
b : β
hwb : w < b
hby : b < y
ha : f w - f x < deriv f a * (w - x)
hb : f y - f w < deriv f b * (y - w)
β’ deriv f a * (w - x) < deriv f b * (w - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
| apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _ | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
hxa : x < a
haw : a < w
b : β
hwb : w < b
hby : b < y
ha : f w - f x < deriv f a * (w - x)
hb : f y - f w < deriv f b * (y - w)
β’ deriv f a < deriv f 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· | exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb) | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· | Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
hxa : x < a
haw : a < w
b : β
hwb : w < b
hby : b < y
ha : f w - f x < deriv f a * (w - x)
hb : f y - f w < deriv f b * (y - w)
β’ 0 β€ deriv f 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· | rw [β hw] | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· | Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
hxa : x < a
haw : a < w
b : β
hwb : w < b
hby : b < y
ha : f w - f x < deriv f a * (w - x)
hb : f y - f w < deriv f b * (y - w)
β’ deriv f w β€ deriv f 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
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
| exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a | Mathlib_Analysis_Calculus_MeanValue |
case neg.intro.intro.intro.intro.intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
a : β
hxa : x < a
haw : a < w
b : β
hwb : w < b
hby : b < y
ha : f w - f x < deriv f a * (w - x)
hb : f y - f w < deriv f b * (y - w)
this : deriv f a * (w - x) < deriv f b * (w - x)
β’ f y - f x < deriv f b * (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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
| linarith | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
| Mathlib.Analysis.Calculus.MeanValue.1036_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv 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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
β’ β a β Ioo x y, deriv f a < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
| have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
| Mathlib.Analysis.Calculus.MeanValue.1069_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
β’ β a β Ioo x y, deriv f a < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
| obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
| Mathlib.Analysis.Calculus.MeanValue.1069_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
β’ β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
case intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
β’ β a β Ioo x y, deriv f a < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
| exact exists_deriv_eq_slope f hxy hf A | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
| Mathlib.Analysis.Calculus.MeanValue.1069_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
β’ β a β Ioo x y, deriv f a < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
| rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β© | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
| Mathlib.Analysis.Calculus.MeanValue.1069_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
b : β
hxb : x < b
hba : b < a
β’ β a β Ioo x y, deriv f a < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
| refine' β¨b, β¨hxb, hba.trans hayβ©, _β© | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
| Mathlib.Analysis.Calculus.MeanValue.1069_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
b : β
hxb : x < b
hba : b < a
β’ deriv f b < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
| rw [β ha] | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
| Mathlib.Analysis.Calculus.MeanValue.1069_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) | Mathlib_Analysis_Calculus_MeanValue |
case intro.intro.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
A : DifferentiableOn β f (Ioo x y)
a : β
ha : deriv f a = (f y - f x) / (y - x)
hxa : x < a
hay : a < y
b : β
hxb : x < b
hba : b < a
β’ deriv f b < deriv 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
#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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
| exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
| Mathlib.Analysis.Calculus.MeanValue.1069_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
β’ β a β Ioo x y, deriv f a < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
#align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux
theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
| by_cases h : β w β Ioo x y, deriv f w β 0 | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
| Mathlib.Analysis.Calculus.MeanValue.1082_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) | Mathlib_Analysis_Calculus_MeanValue |
case pos
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w β 0
β’ β a β Ioo x y, deriv f a < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
#align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux
theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· | apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· | Mathlib.Analysis.Calculus.MeanValue.1082_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) | Mathlib_Analysis_Calculus_MeanValue |
case neg
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : Β¬β w β Ioo x y, deriv f w β 0
β’ β a β Ioo x y, deriv f a < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
#align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux
theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· | push_neg at h | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· | Mathlib.Analysis.Calculus.MeanValue.1082_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) | Mathlib_Analysis_Calculus_MeanValue |
case neg
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
h : β w β Ioo x y, deriv f w = 0
β’ β a β Ioo x y, deriv f a < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
#align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux
theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
| rcases h with β¨w, β¨hxw, hwyβ©, hwβ© | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
| Mathlib.Analysis.Calculus.MeanValue.1082_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) | Mathlib_Analysis_Calculus_MeanValue |
case neg.intro.intro.intro
E : Type u_1
instβΒ³ : NormedAddCommGroup E
instβΒ² : NormedSpace β E
F : Type u_2
instβΒΉ : NormedAddCommGroup F
instβ : NormedSpace β F
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
β’ β a β Ioo x y, deriv f a < (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
_ = β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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
#align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux
theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
| obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2 | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
| Mathlib.Analysis.Calculus.MeanValue.1082_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
β’ β a β Ioo x w, deriv f a < (f w - f x) / (w - 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) (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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
#align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux
theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
| apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _ | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
| Mathlib.Analysis.Calculus.MeanValue.1082_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
β’ ContinuousOn f (Icc x w) | /-
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
#align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux
theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
Β· | exact hf.mono (Icc_subset_Icc le_rfl hwy.le) | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
Β· | Mathlib.Analysis.Calculus.MeanValue.1082_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
β’ StrictMonoOn (deriv f) (Ioo x w) | /-
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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
#align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux
theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· | exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· | Mathlib.Analysis.Calculus.MeanValue.1082_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
β’ β w_1 β Ioo x w, deriv f w_1 β 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; 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
#align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux
theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· | intro z hz | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· | Mathlib.Analysis.Calculus.MeanValue.1082_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (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
x y : β
f : β β β
hf : ContinuousOn f (Icc x y)
hxy : x < y
hf'_mono : StrictMonoOn (deriv f) (Ioo x y)
w : β
hw : deriv f w = 0
hxw : x < w
hwy : w < y
z : β
hz : z β Ioo x w
β’ deriv 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; 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
have hhh' : β x β Ioo a b, HasDerivAt h (h' x) x := by
intro x hx
exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _)
rcases exists_hasDerivAt_eq_zero' hab hha hhb 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'
/-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/
theorem exists_hasDerivAt_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) := by
obtain β¨c, cmem, hcβ© : β c β Ioo a b, (b - a) * f' c = (f b - f a) * 1 :=
exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id
fun x _ => hasDerivAt_id x
use c, cmem
rwa [mul_one, mul_comm, β eq_div_iff (sub_ne_zero.2 hab.ne')] at hc
#align exists_has_deriv_at_eq_slope exists_hasDerivAt_eq_slope
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc
(fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g
(deriv g) hgc fun x hx =>
((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_ratio_deriv_eq_ratio_slope exists_ratio_deriv_eq_ratio_slope
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : DifferentiableOn β f <| Ioo a b) (hdg : DifferentiableOn β g <| Ioo a b)
(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) * deriv f c = (lfb - lfa) * deriv g c :=
exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _
(fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt)
(fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb
#align exists_ratio_deriv_eq_ratio_slope' exists_ratio_deriv_eq_ratio_slope'
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
theorem exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx =>
((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt
#align exists_deriv_eq_slope exists_deriv_eq_slope
end Interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_gt : β x β interior D, C < deriv f x) :
βα΅ (x β D) (y β D), x < y β C * (y - x) < f y - f x := by
intro x hx y hy hxy
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
have : C < (f y - f x) / (y - x) := ha βΈ hf'_gt _ (hxyD' a_mem)
exact (lt_div_iff (sub_pos.2 hxy)).1 this
#align convex.mul_sub_lt_image_sub_of_lt_deriv Convex.mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) : C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_gt x) x trivial y trivial hxy
#align mul_sub_lt_image_sub_of_lt_deriv mul_sub_lt_image_sub_of_lt_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(hf'_ge : β x β interior D, C β€ deriv f x) :
βα΅ (x β D) (y β D), x β€ y β C * (y - x) β€ f y - f x := by
intro x hx y hy hxy
cases' eq_or_lt_of_le hxy with hxy' hxy'
Β· rw [hxy', sub_self, sub_self, mul_zero]
have hxyD : Icc x y β D := hD.ordConnected.out hx hy
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD')
have : C β€ (f y - f x) / (y - x) := ha βΈ hf'_ge _ (hxyD' a_mem)
exact (le_div_iff (sub_pos.2 hxy')).1 this
#align convex.mul_sub_le_image_sub_of_le_deriv Convex.mul_sub_le_image_sub_of_le_deriv
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : Differentiable β f) {C}
(hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) : C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn
(fun x _ => hf'_ge x) x trivial y trivial hxy
#align mul_sub_le_image_sub_of_le_deriv mul_sub_le_image_sub_of_le_deriv
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(lt_hf' : β x β interior D, deriv f x < C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x < y) : f y - f x < C * (y - x) :=
have hf'_gt : β x β interior D, -C < deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_lt_neg_iff]
exact lt_hf' x hx
by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy]
#align convex.image_sub_lt_mul_sub_of_deriv_lt Convex.image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : Differentiable β f) {C}
(lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) : f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn
(fun x _ => lt_hf' x) x trivial y trivial hxy
#align image_sub_lt_mul_sub_of_deriv_lt image_sub_lt_mul_sub_of_deriv_lt
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D)) {C}
(le_hf' : β x β interior D, deriv f x β€ C) (x : β) (hx : x β D) (y : β) (hy : y β D)
(hxy : x β€ y) : f y - f x β€ C * (y - x) :=
have hf'_ge : β x β interior D, -C β€ deriv (fun y => -f y) x := fun x hx => by
rw [deriv.neg, neg_le_neg_iff]
exact le_hf' x hx
by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy]
#align convex.image_sub_le_mul_sub_of_deriv_le Convex.image_sub_le_mul_sub_of_deriv_le
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : Differentiable β f) {C}
(le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) : f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn
(fun x _ => le_hf' x) x trivial y trivial hxy
#align image_sub_le_mul_sub_of_deriv_le image_sub_le_mul_sub_of_deriv_le
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem Convex.strictMonoOn_of_deriv_pos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, 0 < deriv f x) : StrictMonoOn f D := by
intro x hx y hy
have : DifferentiableOn β f (interior D) := fun z hz =>
(differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt
simpa only [zero_mul, sub_pos] using
hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy
#align convex.strict_mono_on_of_deriv_pos Convex.strictMonoOn_of_deriv_pos
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strictMono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : StrictMono f :=
strictMonoOn_univ.1 <| convex_univ.strictMonoOn_of_deriv_pos (fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_mono_of_deriv_pos strictMono_of_deriv_pos
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem Convex.monotoneOn_of_deriv_nonneg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonneg] using
hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
#align convex.monotone_on_of_deriv_nonneg Convex.monotoneOn_of_deriv_nonneg
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : Differentiable β f) (hf' : β x, 0 β€ deriv f x) :
Monotone f :=
monotoneOn_univ.1 <|
convex_univ.monotoneOn_of_deriv_nonneg hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align monotone_of_deriv_nonneg monotone_of_deriv_nonneg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem Convex.strictAntiOn_of_deriv_neg {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : β x β interior D, deriv f x < 0) : StrictAntiOn f D :=
fun x hx y => by
simpa only [zero_mul, sub_lt_zero] using
hD.image_sub_lt_mul_sub_of_deriv_lt hf
(fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x
hx y
#align convex.strict_anti_on_of_deriv_neg Convex.strictAntiOn_of_deriv_neg
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strictAnti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) : StrictAnti f :=
strictAntiOn_univ.1 <|
convex_univ.strictAntiOn_of_deriv_neg
(fun z _ =>
(differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt)
fun x _ => hf' x
#align strict_anti_of_deriv_neg strictAnti_of_deriv_neg
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem Convex.antitoneOn_of_deriv_nonpos {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) : AntitoneOn f D := fun x hx y hy hxy => by
simpa only [zero_mul, sub_nonpos] using
hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
#align convex.antitone_on_of_deriv_nonpos Convex.antitoneOn_of_deriv_nonpos
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : Differentiable β f) (hf' : β x, deriv f x β€ 0) :
Antitone f :=
antitoneOn_univ.1 <|
convex_univ.antitoneOn_of_deriv_nonpos hf.continuous.continuousOn hf.differentiableOn fun x _ =>
hf' x
#align antitone_of_deriv_nonpos antitone_of_deriv_nonpos
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn β D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z β D := hD.ordConnected.out hx hz
have hxyD : Icc x y β D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyDβ©
have hyzD : Icc y z β D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z β interior D :=
subset_sUnion_of_mem β¨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzDβ©
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y)
exact exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [β ha, β hb]
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le)
#align monotone_on.convex_on_of_deriv MonotoneOn.convexOn_of_deriv
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set β} (hD : Convex β D) {f : β β β}
(hf : ContinuousOn f D) (hf' : DifferentiableOn β f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn β D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [β deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
#align antitone_on.concave_on_of_deriv AntitoneOn.concaveOn_of_deriv
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©
refine' β¨b, β¨hxa.trans hab, hbyβ©, _β©
rw [β ha]
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
#align strict_mono_on.exists_slope_lt_deriv_aux StrictMonoOn.exists_slope_lt_deriv_aux
theorem StrictMonoOn.exists_slope_lt_deriv {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
rw [β hw]
apply ne_of_lt
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β b β Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
Β· refine' hf.mono (Icc_subset_Icc hxw.le le_rfl)
Β· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
Β· intro z hz
rw [β hw]
apply ne_of_gt
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1
refine' β¨b, β¨hxw.trans hwb, hbyβ©, _β©
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb β’
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
Β· exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb)
Β· rw [β hw]
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le
linarith
#align strict_mono_on.exists_slope_lt_deriv StrictMonoOn.exists_slope_lt_deriv
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn β f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x)
exact exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©
refine' β¨b, β¨hxb, hba.trans hayβ©, _β©
rw [β ha]
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
#align strict_mono_on.exists_deriv_lt_slope_aux StrictMonoOn.exists_deriv_lt_slope_aux
theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
| rw [β hw] | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : β w β Ioo x y, deriv f w β 0
Β· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
Β· push_neg at h
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©
obtain β¨a, β¨hxa, hawβ©, haβ© : β a β Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
Β· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
Β· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
Β· intro z hz
| Mathlib.Analysis.Calculus.MeanValue.1082_0.ReDurB0qNQAwk9I | theorem StrictMonoOn.exists_deriv_lt_slope {x y : β} {f : β β β} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) | Mathlib_Analysis_Calculus_MeanValue |
Subsets and Splits