Moving sofa: related mathematical developments #
LeanCert.Engine.AD.PartialCorrectness.LeanCert.Engine.IntervalEvalDyadic.LeanCert.Engine.AD.Dyadic.LeanCert.Engine.AD.LeanCert.Engine.Optimization.Box.LeanCert.Engine.Optimize.LeanCert.Engine.Optimization.Gradient.LeanCert.Engine.RootFinding.Krawczyk.
Automatic Differentiation - Partial Correctness Theorems #
This file proves the correctness of the partial dual evaluator evalDualOption
which handles expressions with inv, log, and other domain-restricted functions.
Main theorems #
evalDualOption_val_correct- Value component is correct when evalDualOption returns someevalDualOption1_val_correct- Single-variable versionevalFunc1_differentiableAt_of_evalDualOption- Differentiability when evalDualOption succeedsevalDualOption_der_correct- Derivative component is correctevalDualOption1_correct- Combined correctness theorem
Design notes #
All theorems are FULLY PROVED with no sorry or axioms.
The key insight is that when evalDualOption returns some, the domain
constraints (nonzero for inv, positive for log) are satisfied.
Correctness of partial dual evaluator #
The value component of evalDualOption is correct when it returns some. This theorem extends to expressions with inv.
Single-variable version of evalDualOption_val_correct
Expressions with inv are differentiable when the denominator is nonzero.
Combined correctness theorem for evalDualOption1
High-Performance Dyadic Interval Evaluator #
This evaluator replaces Rat with Dyadic to prevent denominator explosion.
It is designed for complex expressions where the standard evaluator becomes slow.
Main definitions #
DyadicConfig- Configuration for precision and Taylor depthLeanCert.Internal.Dyadic.evalUnchecked- Dyadic interval evaluator for expressionsevalIntervalDyadic_correct- Correctness theorem
Performance #
In v1.0, every Rat multiplication required GCD normalization. For deep
expressions (e.g., Taylor series with 20+ terms, or optimization with 100+
iterations), denominators grow exponentially, causing timeouts.
In v1.1, Dyadic arithmetic uses bit-shifts instead of GCD. With roundOut,
we can enforce a maximum precision after each operation, keeping computation
bounded regardless of expression depth.
Example #
Consider computing sin(sin(sin(x))) with 15-term Taylor series:
- v1.0 (Rat): ~500ms per call, denominators grow to millions of digits
- v1.1 (Dyadic): ~5ms per call, precision stays at 53 bits
Design notes #
For transcendental functions (sin, cos, exp), we delegate to the existing
IntervalRat implementation with Taylor series, then convert the result
to IntervalDyadic with outward rounding. This reuses verified code while
gaining the performance benefits of Dyadic for polynomial operations.
Configuration #
Configuration for Dyadic interval evaluation.
precision- Minimum exponent for outward rounding. A value of -53 gives IEEE double-like precision (~15 decimal digits). Use -100 for higher precision.taylorDepth- Number of Taylor terms for transcendental functions.
- precision : ℤ
Minimum exponent (higher = coarser). -53 ≈ IEEE double precision.
- taylorDepth : ℕ
Number of Taylor series terms for transcendental functions
Instances For
Equations
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
Default configuration with IEEE double-like precision
High-precision configuration for critical calculations
Equations
- LeanCert.Engine.DyadicConfig.highPrecision = { precision := -100, taylorDepth := 20 }
Instances For
Fast configuration for rapid evaluation (lower precision)
Equations
- LeanCert.Engine.DyadicConfig.fast = { precision := -30, taylorDepth := 8 }
Instances For
Variable Environment #
Variable assignment as Dyadic intervals
Equations
Instances For
Convert a rational interval environment to Dyadic
Equations
- LeanCert.Engine.toDyadicEnv ρ prec i = LeanCert.Core.IntervalDyadic.ofIntervalRat (ρ i) prec
Instances For
Transcendental Function Wrappers #
Compute sin interval using rational Taylor series, convert to Dyadic
Equations
Instances For
Compute cos interval using rational Taylor series, convert to Dyadic
Equations
Instances For
Compute exp interval using rational Taylor series, convert to Dyadic
Equations
Instances For
Compute sinh interval using rational Taylor series, convert to Dyadic
Equations
Instances For
Compute cosh interval using rational Taylor series, convert to Dyadic
Equations
Instances For
atan interval: global bound [-2, 2]
Equations
- LeanCert.Engine.atanIntervalDyadic _I _cfg = { lo := LeanCert.Core.Dyadic.ofInt (-2), hi := LeanCert.Core.Dyadic.ofInt 2, le := LeanCert.Engine.atanIntervalDyadic._proof_1 }
Instances For
tanh interval: global bound [-1, 1]
Equations
- LeanCert.Engine.tanhIntervalDyadic _I _cfg = { lo := LeanCert.Core.Dyadic.ofInt (-1), hi := LeanCert.Core.Dyadic.ofInt 1, le := LeanCert.Engine.tanhIntervalDyadic._proof_1 }
Instances For
arsinh interval: wide box bound via rational arsinhInterval
Equations
Instances For
atanh interval: computable Taylor series via rational atanhComputable
Equations
Instances For
sinc interval: global bound [-1, 1]
Equations
- LeanCert.Engine.sincIntervalDyadic _I _cfg = { lo := LeanCert.Core.Dyadic.ofInt (-1), hi := LeanCert.Core.Dyadic.ofInt 1, le := LeanCert.Engine.tanhIntervalDyadic._proof_1 }
Instances For
erf interval: global bound [-1, 1]
Equations
- LeanCert.Engine.erfIntervalDyadic _I _cfg = { lo := LeanCert.Core.Dyadic.ofInt (-1), hi := LeanCert.Core.Dyadic.ofInt 1, le := LeanCert.Engine.tanhIntervalDyadic._proof_1 }
Instances For
Compute inv interval: convert to Rat, use invInterval, convert back to Dyadic
Equations
Instances For
sqrt interval: uses conservative bound [0, max(hi, 1)]
Equations
- LeanCert.Engine.sqrtIntervalDyadic I cfg = I.sqrt cfg.precision
Instances For
log interval: conservative global bound. For any x > 0, log(x) ∈ (-∞, ∞), but we use a finite interval. For x ∈ [lo, hi] with lo > 0:
- log is monotone, so log(x) ∈ [log(lo), log(hi)]
- Legacy total-evaluator fallback; strict callers reject this domain
Equations
- One or more equations did not get rendered due to their size.
Instances For
Real power from a cached logarithm interval.
If Real.log x ∈ logBase, this computes an interval for
x ^ (p : ℝ) as exp(p * log x) without recomputing log x.
This is the hot-path primitive for cached finite sums with many terms of
the form x ^ q_k.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Real power x^p for x > 0 and rational p, computed via exp(p * log(x)).
For x ∈ [lo, hi] with lo > 0 and rational exponent p:
- x^p = exp(p * log(x))
- We compute log(x), multiply by p, then apply exp
This is the key operation for BKLNW-style sums where terms are x^(1/k - 1/3).
Equations
- LeanCert.Engine.rpowIntervalDyadic base p cfg = LeanCert.Engine.rpowFromCachedLogDyadic (LeanCert.Engine.logIntervalDyadic base cfg) p cfg
Instances For
Correctness of rpowFromCachedLogDyadic: a cached interval containing
Real.log x is enough to enclose x ^ p.
Correctness of rpowIntervalDyadic: if x ∈ base and base.lo > 0, then x^p ∈ result
Main Evaluator #
High-performance Dyadic interval evaluator.
This is the core function for v1.1. It evaluates expressions using Dyadic arithmetic for polynomial operations (add, mul, neg) and delegates to rational Taylor series for transcendentals.
Returns an interval guaranteed to contain all possible values of the expression
when ExprSupportedCore holds. For other expressions, it computes conservative
fallbacks (e.g., inv/log), but the core correctness theorem does not apply.
Equations
- LeanCert.Internal.Dyadic.evalUnchecked (LeanCert.Core.Expr.const q) ρ cfg = LeanCert.Core.IntervalDyadic.ofIntervalRat (LeanCert.Core.IntervalRat.singleton q) cfg.precision
- LeanCert.Internal.Dyadic.evalUnchecked (LeanCert.Core.Expr.var idx) ρ cfg = ρ idx
- LeanCert.Internal.Dyadic.evalUnchecked (e₁.add e₂) ρ cfg = ((LeanCert.Internal.Dyadic.evalUnchecked e₁ ρ cfg).add (LeanCert.Internal.Dyadic.evalUnchecked e₂ ρ cfg)).roundOut cfg.precision
- LeanCert.Internal.Dyadic.evalUnchecked (e₁.mul e₂) ρ cfg = ((LeanCert.Internal.Dyadic.evalUnchecked e₁ ρ cfg).mul (LeanCert.Internal.Dyadic.evalUnchecked e₂ ρ cfg)).roundOut cfg.precision
- LeanCert.Internal.Dyadic.evalUnchecked e_2.neg ρ cfg = (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg).neg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.inv ρ cfg = LeanCert.Engine.invIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.exp ρ cfg = LeanCert.Engine.expIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.sin ρ cfg = LeanCert.Engine.sinIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.cos ρ cfg = LeanCert.Engine.cosIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.log ρ cfg = LeanCert.Engine.logIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.atan ρ cfg = LeanCert.Engine.atanIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.arsinh ρ cfg = LeanCert.Engine.arsinhIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.atanh ρ cfg = LeanCert.Engine.atanhIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.sinc ρ cfg = LeanCert.Engine.sincIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.erf ρ cfg = LeanCert.Engine.erfIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.sinh ρ cfg = LeanCert.Engine.sinhIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.cosh ρ cfg = LeanCert.Engine.coshIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.tanh ρ cfg = LeanCert.Engine.tanhIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked e_2.sqrt ρ cfg = LeanCert.Engine.sqrtIntervalDyadic (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg) cfg
- LeanCert.Internal.Dyadic.evalUnchecked (LeanCert.Core.Expr.namedConst c) ρ cfg = LeanCert.Core.IntervalDyadic.ofIntervalRat c.interval cfg.precision
Instances For
Correctness #
A real environment is contained in a Dyadic interval environment
Equations
- LeanCert.Engine.envMemDyadic ρ_real ρ_dyad = ∀ (i : ℕ), ρ_real i ∈ ρ_dyad i
Instances For
Domain validity for Dyadic evaluation. This is defined directly in terms of LeanCert.Internal.Dyadic.evalUnchecked to ensure compatibility. For log, we require the argument interval (converted to Rat) to have positive lower bound.
Equations
- One or more equations did not get rendered due to their size.
- LeanCert.Engine.evalDomainValidDyadic (LeanCert.Core.Expr.const q) ρ cfg = True
- LeanCert.Engine.evalDomainValidDyadic (LeanCert.Core.Expr.var idx) ρ cfg = True
- LeanCert.Engine.evalDomainValidDyadic (e₁.add e₂) ρ cfg = (LeanCert.Engine.evalDomainValidDyadic e₁ ρ cfg ∧ LeanCert.Engine.evalDomainValidDyadic e₂ ρ cfg)
- LeanCert.Engine.evalDomainValidDyadic (e₁.mul e₂) ρ cfg = (LeanCert.Engine.evalDomainValidDyadic e₁ ρ cfg ∧ LeanCert.Engine.evalDomainValidDyadic e₂ ρ cfg)
- LeanCert.Engine.evalDomainValidDyadic e_2.neg ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.exp ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.sin ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.cos ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.log ρ cfg = (LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg ∧ (LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg).toIntervalRat.lo > 0)
- LeanCert.Engine.evalDomainValidDyadic e_2.atan ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.arsinh ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.sinc ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.erf ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.sinh ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.cosh ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.tanh ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic e_2.sqrt ρ cfg = LeanCert.Engine.evalDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.evalDomainValidDyadic (LeanCert.Core.Expr.namedConst c) ρ cfg = True
Instances For
Computable (Bool) domain validity check for Dyadic evaluation.
Equations
- One or more equations did not get rendered due to their size.
- LeanCert.Engine.checkDomainValidDyadic (LeanCert.Core.Expr.const q) ρ cfg = true
- LeanCert.Engine.checkDomainValidDyadic (LeanCert.Core.Expr.var idx) ρ cfg = true
- LeanCert.Engine.checkDomainValidDyadic (e₁.add e₂) ρ cfg = (LeanCert.Engine.checkDomainValidDyadic e₁ ρ cfg && LeanCert.Engine.checkDomainValidDyadic e₂ ρ cfg)
- LeanCert.Engine.checkDomainValidDyadic (e₁.mul e₂) ρ cfg = (LeanCert.Engine.checkDomainValidDyadic e₁ ρ cfg && LeanCert.Engine.checkDomainValidDyadic e₂ ρ cfg)
- LeanCert.Engine.checkDomainValidDyadic e_2.neg ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.exp ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.sin ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.cos ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.log ρ cfg = (LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg && decide ((LeanCert.Internal.Dyadic.evalUnchecked e_2 ρ cfg).toIntervalRat.lo > 0))
- LeanCert.Engine.checkDomainValidDyadic e_2.atan ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.arsinh ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.sinc ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.erf ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.sinh ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.cosh ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.tanh ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic e_2.sqrt ρ cfg = LeanCert.Engine.checkDomainValidDyadic e_2 ρ cfg
- LeanCert.Engine.checkDomainValidDyadic (LeanCert.Core.Expr.namedConst c) ρ cfg = true
Instances For
Static data prepared once for repeated Dyadic evaluation.
The context is operation-independent: logarithm, exponential, trigonometric, and inverse-hyperbolic kernels share certified constants and coefficient families without changing the public evaluator configuration.
- cfg : Engine.DyadicConfig
Precision and rounding settings shared by prepared interval computations.
- ln2 : Core.IntervalRat
A precomputed rational enclosure of the natural logarithm of two.
Precomputed rational coefficients for the exponential Taylor polynomial.
Precomputed rational coefficients for the sine Taylor polynomial.
Precomputed rational coefficients for the cosine Taylor polynomial.
Precomputed rational coefficients for the inverse hyperbolic tangent expansion.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Deterministically prepare all configuration-dependent numerical data.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Logarithm kernel using the context's prepared certified constants.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Exponential kernel using the context's prepared Taylor coefficients.
Equations
Instances For
Sine kernel using the context's prepared Taylor coefficients.
Equations
Instances For
Cosine kernel using the context's prepared Taylor coefficients.
Equations
Instances For
Inverse-hyperbolic-tangent kernel using prepared Taylor coefficients.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluate an expression and its domain-validity bit in one traversal.
The value component is exactly LeanCert.Internal.Dyadic.evalUnchecked; the validity component is
exactly checkDomainValidDyadic.
Equations
- One or more equations did not get rendered due to their size.
- LeanCert.Internal.Dyadic.evalCached (LeanCert.Core.Expr.const q) ρ cfg = (LeanCert.Core.IntervalDyadic.ofIntervalRat (LeanCert.Core.IntervalRat.singleton q) cfg.precision, true)
- LeanCert.Internal.Dyadic.evalCached (LeanCert.Core.Expr.var idx) ρ cfg = (ρ idx, true)
- LeanCert.Internal.Dyadic.evalCached e_2.neg ρ cfg = ((LeanCert.Internal.Dyadic.evalCached e_2 ρ cfg).1.neg, (LeanCert.Internal.Dyadic.evalCached e_2 ρ cfg).2)
- LeanCert.Internal.Dyadic.evalCached e_2.exp ρ cfg = (LeanCert.Engine.expIntervalDyadic (LeanCert.Internal.Dyadic.evalCached e_2 ρ cfg).1 cfg, (LeanCert.Internal.Dyadic.evalCached e_2 ρ cfg).2)
- LeanCert.Internal.Dyadic.evalCached e_2.sin ρ cfg = (LeanCert.Engine.sinIntervalDyadic (LeanCert.Internal.Dyadic.evalCached e_2 ρ cfg).1 cfg, (LeanCert.Internal.Dyadic.evalCached e_2 ρ cfg).2)
- LeanCert.Internal.Dyadic.evalCached e_2.cos ρ cfg = (LeanCert.Engine.cosIntervalDyadic (LeanCert.Internal.Dyadic.evalCached e_2 ρ cfg).1 cfg, (LeanCert.Internal.Dyadic.evalCached e_2 ρ cfg).2)
- LeanCert.Internal.Dyadic.evalCached e_2.erf ρ cfg = (LeanCert.Engine.erfIntervalDyadic (LeanCert.Internal.Dyadic.evalCached e_2 ρ cfg).1 cfg, (LeanCert.Internal.Dyadic.evalCached e_2 ρ cfg).2)
- LeanCert.Internal.Dyadic.evalCached (LeanCert.Core.Expr.namedConst c) ρ cfg = (LeanCert.Core.IntervalDyadic.ofIntervalRat c.interval cfg.precision, true)
Instances For
Prepared evaluator: identical certificate semantics to evalCached, but
configuration-dependent data is shared across every evaluation.
Equations
- One or more equations did not get rendered due to their size.
- LeanCert.Internal.Dyadic.evalPreparedCached (LeanCert.Core.Expr.const q) ρ ctx = (LeanCert.Core.IntervalDyadic.ofIntervalRat (LeanCert.Core.IntervalRat.singleton q) ctx.cfg.precision, true)
- LeanCert.Internal.Dyadic.evalPreparedCached (LeanCert.Core.Expr.var idx) ρ ctx = (ρ idx, true)
- LeanCert.Internal.Dyadic.evalPreparedCached e_2.neg ρ ctx = ((LeanCert.Internal.Dyadic.evalPreparedCached e_2 ρ ctx).1.neg, (LeanCert.Internal.Dyadic.evalPreparedCached e_2 ρ ctx).2)
- LeanCert.Internal.Dyadic.evalPreparedCached (LeanCert.Core.Expr.namedConst c) ρ ctx = (LeanCert.Core.IntervalDyadic.ofIntervalRat c.interval ctx.cfg.precision, true)
Instances For
Diagnose the first failed Dyadic domain check.
Equations
- One or more equations did not get rendered due to their size.
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.neg ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.exp ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.sin ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.cos ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.atan ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.arsinh ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.sinc ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.erf ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.sinh ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.cosh ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.tanh ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2.sqrt ρ cfg = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalDyadicFailure e_2 ρ cfg)
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure (LeanCert.Core.Expr.const q) ρ cfg = LeanCert.Engine.EvalError.unsupportedBackend "internal: total Dyadic expression unexpectedly failed"
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure (LeanCert.Core.Expr.var idx) ρ cfg = LeanCert.Engine.EvalError.unsupportedBackend "internal: total Dyadic expression unexpectedly failed"
- LeanCert.Engine.diagnoseEvalIntervalDyadicFailure (LeanCert.Core.Expr.namedConst c) ρ cfg = LeanCert.Engine.EvalError.unsupportedBackend "internal: total Dyadic expression unexpectedly failed"
Instances For
Checked Dyadic evaluator. The finite fallback branches of the legacy total evaluator are never exposed after a failed domain check.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Domain validity is trivially true for ADSupported expressions (which exclude log).
Fundamental correctness theorem for Dyadic evaluation.
This theorem states that for any supported expression and any real values within the input intervals, the result of evaluating the expression is contained in the computed Dyadic interval.
The proof follows the same structure as evalIntervalCore_correct, but
with additional steps for handling Dyadic ↔ Rat conversions and rounding.
Requires cfg.precision ≤ 0 (the default -53 satisfies this).
Note: Requires domain validity for log (positive argument interval).
Correctness of Dyadic evaluation for every expression whose recursively checked domain conditions hold.
Successful checked Dyadic evaluation encloses the true value for every expression, provided outward-rounding precision is nonpositive.
Verification Checkers #
Check if expression is bounded above by q
Equations
- LeanCert.Engine.checkUpperBoundDyadic e ρ q cfg = (LeanCert.Internal.Dyadic.evalUnchecked e ρ cfg).upperBoundedBy q
Instances For
Check if expression is bounded below by q
Equations
- LeanCert.Engine.checkLowerBoundDyadic e ρ q cfg = (LeanCert.Internal.Dyadic.evalUnchecked e ρ cfg).lowerBoundedBy q
Instances For
Check if expression is bounded in interval [lo, hi]
Equations
- LeanCert.Engine.checkBoundsDyadic e ρ lo hi cfg = ((LeanCert.Internal.Dyadic.evalUnchecked e ρ cfg).lowerBoundedBy lo && (LeanCert.Internal.Dyadic.evalUnchecked e ρ cfg).upperBoundedBy hi)
Instances For
Domain-aware automatic differentiation with Dyadic intervals #
This module is the bounded-denominator counterpart of AD.DomainChecked.
Polynomial dual arithmetic is performed with Dyadic endpoints and outward
rounding after every addition and multiplication. Transcendental values use
the same verified rational Taylor kernels as the Dyadic value evaluator and
are rounded back to Dyadic endpoints.
The public entry points are checked: unsupported syntax, invalid reciprocal or
logarithm domains, and positive rounding precisions return EvalError rather
than a finite interval.
A value interval and one directional derivative interval, both Dyadic.
- val : Core.IntervalDyadic
The interval enclosing the function value.
- der : Core.IntervalDyadic
The interval enclosing the derivative.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
An environment of Dyadic dual intervals.
Instances For
The singleton dyadic interval at zero.
Equations
Instances For
The singleton dyadic interval at one.
Equations
Instances For
Enclose a rational constant in a dyadic interval with zero derivative.
Equations
- One or more equations did not get rendered due to their size.
Instances For
An input interval whose derivative is the singleton one.
Equations
- LeanCert.Engine.DualIntervalDyadic.varActive I = { val := I, der := LeanCert.Engine.DualIntervalDyadic.one }
Instances For
An input interval held constant, with singleton zero derivative.
Equations
- LeanCert.Engine.DualIntervalDyadic.varPassive I = { val := I, der := LeanCert.Engine.DualIntervalDyadic.zero }
Instances For
Addition with dyadic interval propagation of values and derivatives.
Equations
Instances For
Multiplication with dyadic interval propagation of values and derivatives.
Equations
- a.mul b cfg = { val := a.val.mulRounded b.val cfg.precision, der := (a.der.mulRounded b.val cfg.precision).addRounded (a.val.mulRounded b.der cfg.precision) cfg.precision }
Instances For
Negation with dyadic interval propagation of values and derivatives.
Instances For
Reciprocal with dyadic interval propagation of values and derivatives.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Exponential with dyadic interval propagation of values and derivatives.
Equations
- a.exp cfg = { val := LeanCert.Engine.expIntervalDyadic a.val cfg, der := (LeanCert.Engine.expIntervalDyadic a.val cfg).mulRounded a.der cfg.precision }
Instances For
Sine with dyadic interval propagation of values and derivatives.
Equations
- a.sin cfg = { val := LeanCert.Engine.sinIntervalDyadic a.val cfg, der := (LeanCert.Engine.cosIntervalDyadic a.val cfg).mulRounded a.der cfg.precision }
Instances For
Cosine with dyadic interval propagation of values and derivatives.
Equations
- a.cos cfg = { val := LeanCert.Engine.cosIntervalDyadic a.val cfg, der := (LeanCert.Engine.sinIntervalDyadic a.val cfg).neg.mulRounded a.der cfg.precision }
Instances For
Natural logarithm with dyadic interval propagation of values and derivatives.
Equations
- a.log cfg = { val := LeanCert.Engine.logIntervalDyadic a.val cfg, der := (LeanCert.Engine.invIntervalDyadic a.val cfg).mulRounded a.der cfg.precision }
Instances For
Total computational kernel. Sound public use goes through the checked entry points below.
Equations
- LeanCert.Internal.AD.Dyadic.evalTotal (LeanCert.Core.Expr.const q) rho cfg = LeanCert.Engine.DualIntervalDyadic.const q cfg
- LeanCert.Internal.AD.Dyadic.evalTotal (LeanCert.Core.Expr.var i) rho cfg = rho i
- LeanCert.Internal.AD.Dyadic.evalTotal (a.add b) rho cfg = (LeanCert.Internal.AD.Dyadic.evalTotal a rho cfg).add (LeanCert.Internal.AD.Dyadic.evalTotal b rho cfg) cfg
- LeanCert.Internal.AD.Dyadic.evalTotal (a.mul b) rho cfg = (LeanCert.Internal.AD.Dyadic.evalTotal a rho cfg).mul (LeanCert.Internal.AD.Dyadic.evalTotal b rho cfg) cfg
- LeanCert.Internal.AD.Dyadic.evalTotal a.neg rho cfg = (LeanCert.Internal.AD.Dyadic.evalTotal a rho cfg).neg
- LeanCert.Internal.AD.Dyadic.evalTotal a.inv rho cfg = (LeanCert.Internal.AD.Dyadic.evalTotal a rho cfg).inv cfg
- LeanCert.Internal.AD.Dyadic.evalTotal a.exp rho cfg = (LeanCert.Internal.AD.Dyadic.evalTotal a rho cfg).exp cfg
- LeanCert.Internal.AD.Dyadic.evalTotal a.sin rho cfg = (LeanCert.Internal.AD.Dyadic.evalTotal a rho cfg).sin cfg
- LeanCert.Internal.AD.Dyadic.evalTotal a.cos rho cfg = (LeanCert.Internal.AD.Dyadic.evalTotal a rho cfg).cos cfg
- LeanCert.Internal.AD.Dyadic.evalTotal a.log rho cfg = (LeanCert.Internal.AD.Dyadic.evalTotal a rho cfg).log cfg
- LeanCert.Internal.AD.Dyadic.evalTotal e rho cfg = default
Instances For
Value projection of a Dyadic dual environment.
Instances For
Dual environment selecting coordinate idx.
Equations
- LeanCert.Engine.mkDualDyadicEnv rho idx i = if i = idx then LeanCert.Engine.DualIntervalDyadic.varActive (rho i) else LeanCert.Engine.DualIntervalDyadic.varPassive (rho i)
Instances For
The deliberately small v1 Dyadic AD fragment.
Equations
- LeanCert.Engine.checkDyadicADFragment (LeanCert.Core.Expr.const q) = true
- LeanCert.Engine.checkDyadicADFragment (LeanCert.Core.Expr.var i) = true
- LeanCert.Engine.checkDyadicADFragment (a.add b) = (LeanCert.Engine.checkDyadicADFragment a && LeanCert.Engine.checkDyadicADFragment b)
- LeanCert.Engine.checkDyadicADFragment (a.mul b) = (LeanCert.Engine.checkDyadicADFragment a && LeanCert.Engine.checkDyadicADFragment b)
- LeanCert.Engine.checkDyadicADFragment a.neg = LeanCert.Engine.checkDyadicADFragment a
- LeanCert.Engine.checkDyadicADFragment a.inv = LeanCert.Engine.checkDyadicADFragment a
- LeanCert.Engine.checkDyadicADFragment a.exp = LeanCert.Engine.checkDyadicADFragment a
- LeanCert.Engine.checkDyadicADFragment a.sin = LeanCert.Engine.checkDyadicADFragment a
- LeanCert.Engine.checkDyadicADFragment a.cos = LeanCert.Engine.checkDyadicADFragment a
- LeanCert.Engine.checkDyadicADFragment a.log = LeanCert.Engine.checkDyadicADFragment a
- LeanCert.Engine.checkDyadicADFragment x✝ = false
Instances For
Box-dependent domain check for the Dyadic AD kernel.
Equations
- LeanCert.Engine.checkDyadicADDomain e rho cfg = (LeanCert.Engine.checkDyadicADFragment e && (LeanCert.Internal.Dyadic.evalCached e rho.values cfg).2)
Instances For
Explain the first failed support or domain check.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Checked Dyadic dual evaluation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Checked value-and-derivative evaluation along coordinate idx.
Equations
- LeanCert.Engine.evalWithDerivDyadicChecked e rho idx cfg = LeanCert.Engine.evalDualDyadicChecked e (LeanCert.Engine.mkDualDyadicEnv rho idx) cfg
Instances For
Checked Dyadic derivative enclosure along coordinate idx.
Equations
- LeanCert.Engine.derivIntervalDyadicChecked e rho idx cfg = do let __do_lift ← LeanCert.Engine.evalWithDerivDyadicChecked e rho idx cfg pure __do_lift.der
Instances For
Checked Dyadic derivative enclosure for a single-variable expression.
Equations
- LeanCert.Engine.derivIntervalDyadicChecked1 e I cfg = LeanCert.Engine.derivIntervalDyadicChecked e (fun (x : ℕ) => I) 0 cfg
Instances For
Convenience boundary for callers whose boxes use rational endpoints.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Single-variable rational-input convenience boundary.
Equations
- LeanCert.Engine.derivIntervalDyadicChecked1OfRat e I cfg = LeanCert.Engine.derivIntervalDyadicCheckedOfRat e (fun (x : ℕ) => I) 0 cfg
Instances For
The value projection of the dual kernel is exactly the ordinary Dyadic value kernel.
Golden theorem for successful checked Dyadic dual evaluation.
Successful checked Dyadic indexed AD proves differentiability throughout the selected input interval.
Golden theorem: successful checked Dyadic indexed AD encloses the true partial derivative.
Golden theorem for the derivative-only Dyadic API.
Golden theorem for rational input boxes converted to the Dyadic backend.
Compute the first n partial derivatives with the checked Dyadic backend.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Rational-input convenience boundary for the first n Dyadic partials.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Golden theorem for the checked Dyadic gradient API.
Golden theorem for checked Dyadic gradients over rational input boxes.
Automatic Differentiation via Intervals #
This module provides forward-mode automatic differentiation using interval arithmetic. We compute both the value and derivative of an expression, with rigorous bounds on both.
Module Structure #
AD.Basic- Core types:DualInterval, basic operations (add,mul,neg)AD.Transcendental- Transcendental functions (sin,cos,exp, etc.)AD.Eval- Evaluators:LeanCert.Internal.AD.evalUnchecked,evalDualOption,derivIntervalAD.Correctness- Correctness theorems for supported expressionsAD.PartialCorrectness- Correctness for partial functions (inv, log, sqrt)AD.Computable- Taylor-based computable evaluatorsAD.DomainChecked- Computable AD with box-dependent checks for inv and logAD.Dyadic- Domain-aware AD with bounded-denominator Dyadic arithmetic
Main definitions #
DualInterval- A pair of intervals representing (value, derivative)LeanCert.Internal.AD.evalUnchecked- Evaluate expression to get value and derivative intervalsevalDualOption- Partial evaluator supporting inv, log, sqrtLeanCert.Internal.AD.evalTotalCore- Computable evaluator for native_decideevalDualChecked,derivIntervalChecked- Computable, structured-failure APIs for inv/logevalDualDyadicChecked,derivIntervalDyadicChecked- Checked Dyadic counterparts
Main theorems #
LeanCert.Engine.evalDualUnchecked_val_correct- Value component is correct for supported expressionsLeanCert.Engine.evalDualUnchecked_der_correct- Derivative component is correct for supported expressionsevalDualOption_val_correct,evalDualOption_der_correct- Correctness with domain checksLeanCert.Internal.AD.evalTotalCore_val_correct,LeanCert.Internal.AD.evalTotalCore_der_correct
- Computable correctness
evalWithDerivChecked_der_correct,derivIntervalChecked_correct- Golden theorems for successful domain-aware computation
All theorems are FULLY PROVED with no sorry or axioms.
N-Dimensional Boxes for Global Optimization #
This file provides the Box type for representing n-dimensional domains
as products of intervals, along with helper functions for branch-and-bound
optimization.
Main definitions #
Box- A list of intervals representing an n-dimensional boxBox.toEnv- Convert a box to an interval environmentBox.mem- Membership: a point (list of reals) is in a boxBox.widestDim- Find the dimension with the largest width (for splitting)Box.split- Split a box along a given dimensionBox.volume- Product of interval widths (heuristic measure)
Design #
A Box is represented as List IntervalRat, where the i-th element is the
interval for the i-th variable. This allows boxes of any dimension.
For expressions with n variables (var 0 through var n-1), a box should
have at least n intervals. The conversion Box.toEnv returns default
for out-of-bounds indices.
Box type and basic operations #
An n-dimensional box as a list of intervals. The i-th element is the interval for variable i.
Instances For
A point in ℝⁿ represented as a list of reals
Equations
Instances For
A rational point in ℚⁿ
Equations
Instances For
Create a one-dimensional box from a single interval.
Equations
Instances For
Convert a box to an interval environment.
Returns default for out-of-bounds indices (i.e., the whole real line approximation).
Instances For
Check if a point is in a box. A point is in a box if each coordinate is in the corresponding interval.
Equations
- LeanCert.Engine.Optimization.Box.mem p B = ∃ (h : List.length p = List.length B), ∀ (i : Fin (List.length B)), p[↑i] ∈ B[↑i]
Instances For
Membership for a real function (environment) in a box. This is the key notion for correctness: ρ ∈ B means ρ i ∈ B[i] for all i < B.length.
Equations
- LeanCert.Engine.Optimization.Box.envMem ρ B = ∀ (i : Fin (List.length B)), ρ ↑i ∈ B[↑i]
Instances For
envMem implies the general IntervalEnv membership for toEnv NOTE: For indices beyond the box dimension, we use the default interval [0,0]. This means expressions should only use variables 0..B.length-1 for correct results.
Width and dimension selection #
Width of an interval
Equations
Instances For
Get the width of each dimension
Equations
Instances For
Find the index of the maximum element in a list (returns 0 for empty list)
Equations
- One or more equations did not get rendered due to their size.
- LeanCert.Engine.Optimization.Box.maxIdx [] = 0
- LeanCert.Engine.Optimization.Box.maxIdx [head] = 0
Instances For
Find the dimension with the widest interval (heuristic for splitting). Returns 0 if the box is empty.
Equations
Instances For
Alternative: find widest dimension with explicit fold
Equations
- One or more equations did not get rendered due to their size.
Instances For
Box splitting #
Splitting preserves the number of box coordinates.
Volume and size heuristics #
Volume of a box (product of widths). Returns 0 for empty box.
Instances For
Box construction helpers #
Create a unit box [0,1]ⁿ
Equations
- LeanCert.Engine.Optimization.Box.unit n = List.replicate n { lo := 0, hi := 1, le := LeanCert.Engine.Optimization.Box.unit._proof_1 }
Instances For
Create a symmetric box [-1,1]ⁿ
Equations
- LeanCert.Engine.Optimization.Box.symmetric n = List.replicate n { lo := -1, hi := 1, le := LeanCert.Engine.Optimization.Box.symmetric._proof_1 }
Instances For
Membership lemmas #
Global Optimization via Branch-and-Bound #
This file implements verified global optimization over intervals using branch-and-bound with interval arithmetic and derivative bounds.
Phase Status #
This module is now largely Phase 1 (verified). The core correctness theorems are fully proved for the ADSupported subset.
Main definitions #
minimizeInterval- Find a lower bound on min f over an intervalmaximizeInterval- Find an upper bound on max f over an interval- Correctness theorems (fully proved for ADSupported)
Algorithm #
Branch-and-bound with the following pruning rules:
- Interval evaluation: If f([a,b]) = [lo, hi], then min f ≥ lo
- Monotonicity: If f'([a,b]) > 0, f is increasing, so min is at a
- Subdivision: Split interval and recurse
Optimization result #
Result of an optimization computation
- valueBound : Core.IntervalRat
Interval containing the optimum value
- argBound : Option Core.IntervalRat
Interval containing an optimizing point (if found)
- depth : ℕ
Depth of search performed
Instances For
Combine two subinterval bounds, preserving their lower and upper bounds.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Minimization #
Check if derivative interval is strictly positive
Equations
- LeanCert.Engine.derivStrictlyPositive e I varIdx = decide (0 < (LeanCert.Engine.derivInterval e (fun (x : ℕ) => I) varIdx).lo)
Instances For
Check if derivative interval is strictly negative
Equations
- LeanCert.Engine.derivStrictlyNegative e I varIdx = decide ((LeanCert.Engine.derivInterval e (fun (x : ℕ) => I) varIdx).hi < 0)
Instances For
Simple branch-and-bound minimization.
Returns an interval [lo, hi] such that:
- lo ≤ min_{x ∈ I} f(x)
- hi ≥ min_{x ∈ I} f(x)
Equations
- LeanCert.Engine.minimizeInterval e I varIdx maxDepth = LeanCert.Engine.minimizeInterval.go e varIdx maxDepth I maxDepth
Instances For
Recursive interval minimization with a decreasing subdivision budget.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Base case correctness: interval evaluation gives a valid lower bound. This theorem is FULLY PROVED - no sorry, no axioms.
Derivative bounds and monotonicity #
For single-variable expressions evaluated with (fun _ => I), derivative is correct. We use evalWithDeriv1 which directly uses varActive for all variables.
Derivative is in derivInterval for expressions that only use var 0. FULLY PROVED - no sorry.
If the derivative interval is strictly positive, derivative is positive everywhere
If the derivative interval is strictly negative, derivative is negative everywhere
Strictly positive derivative implies strict monotonicity
Strictly negative derivative implies strict antitonicity
Monotonicity-based bounds #
For increasing functions, minimum is at the left endpoint
For decreasing functions, minimum is at the right endpoint
Interval at left endpoint gives valid lower bound for increasing functions
Interval at right endpoint gives valid lower bound for decreasing functions
Full optimization correctness #
Helper lemma for go correctness. FULLY PROVED for varIdx = 0 and UsesOnlyVar0 expressions.
Correctness: the minimum is in the computed interval. FULLY PROVED for varIdx = 0 and UsesOnlyVar0 expressions.
Maximization #
Maximize by minimizing the negation
Equations
- One or more equations did not get rendered due to their size.
Instances For
Correctness: the maximum is in the computed interval. FULLY PROVED for varIdx = 0 and UsesOnlyVar0 expressions.
Bounds checking #
Check if f(x) ≥ c for all x in I
Equations
- LeanCert.Engine.checkLowerBound e I c varIdx maxDepth = decide (c ≤ (LeanCert.Engine.minimizeInterval e I varIdx maxDepth).valueBound.lo)
Instances For
Check if f(x) ≤ c for all x in I
Equations
- LeanCert.Engine.checkUpperBound e I c varIdx maxDepth = decide ((LeanCert.Engine.maximizeInterval e I varIdx maxDepth).valueBound.hi ≤ c)
Instances For
N-Variable Optimization Infrastructure #
The following section provides generalized optimization infrastructure that works with arbitrary variable indices and multi-variable environments. This allows optimizing along any coordinate while holding other variables fixed.
Key types:
IntervalEnv := Nat → IntervalRat- maps variable indices to intervalsevalAlong e ρ idx- evaluateseas a function of variableidx
The main advantage is that we can now optimize expressions with multiple variables by fixing all but one variable and optimizing along that coordinate.
N-variable derivative bounds #
If the derivative interval along idx is strictly positive, derivative is positive everywhere.
Generalized version that works with any variable index and environment.
If the derivative interval along idx is strictly negative, derivative is negative everywhere.
Generalized version that works with any variable index and environment.
Strictly positive derivative along idx implies strict monotonicity.
Generalized n-variable version.
Strictly negative derivative along idx implies strict antitonicity.
Generalized n-variable version.
N-variable monotonicity-based bounds #
For increasing functions along idx, minimum is at the left endpoint.
Generalized n-variable version.
For decreasing functions along idx, minimum is at the right endpoint.
Generalized n-variable version.
N-variable minimization algorithm #
Check if derivative interval along idx is strictly positive
Equations
- LeanCert.Engine.derivStrictlyPositiveIdx e ρ idx = decide (0 < (LeanCert.Engine.derivInterval e ρ idx).lo)
Instances For
Check if derivative interval along idx is strictly negative
Equations
- LeanCert.Engine.derivStrictlyNegativeIdx e ρ idx = decide ((LeanCert.Engine.derivInterval e ρ idx).hi < 0)
Instances For
Update an interval environment at a specific index
Instances For
N-variable branch-and-bound minimization along coordinate idx.
Returns an interval [lo, hi] such that for any ρ_real with ρ_real i ∈ ρ i:
- lo ≤ min_{t ∈ ρ idx} evalAlong e ρ_real idx t
- hi ≥ min_{t ∈ ρ idx} evalAlong e ρ_real idx t
Equations
- LeanCert.Engine.minimizeIntervalIdx e ρ idx maxDepth = LeanCert.Engine.minimizeIntervalIdx.go e ρ idx maxDepth (ρ idx) maxDepth
Instances For
Recursive coordinate minimization with a decreasing subdivision budget.
Equations
- One or more equations did not get rendered due to their size.
Instances For
N-variable minimization correctness #
Base case correctness for n-variable optimization. Interval evaluation gives a valid lower bound.
Helper lemma for go correctness in n-variable setting
Correctness theorem for n-variable minimization: For any real environment ρ_real satisfying ρ_int, and any t in ρ_int idx, the computed lower bound is valid.
FULLY PROVED - no sorry, no axioms.
N-variable maximization via minimization of negation
Equations
- One or more equations did not get rendered due to their size.
Instances For
Correctness theorem for n-variable maximization
Gradient Interval Computation for Optimization #
This file provides functions to compute interval bounds on the gradient ∇f(B) of an expression over a box B. This is used for monotonicity-based pruning in branch-and-bound global optimization.
Main definitions #
gradientInterval- Compute interval bounds on all partial derivatives over a boxgradientSignature- Determine the sign of each partial derivativecanPruneToLo/canPruneToHi- Check if a coordinate can be pruned by monotonicity
Design #
The gradient is computed by running forward-mode AD (from AD.lean) for each coordinate direction. The result is a list of intervals, one per variable.
Monotonicity pruning: If ∂f/∂xᵢ > 0 on the entire box B, then f is minimized when xᵢ = B[i].lo. We can shrink the box in that dimension to a point.
Gradient computation #
Compute the gradient interval: bounds on each partial derivative over a box. Returns a list of intervals, where the i-th interval contains ∂f/∂xᵢ for all x ∈ B.
Equations
- LeanCert.Engine.Optimization.gradientInterval e B = List.ofFn fun (i : Fin (List.length B)) => LeanCert.Engine.derivInterval e B.toEnv ↑i
Instances For
Compute gradient for n variables (explicit dimension)
Equations
- LeanCert.Engine.Optimization.gradientIntervalN e B n = List.map (fun (i : ℕ) => LeanCert.Engine.derivInterval e B.toEnv i) (List.range n)
Instances For
Computable versions #
Create dual environment for differentiating with respect to variable idx (computable).
Active variable gets der = 1, passive variables get der = 0.
Equations
- LeanCert.Engine.Optimization.mkDualEnvCore ρ idx i = if i = idx then LeanCert.Engine.DualInterval.varActive (ρ i) else LeanCert.Engine.DualInterval.varPassive (ρ i)
Instances For
Evaluate with derivative with respect to variable idx (computable version)
Equations
Instances For
Computable derivative interval for multi-variable expressions. Computes the interval containing ∂f/∂xᵢ over the box.
Equations
- LeanCert.Engine.Optimization.derivIntervalCoreN e ρ idx cfg = (LeanCert.Engine.Optimization.evalWithDerivCore e ρ idx cfg).der
Instances For
Correctness of the computable derivative evaluator for an arbitrary coordinate of a multivariate expression.
Computable version of gradient interval for Core expressions.
This can be used with native_decide for verified optimization.
Equations
- LeanCert.Engine.Optimization.gradientIntervalCore e B cfg = List.map (fun (i : ℕ) => LeanCert.Engine.Optimization.derivIntervalCoreN e B.toEnv i cfg) (List.range (List.length B))
Instances For
Compute every partial derivative using the domain-aware checked AD path.
Unlike gradientIntervalCore, this rejects unsupported syntax, reciprocal
arguments containing zero, and nonpositive logarithm arguments instead of
returning a finite interval that could be mistaken for a certificate.
Equations
- LeanCert.Engine.Optimization.gradientIntervalChecked e B cfg = List.mapM (fun (i : ℕ) => LeanCert.Engine.derivIntervalChecked e B.toEnv i cfg) (List.range (List.length B))
Instances For
Golden soundness theorem for a successfully computed checked gradient.
The output list is aligned with coordinates 0, …, B.length - 1.
Sign classification #
Classification of an interval's sign
- positive : IntervalSign
- negative : IntervalSign
- nonpositive : IntervalSign
- nonnegative : IntervalSign
- indefinite : IntervalSign
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Classify the sign of an interval
Equations
- One or more equations did not get rendered due to their size.
Instances For
The gradient signature: sign of each partial derivative (noncomputable wrapper)
Equations
Instances For
Monotonicity predicates #
Check if interval is strictly positive
Equations
Instances For
Check if interval is strictly negative
Equations
Instances For
Check if interval is nonnegative
Equations
Instances For
Check if interval is nonpositive
Equations
Instances For
Pruning queries #
Can we prune coordinate i to its low endpoint for minimization? True if ∂f/∂xᵢ > 0 on B (f is increasing in xᵢ, so min is at lo).
Equations
Instances For
Can we prune coordinate i to its high endpoint for minimization? True if ∂f/∂xᵢ < 0 on B (f is decreasing in xᵢ, so min is at hi).
Equations
Instances For
Prune a box for minimization by fixing monotonic coordinates. Returns a (potentially smaller) box and a list of fixed coordinates.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Correctness theorems #
The computed gradient interval contains the true partial derivatives. This follows from evalDual_der_correct_idx in AD.lean.
If we prune a coordinate to lo because ∂f/∂xᵢ > 0, the minimum is preserved. Informal: if f is increasing in xᵢ on B, then min{f(x) : x ∈ B} = min{f(x) : xᵢ = B[i].lo}. NOTE: Requires ρ j = 0 for j ≥ B.length (standard assumption for box membership).
If we prune a coordinate to hi because ∂f/∂xᵢ < 0, the minimum is preserved. NOTE: Requires ρ j = 0 for j ≥ B.length (standard assumption for box membership).
Pruned box membership and correctness #
Helper: membership in the pruned box implies membership in the original box. The pruned box only shrinks coordinates, never expands them.
The pruned box has the same length as the original box
A positive computable derivative enclosure makes the objective increasing along the selected coordinate.
A negative computable derivative enclosure makes the objective decreasing along the selected coordinate.
Certified roots of differentiable systems #
This module implements a strong, norm-form Krawczyk test for square systems in
LeanCert's ADSupported expression fragment. The center and rational
preconditioner are untrusted certificate data;
krawczykCheck verifies AD support, center containment, invertibility,
a strict infinity-norm contraction bound, and a strict self-map enclosure.
The golden theorem krawczykCheck_sound turns a successful Boolean check into
existence and uniqueness of a real root in the supplied box.
Use the singleton zero interval as the additive identity.
Equations
Instances For
Use endpoint-wise interval addition for finite interval sums.
Equations
Instances For
Natural scalar multiplication by repeated interval addition.
Equations
Instances For
The additive commutative monoid of rational intervals.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluate an expression in the environment of a finite real coordinate vector.
Equations
Instances For
Evaluate all coordinate expressions of a finite system.
Equations
- LeanCert.Engine.systemEval F x i = LeanCert.Engine.evalFin (F i) x
Instances For
Extend a finite interval box to the evaluator’s indexed environment.
Equations
- LeanCert.Engine.finBoxEnv X i = if h : i < n then X ⟨i, h⟩ else LeanCert.Core.IntervalRat.singleton 0
Instances For
Coordinatewise membership of a real vector in a rational interval box.
Equations
- LeanCert.Engine.FinBoxMem x X = ∀ (i : Fin n), x i ∈ X i
Instances For
Enclose the Jacobian entries by interval automatic differentiation.
Equations
- LeanCert.Engine.intervalJacobian F X cfg i j = LeanCert.Engine.Optimization.derivIntervalCoreN (F i) (LeanCert.Engine.finBoxEnv X) (↑j) cfg
Instances For
The set of real vectors lying coordinatewise in the interval box.
Equations
- LeanCert.Engine.finBoxSet X = {x : Fin n → ℝ | LeanCert.Engine.FinBoxMem x X}
Instances For
The identity matrix represented by singleton rational intervals.
Equations
- LeanCert.Engine.intervalIdentity i j = LeanCert.Core.IntervalRat.singleton (if i = j then 1 else 0)
Instances For
Multiply a rational matrix by an interval matrix using interval sums.
Equations
- LeanCert.Engine.ratMulInterval Y J i j = ∑ k : Fin n, LeanCert.Core.IntervalRat.scale (Y i k) (J k j)
Instances For
The interval matrix I - Y J enclosing the Newton-map derivative.
Equations
- LeanCert.Engine.preconditionedJacobian Y J i j = (LeanCert.Engine.intervalIdentity i j).sub (LeanCert.Engine.ratMulInterval Y J i j)
Instances For
The larger absolute endpoint, bounding absolute values in the interval.
Instances For
The sum of absolute interval bounds in a selected matrix row.
Equations
- LeanCert.Engine.intervalMatrixRowBound A i = ∑ j : Fin n, LeanCert.Engine.intervalAbsBound (A i j)
Instances For
The maximum interval row sum, bounding the matrix’s sup-norm operator norm.
Equations
- LeanCert.Engine.intervalMatrixBound A = List.foldl max 0 (List.ofFn fun (i : Fin n) => LeanCert.Engine.intervalMatrixRowBound A i)
Instances For
Represent a rational center by singleton intervals in the evaluation environment.
Equations
- LeanCert.Engine.pointIntervalEnv m i = if h : i < n then LeanCert.Core.IntervalRat.singleton (m ⟨i, h⟩) else LeanCert.Core.IntervalRat.singleton 0
Instances For
Enclose the expression system at a rational center by interval evaluation.
Equations
- LeanCert.Engine.pointEvalIntervals F m cfg i = LeanCert.Internal.Rational.evalTotalCore (F i) (LeanCert.Engine.pointIntervalEnv m) cfg
Instances For
Multiply a rational matrix by an interval vector.
Equations
- LeanCert.Engine.intervalRatMatVec Y v i = ∑ j : Fin n, LeanCert.Core.IntervalRat.scale (Y i j) (v j)
Instances For
An interval enclosure of the preconditioned Newton map at the chosen center.
Equations
- LeanCert.Engine.newtonCenterInterval F m Y cfg i = (LeanCert.Core.IntervalRat.singleton (m i)).sub (LeanCert.Engine.intervalRatMatVec Y (LeanCert.Engine.pointEvalIntervals F m cfg) i)
Instances For
The maximum coordinate radius of the box around the chosen center.
Equations
- LeanCert.Engine.boxRadius X m = List.foldl max 0 (List.ofFn fun (i : Fin n) => LeanCert.Engine.coordinateRadius X m i)
Instances For
The rational interval with endpoints -d and d.
Instances For
Enclose the Newton image using its center value and a uniform derivative bound.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Test whether both endpoints lie strictly inside another interval.
Instances For
Rational center and preconditioner data for a checkable Krawczyk certificate.
The rational center used by the Newton-image enclosure.
The rational matrix used to precondition the equation system.
Instances For
Equations
Check supported derivatives, center containment, invertibility, contraction and self-map bounds.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Every expression in the finite system evaluates to zero at the given point.
Equations
- LeanCert.Engine.SystemZero F x = ∀ (i : Fin n), LeanCert.Engine.evalFin (F i) x = 0