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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.