Documentation

LeanCert.Engine.IntervalEvalAffine

Affine Arithmetic Expression Evaluator #

This module provides expression evaluation using Affine Arithmetic (AA). Affine arithmetic tracks correlations between variables, solving the "dependency problem" that causes interval arithmetic to over-approximate.

Main definitions #

Performance #

For expressions with repeated variables:

Affine arithmetic gives 50-90% tighter bounds for many real-world expressions, especially in neural network verification where the same inputs flow through multiple paths.

Limitations #

Some transcendental functions (sin, cos, atan) fall back to interval arithmetic because affine approximations aren't yet implemented.

Configuration #

Configuration for Affine evaluation.

  • taylorDepth - Number of Taylor terms for transcendental functions
  • maxNoiseSymbols - Maximum noise symbols before consolidation (0 = unlimited)
  • taylorDepth :

    Number of Taylor series terms for transcendental functions

  • maxNoiseSymbols :

    Max noise symbols before consolidation (0 = no limit)

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

        Variable Environment #

        @[reducible, inline]

        Variable assignment as Affine forms

        Equations
        Instances For

          Create an affine environment from rational intervals.

          Each variable gets a unique noise symbol to track correlations.

          Equations
          Instances For

            Main Evaluator #

            Evaluate expression using Affine Arithmetic.

            This function recursively evaluates an expression, using:

            • Exact affine operations for linear functions (add, sub, neg, scale)
            • Controlled approximations for nonlinear functions (mul, sq)
            • Interval fallbacks for unsupported transcendentals (sin, cos, atan)

            The result is an AffineForm that can be converted to an interval via toInterval, typically giving tighter bounds than pure interval arithmetic.

            Equations
            Instances For

              Convenience Functions #

              Check if expression is bounded above

              Equations
              Instances For

                Check if expression is bounded below

                Equations
                Instances For

                  Correctness Theorem #

                  Environment membership: real value is represented by the affine form

                  Equations
                  Instances For

                    Domain validity for Affine evaluation. This is defined directly in terms of evalIntervalAffine to ensure compatibility. For log, we require the argument's toInterval to have positive lower bound.

                    Equations
                    Instances For

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

                      theorem LeanCert.Engine.evalIntervalAffine_correct (e : Core.Expr) (hsupp : ExprSupportedCore e) (ρ_real : ) (ρ_affine : AffineEnv) (eps : Affine.AffineForm.NoiseAssignment) (hvalid : Affine.AffineForm.validNoise eps) ( : envMemAffine ρ_real ρ_affine eps) (cfg : AffineConfig := { }) (hdom : evalDomainValidAffine e ρ_affine cfg) :
                      (evalIntervalAffine e ρ_affine cfg).mem_affine eps (Core.Expr.eval ρ_real e)

                      Correctness theorem for Affine interval evaluation.

                      If all input variables are represented by their affine forms (via noise assignment eps), then the real evaluation of the expression is represented by the affine result.

                      This proves soundness: the affine form always contains the true value.

                      Note: Requires valid noise assignment and domain validity for log. Some transcendental cases (sin, cos, pi) use interval fallback and have separate soundness via interval bounds.

                      theorem LeanCert.Engine.evalIntervalAffine_toInterval_correct (e : Core.Expr) (hsupp : ExprSupportedCore e) (ρ_real : ) (ρ_affine : AffineEnv) (eps : Affine.AffineForm.NoiseAssignment) (hvalid : Affine.AffineForm.validNoise eps) ( : envMemAffine ρ_real ρ_affine eps) (cfg : AffineConfig := { }) (hlen : List.length eps = (evalIntervalAffine e ρ_affine cfg).coeffs.length) (hdom : evalDomainValidAffine e ρ_affine cfg) :
                      Core.Expr.eval ρ_real e (evalIntervalAffine e ρ_affine cfg).toInterval

                      Corollary: The interval produced by toInterval contains the true value.

                      This is the key result for optimization: if we compute an affine form and convert to an interval, the interval is guaranteed to contain the true value.