Documentation

LeanCert.Engine.AD.Correctness

Automatic Differentiation - Correctness Theorems #

This file proves the correctness of forward-mode automatic differentiation for supported expressions (ExprSupported).

Main theorems #

Design notes #

All theorems in this file are FULLY PROVED with no sorry or axioms. The correctness relies on the chain rule for each supported operation.

Correctness #

theorem LeanCert.Engine.evalDual_val_correct (e : Core.Expr) (hsupp : ExprSupported e) (ρ_real : ) (ρ_dual : DualEnv) ( : ∀ (i : ), ρ_real i (ρ_dual i).val) :
Core.Expr.eval ρ_real e (evalDual e ρ_dual).val

The value component is correct for supported expressions.

This theorem is FULLY PROVED (no sorry, no axioms) for supported expressions. The hsupp hypothesis ensures we only consider expressions in the verified subset.

Single-variable evaluation for derivative proofs #

@[reducible, inline]
noncomputable abbrev LeanCert.Engine.evalFunc1 (e : Core.Expr) :

The function t ↦ Expr.eval (fun _ => t) e for single-variable expressions

Equations
Instances For

    Differentiability of supported expressions #

    Supported expressions are differentiable as single-variable functions. This theorem shows that for any supported expression, the function evalFunc1 e is differentiable.

    FULLY PROVED - no sorry, no axioms.

    Core derivative correctness micro-lemmas #

    Real.cos y is always in cosInterval I (which is [-1, 1]). This micro-lemma encapsulates the fact that cosInterval uses the global bound.

    Real.sin y is always in sinInterval I (which is [-1, 1]). This micro-lemma encapsulates the fact that sinInterval uses the global bound.

    -Real.sin y is always in IntervalRat.neg (sinInterval I). This combines the sin global bound with negation for the cos derivative rule.

    theorem LeanCert.Engine.updateVar_mem_mkDualEnv_val (ρ_real : ) (ρ_int : IntervalEnv) (idx : ) (x : ) (hx : x ρ_int idx) ( : ∀ (i : ), ρ_real i ρ_int i) (i : ) :
    (ρ_real[idx x]) i (mkDualEnv ρ_int idx i).val

    The key lemma for n-variable AD: updateVar ρ_real idx x respects mkDualEnv ρ_int idx. This encapsulates the repeated proof that appears in mul/exp cases.

    evalFunc1 unfolding lemmas #

    theorem LeanCert.Engine.evalFunc1_add (e₁ e₂ : Core.Expr) :
    evalFunc1 (e₁.add e₂) = fun (t : ) => evalFunc1 e₁ t + evalFunc1 e₂ t

    Helper lemma: evalFunc1 for addition unfolds correctly

    theorem LeanCert.Engine.evalFunc1_add_pi (e₁ e₂ : Core.Expr) :
    evalFunc1 (e₁.add e₂) = evalFunc1 e₁ + evalFunc1 e₂

    Helper lemma: evalFunc1 for addition in Pi form

    theorem LeanCert.Engine.evalFunc1_mul (e₁ e₂ : Core.Expr) :
    evalFunc1 (e₁.mul e₂) = fun (t : ) => evalFunc1 e₁ t * evalFunc1 e₂ t

    Helper lemma: evalFunc1 for multiplication unfolds correctly

    theorem LeanCert.Engine.evalFunc1_mul_pi (e₁ e₂ : Core.Expr) :
    evalFunc1 (e₁.mul e₂) = evalFunc1 e₁ * evalFunc1 e₂

    Helper lemma: evalFunc1 for multiplication in Pi form

    Helper lemma: evalFunc1 for negation unfolds correctly

    Helper lemma: evalFunc1 for negation in Pi form

    Helper lemma: evalFunc1 for sin unfolds correctly

    Helper lemma: evalFunc1 for cos unfolds correctly

    Helper lemma: evalFunc1 for exp unfolds correctly

    Helper lemma: evalFunc1 for log unfolds correctly

    Helper lemma: evalFunc1 for atan unfolds correctly

    Helper lemma: evalFunc1 for arsinh unfolds correctly

    Helper lemma: evalFunc1 for atanh unfolds correctly

    Helper lemma: evalFunc1 for sinc unfolds correctly

    Helper lemma: evalFunc1 for erf unfolds correctly

    Helper lemma: evalFunc1 for sqrt unfolds correctly

    @[simp]
    theorem LeanCert.Engine.evalFunc1_const (q : ) :
    evalFunc1 (Core.Expr.const q) = fun (x : ) => q

    Helper lemma: evalFunc1 for const

    @[simp]

    Helper lemma: evalFunc1 for var

    @[simp]

    Helper lemma: evalFunc1 for pi (constant function)

    theorem LeanCert.Engine.deriv_mem_dualDer (e : Core.Expr) (hsupp : ExprSupported e) (I : Core.IntervalRat) (x : ) (hx : x I) :

    Helper: the dual environment evaluation gives correct derivative. This connects the interval-based AD to actual calculus derivatives.

    FULLY PROVED - no sorry, no axioms.

    theorem LeanCert.Engine.evalDual_der_correct (e : Core.Expr) (hsupp : ExprSupported e) (I : Core.IntervalRat) (x : ) (hx : x I) :
    deriv (fun (t : ) => Core.Expr.eval (fun (x : ) => t) e) x (evalDual e fun (x : ) => DualInterval.varActive I).der

    The derivative component of dual interval evaluation is correct. For a supported expression evaluated at a point x in the interval I, the derivative of the expression (as a function of x) lies in the computed derivative interval.

    This is the fundamental correctness theorem for forward-mode AD: the derivative bounds computed by interval arithmetic contain the true derivative at every point in the domain.

    FULLY PROVED - no sorry, no axioms.

    Generalized n-variable derivative correctness #

    theorem LeanCert.Engine.evalAlong_differentiable (e : Core.Expr) (hsupp : ExprSupported e) (ρ : ) (idx : ) :

    Helper: evalAlong is differentiable for supported expressions

    theorem LeanCert.Engine.evalDual_der_correct_idx (e : Core.Expr) (hsupp : ExprSupported e) (ρ_real : ) (ρ_int : IntervalEnv) (idx : ) ( : ∀ (i : ), ρ_real i ρ_int i) (x : ) (hx : x ρ_int idx) :
    deriv (e.evalAlong ρ_real idx) x (evalDual e (mkDualEnv ρ_int idx)).der

    The derivative of evalAlong with respect to coordinate idx lies in the computed derivative interval from mkDualEnv.

    This is the fundamental n-variable derivative correctness theorem. It shows that for any expression, if we differentiate along coordinate idx while holding all other coordinates fixed according to ρ, the derivative at any point x in the interval ρ_int idx lies in the computed interval.

    FULLY PROVED - no sorry, no axioms.

    theorem LeanCert.Engine.derivInterval_correct_idx (e : Core.Expr) (hsupp : ExprSupported e) (ρ_real : ) (ρ_int : IntervalEnv) (idx : ) ( : ∀ (i : ), ρ_real i ρ_int i) (x : ) (hx : x ρ_int idx) :
    deriv (e.evalAlong ρ_real idx) x derivInterval e ρ_int idx

    Convenience theorem: derivInterval correctness for n-variable expressions. The derivative of evalAlong e ρ idx at any point x in the interval lies in derivInterval e ρ_int idx.

    Single-variable expressions #

    Predicate: expression only uses variable index 0. This is useful for proving that different environments give the same result when they agree at index 0.

    Instances For
      theorem LeanCert.Engine.evalDual_congr_at_0 (e : Core.Expr) (h : UsesOnlyVar0 e) (ρ₁ ρ₂ : DualEnv) (heq : ρ₁ 0 = ρ₂ 0) :
      evalDual e ρ₁ = evalDual e ρ₂

      For expressions using only var 0, evalDual agrees for environments that match at 0

      mkDualEnv at index 0 equals varActive at 0

      For expressions using only var 0, derivInterval equals evalWithDeriv1

      theorem LeanCert.Engine.evalWithDeriv1_correct (e : Core.Expr) (hsupp : ExprSupported e) (I : Core.IntervalRat) (x : ) (hx : x I) :
      Core.Expr.eval (fun (x_1 : ) => x) e (evalWithDeriv1 e I).val deriv (fun (t : ) => Core.Expr.eval (fun (x : ) => t) e) x (evalWithDeriv1 e I).der

      Correctness of single-variable derivative bounds