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.
  • roundAfterOps - Round after this many operations (0 = after every op).
  • precision :

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

  • taylorDepth :

    Number of Taylor series terms for transcendental functions

  • roundAfterOps :

    Round after this many arithmetic operations (0 = always)

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

        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)]
                  • Conservative bound: use [-100, max(hi, 1)] as a wide safe interval
                  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
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      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 evalIntervalDyadic 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

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

                              theorem LeanCert.Engine.evalIntervalDyadic_correct (e : Core.Expr) (hsupp : ExprSupportedCore e) (ρ_real : ) (ρ_dyad : IntervalDyadicEnv) ( : envMemDyadic ρ_real ρ_dyad) (cfg : DyadicConfig := { }) (hprec : cfg.precision 0 := by norm_num) (hdom : evalDomainValidDyadic e ρ_dyad cfg) :
                              Core.Expr.eval ρ_real e evalIntervalDyadic 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_withInv (e : Core.Expr) (hsupp : ExprSupportedWithInv e) (ρ_real : ) (ρ_dyad : IntervalDyadicEnv) ( : envMemDyadic ρ_real ρ_dyad) (cfg : DyadicConfig := { }) (hprec : cfg.precision 0 := by norm_num) (hdom : evalDomainValidDyadic e ρ_dyad cfg) :
                              Core.Expr.eval ρ_real e evalIntervalDyadic e ρ_dyad cfg

                              Correctness theorem for Dyadic evaluation with ExprSupportedWithInv.

                              Extends evalIntervalDyadic_correct to handle inv (and delegates to it for all ExprSupportedCore cases). Requires the inv argument interval to be bounded away from zero.

                              Convenience Functions #

                              Evaluate with standard (double-like) precision

                              Equations
                              Instances For

                                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