Documentation

LeanCert.Engine.IntervalEvalDyadic

High-Performance Dyadic Interval Evaluator #

This evaluator replaces Rat with Dyadic to prevent denominator explosion. It is designed for complex expressions where the standard evaluator becomes slow.

Main definitions #

Performance #

In v1.0, every Rat multiplication required GCD normalization. For deep expressions (e.g., Taylor series with 20+ terms, or optimization with 100+ iterations), denominators grow exponentially, causing timeouts.

In v1.1, Dyadic arithmetic uses bit-shifts instead of GCD. With roundOut, we can enforce a maximum precision after each operation, keeping computation bounded regardless of expression depth.

Example #

Consider computing sin(sin(sin(x))) with 15-term Taylor series:

Design notes #

For transcendental functions (sin, cos, exp), we delegate to the existing IntervalRat implementation with Taylor series, then convert the result to IntervalDyadic with outward rounding. This reuses verified code while gaining the performance benefits of Dyadic for polynomial operations.

Configuration #

Configuration for Dyadic interval evaluation.

  • precision - Minimum exponent for outward rounding. A value of -53 gives IEEE double-like precision (~15 decimal digits). Use -100 for higher precision.
  • taylorDepth - Number of Taylor terms for transcendental functions.
  • precision : ℤ

    Minimum exponent (higher = coarser). -53 ≈ IEEE double precision.

  • taylorDepth : ℕ

    Number of Taylor series terms for transcendental functions

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

        Default configuration with IEEE double-like precision

        Equations

        High-precision configuration for critical calculations

        Equations
        Instances For

          Fast configuration for rapid evaluation (lower precision)

          Equations
          Instances For

            Variable Environment #

            @[reducible, inline]

            Variable assignment as Dyadic intervals

            Equations
            Instances For

              Convert a rational interval environment to Dyadic

              Equations
              Instances For

                Transcendental Function Wrappers #

                sqrt interval: uses conservative bound [0, max(hi, 1)]

                Equations
                Instances For

                  log interval: conservative global bound. For any x > 0, log(x) ∈ (-∞, ∞), but we use a finite interval. For x ∈ [lo, hi] with lo > 0:

                  • log is monotone, so log(x) ∈ [log(lo), log(hi)]
                  • Legacy total-evaluator fallback; strict callers reject this domain
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Real power from a cached logarithm interval.

                    If Real.log x ∈ logBase, this computes an interval for x ^ (p : ℝ) as exp(p * log x) without recomputing log x. This is the hot-path primitive for cached finite sums with many terms of the form x ^ q_k.

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

                      Real power x^p for x > 0 and rational p, computed via exp(p * log(x)).

                      For x ∈ [lo, hi] with lo > 0 and rational exponent p:

                      • x^p = exp(p * log(x))
                      • We compute log(x), multiply by p, then apply exp

                      This is the key operation for BKLNW-style sums where terms are x^(1/k - 1/3).

                      Equations
                      Instances For
                        theorem LeanCert.Engine.mem_rpowFromCachedLogDyadic {x : ℝ} {logBase : Core.IntervalDyadic} (hlog : Real.log x ∈ logBase) (hx_pos : 0 < x) (p : ℚ) (cfg : DyadicConfig) (hprec : cfg.precision ≤ 0 := by norm_num) :
                        x ^ ↑p ∈ rpowFromCachedLogDyadic logBase p cfg

                        Correctness of rpowFromCachedLogDyadic: a cached interval containing Real.log x is enough to enclose x ^ p.

                        theorem LeanCert.Engine.mem_rpowIntervalDyadic {x : ℝ} {base : Core.IntervalDyadic} (hx : x ∈ base) (hpos : base.toIntervalRat.lo > 0) (p : ℚ) (cfg : DyadicConfig) (hprec : cfg.precision ≤ 0 := by norm_num) :
                        x ^ ↑p ∈ rpowIntervalDyadic base p cfg

                        Correctness of rpowIntervalDyadic: if x ∈ base and base.lo > 0, then x^p ∈ result

                        Main Evaluator #

                        High-performance Dyadic interval evaluator.

                        This is the core function for v1.1. It evaluates expressions using Dyadic arithmetic for polynomial operations (add, mul, neg) and delegates to rational Taylor series for transcendentals.

                        Returns an interval guaranteed to contain all possible values of the expression when ExprSupportedCore holds. For other expressions, it computes conservative fallbacks (e.g., inv/log), but the core correctness theorem does not apply.

                        Equations
                        Instances For

                          Correctness #

                          def LeanCert.Engine.envMemDyadic (ρ_real : ℕ → ℝ) (ρ_dyad : IntervalDyadicEnv) :

                          A real environment is contained in a Dyadic interval environment

                          Equations
                          Instances For

                            Domain validity for Dyadic evaluation. This is defined directly in terms of LeanCert.Internal.Dyadic.evalUnchecked to ensure compatibility. For log, we require the argument interval (converted to Rat) to have positive lower bound.

                            Equations
                            Instances For

                              Computable (Bool) domain validity check for Dyadic evaluation.

                              Equations
                              Instances For

                                Static data prepared once for repeated Dyadic evaluation.

                                The context is operation-independent: logarithm, exponential, trigonometric, and inverse-hyperbolic kernels share certified constants and coefficient families without changing the public evaluator configuration.

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

                                    Deterministically prepare all configuration-dependent numerical data.

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

                                      Logarithm kernel using the context's prepared certified constants.

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

                                        Inverse-hyperbolic-tangent kernel using prepared Taylor coefficients.

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

                                          Evaluate an expression and its domain-validity bit in one traversal. The value component is exactly LeanCert.Internal.Dyadic.evalUnchecked; the validity component is exactly checkDomainValidDyadic.

                                          Equations
                                          Instances For
                                            @[irreducible]

                                            Diagnose the first failed Dyadic domain check.

                                            Equations
                                            Instances For

                                              Checked Dyadic evaluator. The finite fallback branches of the legacy total evaluator are never exposed after a failed domain check.

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

                                                Domain validity is trivially true for ADSupported expressions (which exclude log).

                                                theorem LeanCert.Engine.evalIntervalDyadic_correct (e : Core.Expr) (hsupp : ExprSupportedCore e) (ρ_real : ℕ → ℝ) (ρ_dyad : IntervalDyadicEnv) (hρ : envMemDyadic ρ_real ρ_dyad) (cfg : DyadicConfig := { }) (hprec : cfg.precision ≤ 0 := by norm_num) (hdom : evalDomainValidDyadic e ρ_dyad cfg) :

                                                Fundamental correctness theorem for Dyadic evaluation.

                                                This theorem states that for any supported expression and any real values within the input intervals, the result of evaluating the expression is contained in the computed Dyadic interval.

                                                The proof follows the same structure as evalIntervalCore_correct, but with additional steps for handling Dyadic ↔ Rat conversions and rounding. Requires cfg.precision ≤ 0 (the default -53 satisfies this).

                                                Note: Requires domain validity for log (positive argument interval).

                                                theorem LeanCert.Engine.evalIntervalDyadic_correct_of_domain (e : Core.Expr) (ρ_real : ℕ → ℝ) (ρ_dyad : IntervalDyadicEnv) (hρ : envMemDyadic ρ_real ρ_dyad) (cfg : DyadicConfig := { }) (hprec : cfg.precision ≤ 0 := by norm_num) (hdom : evalDomainValidDyadic e ρ_dyad cfg) :

                                                Correctness of Dyadic evaluation for every expression whose recursively checked domain conditions hold.

                                                theorem LeanCert.Engine.evalIntervalDyadicChecked_correct (e : Core.Expr) (ρ_real : ℕ → ℝ) (ρ_dyad : IntervalDyadicEnv) (hρ : envMemDyadic ρ_real ρ_dyad) (cfg : DyadicConfig := { }) (hprec : cfg.precision ≤ 0 := by norm_num) (result : Core.IntervalDyadic) (hsuccess : evalIntervalDyadicChecked e ρ_dyad cfg = Except.ok result) :
                                                Core.Expr.eval ρ_real e ∈ result

                                                Successful checked Dyadic evaluation encloses the true value for every expression, provided outward-rounding precision is nonpositive.

                                                Verification Checkers #

                                                Check if expression is bounded above by q

                                                Equations
                                                Instances For

                                                  Check if expression is bounded below by q

                                                  Equations
                                                  Instances For

                                                    Check if expression is bounded in interval [lo, hi]

                                                    Equations
                                                    Instances For