Documentation

LeanCert.Core.IntervalRat.Taylor

Rational Endpoint Intervals - Computable Taylor Series #

This file provides computable interval enclosures for transcendental functions using Taylor series with rational coefficients and rigorous remainder bounds.

Main definitions #

Main theorems #

Design notes #

All definitions in this file use only rational arithmetic and are fully computable. The proofs connect these to the real-valued functions via Taylor's theorem.

Computable Taylor series helpers #

Compute n! as a Rational

Equations
Instances For

    Compute the integer power of an interval using repeated multiplication. This is a simple but correct implementation.

    Equations
    Instances For

      Compute the absolute value interval: |I| = [0, max(|lo|, |hi|)] if 0 ∈ I, or [min(|lo|,|hi|), max(|lo|,|hi|)] otherwise

      Equations
      Instances For

        Maximum absolute value of an interval

        Equations
        Instances For

          Evaluate Taylor series ∑_{i=0}^{n} c_i * x^i at interval I. Uses direct interval arithmetic with incremental powers to avoid recomputing I^i from scratch for each coefficient.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            Computable exp via Taylor series #

            Taylor coefficients for exp: 1/i! for i = 0, 1, ..., n. Implemented iteratively to avoid repeated factorial recomputation.

            Equations
            Instances For

              Computable exp remainder bound using rational arithmetic. The Lagrange remainder is exp(ξ) * x^{n+1} / (n+1)! where ξ is between 0 and x. We use e < 3, so e^r ≤ 3^(⌈r⌉+1) as a conservative bound.

              Returns an interval [-R, R] where R bounds the remainder.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For

                Computable interval enclosure for exp at a single rational point. Uses argument reduction: exp(q) = exp(q/2^k)^(2^k).

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  Hull of two intervals: smallest interval containing both.

                  Equations
                  Instances For
                    theorem LeanCert.Core.IntervalRat.mem_hull_left {x : } {I J : IntervalRat} (hx : x I) :
                    x I.hull J

                    Membership in hull

                    Computable interval enclosure for exp using Taylor series with monotonicity optimization.

                    exp(x) = ∑_{i=0}^{n} x^i/i! + R where |R| ≤ exp(|x|) * |x|^{n+1} / (n+1)!

                    For intervals not crossing 0, we use endpoint evaluation and take the hull, which is tighter than direct Taylor evaluation due to interval widening.

                    This is fully computable using only rational arithmetic.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      Computable sin via Taylor series #

                      Taylor coefficients for sin: 0, 1, 0, -1/6, 0, 1/120, ...

                      Equations
                      Instances For

                        Computable sin remainder bound. Since |sin^{(k)}(x)| ≤ 1 for all k, x, the remainder is bounded by |x|^{n+1}/(n+1)!

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Computable interval enclosure for sin using Taylor series.

                          sin(x) = ∑_{k=0}^{n/2} (-1)^k x^{2k+1}/(2k+1)! + R where |R| ≤ |x|^{n+1}/(n+1)! since all derivatives of sin are bounded by 1.

                          We intersect with [-1, 1] for tighter bounds on small intervals.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            Computable cos via Taylor series #

                            Taylor coefficients for cos: 1, 0, -1/2, 0, 1/24, 0, ...

                            Equations
                            Instances For

                              Computable cos remainder bound. Since |cos^{(k)}(x)| ≤ 1 for all k, x, the remainder is bounded by |x|^{n+1}/(n+1)!

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For

                                Computable interval enclosure for cos using Taylor series.

                                cos(x) = ∑_{k=0}^{n/2} (-1)^k x^{2k}/(2k)! + R where |R| ≤ |x|^{n+1}/(n+1)! since all derivatives of cos are bounded by 1.

                                We intersect with [-1, 1] for tighter bounds on small intervals.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For

                                  Computable sinh and cosh via exp #

                                  Computable interval enclosure for sinh at a single rational point. Uses the definition sinh(q) = (exp(q) - exp(-q)) / 2.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    Computable interval enclosure for cosh at a single rational point. Uses the definition cosh(q) = (exp(q) + exp(-q)) / 2.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For

                                      The lower bound of coshPointComputable is always at least 1.

                                      Computable interval enclosure for sinh using exp with endpoint evaluation.

                                      sinh(x) = (exp(x) - exp(-x)) / 2 Since sinh is strictly monotone increasing, sinh([a,b]) = [sinh(a), sinh(b)]. We use endpoint evaluation for tight bounds.

                                      Equations
                                      Instances For

                                        Computable interval enclosure for cosh using exp with endpoint evaluation.

                                        cosh(x) = (exp(x) + exp(-x)) / 2 cosh has minimum 1 at x = 0, and is symmetric: cosh(-x) = cosh(x).

                                        • cosh is decreasing on (-∞, 0]
                                        • cosh is increasing on [0, ∞)

                                        We use endpoint evaluation with monotonicity for tight bounds.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For

                                          FTIA for pow #

                                          theorem LeanCert.Core.IntervalRat.mem_pow {x : } {I : IntervalRat} (hx : x I) (n : ) :
                                          x ^ n I.pow n

                                          FTIA for interval power

                                          Helper lemmas for Taylor series membership #

                                          Any x in I has |x| ≤ maxAbs I

                                          theorem LeanCert.Core.IntervalRat.abs_le_mem_symmetric_interval {x : } {R : } (hR : 0 R) (h : |x| R) :
                                          x { lo := -R, hi := R, le := }

                                          If |x| ≤ R for nonnegative R, then x ∈ [-R, R]. This is the key micro-lemma for embedding Lagrange remainder bounds into intervals.

                                          theorem LeanCert.Core.IntervalRat.domain_from_abs_bound {x : } {r : } (_hr : 0 r) (habs : |x| r) :
                                          x Set.Icc ↑(-r) r

                                          Domain setup for Taylor theorem: if |x| ≤ r for nonnegative r, then x ∈ [-r, r] as an Icc with the required inequalities.

                                          theorem LeanCert.Core.IntervalRat.domain_from_mem {x : } {I : IntervalRat} (hx : x I) :
                                          have r := I.maxAbs; 0 r |x| r x Set.Icc ↑(-r) r ↑(-r) 0 0 r ↑(-r) r

                                          Combined domain setup from interval membership.

                                          theorem LeanCert.Core.IntervalRat.remainder_to_interval {v : } {R : } (hbound : |v| R) :
                                          v { lo := -R, hi := R, le := }

                                          Convert an absolute value bound |v| ≤ R to interval membership v ∈ [-R, R]. This is the key micro-lemma for the final step of Taylor remainder bounds.

                                          theorem LeanCert.Core.IntervalRat.exp_bound_by_pow3 {r : } (_hr : 0 r) {ξ : } ( : |ξ| r) :

                                          Key lemma: exp(ξ) ≤ 3^(⌈r⌉+1) for |ξ| ≤ r

                                          Coefficient matching lemmas #

                                          For exp, all iterated derivatives at 0 equal 1.

                                          Helper lemmas for Taylor series membership #

                                          theorem LeanCert.Core.IntervalRat.mem_evalTaylorSeries {x : } {I : IntervalRat} (hx : x I) (coeffs : List ) :
                                          (List.map (fun (x_1 : × ) => match x_1 with | (c, i) => c * x ^ i) coeffs.zipIdx).sum evalTaylorSeries coeffs I

                                          General FTIA for evalTaylorSeries: if coeffs has length n+1, then ∑_{i=0}^{n} coeffs[i] * x^i ∈ evalTaylorSeries coeffs I for x ∈ I.

                                          The exp Taylor polynomial value matches our evalTaylorSeries. The proof shows that our list-based polynomial evaluation produces the same sum as the Finset.sum form used in Mathlib's Taylor theorem.

                                          The sin Taylor polynomial value matches our evalTaylorSeries. Key: iteratedDeriv i sin 0 = 0, 1, 0, -1, 0, 1, ... matches sinTaylorCoeffs.

                                          The cos Taylor polynomial value matches our evalTaylorSeries. Key: iteratedDeriv i cos 0 = 1, 0, -1, 0, 1, 0, ... matches cosTaylorCoeffs.

                                          Taylor remainder micro-lemmas #

                                          Unified Taylor remainder bound for exp: given x ∈ I with r = maxAbs I, the Taylor remainder |exp x - poly(x)| ≤ 3^(⌈r⌉+1) * r^(n+1) / (n+1)!. This encapsulates the domain setup and remainder calculation.

                                          Unified Taylor remainder bound for sin: given x ∈ I with r = maxAbs I, the Taylor remainder |sin x - poly(x)| ≤ r^(n+1) / (n+1)!. Uses the fact that |sin^(k)(x)| ≤ 1 for all k, x.

                                          Unified Taylor remainder bound for cos: given x ∈ I with r = maxAbs I, the Taylor remainder |cos x - poly(x)| ≤ r^(n+1) / (n+1)!. Uses the fact that |cos^(k)(x)| ≤ 1 for all k, x.

                                          FTIA for computable functions #

                                          FTIA for single-point exp: Real.exp q ∈ expPointComputable q n

                                          FTIA for sinComputable: Real.sin x ∈ sinComputable I n for any x ∈ I.

                                          The proof uses the Taylor remainder micro-lemma and the global bound sin ∈ [-1, 1].

                                          FTIA for cosComputable: Real.cos x ∈ cosComputable I n for any x ∈ I.

                                          The proof uses the Taylor remainder micro-lemma and the global bound cos ∈ [-1, 1].

                                          FTIA for sinhPointComputable: Real.sinh q ∈ sinhPointComputable q n

                                          FTIA for coshPointComputable: Real.cosh q ∈ coshPointComputable q n

                                          FTIA for sinhComputable: Real.sinh x ∈ sinhComputable I n for any x ∈ I.

                                          Uses endpoint evaluation and monotonicity of sinh.

                                          FTIA for coshComputable: Real.cosh x ∈ coshComputable I n for any x ∈ I.

                                          Uses endpoint evaluation and monotonicity properties of cosh.

                                          Computable atanh via Taylor series #

                                          For |y| < 1, atanh(y) = y + y³/3 + y⁵/5 + ... We compute this series for y ∈ [-1/3, 1/3] where it converges rapidly.

                                          Taylor coefficients for atanh: 0, 1, 0, 1/3, 0, 1/5, ... atanh(y) = Σ y^(2k+1)/(2k+1) = y + y³/3 + y⁵/5 + ...

                                          Equations
                                          Instances For

                                            Computable atanh remainder bound. For |y| ≤ r < 1, the remainder after n terms is bounded by r^(n+1)/(1 - r²). We use a conservative bound: r^(n+1) / ((n+1) * (1 - r)) for simplicity.

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For

                                              Computable interval enclosure for atanh at a single rational point. Requires |q| < 1 for convergence. For |q| ≤ 1/3, this is very accurate.

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For
                                                theorem LeanCert.Core.IntervalRat.Real.atanh_hasSum' {x : } (hx : |x| < 1) :
                                                HasSum (fun (k : ) => x ^ (2 * k + 1) / (2 * k + 1)) (Real.atanh x)

                                                The atanh series: atanh(x) = Σ_{k=0}^∞ x^(2k+1)/(2k+1) for |x| < 1. Derived from Mathlib's hasSum_log_sub_log_of_abs_lt_one.

                                                The atanh Taylor polynomial membership: the partial sum of atanh coefficients at q is in evalTaylorSeries (atanhTaylorCoeffs n) (singleton q).

                                                theorem LeanCert.Core.IntervalRat.atanh_taylor_remainder_in_interval {q : } (hq : |q| < 1) (n : ) :
                                                Real.atanh q - (List.map (fun (x : × ) => match x with | (c, i) => c * q ^ i) (atanhTaylorCoeffs n).zipIdx).sum atanhRemainderBoundComputable |q| n

                                                The atanh Taylor remainder bound: for |q| < 1, the remainder after n terms is bounded. The remainder is |Σ_{k: 2k+1 > n} q^(2k+1)/(2k+1)| ≤ |q|^(n+1)/(1-|q|).

                                                FTIA for atanhPointComputable: Real.atanh q ∈ atanhPointComputable q n for |q| < 1.

                                                Computable ln(2) via atanh #

                                                ln(2) = 2 * atanh(1/3), since: 2 = (1 + 1/3) / (1 - 1/3) = (4/3) / (2/3) So atanh(1/3) = (1/2) * ln(2), giving ln(2) = 2 * atanh(1/3)

                                                Compute ln(2) as an interval using 2 * atanh(1/3). This converges rapidly since atanh series at 1/3 has |y| = 1/3.

                                                Equations
                                                Instances For

                                                  FTIA for ln2Computable: Real.log 2 ∈ ln2Computable n. Uses the identity log(2) = 2 * atanh(1/3) from log_via_atanh.

                                                  Computable log via argument reduction #

                                                  For q > 0, we compute:

                                                  1. Reduce q to m * 2^k where m ∈ [1/2, 2]
                                                  2. Compute log(m) = 2 * atanh((m-1)/(m+1)), which has |arg| ≤ 1/3
                                                  3. Result = log(m) + k * ln(2)

                                                  Reduction exponent k such that q * 2^(-k) ≈ 1

                                                  Equations
                                                  Instances For

                                                    Computable log at a single rational point q > 0. Returns log(q) = log(m) + k * ln(2) where m = q * 2^(-k).

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For

                                                      Computable interval enclosure for log using endpoint evaluation. Since log is strictly increasing on (0, ∞), we evaluate at endpoints.

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For

                                                        FTIA for logPointComputable

                                                        theorem LeanCert.Core.IntervalRat.mem_logComputable {x : } {I : IntervalRat} (hx : x I) (hpos : 0 < I.lo) (n : ) :

                                                        FTIA for logComputable: if x ∈ I and I.lo > 0, then log(x) ∈ logComputable I n

                                                        theorem LeanCert.Core.IntervalRat.mem_logComputable' {x : } {I : IntervalRat} (hx : x I) (hpos : 0 < I.lo) (n : ) :

                                                        Conditional version of mem_logComputable for use in correctness proofs. Requires I.lo > 0 so the log interval is well-defined and monotone.

                                                        Computable erf via Taylor series #

                                                        Interval containing 2/√π ≈ 1.128379... Used for erf calculations. 2/√π is in (1.128, 1.129).

                                                        Equations
                                                        Instances For

                                                          Taylor coefficients for erf (without the 2/√π factor): erf(x) = (2/√π) * Σ_{n=0}^∞ (-1)^n * x^(2n+1) / (n! * (2n+1))

                                                          So the coefficient of x^k is:

                                                          • 0 if k is even
                                                          • (-1)^((k-1)/2) / (((k-1)/2)! * k) if k is odd
                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For

                                                            Computable erf remainder bound. Since |erf^{(k)}(x)| ≤ (2/√π) * 2^k for all x (rough bound), and erf is bounded by 1, we use a combination.

                                                            For the Taylor remainder centered at 0, we use: |R_n(x)| ≤ sup|f^{(n+1)}(ξ)| * |x|^{n+1} / (n+1)!

                                                            A conservative bound: |erf^{(k)}(x)| ≤ (2/√π) * k! / (k/2)! ≤ 2 * k^{k/2} But since |erf| ≤ 1, we can intersect with [-1, 1].

                                                            We use: remainder ≤ 2 * |x|^{n+1} / (n+1)! (very conservative).

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              Computable interval enclosure for erf at a single rational point. Uses sign-aware global bounds:

                                                              • q < 0 => erf(q) ∈ [-1, 0]
                                                              • q = 0 => erf(q) = 0
                                                              • q > 0 => erf(q) ∈ [0, 1]
                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For

                                                                Computable interval enclosure for erf using Taylor series with monotonicity.

                                                                erf(x) = (2/√π) * Σ_{n=0}^∞ (-1)^n * x^(2n+1) / (n! * (2n+1))

                                                                Since erf is strictly monotone increasing (erf'(x) = (2/√π)e^{-x²} > 0), we use endpoint evaluation: erf([a,b]) ⊆ [erf(a), erf(b)].

                                                                We intersect with [-1, 1] for safety.

                                                                Instances For

                                                                  2/√π is in the interval two_div_sqrt_pi. 2/√π ≈ 1.1283791670955126, which is in (1.128, 1.129).

                                                                  This is a helper theorem for correctness proofs. The computation of erfComputable is independent of this theorem.

                                                                  noncomputable def LeanCert.Core.IntervalRat.erfInner (x : ) :

                                                                  The "inner" erf function without the 2/√π factor: erfInner(x) = ∫₀ˣ exp(-t²) dt = (√π/2) * erf(x)

                                                                  This is the function whose Taylor series coefficients are erfTaylorCoeffs.

                                                                  Equations
                                                                  Instances For

                                                                    erf(x) = (2/√π) * erfInner(x)

                                                                    The derivatives of erfInner(x) = ∫₀ˣ exp(-t²) dt. erfInner'(x) = exp(-x²) erfInner''(x) = -2x * exp(-x²) etc.

                                                                    exp(-x²) is smooth.

                                                                    exp(-x²) is analytic everywhere.

                                                                    exp(-x²) is analytic on ℝ.

                                                                    Computable atanh interval via endpoint evaluation #

                                                                    Computable interval enclosure for atanh using endpoint evaluation. Since atanh is strictly increasing on (-1, 1), we evaluate at endpoints. Requires the interval to be strictly inside (-1, 1); returns a wide fallback otherwise.

                                                                    Equations
                                                                    • One or more equations did not get rendered due to their size.
                                                                    Instances For
                                                                      theorem LeanCert.Core.IntervalRat.mem_atanhComputable {x : } {I : IntervalRat} (hx : x I) (hlo : -1 < I.lo) (hhi : I.hi < 1) (n : ) :

                                                                      FTIA for atanhComputable: if x ∈ I and I ⊂ (-1, 1), then atanh(x) ∈ atanhComputable I n.