Imports
import Mathlib.Tactic import Mathlib.Analysis.Calculus.Deriv.Basic

Analysis I, Section 10.1: Basic definitions

I have attempted to make the translation as faithful a paraphrasing as possible of the original text. When there is a choice between a more idiomatic Lean solution and a more faithful translation, I have generally chosen the latter. In particular, there will be places where the Lean code could be "golfed" to be more elegant and idiomatic, but I have consciously avoided doing so.

Main constructions and results of this section:

  • API for Mathlib's HasDerivWithinAt, derivWithin, and DifferentiableWithinAt.

Note that the Mathlib conventions differ slightly from that in the text, in that differentiability is defined even at points that are not limit points of the domain; derivatives in such cases may not be unique, but derivWithin still selects one such derivative in such cases (or 0, if no derivative exists).

namespace Chapter10variable (x₀ : )

Definition 10.1.1 (Differentiability at a point). For the Mathlib notion HasDerivWithinAt, the hypothesis that x₀ is a limit point is not needed.

theorem _root_.HasDerivWithinAt.iff (X: Set ) (x₀ : ) (f: ) (L:) : HasDerivWithinAt f L X x₀ (nhdsWithin x₀ (X \ {x₀})).Tendsto (fun x (f x - f x₀) / (x - x₀)) (nhds L) := X:Set x₀:f: L:HasDerivWithinAt f L X x₀ Filter.Tendsto (fun x (f x - f x₀) / (x - x₀)) (nhdsWithin x₀ (X \ {x₀})) (nhds L) All goals completed! 🐙
theorem _root_.DifferentiableWithinAt.iff (X: Set ) (x₀ : ) (f: ) : DifferentiableWithinAt f X x₀ L, HasDerivWithinAt f L X x₀ := X:Set x₀:f: DifferentiableWithinAt f X x₀ L, HasDerivWithinAt f L X x₀ X:Set x₀:f: DifferentiableWithinAt f X x₀ L, HasDerivWithinAt f L X x₀X:Set x₀:f: (∃ L, HasDerivWithinAt f L X x₀) DifferentiableWithinAt f X x₀ X:Set x₀:f: DifferentiableWithinAt f X x₀ L, HasDerivWithinAt f L X x₀ X:Set x₀:f: h:DifferentiableWithinAt f X x₀ L, HasDerivWithinAt f L X x₀; X:Set x₀:f: h:DifferentiableWithinAt f X x₀HasDerivWithinAt f (derivWithin f X x₀) X x₀; All goals completed! 🐙 X:Set x₀:f: L:h:HasDerivWithinAt f L X x₀DifferentiableWithinAt f X x₀; All goals completed! 🐙theorem _root_.DifferentiableWithinAt.of_hasDeriv {X: Set } {x₀ : } {f: } {L:} (hL: HasDerivWithinAt f L X x₀) : DifferentiableWithinAt f X x₀ := X:Set x₀:f: L:hL:HasDerivWithinAt f L X x₀DifferentiableWithinAt f X x₀ X:Set x₀:f: L:hL:HasDerivWithinAt f L X x₀ L, HasDerivWithinAt f L X x₀; All goals completed! 🐙theorem derivative_unique {X: Set } {x₀ : } (hx₀: ClusterPt x₀ (.principal (X \ {x₀}))) {f: } {L L':} (hL: HasDerivWithinAt f L X x₀) (hL': HasDerivWithinAt f L' X x₀) : L = L' := X:Set x₀:hx₀:ClusterPt x₀ (Filter.principal (X \ {x₀}))f: L:L':hL:HasDerivWithinAt f L X x₀hL':HasDerivWithinAt f L' X x₀L = L' X:Set x₀:hx₀:ClusterPt x₀ (Filter.principal (X \ {x₀}))f: L:L':hL:Filter.Tendsto (fun x (f x - f x₀) / (x - x₀)) (nhdsWithin x₀ (X \ {x₀})) (nhds L)hL':Filter.Tendsto (fun x (f x - f x₀) / (x - x₀)) (nhdsWithin x₀ (X \ {x₀})) (nhds L')L = L' X:Set x₀:hx₀:(nhds x₀ Filter.principal (X \ {x₀})).NeBotf: L:L':hL:Filter.Tendsto (fun x (f x - f x₀) / (x - x₀)) (nhdsWithin x₀ (X \ {x₀})) (nhds L)hL':Filter.Tendsto (fun x (f x - f x₀) / (x - x₀)) (nhdsWithin x₀ (X \ {x₀})) (nhds L')L = L' All goals completed! 🐙DifferentiableWithinAt.hasDerivWithinAt.{u, v} {𝕜 : Type u} [NontriviallyNormedField 𝕜] {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {f : 𝕜 F} {x : 𝕜} {s : Set 𝕜} (h : DifferentiableWithinAt 𝕜 f s x) : HasDerivWithinAt f (derivWithin f s x) s x#check DifferentiableWithinAt.hasDerivWithinAt
DifferentiableWithinAt.hasDerivWithinAt.{u, v} {𝕜 : Type u} [NontriviallyNormedField 𝕜] {F : Type v}
  [NormedAddCommGroup F] [NormedSpace 𝕜 F] {f : 𝕜  F} {x : 𝕜} {s : Set 𝕜} (h : DifferentiableWithinAt 𝕜 f s x) :
  HasDerivWithinAt f (derivWithin f s x) s x
theorem derivative_unique' (X: Set ) {x₀ : } (hx₀: ClusterPt x₀ (.principal (X \ {x₀}))) {f: } {L :} (hL: HasDerivWithinAt f L X x₀) (hdiff : DifferentiableWithinAt f X x₀): L = derivWithin f X x₀ := X:Set x₀:hx₀:ClusterPt x₀ (Filter.principal (X \ {x₀}))f: L:hL:HasDerivWithinAt f L X x₀hdiff:DifferentiableWithinAt f X x₀L = derivWithin f X x₀ All goals completed! 🐙/-- Example 10.1.3 -/ declaration uses `sorry`example (x₀:) : HasDerivWithinAt (fun x x^2) (2 * x₀) .univ x₀ := x₀✝:x₀:HasDerivWithinAt (fun x x ^ 2) (2 * x₀) Set.univ x₀ All goals completed! 🐙declaration uses `sorry`example (x₀:) : DifferentiableWithinAt (fun x x^2) .univ x₀ := x₀✝:x₀:DifferentiableWithinAt (fun x x ^ 2) Set.univ x₀ All goals completed! 🐙declaration uses `sorry`example (x₀:) : derivWithin (fun x x^2) .univ x₀ = 2 * x₀ := x₀✝:x₀:derivWithin (fun x x ^ 2) Set.univ x₀ = 2 * x₀ All goals completed! 🐙/-- Remark 10.1.4 -/ example (X: Set ) (x₀ : ) {f g: } (hfg: f = g): DifferentiableWithinAt f X x₀ DifferentiableWithinAt g X x₀ := x₀✝:X:Set x₀:f: g: hfg:f = gDifferentiableWithinAt f X x₀ DifferentiableWithinAt g X x₀ All goals completed! 🐙example (X: Set ) (x₀ : ) {f g: } (L:) (hfg: f = g): HasDerivWithinAt f L X x₀ HasDerivWithinAt g L X x₀ := x₀✝:X:Set x₀:f: g: L:hfg:f = gHasDerivWithinAt f L X x₀ HasDerivWithinAt g L X x₀ All goals completed! 🐙declaration uses `sorry`example : (X: Set ) (x₀ :) (f g: ) (L:) (hfg: f x₀ = g x₀), HasDerivWithinAt f L X x₀ ¬ HasDerivWithinAt g L X x₀ := x₀: X x₀ f g L, (_ : f x₀ = g x₀), HasDerivWithinAt f L X x₀ ¬HasDerivWithinAt g L X x₀ All goals completed! 🐙

Example 10.1.6

abbrev f_10_1_6 : := abs
declaration uses `sorry`example : (nhdsWithin 0 (.Ioi 0)).Tendsto (fun x (f_10_1_6 x - f_10_1_6 0) / (x - 0)) (nhds 1) := x₀:Filter.Tendsto (fun x (f_10_1_6 x - f_10_1_6 0) / (x - 0)) (nhdsWithin 0 (Set.Ioi 0)) (nhds 1) All goals completed! 🐙declaration uses `sorry`example : (nhdsWithin 0 (.Iio 0)).Tendsto (fun x (f_10_1_6 x - f_10_1_6 0) / (x - 0)) (nhds (-1)) := x₀:Filter.Tendsto (fun x (f_10_1_6 x - f_10_1_6 0) / (x - 0)) (nhdsWithin 0 (Set.Iio 0)) (nhds (-1)) All goals completed! 🐙declaration uses `sorry`example : ¬ L, (nhdsWithin 0 (.univ \ {0})).Tendsto (fun x (f_10_1_6 x - f_10_1_6 0) / (x - 0)) (nhds L) := x₀:¬ L, Filter.Tendsto (fun x (f_10_1_6 x - f_10_1_6 0) / (x - 0)) (nhdsWithin 0 (Set.univ \ {0})) (nhds L) All goals completed! 🐙declaration uses `sorry`example : ¬ DifferentiableWithinAt f_10_1_6 (.univ) 0 := x₀:¬DifferentiableWithinAt f_10_1_6 Set.univ 0 All goals completed! 🐙declaration uses `sorry`example : DifferentiableWithinAt f_10_1_6 (.Ioi 0) 0 := x₀:DifferentiableWithinAt f_10_1_6 (Set.Ioi 0) 0 All goals completed! 🐙declaration uses `sorry`example : derivWithin f_10_1_6 (.Ioi 0) 0 = 1 := x₀:derivWithin f_10_1_6 (Set.Ioi 0) 0 = 1 All goals completed! 🐙declaration uses `sorry`example : DifferentiableWithinAt f_10_1_6 (.Iio 0) 0 := x₀:DifferentiableWithinAt f_10_1_6 (Set.Iio 0) 0 All goals completed! 🐙declaration uses `sorry`example : derivWithin f_10_1_6 (.Iio 0) 0 = -1 := x₀:derivWithin f_10_1_6 (Set.Iio 0) 0 = -1 All goals completed! 🐙

Proposition 10.1.7 (Newton's approximation) / Exercise 10.1.2

theorem declaration uses `sorry`_root_.HasDerivWithinAt.iff_approx_linear (X: Set ) (x₀ :) (f: ) (L:) : HasDerivWithinAt f L X x₀ ε > 0, δ > 0, x X, |x - x₀| < δ |f x - f x₀ - L * (x - x₀)| ε * |x - x₀| := X:Set x₀:f: L:HasDerivWithinAt f L X x₀ ε > 0, δ > 0, x X, |x - x₀| < δ |f x - f x₀ - L * (x - x₀)| ε * |x - x₀| All goals completed! 🐙

Proposition 10.1.10 / Exercise 10.1.3

theorem declaration uses `sorry`_root_.ContinuousWithinAt.of_differentiableWithinAt {X: Set } {x₀ : } {f: } (h: DifferentiableWithinAt f X x₀) : ContinuousWithinAt f X x₀ := X:Set x₀:f: h:DifferentiableWithinAt f X x₀ContinuousWithinAt f X x₀ All goals completed! 🐙
/-Definition 10.1.11 (Differentiability on a domain)-/ DifferentiableOn.eq_1.{u_1, u_2, u_3} (𝕜 : Type u_1) [NontriviallyNormedField 𝕜] {E : Type u_2} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] {F : Type u_3} [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] (f : E F) (s : Set E) : DifferentiableOn 𝕜 f s = x s, DifferentiableWithinAt 𝕜 f s x#check DifferentiableOn.eq_1

Corollary 10.1.12

theorem _root_.ContinuousOn.of_differentiableOn {X: Set } {f: } (h: DifferentiableOn f X) : ContinuousOn f X := X:Set f: h:DifferentiableOn f XContinuousOn f X All goals completed! 🐙

Theorem 10.1.13 (a) (Differential calculus) / Exercise 10.1.4

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_const (X: Set ) (x₀ : ) (c:) : HasDerivWithinAt (fun x c) 0 X x₀ := X:Set x₀:c:HasDerivWithinAt (fun x c) 0 X x₀ All goals completed! 🐙

Theorem 10.1.13 (b) (Differential calculus) / Exercise 10.1.4

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_id (X: Set ) (x₀ : ) : HasDerivWithinAt (fun x x) 1 X x₀ := X:Set x₀:HasDerivWithinAt (fun x x) 1 X x₀ All goals completed! 🐙

Theorem 10.1.13 (c) (Sum rule) / Exercise 10.1.4

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_add {X: Set } {x₀ f'x₀ g'x₀: } {f g: } (hf: HasDerivWithinAt f f'x₀ X x₀) (hg: HasDerivWithinAt g g'x₀ X x₀) : HasDerivWithinAt (f + g) (f'x₀ + g'x₀) X x₀ := X:Set x₀:f'x₀:g'x₀:f: g: hf:HasDerivWithinAt f f'x₀ X x₀hg:HasDerivWithinAt g g'x₀ X x₀HasDerivWithinAt (f + g) (f'x₀ + g'x₀) X x₀ All goals completed! 🐙

Theorem 10.1.13 (d) (Product rule) / Exercise 10.1.4

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_mul {X: Set } {x₀ f'x₀ g'x₀: } {f g: } (hf: HasDerivWithinAt f f'x₀ X x₀) (hg: HasDerivWithinAt g g'x₀ X x₀) : HasDerivWithinAt (f * g) (f'x₀ * (g x₀) + (f x₀) * g'x₀) X x₀ := X:Set x₀:f'x₀:g'x₀:f: g: hf:HasDerivWithinAt f f'x₀ X x₀hg:HasDerivWithinAt g g'x₀ X x₀HasDerivWithinAt (f * g) (f'x₀ * g x₀ + f x₀ * g'x₀) X x₀ All goals completed! 🐙

Theorem 10.1.13 (e) (Differential calculus) / Exercise 10.1.4

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_smul {X: Set } {x₀ f'x₀: } (c:) {f: } (hf: HasDerivWithinAt f f'x₀ X x₀) : HasDerivWithinAt (c f) (c * f'x₀) X x₀ := X:Set x₀:f'x₀:c:f: hf:HasDerivWithinAt f f'x₀ X x₀HasDerivWithinAt (c f) (c * f'x₀) X x₀ All goals completed! 🐙

Theorem 10.1.13 (f) (Difference rule) / Exercise 10.1.4

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_sub {X: Set } {x₀ f'x₀ g'x₀: } {f g: } (hf: HasDerivWithinAt f f'x₀ X x₀) (hg: HasDerivWithinAt g g'x₀ X x₀) : HasDerivWithinAt (f - g) (f'x₀ - g'x₀) X x₀ := X:Set x₀:f'x₀:g'x₀:f: g: hf:HasDerivWithinAt f f'x₀ X x₀hg:HasDerivWithinAt g g'x₀ X x₀HasDerivWithinAt (f - g) (f'x₀ - g'x₀) X x₀ All goals completed! 🐙

Theorem 10.1.13 (g) (Differential calculus) / Exercise 10.1.4

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_inv {X: Set } {x₀ g'x₀: } {g: } (hgx₀ : g x₀ 0) (hg: HasDerivWithinAt g g'x₀ X x₀) : HasDerivWithinAt (1/g) (-g'x₀ / (g x₀)^2) X x₀ := X:Set x₀:g'x₀:g: hgx₀:g x₀ 0hg:HasDerivWithinAt g g'x₀ X x₀HasDerivWithinAt (1 / g) (-g'x₀ / g x₀ ^ 2) X x₀ All goals completed! 🐙

Theorem 10.1.13 (h) (Quotient rule) / Exercise 10.1.4

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_div {X: Set } {x₀ f'x₀ g'x₀: } {f g: } (hgx₀ : g x₀ 0) (hf: HasDerivWithinAt f f'x₀ X x₀) (hg: HasDerivWithinAt g g'x₀ X x₀) : HasDerivWithinAt (f / g) ((f'x₀ * (g x₀) - (f x₀) * g'x₀) / (g x₀)^2) X x₀ := X:Set x₀:f'x₀:g'x₀:f: g: hgx₀:g x₀ 0hf:HasDerivWithinAt f f'x₀ X x₀hg:HasDerivWithinAt g g'x₀ X x₀HasDerivWithinAt (f / g) ((f'x₀ * g x₀ - f x₀ * g'x₀) / g x₀ ^ 2) X x₀ All goals completed! 🐙
declaration uses `sorry`example (x₀:) (hx₀: x₀ 1): HasDerivWithinAt (fun x (x-2)/(x-1)) (1 /(x₀-1)^2) (.univ \ {1}) x₀ := x₀✝:x₀:hx₀:x₀ 1HasDerivWithinAt (fun x (x - 2) / (x - 1)) (1 / (x₀ - 1) ^ 2) (Set.univ \ {1}) x₀ All goals completed! 🐙

Theorem 10.1.15 (Chain rule) / Exercise 10.1.7

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_comp {X Y: Set } {x₀ y₀ f'x₀ g'y₀: } {f g: } (hfx₀: f x₀ = y₀) (hfX : x X, f x Y) (hf: HasDerivWithinAt f f'x₀ X x₀) (hg: HasDerivWithinAt g g'y₀ Y y₀) : HasDerivWithinAt (g f) (g'y₀ * f'x₀) X x₀ := X:Set Y:Set x₀:y₀:f'x₀:g'y₀:f: g: hfx₀:f x₀ = y₀hfX: x X, f x Yhf:HasDerivWithinAt f f'x₀ X x₀hg:HasDerivWithinAt g g'y₀ Y y₀HasDerivWithinAt (g f) (g'y₀ * f'x₀) X x₀ All goals completed! 🐙

Exercise 10.1.5

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_pow (n:) (x₀:) : HasDerivWithinAt (fun x x^n) (n * x₀^((n:)-1)) .univ x₀ := n:x₀:HasDerivWithinAt (fun x x ^ n) (n * x₀ ^ (n - 1)) Set.univ x₀ All goals completed! 🐙

Exercise 10.1.6

theorem declaration uses `sorry`_root_.HasDerivWithinAt.of_zpow (n:) (x₀:) (hx₀: x₀ 0) : HasDerivWithinAt (fun x x^n) (n * x₀^(n-1)) (.univ \ {0}) x₀ := n:x₀:hx₀:x₀ 0HasDerivWithinAt (fun x x ^ n) (n * x₀ ^ (n - 1)) (Set.univ \ {0}) x₀ All goals completed! 🐙
end Chapter10