Certificate-Driven Verification #
This file provides the infrastructure for certificate-driven verification of numerical bounds. Instead of Lean searching for a proof, an external agent (e.g., Python) provides a Certificate containing:
Expr: The function f(x)Domain: The interval IClaim: E.g., f(I) ⊆ [a, b]ProofParams: Parameters like Taylor series depth
If the agent determines that exp(x) needs 20 Taylor terms to satisfy a bound,
it passes taylorDepth := 20 to Lean. Lean runs the computation with that
depth and checks the boolean result via native_decide.
Main definitions #
Boolean Checkers #
checkUpperBound- Check if∀ x ∈ I, f(x) ≤ cvia interval arithmeticcheckLowerBound- Check if∀ x ∈ I, c ≤ f(x)via interval arithmeticcheckStrictUpperBound- Check if∀ x ∈ I, f(x) < ccheckStrictLowerBound- Check if∀ x ∈ I, c < f(x)
Golden Theorems #
verify_upper_bound- ConvertscheckUpperBound = trueto semantic proofverify_lower_bound- ConvertscheckLowerBound = trueto semantic proofverify_strict_upper_bound- ConvertscheckStrictUpperBound = trueto semantic proofverify_strict_lower_bound- ConvertscheckStrictLowerBound = trueto semantic proof
Design #
The boolean checkers are fully computable and can be evaluated by native_decide.
The golden theorems bridge the gap between the boolean result and the semantic
proof about real numbers.
Usage #
Manual usage (before tactic implementation): #
example : ∀ x ∈ I01, Expr.eval (fun _ => x) exprExp ≤ 3 :=
verify_upper_bound exprExp exprExp_core I01 3 { taylorDepth := 15 } (by native_decide)
RPC workflow: #
- Python receives a request: "Prove x·e^x ≤ 5 on [0, 1.2]"
- Python runs its own fast implementation to find sufficient depth (e.g., 15)
- Python generates Lean code with the certificate:
verify_upper_bound myExpr myExpr_core I_0_1_2 5 { taylorDepth := 15 } (by native_decide) - Lean executes, running
evalIntervalCorewith depth 15, checks boolean, closes goal
Check if an expression is bounded above by c on interval I.
Returns true iff domain validity holds AND the computed upper bound is ≤ c.
Equations
- LeanCert.Validity.checkUpperBound e I c cfg = (LeanCert.Engine.checkDomainValid1 e I cfg && decide ((LeanCert.Engine.evalIntervalCore1 e I cfg).hi ≤ c))
Instances For
Check if an expression is bounded below by c on interval I.
Returns true iff domain validity holds AND the computed lower bound is ≥ c.
Equations
- LeanCert.Validity.checkLowerBound e I c cfg = (LeanCert.Engine.checkDomainValid1 e I cfg && decide (c ≤ (LeanCert.Engine.evalIntervalCore1 e I cfg).lo))
Instances For
Check if an expression is strictly bounded above by c on interval I.
Returns true iff domain validity holds AND the computed upper bound is < c.
Equations
- LeanCert.Validity.checkStrictUpperBound e I c cfg = (LeanCert.Engine.checkDomainValid1 e I cfg && decide ((LeanCert.Engine.evalIntervalCore1 e I cfg).hi < c))
Instances For
Check if an expression is strictly bounded below by c on interval I.
Returns true iff domain validity holds AND the computed lower bound is > c.
Equations
- LeanCert.Validity.checkStrictLowerBound e I c cfg = (LeanCert.Engine.checkDomainValid1 e I cfg && decide (c < (LeanCert.Engine.evalIntervalCore1 e I cfg).lo))
Instances For
Golden Theorems #
These theorems convert the boolean true from the checkers into semantic proofs
about Real numbers. They are the theorems a tactic will apply.
Golden Theorem for Upper Bounds
If checkUpperBound e I c cfg = true, then ∀ x ∈ I, Expr.eval (fun _ => x) e ≤ c.
This is the key theorem for certificate-driven verification of upper bounds. The proof uses:
- The boolean check ensures
(evalIntervalCore1 e I cfg).hi ≤ c - The fundamental correctness theorem ensures
Expr.eval ... e ≤ hi - Transitivity gives
Expr.eval ... e ≤ c
Golden Theorem for Lower Bounds
If checkLowerBound e I c cfg = true, then ∀ x ∈ I, c ≤ Expr.eval (fun _ => x) e.
This is the key theorem for certificate-driven verification of lower bounds. The proof uses:
- The boolean check ensures
c ≤ (evalIntervalCore1 e I cfg).lo - The fundamental correctness theorem ensures
lo ≤ Expr.eval ... e - Transitivity gives
c ≤ Expr.eval ... e
Golden Theorem for Strict Upper Bounds
If checkStrictUpperBound e I c cfg = true, then ∀ x ∈ I, Expr.eval (fun _ => x) e < c.
Golden Theorem for Strict Lower Bounds
If checkStrictLowerBound e I c cfg = true, then ∀ x ∈ I, c < Expr.eval (fun _ => x) e.
Convenience lemmas for pointwise bounds #
Pointwise upper bound: if check passes and x ∈ I, then f(x) ≤ c
Pointwise lower bound: if check passes and x ∈ I, then c ≤ f(x)
Two-sided bounds #
Check both lower and upper bounds simultaneously
Equations
- LeanCert.Validity.checkBounds e I lo hi cfg = (LeanCert.Validity.checkLowerBound e I lo cfg && LeanCert.Validity.checkUpperBound e I hi cfg)
Instances For
Two-sided bound verification: if both checks pass, then lo ≤ f(x) ≤ hi for all x ∈ I
Argmax/Argmin Verification #
These theorems support proving ∀ y ∈ I, f(y) ≤ f(x) (argmax) and
∀ y ∈ I, f(x) ≤ f(y) (argmin) via a concrete rational bound.
Check that evaluating f at a point x gives a value ≥ c. We evaluate on the point interval [x, x] and check the lower bound. This gives us c ≤ f(x) when x is rational.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check that evaluating f at a point x gives a value ≤ c.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Verify that c ≤ f(x) at a specific point x.
Verify that f(x) ≤ c at a specific point x.
Argmax Verification Theorem
Proves ∀ y ∈ I, f(y) ≤ f(x) (x is a maximizer) by:
- Checking that
∀ y ∈ I, f(y) ≤ c(the max over I is at most c) - Checking that
c ≤ f(x)(the value at x is at least c) This impliesf(y) ≤ c ≤ f(x)by transitivity.
Argmin Verification Theorem
Proves ∀ y ∈ I, f(x) ≤ f(y) (x is a minimizer) by:
- Checking that
∀ y ∈ I, c ≤ f(y)(the min over I is at least c) - Checking that
f(x) ≤ c(the value at x is at most c) This impliesf(x) ≤ c ≤ f(y)by transitivity.
ExprSupportedWithInv bounds #
Support for expressions with inv, log, atan, arsinh, atanh. These use the
evalInterval? evaluator which may return none for invalid inputs.
NOTE: These are noncomputable because evalInterval? uses Real Taylor approximations.
They cannot be used with native_decide. Use the verification theorems directly
in term proofs or with explicit computation.
Check upper bound for ExprSupportedWithInv expressions.
Returns true iff evalInterval?1 succeeds and the upper bound is ≤ c.
NOTE: Noncomputable - cannot be used with native_decide.
Equations
- LeanCert.Validity.checkUpperBoundWithInv e I c = match LeanCert.Engine.evalInterval?1 e I with | some J => decide (J.hi ≤ c) | none => false
Instances For
Check lower bound for ExprSupportedWithInv expressions.
Returns true iff evalInterval?1 succeeds and the lower bound is ≥ c.
NOTE: Noncomputable - cannot be used with native_decide.
Equations
- LeanCert.Validity.checkLowerBoundWithInv e I c = match LeanCert.Engine.evalInterval?1 e I with | some J => decide (c ≤ J.lo) | none => false
Instances For
Check strict upper bound for ExprSupportedWithInv expressions. NOTE: Noncomputable - cannot be used with native_decide.
Equations
- LeanCert.Validity.checkStrictUpperBoundWithInv e I c = match LeanCert.Engine.evalInterval?1 e I with | some J => decide (J.hi < c) | none => false
Instances For
Check strict lower bound for ExprSupportedWithInv expressions. NOTE: Noncomputable - cannot be used with native_decide.
Equations
- LeanCert.Validity.checkStrictLowerBoundWithInv e I c = match LeanCert.Engine.evalInterval?1 e I with | some J => decide (c < J.lo) | none => false
Instances For
Verification theorem for upper bounds with ExprSupportedWithInv.
Verification theorem for lower bounds with ExprSupportedWithInv.
Verification theorem for strict upper bounds with ExprSupportedWithInv.
Verification theorem for strict lower bounds with ExprSupportedWithInv.
Bridge theorem for Set.Icc upper bounds with ExprSupportedWithInv.
Bridge theorem for Set.Icc lower bounds with ExprSupportedWithInv.
Bridge theorem for Set.Icc strict upper bounds with ExprSupportedWithInv.
Bridge theorem for Set.Icc strict lower bounds with ExprSupportedWithInv.
Smart Bounds with Monotonicity #
These checkers use derivative information to get tighter bounds at interval endpoints. If the function is monotonic on the interval, we can evaluate at the appropriate endpoint to get an exact bound, avoiding Taylor series remainder widening.
Smart lower bound check using monotonicity.
- Tries standard interval check first (fastest).
- If fails, computes derivative interval.
- If derivative > 0 (increasing), checks if f(I.lo) ≥ c.
- If derivative < 0 (decreasing), checks if f(I.hi) ≥ c.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Smart upper bound check using monotonicity.
- Tries standard interval check first.
- If fails, computes derivative interval.
- If derivative > 0 (increasing), checks if f(I.hi) ≤ c.
- If derivative < 0 (decreasing), checks if f(I.lo) ≤ c.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Smart Golden Theorems #
Helper: For increasing functions, the minimum is at the left endpoint
Helper: For decreasing functions, the minimum is at the right endpoint
Smart lower bound verification using monotonicity
Helper: For increasing functions, the maximum is at the right endpoint
Helper: For decreasing functions, the maximum is at the left endpoint
Smart upper bound verification using monotonicity
Set.Icc Bridge Theorems #
These theorems bridge between IntervalRat-based proofs and Set.Icc goals, allowing tactics to work with the more natural Set.Icc syntax.
Bridge from IntervalRat proof to Set.Icc upper bound goal
Bridge from IntervalRat proof to Set.Icc lower bound goal
Bridge from IntervalRat proof to Set.Icc upper bound goal (Core version). This version uses ExprSupportedCore and the basic checkUpperBound (no monotonicity).
Bridge from IntervalRat proof to Set.Icc lower bound goal (Core version). This version uses ExprSupportedCore and the basic checkLowerBound (no monotonicity).
Bridge from IntervalRat proof to Set.Icc strict upper bound goal (Core version).
Bridge from IntervalRat proof to Set.Icc strict lower bound goal (Core version).
Subdivision Theorems #
These theorems allow combining bounds from interval subdivisions. When interval arithmetic gives overly wide bounds, subdividing the domain and proving bounds on each piece can help.
Combine upper bounds from two halves using splitMid. If f ≤ c on both halves, then f ≤ c on the whole interval.
Combine lower bounds from two halves using splitMid.
Combine strict upper bounds from two halves.
Combine strict lower bounds from two halves.
Bridge from subdivision to Set.Icc upper bound goal.
Bridge from subdivision to Set.Icc lower bound goal.
Bridge from subdivision to Set.Icc strict upper bound goal.
Bridge from subdivision to Set.Icc strict lower bound goal.
General Split Theorems #
These theorems work with arbitrary split points, not just midpoints. Useful for adaptive subdivision algorithms.
Combine upper bounds from two arbitrary adjacent intervals. If f ≤ c on [lo, mid] and f ≤ c on [mid, hi], then f ≤ c on [lo, hi].
Combine lower bounds from two arbitrary adjacent intervals.
Combine strict upper bounds from two arbitrary adjacent intervals.
Combine strict lower bounds from two arbitrary adjacent intervals.
Global Optimization Certificates #
These checkers and theorems extend the certificate pattern to multivariate global optimization over n-dimensional boxes.
Boolean Checkers for Global Optimization #
Check if c is a lower bound for e over box B.
Returns true iff globalMinimizeCore(e, B, cfg).bound.lo ≥ c.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check if c is an upper bound for e over box B.
Returns true iff globalMaximizeCore(e, B, cfg).bound.hi ≤ c.
(i.e., the upper bound on max(e) is ≤ c, which proves ∀ρ, e(ρ) ≤ c)
Note: bound.hi = -globalMinimizeCore(-e).bound.lo, and by correctness globalMinimizeCore(-e).bound.lo ≤ -e(ρ) for all ρ, so e(ρ) ≤ bound.hi.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check both lower and upper bounds for global optimization
Equations
- LeanCert.Validity.GlobalOpt.checkGlobalBounds e B lo hi cfg = (LeanCert.Validity.GlobalOpt.checkGlobalLowerBound e B lo cfg && LeanCert.Validity.GlobalOpt.checkGlobalUpperBound e B hi cfg)
Instances For
Golden Theorems for Global Optimization #
Golden Theorem for Global Lower Bounds
If checkGlobalLowerBound e B c cfg = true, then ∀ ρ ∈ B, c ≤ Expr.eval ρ e.
This converts the boolean certificate into a semantic proof about all points in the box.
Note: This uses ExprSupported (no log) which guarantees domain validity automatically. For expressions with log, use the Core version with explicit domain validity proofs.
Golden Theorem for Global Upper Bounds
If checkGlobalUpperBound e B c cfg = true, then ∀ ρ ∈ B, Expr.eval ρ e ≤ c.
The maximization problem is reduced to minimization of -e.
Note: This uses ExprSupported (no log) which guarantees domain validity automatically. For expressions with log, use the Core version with explicit domain validity proofs.
Two-sided global bound verification
Root Finding Certificates #
These checkers and theorems provide certificate-driven verification for root existence and uniqueness.
Configuration for root finding certificates #
Configuration for root-finding checks
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Configuration for Newton uniqueness checks
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Boolean Checkers for Root Finding #
Check if expression has a sign change on interval (indicating a root). Uses interval arithmetic to check if f(lo) and f(hi) have opposite signs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check if interval definitely has no root (function has constant sign).
Returns true if the function's interval evaluation doesn't contain 0.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Computable Newton Step for Unique Root Verification #
Computable Newton step using evalIntervalCore1 and derivIntervalCore.
This is the computable equivalent of newtonStepSimple. It performs one
interval Newton iteration: N(I) = c - f(c)/f'(I) where c = midpoint(I).
Returns none if the derivative interval contains 0 (can't safely divide).
Returns some (I ∩ N) otherwise.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract structure from newtonStepCore.
Computable check if Newton iteration contracts.
Returns true if newtonStepCore produces N with I.lo < N.lo and N.hi < I.hi.
This can be used with native_decide for unique root verification.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check if Newton iteration contracts, indicating unique root existence.
Returns true if the Newton step from I gives N ⊂ interior(I).
Note: This is noncomputable because newtonStepSimple uses derivInterval which uses evalInterval (noncomputable). For native_decide, we would need a fully computable version using evalIntervalCore.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Golden Theorems for Root Finding #
Golden Theorem for No Root
If checkNoRoot e I cfg = true, then ∀ x ∈ I, Expr.eval (fun _ => x) e ≠ 0.
Golden Theorem for Newton Contraction (Unique Root Existence)
If checkNewtonContracts e I cfg = true, then there exists a unique root in I.
This theorem requires additional hypotheses that the external checker must verify:
- The expression is supported
- The expression uses only variable 0
- The function is continuous on I
Core MVT Lemmas for Newton Contraction Contradiction #
These lemmas prove that if Newton contraction holds but f has constant sign at both endpoints, we get a contradiction via MVT bounds.
Key insight: If f doesn't change sign on I (both endpoints positive or both negative), then by monotonicity (from nonzero derivative), f has constant sign throughout I. But Newton contraction requires specific quotient bounds that MVT proves are violated.
MVT lower bound using derivIntervalCore: if f'(ξ) ∈ [dI.lo, dI.hi] for all ξ ∈ I, then f(y) - f(x) ≥ dI.lo * (y - x) for x ≤ y in I.
MVT upper bound using derivIntervalCore: if f'(ξ) ∈ [dI.lo, dI.hi] for all ξ ∈ I, then f(y) - f(x) ≤ dI.hi * (y - x) for x ≤ y in I.
Golden Theorem for Computable Newton Contraction (Unique Root Existence)
This version assumes both:
- Core contraction check (computable, used by search/external tools)
- Non-core contraction check (used for the formal proof, via
verify_unique_root_newton).
The formal proof only relies on the non-core checker; the core checker can be used by the external agent for optimization but is not needed logically. This avoids the need to prove complex MVT-based contradiction lemmas for the Core interval functions.
Note: The h_cert_core hypothesis is not used in the proof but is kept
in the signature so the certificate format can include it for external
tooling purposes.
Fully Computable Unique Root Verification #
The following theorems provide a fully computable path to proving unique root existence
using only checkNewtonContractsCore. This allows native_decide to work without requiring
noncomputable functions like Real.exp or Real.log.
Newton step preserves roots when using Core evaluation functions. If x is a root in I and newtonStepCore produces N, then x ∈ N.
If Newton step succeeds, there's at most one root in I (via Rolle's theorem). This uses the fact that if dI doesn't contain zero, the derivative is nonzero everywhere on I, so f is strictly monotonic.
MVT bound using Core functions: If f' ≥ dI.lo > 0 (increasing) and f(I.lo) > 0, then f(c) > dI.lo * hw where c = midpoint and hw = half-width.
MVT bound using Core functions: If f' ≥ dI.lo > 0 (increasing) and f(I.hi) < 0, then f(c) < -dI.lo * hw where c = midpoint and hw = half-width.
MVT bound using Core functions: If f' ≤ dI.hi < 0 (decreasing) and f(I.lo) < 0, then f(c) < 0 and more specifically, fc.lo / dI.hi ≥ hw.
MVT bound using Core functions: If f' ≤ dI.hi < 0 (decreasing) and f(I.hi) > 0, then f(c) > 0 and more specifically, fc.hi / dI.hi ≤ -hw.
Golden Theorem for Computable Unique Root (Fully Computable)
If checkNewtonContractsCore e I cfg = true, then there exists a unique root in I.
This theorem uses ONLY computable functions (no Real.exp, Real.log, etc.),
making it suitable for native_decide verification.
Sign Change Root Existence #
Golden Theorem for Sign Change Root Existence
If checkSignChange e I cfg = true, then there exists a root in I.
This uses the Intermediate Value Theorem: if f(lo) and f(hi) have opposite signs, and f is continuous on I, then f has a root in I.
Bisection-Based Root Existence #
Check if bisection finds a root (returns hasRoot for some sub-interval). This runs the bisection algorithm and checks if any interval has hasRoot status.
Note: This is noncomputable because bisectRoot uses evalInterval1.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Golden Theorem for Bisection Root Existence
If checkHasRoot e I cfg = true, then there exists a root in I.
This uses bisectRoot_hasRoot_correct which proves that if bisection returns hasRoot for a sub-interval J ⊆ I, then there exists a root in J (hence in I).
Integration Certificates #
Computable Integration Infrastructure #
For interval_integrate tactic, we need:
- A computable integration function using
evalIntervalCore1 - A theorem that
ExprSupportedCoreimpliesIntervalIntegrable - A verification theorem linking the computation to the real integral
Computable uniform partition using evalIntervalCore1
Equations
Instances For
Sum of interval bounds over a partition using computable evalIntervalCore1
Equations
- One or more equations did not get rendered due to their size.
Instances For
Computable interval bounds on ∫_a^b f(x) dx using uniform partitioning
Equations
Instances For
For single-interval integration (n=1), computable version
Equations
Instances For
IntervalIntegrable from ExprSupportedCore #
All ExprSupportedCore expressions are continuous, hence integrable on compact intervals.
All ExprSupportedCore expressions are interval integrable on any compact interval.
This follows because ExprSupportedCore expressions are continuous (see exprSupportedCore_continuousOn), and continuous functions on compact intervals are integrable.
Note: Requires domain validity for expressions with log.
Correctness of Computable Integration #
Single-interval integration correctness for ExprSupportedCore.
This is proved directly using the same structure as integrateInterval1_correct but with the computable evalIntervalCore1 instead of noncomputable evalInterval1.
The hdom hypothesis ensures evaluation domain validity (e.g., log arguments have positive interval bounds).
The hcontdom hypothesis ensures continuity domain validity (e.g., log arguments are positive on the set).
Check if the integral bound contains a given rational value. Returns true if domain is valid and the computed integral bound contains the target value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Golden Theorem for Integration Bounds
If checkIntegralBoundsCore e I target cfg = true, then the integral is bounded by the
computed interval.
Note: The target parameter and h_cert hypothesis are used for the native_decide workflow
where we verify at compile time that target is in the computed interval. The actual proof
of interval membership uses integrateInterval1Core_correct directly.
This theorem allows proving statements like "∫_a^b f(x) dx ∈ [lo, hi]".
Note: Requires continuity domain validity for expressions with log.
Extract the computed integral bound as an interval
Equations
Instances For
The integral lies within the computed bound (computable version)
Note: Requires continuity domain validity for expressions with log.
Single-interval integration for ExprSupportedWithInv #
Computable single-interval integration using evalInterval?1.
Returns none if interval evaluation fails (e.g., log domain invalid).
Equations
- LeanCert.Validity.Integration.integrateInterval1WithInv e I = match LeanCert.Engine.evalInterval?1 e I with | some J => some ((LeanCert.Core.IntervalRat.singleton I.width).mul J) | none => none
Instances For
Single-interval integration correctness for ExprSupportedWithInv. Requires that evalInterval?1 succeeds on the interval.
Check if the computed integration bound contains a target value. Returns false if interval evaluation fails.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Golden Theorem for Integration Bounds (WithInv)
If checkIntegralBoundsWithInv e I target = true, then the integral lies in the
computed bound. The target parameter is for the native_decide workflow.
Partitioned integration for ExprSupportedWithInv #
Collect per-subinterval bounds using evalInterval?1.
Returns none if any subinterval fails.
Equations
Instances For
Sum bounds over a uniform partition using evalInterval?1.
Equations
- One or more equations did not get rendered due to their size.