|
| 1 | +/- |
| 2 | +Copyright (c) 2025 Moritz Doll. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Moritz Doll |
| 5 | +-/ |
| 6 | +module |
| 7 | + |
| 8 | +public import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts |
| 9 | +public import Mathlib.Analysis.Calculus.ContDiff.Basic |
| 10 | +public import Mathlib.Analysis.Calculus.Deriv.Pow |
| 11 | +public import Mathlib.Analysis.Calculus.IteratedDeriv.Defs |
| 12 | + |
| 13 | +/-! |
| 14 | +# Taylor's formula with an integral remainder in higher dimensions |
| 15 | +
|
| 16 | +In this file we prove Taylor's formula with the remainder term in integral form. |
| 17 | +
|
| 18 | +* `map_add_eq_sum_add_integral_iteratedFDeriv`: version for higher dimensions with `iteratedFDeriv` |
| 19 | +
|
| 20 | +TODO: add a version that assumes `ContDiffOn f (closedBall x (‖y‖))` |
| 21 | +
|
| 22 | +-/ |
| 23 | + |
| 24 | +@[expose] public section |
| 25 | + |
| 26 | +open Nat |
| 27 | + |
| 28 | +variable {𝕜 E F : Type*} |
| 29 | +variable [NormedAddCommGroup E] [NormedAddCommGroup F] |
| 30 | + |
| 31 | +section NontriviallyNormedField |
| 32 | + |
| 33 | +variable [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] |
| 34 | + |
| 35 | +variable {f : E → F} {x y : E} {t : 𝕜} {n : ℕ} |
| 36 | + |
| 37 | +theorem DifferentiableAt.deriv_comp_add_smul (hf : DifferentiableAt 𝕜 f (x + t • y)) : |
| 38 | + deriv (fun (s : 𝕜) ↦ f (x + s • y)) t = fderiv 𝕜 f (x + t • y) y := by |
| 39 | + have hg : Differentiable 𝕜 (fun (s : 𝕜) ↦ (x + s • y)) := by fun_prop |
| 40 | + convert fderiv_comp_deriv t hf hg.differentiableAt |
| 41 | + · simp |
| 42 | + · simpa using (deriv_smul_const (x := t) differentiableAt_id y).symm |
| 43 | + |
| 44 | +theorem ContDiffAt.deriv_fderiv_add_smul (hf : ContDiffAt 𝕜 (n + 1) f (x + t • y)) : |
| 45 | + deriv (fun (s : 𝕜) ↦ iteratedFDeriv 𝕜 n f (x + s • y) (fun _ ↦ y)) t = |
| 46 | + iteratedFDeriv 𝕜 (n + 1) f (x + t • y) (fun _ ↦ y) := by |
| 47 | + have hf' : DifferentiableAt 𝕜 (iteratedFDeriv 𝕜 n f) (x + t • y) := by |
| 48 | + apply hf.differentiableAt_iteratedFDeriv |
| 49 | + norm_cast |
| 50 | + exact lt_add_one n |
| 51 | + convert (hf'.continuousMultilinear_apply_const _).deriv_comp_add_smul |
| 52 | + exact hf'.iteratedFDeriv_succ_apply_left' |
| 53 | + |
| 54 | +end NontriviallyNormedField |
| 55 | + |
| 56 | +variable [NormedSpace ℝ E] [NormedSpace ℝ F] |
| 57 | + |
| 58 | +variable {f : E → F} {x y : E} {n : ℕ} |
| 59 | + |
| 60 | +variable [CompleteSpace F] |
| 61 | + |
| 62 | +/-- *Taylor's theorem with remainder in integral form*. If `f` is `n + 1` times continuously |
| 63 | +differentiable, then `f (x + y)` is given by |
| 64 | +`∑ k in 0..n, D^k f(x; y,..,y) / k! + 1/n! ∫ t in 0..1, (1 - t) ^ n • D^{n+1}f (x + t • y; y,..,y)`, |
| 65 | +where `D^k f` denotes the iterated derivative of `f`. |
| 66 | +
|
| 67 | +In the case that `n = 1`, this is a reformulation of the fundamental theorem of calculus, namely |
| 68 | +`f (x + y) = f x + ∫ t in 0..1, D f(x + t • y; y)`. -/ |
| 69 | +theorem map_add_eq_sum_add_integral_iteratedFDeriv (hf : ∀ (t : ℝ) (_ht : t ∈ Set.Icc 0 1), |
| 70 | + ContDiffAt ℝ (n + 1) f (x + t • y)) : |
| 71 | + f (x + y) = ∑ k ∈ Finset.range (n + 1), (k ! : ℝ)⁻¹ • (iteratedFDeriv ℝ k f x (fun _ ↦ y)) + |
| 72 | + (n ! : ℝ)⁻¹ • ∫ t in 0..1, (1 - t)^n • iteratedFDeriv ℝ (n + 1) f (x + t • y) (fun _ ↦ y) := by |
| 73 | + simp_rw [← Set.uIcc_of_le zero_le_one] at hf |
| 74 | + induction n with |
| 75 | + | zero => |
| 76 | + -- The base case follows from the fundamental theorem of calculus |
| 77 | + have h_eq : Set.EqOn (fun t ↦ (fderiv ℝ f (x + t • y)) y) (deriv fun (s : ℝ) ↦ f (x + s • y)) |
| 78 | + (Set.uIcc 0 1) := by |
| 79 | + intro t ht |
| 80 | + rw [DifferentiableAt.deriv_comp_add_smul] |
| 81 | + exact (hf t ht).differentiableAt (by simp) |
| 82 | + simp only [zero_add, Finset.range_one, Finset.sum_singleton, factorial_zero, cast_one, inv_one, |
| 83 | + iteratedFDeriv_zero_apply, one_smul, pow_zero, reduceAdd, iteratedFDeriv_one_apply] |
| 84 | + rw [← sub_eq_iff_eq_add', Eq.comm, intervalIntegral.integral_congr h_eq] |
| 85 | + have hf' : ∀ (t : ℝ) (ht : t ∈ Set.uIcc 0 1), DifferentiableAt ℝ (fun s ↦ f (x + s • y)) t := |
| 86 | + fun t ht ↦ ((hf t ht).differentiableAt (by simp)).comp t (by fun_prop) |
| 87 | + have hint : IntervalIntegrable (deriv (fun s ↦ f (x + s • y))) MeasureTheory.volume 0 1 := by |
| 88 | + have h₁ : ContinuousOn (fderiv ℝ f) ((fun t ↦ x + t • y) '' Set.uIcc (0 : ℝ) 1) := by |
| 89 | + intro z ⟨t, ht, hz⟩ |
| 90 | + rw [← hz] |
| 91 | + exact (((hf t ht).fderiv_right (le_refl _)).continuousAt (n := 0)).continuousWithinAt |
| 92 | + have h₂ : ContinuousOn (fun x_1 ↦ fderiv ℝ f (x + x_1 • y)) (Set.uIcc (0 : ℝ) 1) := by |
| 93 | + apply h₁.comp (t := (fun t ↦ x + t • y) '' (Set.uIcc (0 : ℝ) 1)) (by fun_prop) |
| 94 | + intro t ht |
| 95 | + use t |
| 96 | + apply (ContinuousOn.congr _ h_eq.symm).intervalIntegrable |
| 97 | + fun_prop |
| 98 | + simpa using intervalIntegral.integral_deriv_eq_sub hf' hint |
| 99 | + | succ n ih => |
| 100 | + -- We use the inductive hypothesis to cancel all lower order terms |
| 101 | + specialize ih (fun t ht ↦ (hf t ht).of_le (by simp)) |
| 102 | + rw [Finset.sum_range_succ, add_assoc] |
| 103 | + convert ih using 2 |
| 104 | + -- We define the functions u and v that we will integrate by parts |
| 105 | + set u := fun (k : ℕ) (t : ℝ) ↦ (k ! : ℝ)⁻¹ * (1 - t) ^ k |
| 106 | + have hu : ∀ (t : ℝ), HasDerivAt (u (n + 1)) (-u n t) t := by |
| 107 | + intro t |
| 108 | + unfold u |
| 109 | + have : (-((n ! : ℝ)⁻¹ * (1 - t) ^ n)) = |
| 110 | + ((n + 1) ! : ℝ)⁻¹ * ((n + 1) * (1 - t) ^ n * (-1)) := by |
| 111 | + field_simp |
| 112 | + congr 1 |
| 113 | + rw [Nat.factorial_succ] |
| 114 | + grind |
| 115 | + rw [this] |
| 116 | + apply HasDerivAt.const_mul |
| 117 | + convert ((hasDerivAt_id t).const_sub 1).pow (n + 1) |
| 118 | + all_goals norm_cast |
| 119 | + have hu' : Continuous (u n) := by fun_prop |
| 120 | + set v := fun (k : ℕ) (t : ℝ) ↦ iteratedFDeriv ℝ k f (x + t • y) (fun _ ↦ y) |
| 121 | + have hv : ∀ (t : ℝ) (ht : t ∈ Set.uIcc 0 1), HasDerivAt (v (n + 1)) (v (n + 1 + 1) t) t := by |
| 122 | + intro t ht |
| 123 | + unfold v |
| 124 | + rw [← (hf t ht).deriv_fderiv_add_smul] |
| 125 | + have h_diff : DifferentiableAt ℝ (iteratedFDeriv ℝ (n + 1) f) (x + t • y) := by |
| 126 | + apply (hf t ht).differentiableAt_iteratedFDeriv |
| 127 | + norm_cast |
| 128 | + grind |
| 129 | + refine DifferentiableAt.hasDerivAt ?_ |
| 130 | + fun_prop |
| 131 | + have hv' : ContinuousOn (v (n + 1 + 1)) (Set.uIcc 0 1) := by |
| 132 | + intro t ht |
| 133 | + have h_cont : ContinuousAt (iteratedFDeriv ℝ (n + 1 + 1) f) (x + t • y) := |
| 134 | + ((hf t ht).iteratedFDeriv_right (i := n + 1 + 1) (m := 0) (by simp)).continuousAt |
| 135 | + exact (h_cont.comp (x := t) (by fun_prop)).continuousWithinAt.eval_const _ |
| 136 | + -- Now we apply integration by parts and simplify |
| 137 | + simpa [← eq_neg_add_iff_add_eq, ← intervalIntegral.integral_smul, smul_smul, u, v] using |
| 138 | + intervalIntegral.integral_smul_deriv_eq_deriv_smul (fun t _ ↦ hu t) hv |
| 139 | + (hu'.neg.intervalIntegrable _ _) hv'.intervalIntegrable |
0 commit comments