Documentation

LeanCert.Core.Taylor

Generic Taylor Series Abstractions #

This file provides generic Taylor series machinery for verified numerics. We wrap Mathlib's Taylor expansion theorems in forms convenient for our interval arithmetic framework.

Phase Status #

This module is now Phase 3 complete. The main Taylor remainder bound theorem taylor_remainder_bound is fully proved with no sorry markers.

The theorem provides rigorous bounds on Taylor polynomial approximation errors using Lagrange's form of the remainder.

Main definitions #

Design notes #

This file provides the abstract theory. Specific Taylor expansions for exp, sin, cos, etc. are built using this machinery in conjunction with Mathlib's calculus lemmas.

Taylor approximation structure #

A Taylor approximation of a function on an interval.

Given a function f, center c, and radius r, this represents:

  • A polynomial approximation poly of degree n
  • A remainder bound R such that for all x with |x - c| ≤ r: |f(x) - poly(x - c)| ≤ R
  • degree :

    Degree of the polynomial

  • coeffs : Fin (self.degree + 1)

    Polynomial coefficients (Taylor coefficients at center)

  • remainder :

    Remainder bound

  • remainder_nonneg : 0 self.remainder

    The remainder is non-negative

Instances For

    Evaluate the polynomial part at a point

    Equations
    Instances For

      Derivative bounds #

      A bound on the n-th derivative of a function on an interval

      • order :

        The derivative order

      • bound :

        Upper bound on |f^(n)(x)| for x in the interval

      • bound_nonneg : 0 self.bound

        The bound is non-negative

      Instances For

        Taylor remainder bounds #

        Helper lemmas for iteratedDerivWithin conversion #

        Unique differentiability at the left endpoint of a closed interval.

        Unique differentiability at the right endpoint of a closed interval.

        theorem LeanCert.Core.derivWithin_Icc_left_eq_deriv {f : } {c x : } (hcx : c < x) (hf : DifferentiableAt f c) :
        derivWithin f (Set.Icc c x) c = deriv f c

        At the left endpoint of [c, x], derivWithin equals deriv for differentiable functions.

        theorem LeanCert.Core.derivWithin_Icc_right_eq_deriv {f : } {c x : } (hcx : c < x) (hf : DifferentiableAt f x) :
        derivWithin f (Set.Icc c x) x = deriv f x

        At the right endpoint of [c, x], derivWithin equals deriv for differentiable functions.

        theorem LeanCert.Core.iteratedDerivWithin_Icc_interior_eq {f : } {a b x : } {n : } (_hab : a < b) (hx : x Set.Ioo a b) :

        Helper lemma: iteratedDerivWithin on Icc a b equals iteratedDeriv at interior points.

        This bridges Mathlib's iteratedDerivWithin-based Taylor theorems with global iteratedDeriv.

        theorem LeanCert.Core.iteratedDerivWithin_Icc_left_eq_iteratedDeriv {f : } {c x : } {n : } (hcx : c < x) (hf : ContDiff (↑n) f) :

        At the left endpoint of [c, x], iteratedDerivWithin equals iteratedDeriv for ContDiff functions.

        theorem LeanCert.Core.iteratedDerivWithin_Icc_left_eq_iteratedDeriv_of_isOpen {f : } {c x : } {n : } {U : Set } (hU_open : IsOpen U) (hcU : c U) (hcx : c < x) (hI_sub : Set.Icc c x U) (hf : ContDiffOn (↑n) f U) :

        At the left endpoint of [c, x], iteratedDerivWithin equals iteratedDeriv for functions that are ContDiffOn on an open set containing c.

        This is useful for functions like log that are only smooth on (0, ∞).

        theorem LeanCert.Core.taylor_remainder_bound_on_c_lt_x {f : } {a b c : } {m : } {M : } {U : Set } (hU_open : IsOpen U) (hI_sub : Set.Icc a b U) (hca : a c) (hf : ContDiffOn (m + 1) f U) (hM : ySet.Icc a b, iteratedDeriv (m + 1) f y M) (x : ) (hx : x Set.Icc a b) (hcx : c < x) :
        f x - iFinset.range (m + 1), iteratedDeriv i f c / i.factorial * (x - c) ^ i M * |x - c| ^ (m + 1) / (m + 1).factorial

        Taylor remainder bound for c < x case with ContDiffOn hypothesis.

        For functions that are ContDiffOn on an open set containing [a, b], this provides the same Lagrange remainder bound as the global ContDiff version.

        theorem LeanCert.Core.iteratedDeriv_reflect_of_contDiffOn {f : } {c : } {n : } {U : Set } (hU_open : IsOpen U) (hf : ContDiffOn (↑n) f U) (t : ) (ht : 2 * c - t U) :
        iteratedDeriv n (fun (s : ) => f (2 * c - s)) t = (-1) ^ n * iteratedDeriv n f (2 * c - t)

        Key lemma for reflection: derivatives of g(t) = f(2c - t) when f is smooth on an open set.

        This is a local version of iteratedDeriv_reflect that works with ContDiffOn on an open set rather than global ContDiff.

        theorem LeanCert.Core.taylor_remainder_bound_on_x_lt_c {f : } {a b c : } {m : } {M : } {U : Set } (hU_open : IsOpen U) (hI_sub : Set.Icc a b U) (hcb : c b) (hf : ContDiffOn (m + 1) f U) (hM : ySet.Icc a b, iteratedDeriv (m + 1) f y M) (x : ) (hx : x Set.Icc a b) (hxc : x < c) :
        f x - iFinset.range (m + 1), iteratedDeriv i f c / i.factorial * (x - c) ^ i M * |x - c| ^ (m + 1) / (m + 1).factorial

        Taylor remainder bound for x < c case with ContDiffOn hypothesis.

        For functions that are ContDiffOn on an open set containing [a, b], this provides the same Lagrange remainder bound as the global ContDiff version.

        The proof uses reflection: define g(t) = f(2c - t), apply Lagrange to g on [c, 2c-x], then convert back.

        theorem LeanCert.Core.taylor_remainder_bound_on {f : } {a b c : } {n : } {M : } {U : Set } (hU_open : IsOpen U) (hI_sub : Set.Icc a b U) (hca : a c) (hcb : c b) (hf : ContDiffOn (↑n) f U) (hM : xSet.Icc a b, iteratedDeriv n f x M) (_hMnonneg : 0 M) (x : ) :
        x Set.Icc a bf x - iFinset.range n, iteratedDeriv i f c / i.factorial * (x - c) ^ i M * |x - c| ^ n / n.factorial

        Combined Taylor remainder bound with ContDiffOn hypothesis.

        For functions that are ContDiffOn on an open set containing [a, b], this provides the Lagrange remainder bound for any x ∈ [a, b] and center c ∈ [a, b].

        theorem LeanCert.Core.iteratedDeriv_reflect {f : } {c : } {n : } (hf : ContDiff (↑n) f) (t : ) :
        iteratedDeriv n (fun (s : ) => f (2 * c - s)) t = (-1) ^ n * iteratedDeriv n f (2 * c - t)

        Key lemma: derivatives of reflected function g(t) = f(2c - t).

        For the x < c case, we use reflection: define g(t) = f(2c - t), apply Lagrange to g on [c, 2c-x], then convert back. This lemma shows how g's derivatives relate to f's derivatives.

        theorem LeanCert.Core.neg_one_pow_mul_self (n : ) :
        (-1) ^ n * (-1) ^ n = 1

        Auxiliary lemma: (-1)^n * (-1)^n = 1 for any natural n.

        theorem LeanCert.Core.taylor_remainder_bound_c_lt_x {f : } {a b c : } {m : } {M : } (hca : a c) (hf : ContDiff (m + 1) f) (hM : ySet.Icc a b, iteratedDeriv (m + 1) f y M) (x : ) (hx : x Set.Icc a b) (hcx : c < x) :
        f x - iFinset.range (m + 1), iteratedDeriv i f c / i.factorial * (x - c) ^ i M * |x - c| ^ (m + 1) / (m + 1).factorial

        Taylor remainder bound for c < x case (Lagrange form).

        For c < x, we apply taylor_mean_remainder_lagrange on [c, x] and convert iteratedDerivWithin to iteratedDeriv using the helper lemmas above.

        theorem LeanCert.Core.taylor_remainder_bound_x_lt_c {f : } {a b c : } {m : } {M : } (hcb : c b) (hf : ContDiff (m + 1) f) (hM : ySet.Icc a b, iteratedDeriv (m + 1) f y M) (x : ) (hx : x Set.Icc a b) (hxc : x < c) :
        f x - iFinset.range (m + 1), iteratedDeriv i f c / i.factorial * (x - c) ^ i M * |x - c| ^ (m + 1) / (m + 1).factorial

        Taylor remainder bound for x < c case (Lagrange form via reflection).

        For x < c, we define g(t) = f(2c - t), apply taylor_mean_remainder_lagrange on [c, 2c-x], then use iteratedDeriv_reflect to convert back to f's derivatives. The key insight is that g's Taylor expansion at c, evaluated at 2c-x, equals f's Taylor expansion at c, evaluated at x, because the (-1)^i factors from the derivatives cancel with the (-1)^i factors from the powers.

        theorem LeanCert.Core.taylor_remainder_bound {f : } {a b c : } {n : } {M : } (_hab : a b) (hca : a c) (hcb : c b) (hf : ContDiff (↑n) f) (hM : xSet.Icc a b, iteratedDeriv n f x M) (_hMnonneg : 0 M) (x : ) :
        x Set.Icc a bf x - iFinset.range n, iteratedDeriv i f c / i.factorial * (x - c) ^ i M * |x - c| ^ n / n.factorial

        Lagrange form remainder bound for Taylor approximation.

        If |f^(n)(x)| ≤ M for all x in [a, b], and c ∈ [a, b], then the Taylor polynomial of degree n-1 (sum over range n) satisfies: for any x ∈ [a, b]: |f(x) - T_{n-1}(x; c)| ≤ M * |x - c|^n / n!

        Note: The sum ∑ i ∈ Finset.range n gives terms 0..n-1 (degree n-1 polynomial). The remainder involves the n-th derivative, matching our bound on iteratedDeriv n f.

        All cases are fully proved:

        Common Taylor expansions #

        Taylor coefficients for exp at 0: 1/n!

        Equations
        Instances For

          Taylor coefficients for sin at 0

          Equations
          Instances For

            Taylor coefficients for cos at 0

            Equations
            Instances For

              Derivative bounds for common functions #

              theorem LeanCert.Core.exp_deriv_bound {a b : } (_hab : a b) (n : ) (x : ) :

              All derivatives of exp are bounded by exp on any bounded interval

              All derivatives of sin and cos are bounded by 1. The derivatives cycle: sin → cos → -sin → -cos → sin → ...

              cosh x ≤ exp |x| for all x

              |sinh x| ≤ cosh x for all x

              All derivatives of sinh and cosh are bounded by exp(max(|a|, |b|)) on [a, b]. The derivatives cycle: sinh → cosh → sinh → cosh → ...

              theorem LeanCert.Core.iteratedDeriv_log {n : } (hn : n 0) {x : } (hx : 0 < x) :
              iteratedDeriv n Real.log x = (-1) ^ (n - 1) * (n - 1).factorial * x ^ (-n)