Automatic Differentiation - Computable Evaluators #
This file provides computable dual evaluators using Taylor-based approximations
for transcendental functions. This enables native_decide for derivative-based
bound checking.
Main definitions #
DualInterval.expCore,sinCore,cosCore- Taylor-based dual functionsDualInterval.sinhCore,coshCore,tanhCore- Hyperbolic Taylor-based dualsLeanCert.Internal.AD.evalTotalCore- Computable dual evaluator for ExprSupportedCorederivIntervalCore- Computable single-variable derivative interval
Main theorems #
LeanCert.Engine.evalDualTotalCore_val_correct- Value component is correctLeanCert.Engine.evalDualTotalCore_der_correct- Derivative component is correctderivIntervalCore_correct- Derivative interval correctnessstrictMonoOn_of_derivIntervalCore_pos- Monotonicity from positive derivativestrictAntiOn_of_derivIntervalCore_neg- Antitonicity from negative derivative
Computable Dual Evaluation for ExprSupportedCore #
This section provides a fully computable dual evaluator that uses Taylor-based
approximations for transcendental functions. This enables native_decide for
derivative-based bound checking.
Computable dual for exp using Taylor series (chain rule: d(exp f) = exp(f) * f')
Equations
- d.expCore n = { val := d.val.expComputable n, der := (d.val.expComputable n).mul d.der }
Instances For
Computable dual for sin using Taylor series
Equations
- d.sinCore n = { val := d.val.sinComputable n, der := (d.val.cosComputable n).mul d.der }
Instances For
Computable dual for cos using Taylor series
Equations
Instances For
Computable dual for log using Taylor series via atanh reduction. Chain rule: d(log f) = f' / f
Equations
- d.logCore n = { val := d.val.logComputable n, der := (LeanCert.Engine.invInterval d.val).mul d.der }
Instances For
Computable dual for sinh using Taylor series (chain rule: d(sinh f) = cosh(f) * f')
Equations
- d.sinhCore n = { val := d.val.sinhComputable n, der := (d.val.coshComputable n).mul d.der }
Instances For
Computable dual for cosh using Taylor series (chain rule: d(cosh f) = sinh(f) * f')
Equations
- d.coshCore n = { val := d.val.coshComputable n, der := (d.val.sinhComputable n).mul d.der }
Instances For
Computable dual for tanh (chain rule: d(tanh f) = sech²(f) * f') Since sech²(x) ∈ (0, 1], we use [0, 1] as a conservative bound.
Equations
Instances For
Computable dual interval evaluator for ExprSupportedCore expressions.
This uses Taylor series approximations for transcendental functions,
making it fully computable and usable with native_decide.
For inv and log, use evalDualChecked or the bounded-denominator
evalDualDyadicChecked; they validate the actual input box before exposing
this total kernel's result. Correctness is not claimed for unchecked
partial-operation branches here.
Equations
- LeanCert.Internal.AD.evalTotalCore (LeanCert.Core.Expr.const q) ρ cfg = LeanCert.Engine.DualInterval.const q
- LeanCert.Internal.AD.evalTotalCore (LeanCert.Core.Expr.var idx) ρ cfg = ρ idx
- LeanCert.Internal.AD.evalTotalCore (e₁.add e₂) ρ cfg = (LeanCert.Internal.AD.evalTotalCore e₁ ρ cfg).add (LeanCert.Internal.AD.evalTotalCore e₂ ρ cfg)
- LeanCert.Internal.AD.evalTotalCore (e₁.mul e₂) ρ cfg = (LeanCert.Internal.AD.evalTotalCore e₁ ρ cfg).mul (LeanCert.Internal.AD.evalTotalCore e₂ ρ cfg)
- LeanCert.Internal.AD.evalTotalCore e_2.neg ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).neg
- LeanCert.Internal.AD.evalTotalCore e_2.inv ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).inv
- LeanCert.Internal.AD.evalTotalCore e_2.exp ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).expCore cfg.taylorDepth
- LeanCert.Internal.AD.evalTotalCore e_2.sin ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).sinCore cfg.taylorDepth
- LeanCert.Internal.AD.evalTotalCore e_2.cos ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).cosCore cfg.taylorDepth
- LeanCert.Internal.AD.evalTotalCore e_2.log ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).logCore cfg.taylorDepth
- LeanCert.Internal.AD.evalTotalCore e_2.atan ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).atan
- LeanCert.Internal.AD.evalTotalCore e_2.arsinh ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).arsinh
- LeanCert.Internal.AD.evalTotalCore e_2.atanh ρ cfg = default
- LeanCert.Internal.AD.evalTotalCore e_2.sinc ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).sinc
- LeanCert.Internal.AD.evalTotalCore e_2.erf ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).erfCore cfg.taylorDepth
- LeanCert.Internal.AD.evalTotalCore e_2.sinh ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).sinhCore cfg.taylorDepth
- LeanCert.Internal.AD.evalTotalCore e_2.cosh ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).coshCore cfg.taylorDepth
- LeanCert.Internal.AD.evalTotalCore e_2.tanh ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).tanhCore cfg.taylorDepth
- LeanCert.Internal.AD.evalTotalCore e_2.sqrt ρ cfg = (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).sqrt
- LeanCert.Internal.AD.evalTotalCore (LeanCert.Core.Expr.namedConst c) ρ cfg = LeanCert.Engine.DualInterval.ofMathConst c
Instances For
Computable single-variable derivative interval
Equations
- LeanCert.Engine.derivIntervalCore e I cfg = (LeanCert.Internal.AD.evalTotalCore e (fun (x : ℕ) => LeanCert.Engine.DualInterval.varActive I) cfg).der
Instances For
Domain validity for dual evaluation. This is defined directly in terms of LeanCert.Internal.AD.evalTotalCore to ensure compatibility. For log, we require the argument interval to have positive lower bound.
Equations
- LeanCert.Engine.evalDomainValidDual (LeanCert.Core.Expr.const q) ρ cfg = True
- LeanCert.Engine.evalDomainValidDual (LeanCert.Core.Expr.var idx) ρ cfg = True
- LeanCert.Engine.evalDomainValidDual (e₁.add e₂) ρ cfg = (LeanCert.Engine.evalDomainValidDual e₁ ρ cfg ∧ LeanCert.Engine.evalDomainValidDual e₂ ρ cfg)
- LeanCert.Engine.evalDomainValidDual (e₁.mul e₂) ρ cfg = (LeanCert.Engine.evalDomainValidDual e₁ ρ cfg ∧ LeanCert.Engine.evalDomainValidDual e₂ ρ cfg)
- LeanCert.Engine.evalDomainValidDual e_2.neg ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.inv ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.exp ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.sin ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.cos ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.log ρ cfg = (LeanCert.Engine.evalDomainValidDual e_2 ρ cfg ∧ (LeanCert.Internal.AD.evalTotalCore e_2 ρ cfg).val.lo > 0)
- LeanCert.Engine.evalDomainValidDual e_2.atan ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.arsinh ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.atanh ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.sinc ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.erf ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.sinh ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.cosh ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.tanh ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual e_2.sqrt ρ cfg = LeanCert.Engine.evalDomainValidDual e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDual (LeanCert.Core.Expr.namedConst c) ρ cfg = True
Instances For
Correctness theorem for computable dual value component.
Note: Requires domain validity for log (positive argument interval).
For ADSupported expressions (which exclude log), domain validity is trivially true. This is because ADSupported has no log constructor.
Correctness theorem for computable dual derivative component. Uses ADSupported since derivative correctness requires differentiability.
Convenience theorem: derivIntervalCore correctness
If derivIntervalCore doesn't contain zero, the derivative is nonzero everywhere on I. This is a key theorem for Newton contraction analysis.
If derivIntervalCore.lo > 0, then the derivative is positive everywhere on I.
If derivIntervalCore.hi < 0, then the derivative is negative everywhere on I.
Strictly positive derivative (via Core bounds) implies strict monotonicity
Strictly negative derivative (via Core bounds) implies strict antitonicity