state
stringlengths 0
159k
| srcUpToTactic
stringlengths 387
167k
| nextTactic
stringlengths 3
9k
| declUpToTactic
stringlengths 22
11.5k
| declId
stringlengths 38
95
| decl
stringlengths 16
1.89k
| file_tag
stringlengths 17
73
|
---|---|---|---|---|---|---|
case e_a
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
n : â
s : Set â
xâ x : â
⢠(x - xâ) ^ (n + 1) ⢠(â(n + 1)!)â»Â¹ ⢠iteratedDerivWithin (n + 1) f s xâ =
((ân !)â»Â¹ * (ân + 1)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
| rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev] | @[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
| Mathlib.Analysis.Calculus.Taylor.83_0.INXnr4jrmq9RIjK | @[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
s : Set â
xâ x : â
⢠taylorWithinEval f 0 s xâ x = f xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
| dsimp only [taylorWithinEval] | /-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
| Mathlib.Analysis.Calculus.Taylor.96_0.INXnr4jrmq9RIjK | /-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
s : Set â
xâ x : â
⢠(PolynomialModule.eval x) (taylorWithin f 0 s xâ) = f xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
| dsimp only [taylorWithin] | /-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
| Mathlib.Analysis.Calculus.Taylor.96_0.INXnr4jrmq9RIjK | /-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
s : Set â
xâ x : â
⢠(PolynomialModule.eval x)
(â k in Finset.range (0 + 1),
(PolynomialModule.comp (Polynomial.X - Polynomial.C xâ))
((PolynomialModule.single â k) (taylorCoeffWithin f k s xâ))) =
f xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
| dsimp only [taylorCoeffWithin] | /-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
| Mathlib.Analysis.Calculus.Taylor.96_0.INXnr4jrmq9RIjK | /-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
s : Set â
xâ x : â
⢠(PolynomialModule.eval x)
(â k in Finset.range (0 + 1),
(PolynomialModule.comp (Polynomial.X - Polynomial.C xâ))
((PolynomialModule.single â k) ((âk !)â»Â¹ ⢠iteratedDerivWithin k f s xâ))) =
f xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
| simp | /-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
| Mathlib.Analysis.Calculus.Taylor.96_0.INXnr4jrmq9RIjK | /-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
n : â
s : Set â
xâ : â
⢠taylorWithinEval f n s xâ xâ = f xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
| induction' n with k hk | /-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
| Mathlib.Analysis.Calculus.Taylor.106_0.INXnr4jrmq9RIjK | /-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ | Mathlib_Analysis_Calculus_Taylor |
case zero
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
s : Set â
xâ : â
⢠taylorWithinEval f Nat.zero s xâ xâ = f xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· | exact taylor_within_zero_eval _ _ _ _ | /-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· | Mathlib.Analysis.Calculus.Taylor.106_0.INXnr4jrmq9RIjK | /-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ | Mathlib_Analysis_Calculus_Taylor |
case succ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
s : Set â
xâ : â
k : â
hk : taylorWithinEval f k s xâ xâ = f xâ
⢠taylorWithinEval f (Nat.succ k) s xâ xâ = f xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
| simp [hk] | /-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
| Mathlib.Analysis.Calculus.Taylor.106_0.INXnr4jrmq9RIjK | /-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
n : â
s : Set â
xâ x : â
⢠taylorWithinEval f n s xâ x = â k in Finset.range (n + 1), ((âk !)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
| induction' n with k hk | theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
| Mathlib.Analysis.Calculus.Taylor.115_0.INXnr4jrmq9RIjK | theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ | Mathlib_Analysis_Calculus_Taylor |
case zero
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
s : Set â
xâ x : â
⢠taylorWithinEval f Nat.zero s xâ x =
â k in Finset.range (Nat.zero + 1), ((âk !)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· | simp | theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· | Mathlib.Analysis.Calculus.Taylor.115_0.INXnr4jrmq9RIjK | theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ | Mathlib_Analysis_Calculus_Taylor |
case succ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
s : Set â
xâ x : â
k : â
hk : taylorWithinEval f k s xâ x = â k in Finset.range (k + 1), ((âk !)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ
⢠taylorWithinEval f (Nat.succ k) s xâ x =
â k in Finset.range (Nat.succ k + 1), ((âk !)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
| rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] | theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
| Mathlib.Analysis.Calculus.Taylor.115_0.INXnr4jrmq9RIjK | theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ | Mathlib_Analysis_Calculus_Taylor |
case succ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
s : Set â
xâ x : â
k : â
hk : taylorWithinEval f k s xâ x = â k in Finset.range (k + 1), ((âk !)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ
⢠â k in Finset.range (k + 1), ((âk !)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ +
(((âk + 1) * âk !)â»Â¹ * (x - xâ) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s xâ =
â x_1 in Finset.range (k + 1), ((âx_1 !)â»Â¹ * (x - xâ) ^ x_1) ⢠iteratedDerivWithin x_1 f s xâ +
((â(k + 1)!)â»Â¹ * (x - xâ) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s xâ | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
| simp [Nat.factorial] | theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
| Mathlib.Analysis.Calculus.Taylor.115_0.INXnr4jrmq9RIjK | theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x : â
n : â
s : Set â
hs : UniqueDiffOn â s
hf : ContDiffOn â (ân) f s
⢠ContinuousOn (fun t => taylorWithinEval f n s t x) s | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
| simp_rw [taylor_within_apply] | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
| Mathlib.Analysis.Calculus.Taylor.124_0.INXnr4jrmq9RIjK | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x : â
n : â
s : Set â
hs : UniqueDiffOn â s
hf : ContDiffOn â (ân) f s
⢠ContinuousOn (fun t => â k in Finset.range (n + 1), ((âk !)â»Â¹ * (x - t) ^ k) ⢠iteratedDerivWithin k f s t) s | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
| refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
| Mathlib.Analysis.Calculus.Taylor.124_0.INXnr4jrmq9RIjK | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x : â
n : â
s : Set â
hs : UniqueDiffOn â s
hf : ContDiffOn â (ân) f s
i : â
hi : i â Finset.range (n + 1)
⢠ContinuousOn (fun t => ((âi !)â»Â¹ * (x - t) ^ i) ⢠iteratedDerivWithin i f s t) s | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
| refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
| Mathlib.Analysis.Calculus.Taylor.124_0.INXnr4jrmq9RIjK | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x : â
n : â
s : Set â
hs : UniqueDiffOn â s
hf : ContDiffOn â (ân) f s
i : â
hi : i â Finset.range (n + 1)
⢠ContinuousOn (fun t => iteratedDerivWithin i f s t) s | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
| rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
| Mathlib.Analysis.Calculus.Taylor.124_0.INXnr4jrmq9RIjK | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x : â
n : â
s : Set â
hs : UniqueDiffOn â s
hf :
(â (m : â), âm †ân â ContinuousOn (iteratedDerivWithin m f s) s) â§
â (m : â), âm < ân â DifferentiableOn â (iteratedDerivWithin m f s) s
i : â
hi : i â Finset.range (n + 1)
⢠ContinuousOn (fun t => iteratedDerivWithin i f s t) s | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
| cases' hf with hf_left | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
| Mathlib.Analysis.Calculus.Taylor.124_0.INXnr4jrmq9RIjK | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s | Mathlib_Analysis_Calculus_Taylor |
case intro
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x : â
n : â
s : Set â
hs : UniqueDiffOn â s
i : â
hi : i â Finset.range (n + 1)
hf_left : â (m : â), âm †ân â ContinuousOn (iteratedDerivWithin m f s) s
rightâ : â (m : â), âm < ân â DifferentiableOn â (iteratedDerivWithin m f s) s
⢠ContinuousOn (fun t => iteratedDerivWithin i f s t) s | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
| specialize hf_left i | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
| Mathlib.Analysis.Calculus.Taylor.124_0.INXnr4jrmq9RIjK | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s | Mathlib_Analysis_Calculus_Taylor |
case intro
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x : â
n : â
s : Set â
hs : UniqueDiffOn â s
i : â
hi : i â Finset.range (n + 1)
rightâ : â (m : â), âm < ân â DifferentiableOn â (iteratedDerivWithin m f s) s
hf_left : âi †ân â ContinuousOn (iteratedDerivWithin i f s) s
⢠ContinuousOn (fun t => iteratedDerivWithin i f s t) s | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
| simp only [Finset.mem_range] at hi | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
| Mathlib.Analysis.Calculus.Taylor.124_0.INXnr4jrmq9RIjK | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s | Mathlib_Analysis_Calculus_Taylor |
case intro
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x : â
n : â
s : Set â
hs : UniqueDiffOn â s
i : â
rightâ : â (m : â), âm < ân â DifferentiableOn â (iteratedDerivWithin m f s) s
hf_left : âi †ân â ContinuousOn (iteratedDerivWithin i f s) s
hi : i < n + 1
⢠ContinuousOn (fun t => iteratedDerivWithin i f s t) s | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
| refine' hf_left _ | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
| Mathlib.Analysis.Calculus.Taylor.124_0.INXnr4jrmq9RIjK | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s | Mathlib_Analysis_Calculus_Taylor |
case intro
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x : â
n : â
s : Set â
hs : UniqueDiffOn â s
i : â
rightâ : â (m : â), âm < ân â DifferentiableOn â (iteratedDerivWithin m f s) s
hf_left : âi †ân â ContinuousOn (iteratedDerivWithin i f s) s
hi : i < n + 1
⢠âi †ân | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
| simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
| Mathlib.Analysis.Calculus.Taylor.124_0.INXnr4jrmq9RIjK | /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
t x : â
n : â
⢠HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(ân + 1) * (x - t) ^ n) t | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
| simp_rw [sub_eq_neg_add] | /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
| Mathlib.Analysis.Calculus.Taylor.140_0.INXnr4jrmq9RIjK | /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
t x : â
n : â
⢠HasDerivAt (fun y => (-y + x) ^ (n + 1)) (-(ân + 1) * (-t + x) ^ n) t | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
| rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc] | /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
| Mathlib.Analysis.Calculus.Taylor.140_0.INXnr4jrmq9RIjK | /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
t x : â
n : â
⢠HasDerivAt (fun y => (-y + x) ^ (n + 1)) ((ân + 1) * (-t + x) ^ n * -1) t | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
| convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) | /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
| Mathlib.Analysis.Calculus.Taylor.140_0.INXnr4jrmq9RIjK | /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t | Mathlib_Analysis_Calculus_Taylor |
case h.e'_7.h.e'_5.h.e'_5
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
t x : â
n : â
⢠ân + 1 = â(n + 1) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
| simp only [Nat.cast_add, Nat.cast_one] | /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
| Mathlib.Analysis.Calculus.Taylor.140_0.INXnr4jrmq9RIjK | /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y
⢠HasDerivWithinAt (fun z => (((âk + 1) * âk !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((âk + 1) * âk !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y)
t y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
| replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y
⢠HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
| convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
case h.e'_7
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y
⢠iteratedDerivWithin (k + 2) f s y = derivWithin (iteratedDerivWithin (k + 1) f s) t y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
| rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
case h.e'_7
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y
⢠derivWithin (iteratedDerivWithin (k + 1) f s) s y = derivWithin (iteratedDerivWithin (k + 1) f s) t y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
| exact (derivWithin_of_mem hs ht hf).symm | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y
⢠HasDerivWithinAt (fun z => (((âk + 1) * âk !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((âk + 1) * âk !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y)
t y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
| have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y
⢠HasDerivWithinAt (fun t => ((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) (-((âk !)â»Â¹ * (x - y) ^ k)) t y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
| have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y
⢠-((âk !)â»Â¹ * (x - y) ^ k) = ((âk + 1) * âk !)â»Â¹ * (-(âk + 1) * (x - y) ^ k) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
| field_simp | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y
⢠-((x - y) ^ k * ((âk + 1) * âk !)) = (-1 + -âk) * (x - y) ^ k * âk ! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; | ring | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; | Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y
this : -((âk !)â»Â¹ * (x - y) ^ k) = ((âk + 1) * âk !)â»Â¹ * (-(âk + 1) * (x - y) ^ k)
⢠HasDerivWithinAt (fun t => ((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) (-((âk !)â»Â¹ * (x - y) ^ k)) t y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
| rw [this] | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y
this : -((âk !)â»Â¹ * (x - y) ^ k) = ((âk + 1) * âk !)â»Â¹ * (-(âk + 1) * (x - y) ^ k)
⢠HasDerivWithinAt (fun t => ((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) (((âk + 1) * âk !)â»Â¹ * (-(âk + 1) * (x - y) ^ k))
t y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
| exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y
this : HasDerivWithinAt (fun t => ((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) (-((âk !)â»Â¹ * (x - y) ^ k)) t y
⢠HasDerivWithinAt (fun z => (((âk + 1) * âk !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((âk + 1) * âk !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y)
t y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
| convert this.smul hf using 1 | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
case h.e'_7
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y
this : HasDerivWithinAt (fun t => ((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) (-((âk !)â»Â¹ * (x - y) ^ k)) t y
⢠(((âk + 1) * âk !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y =
(((âk + 1) * âk !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y +
-((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
| field_simp | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
case h.e'_7
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
k : â
s t : Set â
ht : UniqueDiffWithinAt â t y
hs : s â ð[t] y
hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y
this : HasDerivWithinAt (fun t => ((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) (-((âk !)â»Â¹ * (x - y) ^ k)) t y
⢠((x - y) ^ (k + 1) / ((âk + 1) * âk !)) ⢠iteratedDerivWithin (k + 2) f s y -
((x - y) ^ k / âk !) ⢠iteratedDerivWithin (k + 1) f s y =
((x - y) ^ (k + 1) / ((âk + 1) * âk !)) ⢠iteratedDerivWithin (k + 2) f s y +
(-(x - y) ^ k / âk !) ⢠iteratedDerivWithin (k + 1) f s y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
| rw [neg_div, neg_smul, sub_eq_add_neg] | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
| Mathlib.Analysis.Calculus.Taylor.149_0.INXnr4jrmq9RIjK | theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
n : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
hf : ContDiffOn â (ân) f s
hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y
⢠HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y)
s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
| induction' n with k hk | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case zero
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
hf : ContDiffOn â (âNat.zero) f s
hf' : DifferentiableWithinAt â (iteratedDerivWithin Nat.zero f s) s y
⢠HasDerivWithinAt (fun t => taylorWithinEval f Nat.zero s t x)
(((âNat.zero !)â»Â¹ * (x - y) ^ Nat.zero) ⢠iteratedDerivWithin (Nat.zero + 1) f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· | simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul] | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· | Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case zero
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
hf : ContDiffOn â (âNat.zero) f s
hf' : DifferentiableWithinAt â (iteratedDerivWithin Nat.zero f s) s y
⢠HasDerivWithinAt (fun t => f t) (iteratedDerivWithin (Nat.zero + 1) f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
| simp only [iteratedDerivWithin_zero] at hf' | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case zero
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
hf : ContDiffOn â (âNat.zero) f s
hf' : DifferentiableWithinAt â f s y
⢠HasDerivWithinAt (fun t => f t) (iteratedDerivWithin (Nat.zero + 1) f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
| rw [iteratedDerivWithin_one (hs_unique _ (h hy))] | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case zero
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
hf : ContDiffOn â (âNat.zero) f s
hf' : DifferentiableWithinAt â f s y
⢠HasDerivWithinAt (fun t => f t) (derivWithin f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
| norm_num | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case zero
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
hf : ContDiffOn â (âNat.zero) f s
hf' : DifferentiableWithinAt â f s y
⢠HasDerivWithinAt (fun t => f t) (derivWithin f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
| exact hf'.hasDerivWithinAt.mono h | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case succ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
k : â
hk :
ContDiffOn â (âk) f s â
DifferentiableWithinAt â (iteratedDerivWithin k f s) s y â
HasDerivWithinAt (fun t => taylorWithinEval f k s t x)
(((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) s' y
hf : ContDiffOn â (â(Nat.succ k)) f s
hf' : DifferentiableWithinAt â (iteratedDerivWithin (Nat.succ k) f s) s y
⢠HasDerivWithinAt (fun t => taylorWithinEval f (Nat.succ k) s t x)
(((â(Nat.succ k)!)â»Â¹ * (x - y) ^ Nat.succ k) ⢠iteratedDerivWithin (Nat.succ k + 1) f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
| simp_rw [Nat.add_succ, taylorWithinEval_succ] | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case succ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
k : â
hk :
ContDiffOn â (âk) f s â
DifferentiableWithinAt â (iteratedDerivWithin k f s) s y â
HasDerivWithinAt (fun t => taylorWithinEval f k s t x)
(((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) s' y
hf : ContDiffOn â (â(Nat.succ k)) f s
hf' : DifferentiableWithinAt â (iteratedDerivWithin (Nat.succ k) f s) s y
⢠HasDerivWithinAt
(fun t =>
taylorWithinEval f k s t x + (((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s t)
(((â(Nat.succ k)!)â»Â¹ * (x - y) ^ Nat.succ k) ⢠iteratedDerivWithin (Nat.succ (Nat.succ k + 0)) f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
| simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case succ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
k : â
hk :
ContDiffOn â (âk) f s â
DifferentiableWithinAt â (iteratedDerivWithin k f s) s y â
HasDerivWithinAt (fun t => taylorWithinEval f k s t x)
(((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) s' y
hf : ContDiffOn â (â(Nat.succ k)) f s
hf' : DifferentiableWithinAt â (iteratedDerivWithin (Nat.succ k) f s) s y
⢠HasDerivWithinAt
(fun t =>
taylorWithinEval f k s t x + (((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s t)
((((âk + 1) * âk !)â»Â¹ * (x - y) ^ Nat.succ k) ⢠iteratedDerivWithin (Nat.succ (Nat.succ k)) f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
| have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case succ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
k : â
hk :
ContDiffOn â (âk) f s â
DifferentiableWithinAt â (iteratedDerivWithin k f s) s y â
HasDerivWithinAt (fun t => taylorWithinEval f k s t x)
(((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) s' y
hf : ContDiffOn â (â(Nat.succ k)) f s
hf' : DifferentiableWithinAt â (iteratedDerivWithin (Nat.succ k) f s) s y
coe_lt_succ : âk < â(Nat.succ k)
⢠HasDerivWithinAt
(fun t =>
taylorWithinEval f k s t x + (((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s t)
((((âk + 1) * âk !)â»Â¹ * (x - y) ^ Nat.succ k) ⢠iteratedDerivWithin (Nat.succ (Nat.succ k)) f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
| have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case succ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
k : â
hk :
ContDiffOn â (âk) f s â
DifferentiableWithinAt â (iteratedDerivWithin k f s) s y â
HasDerivWithinAt (fun t => taylorWithinEval f k s t x)
(((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) s' y
hf : ContDiffOn â (â(Nat.succ k)) f s
hf' : DifferentiableWithinAt â (iteratedDerivWithin (Nat.succ k) f s) s y
coe_lt_succ : âk < â(Nat.succ k)
hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s'
⢠HasDerivWithinAt
(fun t =>
taylorWithinEval f k s t x + (((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s t)
((((âk + 1) * âk !)â»Â¹ * (x - y) ^ Nat.succ k) ⢠iteratedDerivWithin (Nat.succ (Nat.succ k)) f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
| specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case succ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
k : â
hf : ContDiffOn â (â(Nat.succ k)) f s
hf' : DifferentiableWithinAt â (iteratedDerivWithin (Nat.succ k) f s) s y
coe_lt_succ : âk < â(Nat.succ k)
hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s'
hk :
HasDerivWithinAt (fun t => taylorWithinEval f k s t x) (((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y)
s' y
⢠HasDerivWithinAt
(fun t =>
taylorWithinEval f k s t x + (((âk + 1) * âk !)â»Â¹ * (x - t) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s t)
((((âk + 1) * âk !)â»Â¹ * (x - y) ^ Nat.succ k) ⢠iteratedDerivWithin (Nat.succ (Nat.succ k)) f s y) s' y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
| convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
case h.e'_7
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
x y : â
s s' : Set â
hs'_unique : UniqueDiffWithinAt â s' y
hs_unique : UniqueDiffOn â s
hs' : s' â ð[s] y
hy : y â s'
h : s' â s
k : â
hf : ContDiffOn â (â(Nat.succ k)) f s
hf' : DifferentiableWithinAt â (iteratedDerivWithin (Nat.succ k) f s) s y
coe_lt_succ : âk < â(Nat.succ k)
hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s'
hk :
HasDerivWithinAt (fun t => taylorWithinEval f k s t x) (((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y)
s' y
⢠(((âk + 1) * âk !)â»Â¹ * (x - y) ^ Nat.succ k) ⢠iteratedDerivWithin (Nat.succ (Nat.succ k)) f s y =
((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y +
((((âk + 1) * âk !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((âk !)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
| exact (add_sub_cancel'_right _ _).symm | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
| Mathlib.Analysis.Calculus.Taylor.173_0.INXnr4jrmq9RIjK | /-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f g g' : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn g (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt g (g' x_1) x_1
g'_ne : â x_1 â Ioo xâ x, g' x_1 â 0
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / ân ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
| rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ© | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
| Mathlib.Analysis.Calculus.Taylor.229_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' | Mathlib_Analysis_Calculus_Taylor |
case intro.intro
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f g g' : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn g (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt g (g' x_1) x_1
g'_ne : â x_1 â Ioo xâ x, g' x_1 â 0
y : â
hy : y â Ioo xâ x
h :
(g x - g xâ) * ((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y =
(taylorWithinEval f n (Icc xâ x) x x - taylorWithinEval f n (Icc xâ x) xâ x) * g' y
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / ân ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
| use y, hy | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
| Mathlib.Analysis.Calculus.Taylor.229_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f g g' : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn g (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt g (g' x_1) x_1
g'_ne : â x_1 â Ioo xâ x, g' x_1 â 0
y : â
hy : y â Ioo xâ x
h :
(g x - g xâ) * ((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y =
(taylorWithinEval f n (Icc xâ x) x x - taylorWithinEval f n (Icc xâ x) xâ x) * g' y
⢠f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - y) ^ n / ân ! * (g x - g xâ) / g' y) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
| simp only [taylorWithinEval_self] at h | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
| Mathlib.Analysis.Calculus.Taylor.229_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f g g' : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn g (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt g (g' x_1) x_1
g'_ne : â x_1 â Ioo xâ x, g' x_1 â 0
y : â
hy : y â Ioo xâ x
h :
(g x - g xâ) * ((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y =
(f x - taylorWithinEval f n (Icc xâ x) xâ x) * g' y
⢠f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - y) ^ n / ân ! * (g x - g xâ) / g' y) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
| rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
| Mathlib.Analysis.Calculus.Taylor.229_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f g g' : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn g (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt g (g' x_1) x_1
g'_ne : â x_1 â Ioo xâ x, g' x_1 â 0
y : â
hy : y â Ioo xâ x
h :
((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y * (g x - g xâ) / g' y =
f x - taylorWithinEval f n (Icc xâ x) xâ x
⢠f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - y) ^ n / ân ! * (g x - g xâ) / g' y) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
| rw [â h] | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
| Mathlib.Analysis.Calculus.Taylor.229_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f g g' : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn g (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt g (g' x_1) x_1
g'_ne : â x_1 â Ioo xâ x, g' x_1 â 0
y : â
hy : y â Ioo xâ x
h :
((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y * (g x - g xâ) / g' y =
f x - taylorWithinEval f n (Icc xâ x) xâ x
⢠((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y * (g x - g xâ) / g' y =
((x - y) ^ n / ân ! * (g x - g xâ) / g' y) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
| field_simp [g'_ne y hy] | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
| Mathlib.Analysis.Calculus.Taylor.229_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f g g' : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn g (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt g (g' x_1) x_1
g'_ne : â x_1 â Ioo xâ x, g' x_1 â 0
y : â
hy : y â Ioo xâ x
h :
((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y * (g x - g xâ) / g' y =
f x - taylorWithinEval f n (Icc xâ x) xâ x
⢠(x - y) ^ n * iteratedDerivWithin (n + 1) f (Icc xâ x) y * (g x - g xâ) =
(x - y) ^ n * (g x - g xâ) * iteratedDerivWithin (n + 1) f (Icc xâ x) y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
| ring | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
| Mathlib.Analysis.Calculus.Taylor.229_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / â(n + 1)! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
| have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
⢠ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
| refine' Continuous.continuousOn _ | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
⢠Continuous fun t => (x - t) ^ (n + 1) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
| exact (continuous_const.sub continuous_id').pow _ | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / â(n + 1)! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
| have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne' | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
⢠â y â Ioo xâ x, (x - y) ^ n â 0 | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
| intro y hy | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
y : â
hy : y â Ioo xâ x
⢠(x - y) ^ n â 0 | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
| refine' pow_ne_zero _ _ | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
y : â
hy : y â Ioo xâ x
⢠x - y â 0 | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
| rw [mem_Ioo] at hy | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
y : â
hy : xâ < y ⧠y < x
⢠x - y â 0 | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
| rw [sub_ne_zero] | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
y : â
hy : xâ < y ⧠y < x
⢠x â y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
| exact hy.2.ne' | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
xy_ne : â y â Ioo xâ x, (x - y) ^ n â 0
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / â(n + 1)! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
| have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
xy_ne : â y â Ioo xâ x, (x - y) ^ n â 0
hg' : â y â Ioo xâ x, -(ân + 1) * (x - y) ^ n â 0
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / â(n + 1)! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
| rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ© | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
case intro.intro
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
xy_ne : â y â Ioo xâ x, (x - y) ^ n â 0
hg' : â y â Ioo xâ x, -(ân + 1) * (x - y) ^ n â 0
y : â
hy : y â Ioo xâ x
h :
f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - y) ^ n / ân ! * ((x - x) ^ (n + 1) - (x - xâ) ^ (n + 1)) / (-(ân + 1) * (x - y) ^ n)) â¢
iteratedDerivWithin (n + 1) f (Icc xâ x) y
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / â(n + 1)! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
| use y, hy | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
xy_ne : â y â Ioo xâ x, (x - y) ^ n â 0
hg' : â y â Ioo xâ x, -(ân + 1) * (x - y) ^ n â 0
y : â
hy : y â Ioo xâ x
h :
f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - y) ^ n / ân ! * ((x - x) ^ (n + 1) - (x - xâ) ^ (n + 1)) / (-(ân + 1) * (x - y) ^ n)) â¢
iteratedDerivWithin (n + 1) f (Icc xâ x) y
⢠f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) y * (x - xâ) ^ (n + 1) / â(n + 1)! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
| simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
xy_ne : â y â Ioo xâ x, (x - y) ^ n â 0
hg' : â y â Ioo xâ x, -(ân + 1) * (x - y) ^ n â 0
y : â
hy : y â Ioo xâ x
h :
f x - taylorWithinEval f n (Icc xâ x) xâ x =
(-((x - y) ^ n / ân ! * (x - xâ) ^ (n + 1)) / (-(ân + 1) * (x - y) ^ n)) â¢
iteratedDerivWithin (n + 1) f (Icc xâ x) y
⢠f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) y * (x - xâ) ^ (n + 1) / â(n + 1)! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
| rw [h, neg_div, â div_neg, neg_mul, neg_neg] | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
xy_ne : â y â Ioo xâ x, (x - y) ^ n â 0
hg' : â y â Ioo xâ x, -(ân + 1) * (x - y) ^ n â 0
y : â
hy : y â Ioo xâ x
h :
f x - taylorWithinEval f n (Icc xâ x) xâ x =
(-((x - y) ^ n / ân ! * (x - xâ) ^ (n + 1)) / (-(ân + 1) * (x - y) ^ n)) â¢
iteratedDerivWithin (n + 1) f (Icc xâ x) y
⢠((x - y) ^ n / ân ! * (x - xâ) ^ (n + 1) / ((ân + 1) * (x - y) ^ n)) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y =
iteratedDerivWithin (n + 1) f (Icc xâ x) y * (x - xâ) ^ (n + 1) / â(n + 1)! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
| field_simp [xy_ne y hy, Nat.factorial] | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
| Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn (fun t => (x - t) ^ (n + 1)) (Icc xâ x)
xy_ne : â y â Ioo xâ x, (x - y) ^ n â 0
hg' : â y â Ioo xâ x, -(ân + 1) * (x - y) ^ n â 0
y : â
hy : y â Ioo xâ x
h :
f x - taylorWithinEval f n (Icc xâ x) xâ x =
(-((x - y) ^ n / ân ! * (x - xâ) ^ (n + 1)) / (-(ân + 1) * (x - y) ^ n)) â¢
iteratedDerivWithin (n + 1) f (Icc xâ x) y
⢠(x - y) ^ n * (x - xâ) ^ (n + 1) * iteratedDerivWithin (n + 1) f (Icc xâ x) y * ((ân + 1) * ân !) =
iteratedDerivWithin (n + 1) f (Icc xâ x) y * (x - xâ) ^ (n + 1) * (ân ! * ((ân + 1) * (x - y) ^ n)) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; | ring | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; | Mathlib.Analysis.Calculus.Taylor.258_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / ân ! * (x - xâ) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
| have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity) | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
| Mathlib.Analysis.Calculus.Taylor.290_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
⢠Continuous id | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by | continuity | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by | Mathlib.Analysis.Calculus.Taylor.290_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn id (Icc xâ x)
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / ân ! * (x - xâ) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
| have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _ | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
| Mathlib.Analysis.Calculus.Taylor.290_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn id (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt id ((fun x => 1) x_1) x_1
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / ân ! * (x - xâ) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
| rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ© | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
| Mathlib.Analysis.Calculus.Taylor.290_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn id (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt id ((fun x => 1) x_1) x_1
xâ¹ : â
xâ : xâ¹ â Ioo xâ x
⢠(fun x => 1) xâ¹ â 0 | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by | simp | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by | Mathlib.Analysis.Calculus.Taylor.290_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) | Mathlib_Analysis_Calculus_Taylor |
case intro.intro
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn id (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt id ((fun x => 1) x_1) x_1
y : â
hy : y â Ioo xâ x
h :
f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - y) ^ n / ân ! * (id x - id xâ) / (fun x => 1) y) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y
⢠â x' â Ioo xâ x,
f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / ân ! * (x - xâ) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
| use y, hy | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
| Mathlib.Analysis.Calculus.Taylor.290_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn id (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt id ((fun x => 1) x_1) x_1
y : â
hy : y â Ioo xâ x
h :
f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - y) ^ n / ân ! * (id x - id xâ) / (fun x => 1) y) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y
⢠f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) y * (x - y) ^ n / ân ! * (x - xâ) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
| rw [h] | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
| Mathlib.Analysis.Calculus.Taylor.290_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn id (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt id ((fun x => 1) x_1) x_1
y : â
hy : y â Ioo xâ x
h :
f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - y) ^ n / ân ! * (id x - id xâ) / (fun x => 1) y) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y
⢠((x - y) ^ n / ân ! * (id x - id xâ) / (fun x => 1) y) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y =
iteratedDerivWithin (n + 1) f (Icc xâ x) y * (x - y) ^ n / ân ! * (x - xâ) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
| field_simp [n.factorial_ne_zero] | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
| Mathlib.Analysis.Calculus.Taylor.290_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) | Mathlib_Analysis_Calculus_Taylor |
case right
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â â
x xâ : â
n : â
hx : xâ < x
hf : ContDiffOn â (ân) f (Icc xâ x)
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)
gcont : ContinuousOn id (Icc xâ x)
gdiff : â x_1 â Ioo xâ x, HasDerivAt id ((fun x => 1) x_1) x_1
y : â
hy : y â Ioo xâ x
h :
f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - y) ^ n / ân ! * (id x - id xâ) / (fun x => 1) y) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) y
⢠(x - y) ^ n * (x - xâ) * iteratedDerivWithin (n + 1) f (Icc xâ x) y =
iteratedDerivWithin (n + 1) f (Icc xâ x) y * (x - y) ^ n * (x - xâ) | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
| ring | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
| Mathlib.Analysis.Calculus.Taylor.290_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
⢠âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / ân ! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
| rcases eq_or_lt_of_le hab with (rfl | h) | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case inl
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a C x : â
n : â
hab : a †a
hf : ContDiffOn â (ân + 1) f (Icc a a)
hx : x â Icc a a
hC : â y â Icc a a, âiteratedDerivWithin (n + 1) f (Icc a a) yâ †C
⢠âf x - taylorWithinEval f n (Icc a a) a xâ †C * (x - a) ^ (n + 1) / ân ! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· | rw [Icc_self, mem_singleton_iff] at hx | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· | Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case inl
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a C x : â
n : â
hab : a †a
hf : ContDiffOn â (ân + 1) f (Icc a a)
hx : x = a
hC : â y â Icc a a, âiteratedDerivWithin (n + 1) f (Icc a a) yâ †C
⢠âf x - taylorWithinEval f n (Icc a a) a xâ †C * (x - a) ^ (n + 1) / ân ! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
| simp [hx] | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case inr
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
⢠âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / ân ! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
| have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h) | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case inr
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
⢠âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / ân ! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
| have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> linarith
-- Estimate the iterated derivative by `C`
· exact hC y âšhay, hyx.le.trans hx.2â© | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
⢠â y â Ico a x, â((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ †(ân !)â»Â¹ * |x - a| ^ n * C | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
| rintro y âšhay, hyxâ© | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case intro
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
y : â
hay : a †y
hyx : y < x
⢠â((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ †(ân !)â»Â¹ * |x - a| ^ n * C | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
| rw [norm_smul, Real.norm_eq_abs] | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case intro
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
y : â
hay : a †y
hyx : y < x
⢠|(ân !)â»Â¹ * (x - y) ^ n| * âiteratedDerivWithin (n + 1) f (Icc a b) yâ †(ân !)â»Â¹ * |x - a| ^ n * C | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
| gcongr | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case intro.hâ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
y : â
hay : a †y
hyx : y < x
⢠|(ân !)â»Â¹ * (x - y) ^ n| †(ân !)â»Â¹ * |x - a| ^ n | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· | rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· | Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case intro.hâ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
y : â
hay : a †y
hyx : y < x
⢠(ân !)â»Â¹ * |x - y| ^ n †(ân !)â»Â¹ * |x - a| ^ n | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
| gcongr | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case intro.hâ.h.hab
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
y : â
hay : a †y
hyx : y < x
⢠|x - y| †|x - a| | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
| rw [abs_of_nonneg, abs_of_nonneg] | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case intro.hâ.h.hab
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
y : â
hay : a †y
hyx : y < x
⢠x - y †x - a | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> | linarith | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> | Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case intro.hâ.h.hab
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
y : â
hay : a †y
hyx : y < x
⢠0 †x - a | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> | linarith | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> | Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case intro.hâ.h.hab
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
y : â
hay : a †y
hyx : y < x
⢠0 †x - y | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> | linarith | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> | Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case intro.hâ
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
y : â
hay : a †y
hyx : y < x
⢠âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> linarith
-- Estimate the iterated derivative by `C`
· | exact hC y âšhay, hyx.le.trans hx.2â© | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> linarith
-- Estimate the iterated derivative by `C`
· | Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
case inr
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
h' : â y â Ico a x, â((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ †(ân !)â»Â¹ * |x - a| ^ n * C
⢠âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / ân ! | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> linarith
-- Estimate the iterated derivative by `C`
· exact hC y âšhay, hyx.le.trans hx.2â©
-- Apply the mean value theorem for vector valued functions:
| have A : â t â Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((ân !)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by
intro t ht
have I : Icc a x â Icc a b := Icc_subset_Icc_right hx.2
exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> linarith
-- Estimate the iterated derivative by `C`
· exact hC y âšhay, hyx.le.trans hx.2â©
-- Apply the mean value theorem for vector valued functions:
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |
ð : Type u_1
E : Type u_2
F : Type u_3
instâ¹ : NormedAddCommGroup E
instâ : NormedSpace â E
f : â â E
a b C x : â
n : â
hab : a †b
hf : ContDiffOn â (ân + 1) f (Icc a b)
hx : x â Icc a b
hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C
h : a < b
hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)
h' : â y â Ico a x, â((ân !)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ †(ân !)â»Â¹ * |x - a| ^ n * C
⢠â t â Icc a x,
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((ân !)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Data.Polynomial.Module
#align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14"
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : â â E`,
where `E` is a normed vector space over `â` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the Peano form of the remainder
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped BigOperators Interval Topology Nat
open Set
variable {ð E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace â E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : â â E) (k : â) (s : Set â) (xâ : â) : E :=
(k ! : â)â»Â¹ ⢠iteratedDerivWithin k f s xâ
#align taylor_coeff_within taylorCoeffWithin
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$â_{k=0}^n \frac{(x - xâ)^k}{k!} f^{(k)}(xâ),$$
where $f^{(k)}(xâ)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : â â E) (n : â) (s : Set â) (xâ : â) : PolynomialModule â E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â k (taylorCoeffWithin f k s xâ))
#align taylor_within taylorWithin
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `â â E`-/
noncomputable def taylorWithinEval (f : â â E) (n : â) (s : Set â) (xâ x : â) : E :=
PolynomialModule.eval x (taylorWithin f n s xâ)
#align taylor_within_eval taylorWithinEval
theorem taylorWithin_succ (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithin f (n + 1) s xâ = taylorWithin f n s xâ +
PolynomialModule.comp (Polynomial.X - Polynomial.C xâ)
(PolynomialModule.single â (n + 1) (taylorCoeffWithin f (n + 1) s xâ)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
#align taylor_within_succ taylorWithin_succ
@[simp]
theorem taylorWithinEval_succ (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f (n + 1) s xâ x = taylorWithinEval f n s xâ x +
(((n + 1 : â) * n !)â»Â¹ * (x - xâ) ^ (n + 1)) ⢠iteratedDerivWithin (n + 1) f s xâ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [â mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
#align taylor_within_eval_succ taylorWithinEval_succ
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : â â E) (s : Set â) (xâ x : â) :
taylorWithinEval f 0 s xâ x = f xâ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
#align taylor_within_zero_eval taylor_within_zero_eval
/-- Evaluating the Taylor polynomial at `x = xâ` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : â â E) (n : â) (s : Set â) (xâ : â) :
taylorWithinEval f n s xâ xâ = f xâ := by
induction' n with k hk
· exact taylor_within_zero_eval _ _ _ _
simp [hk]
#align taylor_within_eval_self taylorWithinEval_self
theorem taylor_within_apply (f : â â E) (n : â) (s : Set â) (xâ x : â) :
taylorWithinEval f n s xâ x =
â k in Finset.range (n + 1), ((k ! : â)â»Â¹ * (x - xâ) ^ k) ⢠iteratedDerivWithin k f s xâ := by
induction' n with k hk
· simp
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
#align taylor_within_apply taylor_within_apply
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s xâ x` is continuous in `xâ`. -/
theorem continuousOn_taylorWithinEval {f : â â E} {x : â} {n : â} {s : Set â}
(hs : UniqueDiffOn â s) (hf : ContDiffOn â n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _
refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _
rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf
cases' hf with hf_left
specialize hf_left i
simp only [Finset.mem_range] at hi
refine' hf_left _
simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi]
#align continuous_on_taylor_within_eval continuousOn_taylorWithinEval
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/
theorem monomial_has_deriv_aux (t x : â) (n : â) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [â neg_one_mul, mul_comm (-1 : â), mul_assoc, mul_comm (-1 : â), â mul_assoc]
convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x)
simp only [Nat.cast_add, Nat.cast_one]
#align monomial_has_deriv_aux monomial_has_deriv_aux
theorem hasDerivWithinAt_taylor_coeff_within {f : â â E} {x y : â} {k : â} {s t : Set â}
(ht : UniqueDiffWithinAt â t y) (hs : s â ð[t] y)
(hf : DifferentiableWithinAt â (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : â) * k !)â»Â¹ * (x - z) ^ (k + 1)) ⢠iteratedDerivWithin (k + 1) f s z)
((((k + 1 : â) * k !)â»Â¹ * (x - y) ^ (k + 1)) ⢠iteratedDerivWithin (k + 2) f s y -
((k ! : â)â»Â¹ * (x - y) ^ k) ⢠iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))]
exact (derivWithin_of_mem hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : â) * k !)â»Â¹ * (x - t) ^ (k + 1))
(-((k ! : â)â»Â¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : â)â»Â¹ * (x - y) ^ k) = ((k + 1 : â) * k !)â»Â¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
#align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : â â E} {x y : â} {n : â} {s s' : Set â}
(hs'_unique : UniqueDiffWithinAt â s' y) (hs_unique : UniqueDiffOn â s) (hs' : s' â ð[s] y)
(hy : y â s') (h : s' â s) (hf : ContDiffOn â n f s)
(hf' : DifferentiableWithinAt â (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f s y) s' y := by
induction' n with k hk
· simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one (hs_unique _ (h hy))]
norm_num
exact hf'.hasDerivWithinAt.mono h
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop â) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn â (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel'_right _ _).symm
#align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : â â E} {a b t : â} (x : â) {n : â} (hx : a < b)
(ht : t â Ioo a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b â ð t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b â ð[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds
#align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo
/-- Calculate the derivative of the Taylor polynomial with respect to `xâ`.
Version for closed intervals -/
theorem has_deriv_within_taylorWithinEval_at_Icc {f : â â E} {a b t : â} (x : â) {n : â}
(hx : a < b) (ht : t â Icc a b) (hf : ContDiffOn â n f (Icc a b))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
#align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`, and `g` is a differentiable function on
`Ioo xâ x` and continuous on `Icc xâ x`. Then there exists an `x' â Ioo xâ x` such that
$$f(x) - (P_n f)(xâ, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(xâ)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : â â â} {g g' : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x))
(gcont : ContinuousOn g (Icc xâ x))
(gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt g (g' x_1) x_1)
(g'_ne : â x_1 : â, x_1 â Ioo xâ x â g' x_1 â 0) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
((x - x') ^ n / n ! * (g x - g xâ) / g' x') ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc xâ x) t x)
(fun t => ((n ! : â)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc xâ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with âšy, hy, hâ©
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, â div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h
rw [â h]
field_simp [g'_ne y hy]
ring
#align taylor_mean_remainder taylor_mean_remainder
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - xâ)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - xâ) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : â => (x - t) ^ (n + 1)) (Icc xâ x) := by
refine' Continuous.continuousOn _
exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity`
have xy_ne : â y : â, y â Ioo xâ x â (x - y) ^ n â 0 := by
intro y hy
refine' pow_ne_zero _ _
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : â y : â, y â Ioo xâ x â -(ân + 1) * (x - y) ^ n â 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
âšy, hy, hâ©
use y, hy
simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, â div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
#align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc xâ x` and
`n+1`-times differentiable on the open set `Ioo xâ x`. Then there exists an `x' â Ioo xâ x` such
that $$f(x) - (P_n f)(xâ, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-xâ)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : â â â} {x xâ : â} {n : â} (hx : xâ < x)
(hf : ContDiffOn â n f (Icc xâ x))
(hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc xâ x)) (Ioo xâ x)) :
â x' â Ioo xâ x, f x - taylorWithinEval f n (Icc xâ x) xâ x =
iteratedDerivWithin (n + 1) f (Icc xâ x) x' * (x - x') ^ n / n ! * (x - xâ) := by
have gcont : ContinuousOn id (Icc xâ x) := Continuous.continuousOn (by continuity)
have gdiff : â x_1 : â, x_1 â Ioo xâ x â HasDerivAt id ((fun _ : â => (1 : â)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with âšy, hy, hâ©
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
#align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> linarith
-- Estimate the iterated derivative by `C`
· exact hC y âšhay, hyx.le.trans hx.2â©
-- Apply the mean value theorem for vector valued functions:
have A : â t â Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((ân !)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by
| intro t ht | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn â (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : â y â Ico a x,
â((n ! : â)â»Â¹ * (x - y) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) yâ â€
(n ! : â)â»Â¹ * |x - a| ^ n * C := by
rintro y âšhay, hyxâ©
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
rw [abs_of_nonneg, abs_of_nonneg] <;> linarith
-- Estimate the iterated derivative by `C`
· exact hC y âšhay, hyx.le.trans hx.2â©
-- Apply the mean value theorem for vector valued functions:
have A : â t â Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((ân !)â»Â¹ * (x - t) ^ n) ⢠iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by
| Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK | /-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : â â E} {a b C x : â} {n : â} (hab : a †b)
(hf : ContDiffOn â (n + 1) f (Icc a b)) (hx : x â Icc a b)
(hC : â y â Icc a b, âiteratedDerivWithin (n + 1) f (Icc a b) yâ †C) :
âf x - taylorWithinEval f n (Icc a b) a xâ †C * (x - a) ^ (n + 1) / n ! | Mathlib_Analysis_Calculus_Taylor |