Extended (Noncomputable) Interval Evaluation #
This file implements the noncomputable interval evaluator for LeanCert.Core.Expr,
supporting exp with floor/ceil bounds and partial evaluation for inv/log.
Main definitions #
evalInterval- Noncomputable interval evaluator supporting expevalInterval_correct- Correctness theorem for extended evaluationevalInterval?- Partial (Option-returning) evaluator with inv/log supportevalInterval?_correct- Correctness theorem for partial evaluation
Design notes #
The extended evaluator uses Real.exp with floor/ceil bounds, which requires
noncomputability. For computability, use LeanCert.Internal.Rational.evalTotalCore instead.
The partial evaluator evalInterval? returns none when:
- The denominator interval for
invcontains zero - The argument interval for
logis not strictly positive - The argument for
atanhis not in (-1, 1)
When it returns some I, correctness is guaranteed.
Extended interval evaluation (noncomputable, supports exp) #
Noncomputable interval evaluator supporting exp.
For supported expressions (const, var, add, mul, neg, sin, cos, exp), this computes correct interval bounds with a fully-verified proof.
For unsupported expressions (inv, log), returns a default interval. Do not rely on results for expressions containing inv or log. Use evalInterval? for partial functions like inv and log.
This evaluator is NONCOMPUTABLE due to exp using Real.exp with floor/ceil.
Equations
- LeanCert.Internal.Rational.evalUnchecked (LeanCert.Core.Expr.const q) ρ = LeanCert.Core.IntervalRat.singleton q
- LeanCert.Internal.Rational.evalUnchecked (LeanCert.Core.Expr.var idx) ρ = ρ idx
- LeanCert.Internal.Rational.evalUnchecked (e₁.add e₂) ρ = (LeanCert.Internal.Rational.evalUnchecked e₁ ρ).add (LeanCert.Internal.Rational.evalUnchecked e₂ ρ)
- LeanCert.Internal.Rational.evalUnchecked (e₁.mul e₂) ρ = (LeanCert.Internal.Rational.evalUnchecked e₁ ρ).mul (LeanCert.Internal.Rational.evalUnchecked e₂ ρ)
- LeanCert.Internal.Rational.evalUnchecked e_2.neg ρ = (LeanCert.Internal.Rational.evalUnchecked e_2 ρ).neg
- LeanCert.Internal.Rational.evalUnchecked e_2.inv ρ = default
- LeanCert.Internal.Rational.evalUnchecked e_2.exp ρ = (LeanCert.Internal.Rational.evalUnchecked e_2 ρ).expInterval
- LeanCert.Internal.Rational.evalUnchecked e_2.sin ρ = LeanCert.Engine.sinInterval (LeanCert.Internal.Rational.evalUnchecked e_2 ρ)
- LeanCert.Internal.Rational.evalUnchecked e_2.cos ρ = LeanCert.Engine.cosInterval (LeanCert.Internal.Rational.evalUnchecked e_2 ρ)
- LeanCert.Internal.Rational.evalUnchecked e_2.log ρ = default
- LeanCert.Internal.Rational.evalUnchecked e_2.atan ρ = LeanCert.Engine.atanInterval (LeanCert.Internal.Rational.evalUnchecked e_2 ρ)
- LeanCert.Internal.Rational.evalUnchecked e_2.arsinh ρ = LeanCert.Engine.arsinhInterval (LeanCert.Internal.Rational.evalUnchecked e_2 ρ)
- LeanCert.Internal.Rational.evalUnchecked e_2.atanh ρ = default
- LeanCert.Internal.Rational.evalUnchecked e_2.sinc ρ = { lo := -1, hi := 1, le := LeanCert.Internal.Rational.evalUnchecked._proof_1 }
- LeanCert.Internal.Rational.evalUnchecked e_2.erf ρ = { lo := -1, hi := 1, le := LeanCert.Internal.Rational.evalUnchecked._proof_1 }
- LeanCert.Internal.Rational.evalUnchecked e_2.sinh ρ = default
- LeanCert.Internal.Rational.evalUnchecked e_2.cosh ρ = default
- LeanCert.Internal.Rational.evalUnchecked e_2.tanh ρ = default
- LeanCert.Internal.Rational.evalUnchecked e_2.sqrt ρ = (LeanCert.Internal.Rational.evalUnchecked e_2 ρ).sqrtInterval
- LeanCert.Internal.Rational.evalUnchecked (LeanCert.Core.Expr.namedConst c) ρ = c.interval
Instances For
Fundamental correctness theorem for extended evaluation.
This theorem is FULLY PROVED (no sorry, no axioms) for supported expressions.
The hsupp hypothesis ensures we only consider expressions in the verified subset.
Convenience functions #
Note: LeanCert.Internal.Rational.evalTotalCore now uses Taylor series for exp/sin/cos, which gives different (often tighter) intervals than evalInterval's floor/ceil bounds. Both are correct, but they are not necessarily equal.
For purely algebraic expressions (const, var, add, mul, neg), both evaluators give identical results.
Internal single-variable wrapper around evalUnchecked.
Equations
- LeanCert.Internal.Rational.evalUnchecked1 e I = LeanCert.Internal.Rational.evalUnchecked e fun (x : ℕ) => I
Instances For
Correctness for single-variable extended evaluation
Partial interval evaluation with inv support #
Partial (Option-returning) interval evaluator supporting inv.
For expressions with inv, this evaluator returns none if the denominator
interval contains zero, and some I with a correct enclosure otherwise.
This allows safe interval evaluation of expressions like 1/x when we can verify the denominator is bounded away from zero.
For expressions without inv, this always returns some with the same
result as evalInterval.
Equations
Instances For
Equations
Instances For
Taylor depth used by the strict atanh evaluator.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
- LeanCert.Engine.evalInterval? (LeanCert.Core.Expr.const q) ρ = some (LeanCert.Core.IntervalRat.singleton q)
- LeanCert.Engine.evalInterval? (LeanCert.Core.Expr.var idx) ρ = some (ρ idx)
- LeanCert.Engine.evalInterval? (e₁.add e₂) ρ = match LeanCert.Engine.evalInterval? e₁ ρ, LeanCert.Engine.evalInterval? e₂ ρ with | some I₁, some I₂ => some (I₁.add I₂) | x, x_1 => none
- LeanCert.Engine.evalInterval? (e₁.mul e₂) ρ = match LeanCert.Engine.evalInterval? e₁ ρ, LeanCert.Engine.evalInterval? e₂ ρ with | some I₁, some I₂ => some (I₁.mul I₂) | x, x_1 => none
- LeanCert.Engine.evalInterval? e_2.neg ρ = match LeanCert.Engine.evalInterval? e_2 ρ with | some I => some I.neg | none => none
- LeanCert.Engine.evalInterval? e_2.exp ρ = match LeanCert.Engine.evalInterval? e_2 ρ with | some I => some (I.expComputable LeanCert.Engine.evalIntervalExpDepth) | none => none
- LeanCert.Engine.evalInterval? e_2.sin ρ = match LeanCert.Engine.evalInterval? e_2 ρ with | some I => some (LeanCert.Engine.sinInterval I) | none => none
- LeanCert.Engine.evalInterval? e_2.cos ρ = match LeanCert.Engine.evalInterval? e_2 ρ with | some I => some (LeanCert.Engine.cosInterval I) | none => none
- LeanCert.Engine.evalInterval? e_2.atan ρ = match LeanCert.Engine.evalInterval? e_2 ρ with | some I => some (LeanCert.Engine.atanInterval I) | none => none
- LeanCert.Engine.evalInterval? e_2.arsinh ρ = match LeanCert.Engine.evalInterval? e_2 ρ with | some I => some (LeanCert.Engine.arsinhInterval I) | none => none
- LeanCert.Engine.evalInterval? e_2.sinh ρ = match LeanCert.Engine.evalInterval? e_2 ρ with | some I => some (LeanCert.Engine.sinhInterval I) | none => none
- LeanCert.Engine.evalInterval? e_2.cosh ρ = match LeanCert.Engine.evalInterval? e_2 ρ with | some I => some (LeanCert.Engine.coshInterval I) | none => none
- LeanCert.Engine.evalInterval? e_2.tanh ρ = match LeanCert.Engine.evalInterval? e_2 ρ with | some I => some (LeanCert.Engine.tanhInterval I) | none => none
- LeanCert.Engine.evalInterval? e_2.sqrt ρ = match LeanCert.Engine.evalInterval? e_2 ρ with | some I => some I.sqrtInterval | none => none
- LeanCert.Engine.evalInterval? (LeanCert.Core.Expr.namedConst c) ρ = some c.interval
Instances For
Main correctness theorem for evalInterval? (approach 1 from plan).
When evalInterval? returns some I:
- The expression evaluates to a value in I for all ρ_real ∈ ρ_int
- All inv denominators along the evaluation are guaranteed nonzero (because their intervals don't contain zero)
This follows your suggestion to keep ADSupported syntactic and add separate semantic hypotheses. The key insight is that if evalInterval? succeeds (returns Some), the interval arithmetic has already verified that no denominator interval contains zero.
Checked API with diagnostics #
Diagnose the first partial-domain failure after evalInterval? returned
none. This function is deliberately separate from the trusted computation:
soundness depends only on successful evalInterval?, while diagnostics may be
refined without changing the correctness theorem.
Equations
- One or more equations did not get rendered due to their size.
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.neg ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.exp ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.sin ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.cos ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.atan ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.arsinh ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.sinc ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.erf ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.sinh ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.cosh ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.tanh ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure e_2.sqrt ρ = LeanCert.Engine.EvalError.nestedFailure "unary operand" (LeanCert.Engine.diagnoseEvalIntervalFailure e_2 ρ)
- LeanCert.Engine.diagnoseEvalIntervalFailure (LeanCert.Core.Expr.const q) ρ = LeanCert.Engine.EvalError.unsupportedBackend "internal: total expression unexpectedly failed"
- LeanCert.Engine.diagnoseEvalIntervalFailure (LeanCert.Core.Expr.var idx) ρ = LeanCert.Engine.EvalError.unsupportedBackend "internal: total expression unexpectedly failed"
- LeanCert.Engine.diagnoseEvalIntervalFailure (LeanCert.Core.Expr.namedConst c) ρ = LeanCert.Engine.EvalError.unsupportedBackend "internal: total expression unexpectedly failed"
Instances For
Checked rational evaluator. Every successful result is a certified finite enclosure; domain-invalid expressions return a structured error.
Equations
- LeanCert.Engine.evalIntervalChecked e ρ = match LeanCert.Engine.evalInterval? e ρ with | some I => Except.ok I | none => Except.error (LeanCert.Engine.diagnoseEvalIntervalFailure e ρ)
Instances For
Success of evalIntervalChecked is sufficient for enclosure correctness
for every expression constructor.
Checked Rational evaluation with a tight path for the verified computable core. Unsupported syntax or a failed core-domain check falls back to the general checked evaluator, preserving its structured domain errors.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Every successful tight checked Rational evaluation encloses the expression value. The core branch uses the core correctness theorem; the fallback uses the general checked evaluator theorem.
Single-variable version of evalInterval?
Equations
- LeanCert.Engine.evalInterval?1 e I = LeanCert.Engine.evalInterval? e fun (x : ℕ) => I
Instances For
Correctness for single-variable partial evaluation
When evalInterval? succeeds, we get bounds
When evalInterval? succeeds, we get lower bounds