Automatic Differentiation - Correctness Theorems #
This file proves the correctness of forward-mode automatic differentiation for supported expressions (ExprSupported).
Main theorems #
evalDual_val_correct- Value component is correctevalDual_der_correct- Derivative component is correctevalFunc1_differentiable- Supported expressions are differentiablederiv_mem_dualDer- Key theorem: computed derivative contains true derivativeevalDual_der_correct_idx- n-variable derivative correctnessevalWithDeriv1_correct- Single-variable correctness
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 #
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 #
The function t ↦ Expr.eval (fun _ => t) e for single-variable expressions
Equations
- LeanCert.Engine.evalFunc1 e t = LeanCert.Core.Expr.eval (fun (x : ℕ) => t) e
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.
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 #
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 erf unfolds correctly
Helper lemma: evalFunc1 for const
Helper lemma: evalFunc1 for var
Helper lemma: evalFunc1 for pi (constant function)
Helper: the dual environment evaluation gives correct derivative. This connects the interval-based AD to actual calculus derivatives.
FULLY PROVED - no sorry, no axioms.
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 #
Helper: evalAlong is differentiable for supported expressions
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.
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.
- const (q : ℚ) : UsesOnlyVar0 (Core.Expr.const q)
- var0 : UsesOnlyVar0 (Core.Expr.var 0)
- add (e₁ e₂ : Core.Expr) (h₁ : UsesOnlyVar0 e₁) (h₂ : UsesOnlyVar0 e₂) : UsesOnlyVar0 (e₁.add e₂)
- mul (e₁ e₂ : Core.Expr) (h₁ : UsesOnlyVar0 e₁) (h₂ : UsesOnlyVar0 e₂) : UsesOnlyVar0 (e₁.mul e₂)
- neg (e : Core.Expr) (h : UsesOnlyVar0 e) : UsesOnlyVar0 e.neg
- sin (e : Core.Expr) (h : UsesOnlyVar0 e) : UsesOnlyVar0 e.sin
- cos (e : Core.Expr) (h : UsesOnlyVar0 e) : UsesOnlyVar0 e.cos
- exp (e : Core.Expr) (h : UsesOnlyVar0 e) : UsesOnlyVar0 e.exp
- atan (e : Core.Expr) (h : UsesOnlyVar0 e) : UsesOnlyVar0 e.atan
- arsinh (e : Core.Expr) (h : UsesOnlyVar0 e) : UsesOnlyVar0 e.arsinh
Instances For
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
Correctness of single-variable derivative bounds