Chapter 04 — The Derivative
Proofs omitted. Hover over highlighted terms to see their Lean types.
Reading sections
4.1 — The Derivative
Lean authors: Zichen Wang, Zaiwen Wen.
Definition 4.1.1: For an interval I ⊆ ℝ, a function f : ℝ → ℝ, and c ∈ I, if the limit L = lim_{x → c} (f x - f c) / (x - c) exists, then f is differentiable at c, L is the derivative f' c, and the quotient (f x - f c) / (x - c) is the difference quotient. If the limit exists at every c ∈ I, then f is differentiable on I and yields a derivative function f' : I → ℝ.
open Filter Topology
noncomputable def differenceQuotient (f : ℝ → ℝ) (c x : ℝ) : ℝ :=
(f x - f c) / (x - c)
The book's notion of differentiability on a subset of ℝ via the limit of the difference quotient.
open Filter Topology
def DifferentiableAtOn (I : Set ℝ) (f : ℝ → ℝ) (c : ℝ) : Prop :=
c ∈ I ∧
∃ L : ℝ,
Tendsto (fun x => differenceQuotient f c x)
(nhdsWithin c {x | x ≠ c}) (𝓝 L)
The derivative value provided by the existence of the difference-quotient limit.
open Filter Topology
noncomputable def derivativeAtOn (I : Set ℝ) (f : ℝ → ℝ) (c : ℝ)
(h : DifferentiableAtOn I f c) : ℝ :=
Classical.choose h.2
The book's differentiability notion agrees with mathlib's HasDerivAt formulation.
open Filter Topology
lemma differentiableAtOn_iff_hasDerivAt {I : Set ℝ} {f : ℝ → ℝ} {c : ℝ} :
DifferentiableAtOn I f c ↔ c ∈ I ∧ ∃ L : ℝ, HasDerivAt f L c
If a function is differentiable at every point of an interval, the derivative defines a function I → ℝ.
open Filter Topology
noncomputable def derivativeOn (I : Set ℝ) (f : ℝ → ℝ)
(h : ∀ c ∈ I, DifferentiableAtOn I f c) : I → ℝ :=
fun x => derivativeAtOn I f x.1 (h x.1 x.property)
Example 4.1.2: For f x = x^2 on ℝ, the derivative at any c satisfies f' c = 2c, since the difference quotient simplifies to x + c and its limit as x → c is 2c.
open Filter Topology
lemma hasDerivAt_sq (c : ℝ) : HasDerivAt (fun x => x ^ 2) (2 * c) c
Example 4.1.3: For an affine function f x = a * x + b with real coefficients, the difference quotient simplifies to a, so the derivative at any point c is the constant slope a.
open Filter Topology
lemma hasDerivAt_affine (a b c : ℝ) :
HasDerivAt (fun x => a * x + b) a c
Example 4.1.4: The square-root function f x = √x is differentiable for x > 0, and for each c > 0 its derivative is 1 / (2√c).
open Filter Topology
lemma hasDerivAt_sqrt_pos {c : ℝ} (hc : 0 < c) :
HasDerivAt Real.sqrt (1 / (2 * Real.sqrt c)) c
Example 4.1.5: The absolute-value function is not differentiable at the origin, since the difference quotient is 1 for x > 0 and -1 for x < 0.
open Filter Topology
lemma differenceQuotient_abs_pos {x : ℝ} (hx : 0 < x) :
differenceQuotient (fun x : ℝ => |x|) 0 x = 1
open Filter Topology
lemma differenceQuotient_abs_neg {x : ℝ} (hx : x < 0) :
differenceQuotient (fun x : ℝ => |x|) 0 x = -1
open Filter Topology
lemma abs_not_differentiable_at_zero :
¬ DifferentiableAt ℝ (fun x : ℝ => |x|) 0
Proposition 4.1.6: If a real function is differentiable at a point of an interval, then it is continuous at that point.
open Filter Topology
theorem differentiableAt_real_continuousAt {f : ℝ → ℝ} {c : ℝ}
(h : DifferentiableAt ℝ f c) : ContinuousAt f c
Proposition 4.1.7 (Linearity): Let I be an interval and let f g : ℝ → ℝ be differentiable at c ∈ I, with α : ℝ. (i) For h x = α * f x, the derivative satisfies deriv h c = α * deriv f c. (ii) For h x = f x + g x, the derivative satisfies deriv h c = deriv f c + deriv g c.
open Filter Topology
theorem deriv_const_mul_at {f : ℝ → ℝ} {c α : ℝ}
(hf : DifferentiableAt ℝ f c) :
DifferentiableAt ℝ (fun x => α * f x) c ∧
deriv (fun x => α * f x) c = α * deriv f c
open Filter Topology
theorem deriv_add_at {f g : ℝ → ℝ} {c : ℝ}
(hf : DifferentiableAt ℝ f c) (hg : DifferentiableAt ℝ g c) :
DifferentiableAt ℝ (fun x => f x + g x) c ∧
deriv (fun x => f x + g x) c = deriv f c + deriv g c
Proposition 4.1.8 (Product rule): For an interval I and functions f g : ℝ → ℝ differentiable at c ∈ I, the product h x = f x * g x is differentiable at c, and its derivative satisfies deriv h c = f c * deriv g c + deriv f c * g c.
open Filter Topology
theorem deriv_mul_at {I : Set ℝ} {f g : ℝ → ℝ} {c : ℝ}
(_hc : c ∈ I) (hf : DifferentiableAt ℝ f c) (hg : DifferentiableAt ℝ g c) :
DifferentiableAt ℝ (fun x => f x * g x) c ∧
deriv (fun x => f x * g x) c =
f c * deriv g c + deriv f c * g c
Proposition 4.1.9 (Quotient rule): For an interval I and functions f g : ℝ → ℝ differentiable at c ∈ I, with g x ≠ 0 for all x ∈ I, the quotient h x = f x / g x is differentiable at c, and its derivative satisfies deriv h c = (deriv f c * g c - f c * deriv g c) / (g c)^2.
open Filter Topology
theorem deriv_div_at {I : Set ℝ} {f g : ℝ → ℝ} {c : ℝ}
(hc : c ∈ I) (hf : DifferentiableAt ℝ f c) (hg : DifferentiableAt ℝ g c)
(hgnz : ∀ x ∈ I, g x ≠ 0) :
DifferentiableAt ℝ (fun x => f x / g x) c ∧
deriv (fun x => f x / g x) c =
(deriv f c * g c - f c * deriv g c) / (g c) ^ 2
Proposition 4.1.10 (Chain rule): Let I₁, I₂ be intervals, with g : ℝ → ℝ differentiable at c ∈ I₁ and taking values in I₂, and f : ℝ → ℝ differentiable at g c. If h x = f (g x), then h is differentiable at c with derivative deriv f (g c) * deriv g c.
open Filter Topology
theorem deriv_comp_at {f g : ℝ → ℝ} {c : ℝ}
(hgd : DifferentiableAt ℝ g c) (hfd : DifferentiableAt ℝ f (g c)) :
DifferentiableAt ℝ (fun x => f (g x)) c ∧
deriv (fun x => f (g x)) c = deriv f (g c) * deriv g c
Helper lemma for Proposition 4.1.10: differentiability of the composition arises from the chain rule for HasDerivAt.
open Filter Topology
lemma hasDerivAt_comp_at {f g : ℝ → ℝ} {c : ℝ}
(hgd : DifferentiableAt ℝ g c) (hfd : DifferentiableAt ℝ f (g c)) :
HasDerivAt (fun x => f (g x)) (deriv f (g c) * deriv g c) c4.2 — Mean Value Theorem
Lean authors: Zichen Wang, Zaiwen Wen.
Definition 4.2.1: A function f : S → ℝ has a relative maximum at c ∈ S if some δ > 0 satisfies f x ≤ f c whenever x ∈ S and |x - c| < δ. The notion of relative minimum reverses the inequality.
open Set Filter
open scoped Topology
def RelativeMaxOn (S : Set ℝ) (f : ℝ → ℝ) (c : ℝ) : Prop :=
∃ δ > 0, ∀ {x}, x ∈ S → |x - c| < δ → f x ≤ f c
open Set Filter
open scoped Topology
def RelativeMinOn (S : Set ℝ) (f : ℝ → ℝ) (c : ℝ) : Prop :=
∃ δ > 0, ∀ {x}, x ∈ S → |x - c| < δ → f c ≤ f x
The relative maximum defined via punctured-δ neighborhoods matches IsLocalMaxOn from mathlib.
open Set Filter
open scoped Topology
lemma relativeMaxOn_iff_isLocalMaxOn {S : Set ℝ} {f : ℝ → ℝ} {c : ℝ} :
RelativeMaxOn S f c ↔ IsLocalMaxOn f S c
The relative minimum defined via punctured-δ neighborhoods matches IsLocalMinOn from mathlib.
open Set Filter
open scoped Topology
lemma relativeMinOn_iff_isLocalMinOn {S : Set ℝ} {f : ℝ → ℝ} {c : ℝ} :
RelativeMinOn S f c ↔ IsLocalMinOn f S c
Lemma 4.2.2: If f : (a, b) → ℝ is differentiable at c ∈ (a, b) and has a relative minimum or maximum at c, then deriv f c = 0.
open Set Filter
open scoped Topology
lemma deriv_eq_zero_of_relative_extremum
{f : ℝ → ℝ} {a b c : ℝ} (hc : c ∈ Set.Ioo a b)
(hf : DifferentiableAt ℝ f c)
(hExt : RelativeMaxOn (Set.Ioo a b) f c ∨ RelativeMinOn (Set.Ioo a b) f c) :
deriv f c = 0
Theorem 4.2.3 (Rolle): If f : [a, b] → ℝ is continuous on the closed interval, differentiable on the open interval, and satisfies f a = f b, then there exists some c ∈ (a, b) with deriv f c = 0.
open Set Filter
open scoped Topology
theorem rolle
{f : ℝ → ℝ} {a b : ℝ} (h₁ : a < b)
(hcont : ContinuousOn f (Set.Icc a b))
(hdiff : DifferentiableOn ℝ f (Set.Ioo a b))
(hend : f a = f b) :
∃ c ∈ Set.Ioo a b, deriv f c = 0
Theorem 4.2.4 (Mean value theorem): If f : [a, b] → ℝ is continuous on the closed interval and differentiable on the open interval, then some c ∈ (a, b) satisfies f b - f a = deriv f c * (b - a).
open Set Filter
open scoped Topology
theorem mean_value_theorem
{f : ℝ → ℝ} {a b : ℝ} (h₁ : a < b)
(hcont : ContinuousOn f (Set.Icc a b))
(hdiff : DifferentiableOn ℝ f (Set.Ioo a b)) :
∃ c ∈ Set.Ioo a b, f b - f a = deriv f c * (b - a)
Theorem 4.2.5 (Cauchy's mean value theorem): If f, φ : [a, b] → ℝ are continuous on the closed interval and differentiable on the open interval, then some c ∈ (a, b) satisfies (f b - f a) * deriv φ c = deriv f c * (φ b - φ a).
open Set Filter
open scoped Topology
theorem cauchy_mean_value_theorem
{f φ : ℝ → ℝ} {a b : ℝ} (hab : a < b)
(hcont_f : ContinuousOn f (Set.Icc a b))
(hcont_φ : ContinuousOn φ (Set.Icc a b))
(hdiff_f : DifferentiableOn ℝ f (Set.Ioo a b))
(hdiff_φ : DifferentiableOn ℝ φ (Set.Ioo a b)) :
∃ c ∈ Set.Ioo a b,
(f b - f a) * deriv φ c = deriv f c * (φ b - φ a)
Proposition 4.2.6: If I is an interval and f : I → ℝ is differentiable with deriv f x = 0 for every x ∈ I, then f is constant on I.
open Set Filter
open scoped Topology
lemma deriv_zero_on_interval_const {I : Set ℝ} (hI : Set.OrdConnected I) {f : ℝ → ℝ}
(hdiff : DifferentiableOn ℝ f I) (hderiv : ∀ x ∈ I, deriv f x = 0) :
∀ {x y}, x ∈ I → y ∈ I → f x = f y
Proposition 4.2.7: For a differentiable real function on a nondegenerate interval, the derivative is nonnegative everywhere exactly when the function is increasing, and nonpositive everywhere exactly when the function is decreasing.
open Set Filter
open scoped Topology
lemma increasingOn_iff_deriv_nonneg {I : Set ℝ} (hI : Set.OrdConnected I)
(hInt : (interior I).Nonempty) {f : ℝ → ℝ} (hdiff : DifferentiableOn ℝ f I) :
(MonotoneOn f I ↔ ∀ x ∈ I, 0 ≤ deriv f x)
open Set Filter
open scoped Topology
lemma decreasingOn_iff_deriv_nonpos {I : Set ℝ} (hI : Set.OrdConnected I)
(hInt : (interior I).Nonempty) {f : ℝ → ℝ} (hdiff : DifferentiableOn ℝ f I) :
(AntitoneOn f I ↔ ∀ x ∈ I, deriv f x ≤ 0)
Proposition 4.2.8: * (i) If I is an interval and f : I → ℝ is differentiable with deriv f x > 0 for every x ∈ I, then f is strictly increasing. * (ii) If I is an interval and f : I → ℝ is differentiable with deriv f x < 0 for every x ∈ I, then f is strictly decreasing.
open Set Filter
open scoped Topology
lemma strictMonoOn_of_deriv_pos' {I : Set ℝ} (hI : Set.OrdConnected I)
{f : ℝ → ℝ} (hdiff : DifferentiableOn ℝ f I)
(hpos : ∀ x ∈ I, 0 < deriv f x) :
StrictMonoOn f I
open Set Filter
open scoped Topology
lemma strictAntiOn_of_deriv_neg' {I : Set ℝ} (hI : Set.OrdConnected I)
{f : ℝ → ℝ} (hdiff : DifferentiableOn ℝ f I)
(hneg : ∀ x ∈ I, deriv f x < 0) :
StrictAntiOn f I
open Set Filter
open scoped Topology
lemma mvt_le_of_deriv_nonpos {f : ℝ → ℝ} {x y : ℝ} (hxy : x < y)
(hcont : ContinuousOn f (Set.Icc x y))
(hdiff : DifferentiableOn ℝ f (Set.Ioo x y))
(hderiv : ∀ z ∈ Set.Ioo x y, deriv f z ≤ 0) :
f y ≤ f x
open Set Filter
open scoped Topology
lemma mvt_ge_of_deriv_nonneg {f : ℝ → ℝ} {x y : ℝ} (hxy : x < y)
(hcont : ContinuousOn f (Set.Icc x y))
(hdiff : DifferentiableOn ℝ f (Set.Ioo x y))
(hderiv : ∀ z ∈ Set.Ioo x y, 0 ≤ deriv f z) :
f x ≤ f y
Proposition 4.2.9: Let f : (a, b) → ℝ be continuous, let c ∈ (a, b), and assume f is differentiable on (a, c) and (c, b). * (i) If deriv f x ≤ 0 for x ∈ (a, c) and deriv f x ≥ 0 for x ∈ (c, b), then f has an absolute minimum at c. * (ii) If deriv f x ≥ 0 for x ∈ (a, c) and deriv f x ≤ 0 for x ∈ (c, b), then f has an absolute maximum at c.
open Set Filter
open scoped Topology
theorem absMinOf_deriv_nonpos_left_nonneg_right
{f : ℝ → ℝ} {a b c : ℝ} (hc : c ∈ Set.Ioo a b)
(hcont : ContinuousOn f (Set.Ioo a b))
(hdiff₁ : DifferentiableOn ℝ f (Set.Ioo a c))
(hdiff₂ : DifferentiableOn ℝ f (Set.Ioo c b))
(hle : ∀ x ∈ Set.Ioo a c, deriv f x ≤ 0)
(hge : ∀ x ∈ Set.Ioo c b, 0 ≤ deriv f x) :
IsMinOn f (Set.Ioo a b) c
open Set Filter
open scoped Topology
theorem absMaxOf_deriv_nonneg_left_nonpos_right
{f : ℝ → ℝ} {a b c : ℝ} (hc : c ∈ Set.Ioo a b)
(hcont : ContinuousOn f (Set.Ioo a b))
(hdiff₁ : DifferentiableOn ℝ f (Set.Ioo a c))
(hdiff₂ : DifferentiableOn ℝ f (Set.Ioo c b))
(hge : ∀ x ∈ Set.Ioo a c, 0 ≤ deriv f x)
(hle : ∀ x ∈ Set.Ioo c b, deriv f x ≤ 0) :
IsMaxOn f (Set.Ioo a b) c
Proposition 4.2.10: * (i) If f : [a, b) → ℝ is continuous, differentiable on (a, b), and lim_{x → a} f' x = L, then f is differentiable at a with deriv f a = L. * (ii) If f : (a, b] → ℝ is continuous, differentiable on (a, b), and lim_{x → b} f' x = L, then f is differentiable at b with deriv f b = L.
open Set Filter
open scoped Topology
theorem deriv_at_left_endpoint_of_tendsto {f : ℝ → ℝ} {a b L : ℝ} (hab : a < b)
(hcont : ContinuousOn f (Set.Icc a b))
(hdiff : DifferentiableOn ℝ f (Set.Ioo a b))
(hlim : Tendsto (fun x => deriv f x) (𝓝[>] a) (𝓝 L)) :
DifferentiableWithinAt ℝ f (Set.Icc a b) a ∧
derivWithin f (Set.Icc a b) a = L
open Set Filter
open scoped Topology
theorem deriv_at_right_endpoint_of_tendsto {f : ℝ → ℝ} {a b L : ℝ} (hab : a < b)
(hcont : ContinuousOn f (Set.Icc a b))
(hdiff : DifferentiableOn ℝ f (Set.Ioo a b))
(hlim : Tendsto (fun x => deriv f x) (𝓝[<] b) (𝓝 L)) :
DifferentiableWithinAt ℝ f (Set.Icc a b) b ∧
derivWithin f (Set.Icc a b) b = L
The derivative within the closed interval at the left endpoint equals the usual derivative when f is differentiable there.
open Set Filter
open scoped Topology
lemma derivWithin_left_eq_deriv {f : ℝ → ℝ} {a b : ℝ}
(hfa : DifferentiableAt ℝ f a) (h₁ : a < b) :
derivWithin f (Set.Icc a b) a = deriv f a
The derivative within the closed interval at the right endpoint equals the usual derivative when f is differentiable there.
open Set Filter
open scoped Topology
lemma derivWithin_right_eq_deriv {f : ℝ → ℝ} {a b : ℝ}
(hfb : DifferentiableAt ℝ f b) (h₁ : a < b) :
derivWithin f (Set.Icc a b) b = deriv f b
Theorem 4.2.11 (Darboux): If f : [a, b] → ℝ is differentiable and y lies strictly between deriv f a and deriv f b, then some c ∈ (a, b) has deriv f c = y.
open Set Filter
open scoped Topology
theorem darboux_deriv
{f : ℝ → ℝ} {a b y : ℝ} (h₁ : a < b)
(hdiff : DifferentiableOn ℝ f (Set.Icc a b))
(ha : DifferentiableAt ℝ f a) (hb : DifferentiableAt ℝ f b)
(hy : (deriv f a < y ∧ y < deriv f b) ∨ (deriv f a > y ∧ y > deriv f b)) :
∃ c ∈ Set.Ioo a b, deriv f c = y
Example 4.2.12: the function x ↦ (x * sin (1/x))^2 is differentiable on ℝ, has derivative 0 at the origin, but its derivative is not continuous there.
open Set Filter
open scoped Topology
noncomputable def oscillatorySquared (x : ℝ) : ℝ :=
(x * Real.sin x⁻¹) ^ 2
open Set Filter
open scoped Topology
lemma oscillatorySquared_abs_le_square (x : ℝ) :
open Set Filter
open scoped Topology
lemma hasDerivAt_oscillatorySquared_zero :
HasDerivAt oscillatorySquared 0 0
open Set Filter
open scoped Topology
lemma hasDerivAt_oscillatorySquared_of_ne_zero {x : ℝ} (hx : x ≠ 0) :
HasDerivAt oscillatorySquared
(2 * Real.sin x⁻¹ *
(x * Real.sin x⁻¹ - Real.cos x⁻¹)) x
open Set Filter
open scoped Topology
lemma differentiable_oscillatorySquared : Differentiable ℝ oscillatorySquared
open Set Filter
open scoped Topology
lemma deriv_oscillatorySquared_of_ne_zero {x : ℝ} (hx : x ≠ 0) :
deriv oscillatorySquared x =
2 * Real.sin x⁻¹ * (x * Real.sin x⁻¹ - Real.cos x⁻¹)
open Set Filter
open scoped Topology
lemma deriv_oscillatorySquared_at_zero : deriv oscillatorySquared 0 = 0
open Set Filter
open scoped Topology
lemma oscillatorySquared_isGlobalMin : IsMinOn oscillatorySquared Set.univ 0
open Set Filter
open scoped Topology
noncomputable def oscSeq₁ (n : ℕ) : ℝ :=
1 / (Real.pi / 4 + (n : ℝ) * (2 * Real.pi))
open Set Filter
open scoped Topology
noncomputable def oscSeq₂ (n : ℕ) : ℝ :=
1 / (3 * Real.pi / 4 + (n : ℝ) * (2 * Real.pi))
open Set Filter
open scoped Topology
lemma oscSeq₁_pos (n : ℕ) : 0 < oscSeq₁ n
open Set Filter
open scoped Topology
lemma oscSeq₂_pos (n : ℕ) : 0 < oscSeq₂ n
open Set Filter
open scoped Topology
lemma tendsto_nat_mul_add_const_atTop {a b : ℝ} (ha : 0 < a) :
Tendsto (fun n : ℕ => (n : ℝ) * a + b) atTop atTop
open Set Filter
open scoped Topology
lemma oscSeq₁_tendsto_zero :
Tendsto oscSeq₁ atTop (𝓝 (0 : ℝ))
open Set Filter
open scoped Topology
lemma oscSeq₂_tendsto_zero :
Tendsto oscSeq₂ atTop (𝓝 (0 : ℝ))
open Set Filter
open scoped Topology
lemma sin_inv_oscSeq₁ (n : ℕ) :
Real.sin (oscSeq₁ n)⁻¹ = Real.sqrt 2 / 2
open Set Filter
open scoped Topology
lemma cos_inv_oscSeq₁ (n : ℕ) :
Real.cos (oscSeq₁ n)⁻¹ = Real.sqrt 2 / 2
open Set Filter
open scoped Topology
lemma sin_inv_oscSeq₂ (n : ℕ) :
Real.sin (oscSeq₂ n)⁻¹ = Real.sqrt 2 / 2
open Set Filter
open scoped Topology
lemma cos_inv_oscSeq₂ (n : ℕ) :
Real.cos (oscSeq₂ n)⁻¹ = -Real.sin (oscSeq₂ n)⁻¹
open Set Filter
open scoped Topology
lemma deriv_oscillatorySquared_oscSeq₁ (n : ℕ) :
deriv oscillatorySquared (oscSeq₁ n) = oscSeq₁ n - 1
open Set Filter
open scoped Topology
lemma deriv_oscillatorySquared_oscSeq₂ (n : ℕ) :
deriv oscillatorySquared (oscSeq₂ n) = oscSeq₂ n + 1
open Set Filter
open scoped Topology
lemma deriv_oscillatorySquared_not_continuous_at_zero :
¬ ContinuousAt (fun x => deriv oscillatorySquared x) 0
open Set Filter
open scoped Topology
lemma deriv_oscillatorySquared_sign_changes :
∀ ε > 0, ∃ x₁ x₂,
x₁ ∈ Set.Ioo (-ε) ε ∧ x₂ ∈ Set.Ioo (-ε) ε ∧
deriv oscillatorySquared x₁ < 0 ∧ deriv oscillatorySquared x₂ > 0
open Set Filter
open scoped Topology
lemma oscSeq₁_ne_zero (n : ℕ) : oscSeq₁ n ≠ 0
open Set Filter
open scoped Topology
lemma oscSeq₂_ne_zero (n : ℕ) : oscSeq₂ n ≠ 04.3 — Taylor's Theorem
Lean authors: Zichen Wang, Zaiwen Wen.
Definition 4.3.1: For an n-times differentiable function f near x0 ∈ ℝ, the nth-order Taylor polynomial at x0 is P_n^{x0}(x) = ∑_{k=0}^n f^(k)(x0) / k! * (x - x0)^k.
open Set SignType
noncomputable def taylorPolynomial (f : ℝ → ℝ) (x0 : ℝ) (n : ℕ) :
Polynomial ℝ :=
Finset.sum (Finset.range (n + 1)) fun k =>
Polynomial.C ((iteratedDeriv k f x0) / (Nat.factorial k)) *
(Polynomial.X - Polynomial.C x0) ^ k
On an interior point of Icc x₀ x, within-iterated derivatives agree with ordinary ones.
open Set SignType
lemma iteratedDerivWithin_eq_iteratedDeriv_Icc {f : ℝ → ℝ} {x0 x c : ℝ} {k n : ℕ}
(hx0x : x0 < x) (hc : c ∈ Set.Ioo x0 x)
(hcont : ContDiffOn ℝ (n + 1) f (Set.Icc x0 x)) (hk : k ≤ n + 1) :
iteratedDerivWithin k f (Set.Icc x0 x) c = iteratedDeriv k f c
Identify taylorWithinEval on an interval with the explicit Taylor polynomial.
open Set SignType
lemma taylorWithinEval_eq_taylorPolynomial {f : ℝ → ℝ} {x0 x : ℝ} {n : ℕ}
(hx0x : x0 < x) (hcontAt : ContDiffAt ℝ (n + 1) f x0) :
taylorWithinEval f n (Set.Icc x0 x) x0 x =
(taylorPolynomial f x0 n).eval x
Taylor's theorem on a positively oriented interval.
open Set SignType
lemma taylor_with_remainder_pos {f : ℝ → ℝ} {x0 x : ℝ} {n : ℕ}
(hx0x : x0 < x) (hcont : ContDiffOn ℝ (n + 1) f (Set.Icc x0 x))
(hcontAt : ContDiffAt ℝ (n + 1) f x0) :
∃ c ∈ Set.Icc x0 x,
f x =
(taylorPolynomial f x0 n).eval x +
(iteratedDeriv (n + 1) f c) / (Nat.factorial (n + 1)) *
(x - x0) ^ (n + 1)
Taylor's theorem on a negatively oriented interval, obtained by reflection.
open Set SignType
lemma taylor_with_remainder_neg {f : ℝ → ℝ} {x0 x : ℝ} {n : ℕ}
(hx0x : x < x0) (hcont : ContDiffOn ℝ (n + 1) f (Set.Icc x x0))
(hcontAt : ContDiffAt ℝ (n + 1) f x0) :
∃ c ∈ Set.Icc x x0,
f x =
(taylorPolynomial f x0 n).eval x +
(iteratedDeriv (n + 1) f c) / (Nat.factorial (n + 1)) *
(x - x0) ^ (n + 1)
Theorem 4.3.2 (Taylor): If f : ℝ → ℝ has n continuous derivatives on [a, b] and the (n+1)st derivative exists on (a, b), then for distinct points x₀, x ∈ [a, b] there is a point c between them such that f x = Pₙ^{x₀}(x) + f^{(n+1)}(c) / (n+1)! * (x - x₀)^{n+1}.
open Set SignType
theorem taylor_with_remainder {f : ℝ → ℝ} {a b x0 x : ℝ} {n : ℕ}
(hx0 : x0 ∈ Set.Ioo a b) (hx : x ∈ Set.Icc a b) (hx0x : x0 ≠ x)
(hcont : ContDiffOn ℝ (n + 1) f (Set.Icc a b)) :
∃ c ∈ Set.Icc (min x0 x) (max x0 x),
f x =
(taylorPolynomial f x0 n).eval x +
(iteratedDeriv (n + 1) f c) / (Nat.factorial (n + 1)) *
(x - x0) ^ (n + 1)
If y lies between x and x₀, then the distance from y to x₀ is bounded by the distance from x to x₀.
open Set SignType
lemma abs_sub_le_of_mem_interval {x x0 y : ℝ}
(hy : y ∈ Set.Icc (min x x0) (max x x0)) : |y - x0| ≤ |x - x0|
Points sufficiently close to x₀ stay inside (a, b), and the whole interval between them and x₀ also lies in (a, b).
open Set SignType
lemma interval_subset_Ioo_of_abs_sub_lt {a b x0 x : ℝ}
(hx0 : x0 ∈ Set.Ioo a b)
(hx : |x - x0| < min (x0 - a) (b - x0)) :
Set.Icc (min x x0) (max x x0) ⊆ Set.Ioo a b
Proposition 4.3.3 (Second derivative test). If f : (a, b) → ℝ is twice continuously differentiable, x0 ∈ (a, b), f' x0 = 0, and f'' x0 > 0, then x0 is a strict relative minimum of f.
open Set SignType
theorem second_derivative_test {f : ℝ → ℝ} {a b x0 : ℝ}
(hx0 : x0 ∈ Set.Ioo a b) (hcont : ContDiffOn ℝ 2 f (Set.Ioo a b))
(hderiv_zero : deriv f x0 = 0) (hpos : deriv (deriv f) x0 > 0) :
∃ ε > 0, ∀ {x}, x ∈ Set.Ioo a b → x ≠ x0 → |x - x0| < ε → f x0 < f x4.4 — Inverse Function Theorem
Lean authors: Zichen Wang, Zaiwen Wen.
Lemma 4.4.1: If I, J ⊆ ℝ are intervals and f : ℝ → ℝ is strictly monotone on I, maps I onto J, is differentiable at x₀ ∈ I, and f' x₀ ≠ 0, then the inverse satisfies (f ⁻¹)' (f x₀) = 1 / f' x₀. If moreover f is continuously differentiable with derivative never zero on I, then the inverse is continuously differentiable on J.
open scoped Topology
lemma inverse_derivative_at {I J : Set ℝ} {f : ℝ → ℝ} {x0 f'x0 : ℝ}
(hI : Set.OrdConnected I) (hJ : Set.OrdConnected J)
(hmono : StrictMonoOn f I) (hmap : Set.MapsTo f I J) (hsurj : Set.SurjOn f I J)
(hx0 : x0 ∈ I)
(hdiff : HasDerivWithinAt f f'x0 I x0) (hzero : f'x0 ≠ 0) :
HasDerivWithinAt (fun y => Function.invFunOn f I y) (f'x0)⁻¹ J (f x0)
Lemma 4.4.1 (smoothness of the inverse): If f : ℝ → ℝ is continuously C¹, strictly monotone on an interval I, maps I onto another interval J, and derivWithin f I x ≠ 0 for every x ∈ I, then the inverse function is continuously differentiable on J.
open scoped Topology
lemma inverse_contDiff_on {I J : Set ℝ} {f : ℝ → ℝ} (hI : Set.OrdConnected I)
(hJ : Set.OrdConnected J) (hmono : StrictMonoOn f I) (hmap : Set.MapsTo f I J)
(hsurj : Set.SurjOn f I J) (hcont : ContDiffOn ℝ 1 f I)
(hzero : ∀ x ∈ I, derivWithin f I x ≠ 0) :
ContDiffOn ℝ 1 (fun y => Function.invFunOn f I y) J
If x₀ ∈ (a, b) then there is a small open interval around x₀ contained in (a, b).
open scoped Topology
lemma exists_Ioo_subset_of_mem {a b x₀ : ℝ} (hx₀ : x₀ ∈ Set.Ioo a b) :
∃ δ > 0, Set.Ioo (x₀ - δ) (x₀ + δ) ⊆ Set.Ioo a b
Theorem 4.4.2 (inverse function theorem). Given a continuously C¹ function f : ℝ → ℝ on (a, b) with derivWithin f (Set.Ioo a b) x₀ ≠ 0 at some x₀ ∈ (a, b), there exists an open interval I ⊆ (a, b) containing x₀ such that f restricts to an injective map on I with a continuously differentiable inverse g : J → I on J = f '' I, and for every y ∈ J we have derivWithin g J y = (derivWithin f (Set.Ioo a b) (g y))⁻¹.
open scoped Topology
theorem inverse_function_open_interval {a b x0 : ℝ} (f : ℝ → ℝ)
(hx0 : x0 ∈ Set.Ioo a b) (hcont : ContDiffOn ℝ 1 f (Set.Ioo a b))
(hderiv : derivWithin f (Set.Ioo a b) x0 ≠ 0) :
∃ I J : Set ℝ, IsOpen I ∧ x0 ∈ I ∧ I ⊆ Set.Ioo a b ∧ J = f '' I ∧
Set.InjOn f I ∧ Set.SurjOn f I J ∧
∃ g : ℝ → ℝ, Set.MapsTo g J I ∧ Set.SurjOn g J I ∧
(∀ x ∈ I, g (f x) = x) ∧ (∀ y ∈ J, f (g y) = y) ∧
ContDiffOn ℝ 1 g J ∧ ∀ y ∈ J, derivWithin g J y =
(derivWithin f (Set.Ioo a b) (g y))⁻¹
Corollary 4.4.3: For n ∈ ℕ and x ≥ 0 there is a unique y ≥ 0 with y ^ n = x. The function g x = x^{1/n} on (0, ∞) is continuously differentiable with derivative g' x = (1 / n) * x ^ ((1 - n) / n), where fractional powers use the convention x ^ (m / n) = (x ^ (1 / n)) ^ m.
open scoped Topology
theorem nth_root_exists_unique_and_deriv (n : ℕ) (hn : 0 < n) (x : ℝ)
(hx : 0 ≤ x) :
(∃! y : ℝ, 0 ≤ y ∧ y ^ n = x) ∧
∃ g : ℝ → ℝ, g = (fun t => t ^ (1 / (n : ℝ))) ∧
ContDiffOn ℝ 1 g (Set.Ioi 0) ∧
∀ t ∈ Set.Ioi (0 : ℝ),
derivWithin g (Set.Ioi 0) t =
(1 / (n : ℝ)) * t ^ (((1 : ℝ) - (n : ℝ)) / (n : ℝ))
Example 4.4.4: For f x = x^2, the derivative at x₀ ≠ 0 is nonzero. At a positive point x₀, the inverse function theorem applies on the maximal open interval (0, ∞) where f is injective; any open set on which f is injective and contains x₀ must lie in (0, ∞).
open scoped Topology
theorem inverse_function_example_square {x0 : ℝ} (hx0 : 0 < x0) :
derivWithin (fun x : ℝ => x ^ 2) (Set.Ioi 0) x0 ≠ 0 ∧
Set.InjOn (fun x : ℝ => x ^ 2) (Set.Ioi 0) ∧
(∀ I : Set ℝ, IsOpen I → Set.OrdConnected I → x0 ∈ I →
Set.InjOn (fun x : ℝ => x ^ 2) I → I ⊆ Set.Ioi 0)
Example 4.4.5: The cubic f x = x^3 : ℝ → ℝ is bijective with a continuous derivative, so it has a set-theoretic inverse g y = y^{1/3} on all of ℝ. Nevertheless the inverse fails to be differentiable at 0 because f' 0 = 0, and the graph of the cube root has a vertical tangent at the origin.
open scoped Topology
theorem cube_inverse_not_differentiable_at_zero :
ContDiff ℝ 1 (fun x : ℝ => x ^ 3) ∧
StrictMono (fun x : ℝ => x ^ 3) ∧ Function.Surjective (fun x : ℝ => x ^ 3) ∧
deriv (fun x : ℝ => x ^ 3) 0 = 0 ∧
∃ g : ℝ → ℝ, Function.LeftInverse g (fun x : ℝ => x ^ 3) ∧
Function.RightInverse g (fun x : ℝ => x ^ 3) ∧
¬ DifferentiableAt ℝ g 0