Documentation

LeanCert.Engine.Eval.Core

Computable Interval Evaluation #

This file implements the computable interval evaluator for LeanCert.Core.Expr. Given an expression and intervals for its variables, we compute an interval guaranteed to contain all possible values.

Main definitions #

Design notes #

This evaluator is COMPUTABLE, allowing use of native_decide for bound checking in tactics. The transcendental functions (exp, sin, cos) use Taylor series with configurable depth for precision control.

For inv: computes bounds using invInterval, but correctness is not covered by evalIntervalCore_correct. Use evalInterval? for inv.

Interval bounds for transcendental functions #

Simple interval bound for sin. Since |sin x| ≤ 1 for all x, we use the global bound [-1, 1]. This is sound but not tight.

Equations
Instances For

    Correctness of sin interval: sin x ∈ [-1, 1] for all x

    Simple interval bound for cos. Since |cos x| ≤ 1 for all x, we use the global bound [-1, 1]. This is sound but not tight.

    Equations
    Instances For

      Correctness of cos interval: cos x ∈ [-1, 1] for all x

      Simple interval bound for atan. Since atan x ∈ (-π/2, π/2) for all x, we use the global bound [-2, 2]. This is sound but not tight (π/2 ≈ 1.57).

      Equations
      Instances For

        Correctness of atan interval: arctan x ∈ [-2, 2] for all x

        Interval bound for erf using computable Taylor series. erf(x) = (2/√π) * ∫₀ˣ exp(-t²) dt, strictly monotone increasing. This computes tight bounds using verified Taylor series.

        Equations
        Instances For

          erf is strictly monotone increasing. Proof: erf'(x) = (2/√π) * exp(-x²) > 0 for all x.

          We use that for a < b, the integral ∫_{a}^{b} exp(-t²) dt > 0 since the integrand is strictly positive.

          Correctness of erfPointComputable. The enclosure is sign-aware and uses monotonicity of erf with erf(0)=0.

          theorem LeanCert.Engine.mem_erfInterval {x : } {I : Core.IntervalRat} (hx : x I) (n : := 15) :

          Correctness of erf interval using monotonicity and endpoint evaluation.

          Since erf is strictly monotone increasing:

          • For x ∈ [I.lo, I.hi], we have erf(I.lo) ≤ erf(x) ≤ erf(I.hi)
          • erfPointComputable(I.lo) contains erf(I.lo)
          • erfPointComputable(I.hi) contains erf(I.hi)
          • hull of these intervals contains [erf(I.lo), erf(I.hi)]
          • Therefore erf(x) ∈ hull(...) ∩ [-1, 1]

          Simple interval bound for arsinh. arsinh is unbounded, so we use a very rough linear bound. We use max(|lo|, |hi|) + 1 as a safe bound that always works.

          Equations
          Instances For

            Correctness of arsinh interval. Uses the bound |arsinh x| ≤ |x| for all x (from IntervalRealEndpoints).

            Interval bound for atanh. atanh is defined for (-1, 1). If interval is within this range, we compute tight bounds using monotonicity. Otherwise returns default.

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

              Correctness of atanh interval: when x ∈ I and I ⊂ (-1, 1), atanh(x) ∈ atanhInterval I.

              Tight interval bound for tanh. Since tanh(x) ∈ (-1, 1) for all x ∈ ℝ, we use the global bound [-1, 1]. This avoids the interval explosion that occurs when desugaring to exp.

              Equations
              Instances For

                Correctness of tanh interval: tanh x ∈ [-1, 1] for all x

                Interval enclosure for π. Uses tight bounds from Mathlib's pi_gt_d20 and pi_lt_d20 which give 20 decimal digits. 3.14159265358979323846 < π < 3.14159265358979323847

                Equations
                Instances For

                  Correctness of pi interval: Real.pi ∈ piInterval

                  Interval bound for sinh using computable Taylor series for exp. sinh(x) = (exp(x) - exp(-x)) / 2, and sinh is strictly monotonic. This computes tight bounds using the verified exp implementation.

                  Equations
                  Instances For

                    Interval bound for cosh using computable Taylor series for exp. cosh(x) = (exp(x) + exp(-x)) / 2, with minimum 1 at x = 0. This computes tight bounds using the verified exp implementation.

                    Equations
                    Instances For

                      Interval inverse #

                      Wide bound constant for when inverse is undefined (denominator contains 0)

                      Equations
                      Instances For

                        Computable interval inverse. For [a,b] with a > 0: returns [1/b, 1/a] (1/x is decreasing on positive reals) For [a,b] with b < 0: returns [1/b, 1/a] (1/x is decreasing on negative reals) For intervals containing 0: returns very wide bounds [-M, M] as a sound default

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem LeanCert.Engine.mem_invInterval_pos {x : } {I : Core.IntervalRat} (hx : x I) (hpos : I.lo > 0) :

                          Correctness of invInterval when denominator interval is positive. For x ∈ [a,b] with a > 0, we have 1/x ∈ [1/b, 1/a]

                          theorem LeanCert.Engine.mem_invInterval_neg {x : } {I : Core.IntervalRat} (hx : x I) (hneg : I.hi < 0) :

                          Correctness of invInterval when denominator interval is negative. For x ∈ [a,b] with b < 0, we have 1/x ∈ [1/b, 1/a]

                          theorem LeanCert.Engine.mem_invInterval_wide {x : } {I : Core.IntervalRat} (_hx : x I) (hlo : ¬I.lo > 0) (hhi : ¬I.hi < 0) (hbnd : |x⁻¹| invWideBound) :

                          Correctness of invInterval when denominator interval contains zero. Requires a bound on |x⁻¹| to be provable, since x can be arbitrarily close to 0.

                          Main correctness theorem for invInterval. Fully proved for intervals bounded away from zero. For intervals containing zero, requires a bound on |x⁻¹|.

                          theorem LeanCert.Engine.mem_invInterval_nonzero {x : } {I : Core.IntervalRat} (hx : x I) (hnonzero : I.lo > 0 I.hi < 0) :

                          Correctness of invInterval for intervals bounded away from zero (no extra hypothesis needed)

                          Core interval evaluation (computable) #

                          @[reducible, inline]

                          Variable assignment as intervals

                          Equations
                          Instances For

                            Configuration for interval evaluation parameters. This allows certificates to specify the required 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
                                Instances For

                                  Default evaluation configuration with 10 Taylor terms

                                  Equations

                                  Computable interval evaluator for core expressions with configurable depth.

                                  For expressions in ExprSupportedCore, this computes correct interval bounds with a fully-verified proof (given domain validity conditions).

                                  For inv: computes bounds using invInterval, but correctness is not covered by evalIntervalCore_correct. Use evalInterval? for inv.

                                  For log: uses logComputable with Taylor series. Correctness requires that the argument interval is positive (see evalDomainValid).

                                  This evaluator is COMPUTABLE, allowing use of native_decide for bound checking in tactics. The transcendental functions (exp, sin, cos, log) use Taylor series with configurable depth for precision control.

                                  Equations
                                  Instances For

                                    Computable interval evaluator with division support.

                                    This extends evalIntervalCore to handle inv/div by computing interval inverse when the denominator is bounded away from zero. Returns wide bounds when the denominator interval contains zero.

                                    NOTE: This is less rigorous than evalInterval? because it doesn't fail when 0 is in the denominator range - it just returns wide bounds. This is useful for applications where we want to continue safely even when the analysis is imprecise.

                                    Equations
                                    Instances For
                                      def LeanCert.Engine.envMem (ρ_real : ) (ρ_int : IntervalEnv) :

                                      A real environment is contained in an interval environment

                                      Equations
                                      Instances For

                                        Domain validity predicate for expressions with domain restrictions.

                                        For log: requires the argument interval to be strictly positive. This ensures that logComputable returns correct bounds.

                                        For other expressions: always true (no domain restrictions).

                                        Equations
                                        Instances For

                                          Single-variable domain validity

                                          Equations
                                          Instances For

                                            Computable (decidable) check for domain validity

                                            Equations
                                            Instances For

                                              Single-variable domain check

                                              Equations
                                              Instances For

                                                checkDomainValid = true implies evalDomainValid

                                                checkDomainValid1 = true implies evalDomainValid1

                                                evalDomainValid is equivalent to checkDomainValid = true

                                                Decidability instance for single-variable domain validity

                                                Equations

                                                ExprSupported expressions (which don't include log) always have valid domains. This is because only log has domain restrictions (positive argument).

                                                Single-variable version of domainValid for ExprSupported

                                                theorem LeanCert.Engine.evalIntervalCore_correct (e : Core.Expr) (hsupp : ExprSupportedCore e) (ρ_real : ) (ρ_int : IntervalEnv) ( : envMem ρ_real ρ_int) (cfg : EvalConfig := { }) (hdom : evalDomainValid e ρ_int cfg) :
                                                Core.Expr.eval ρ_real e evalIntervalCore e ρ_int cfg

                                                Fundamental correctness theorem for core evaluation.

                                                This theorem is FULLY PROVED for core expressions (no sorry, no axioms). The hsupp hypothesis ensures we only consider expressions in the computable verified subset. The hdom hypothesis ensures domain validity (e.g., log arguments are positive). Works for any Taylor depth.

                                                Convenience functions #

                                                Computable single-variable evaluation for core expressions

                                                Equations
                                                Instances For
                                                  theorem LeanCert.Engine.evalIntervalCore1_correct (e : Core.Expr) (hsupp : ExprSupportedCore e) (x : ) (I : Core.IntervalRat) (hx : x I) (cfg : EvalConfig := { }) (hdom : evalDomainValid1 e I cfg) :
                                                  Core.Expr.eval (fun (x_1 : ) => x) e evalIntervalCore1 e I cfg

                                                  Correctness for single-variable core evaluation

                                                  Smart constructors for supported expressions #

                                                  Build a constant expression (always supported)

                                                  Equations
                                                  Instances For

                                                    Build a variable expression (always supported)

                                                    Equations
                                                    Instances For

                                                      Build an addition (supported if both operands are supported)

                                                      Equations
                                                      Instances For

                                                        Build a multiplication (supported if both operands are supported)

                                                        Equations
                                                        Instances For

                                                          Build a negation (supported if operand is supported)

                                                          Equations
                                                          Instances For

                                                            Build a sin (supported if operand is supported)

                                                            Equations
                                                            Instances For

                                                              Build a cos (supported if operand is supported)

                                                              Equations
                                                              Instances For

                                                                Build an exp (supported if operand is supported)

                                                                Equations
                                                                Instances For