Numerics Examples #
This file demonstrates numerical integration, optimization, and root finding using LeanCert.
Verified Integration Examples #
The integrateInterval_correct_n1 theorem is FULLY PROVED for the
supported expression subset {const, var, add, mul, neg, sin, cos}.
This demonstrates end-to-end verified numerical integration.
Verified Integration Examples #
The constant function 1
Instances For
Proof that constOne is in the supported subset
Equations
Instances For
The identity function x
Instances For
Proof that identity is supported
Equations
Instances For
The expression x²
Equations
Instances For
Proof that xSquared is supported
Equations
Instances For
Unit interval for integration
Equations
- LeanCert.Examples.Numerics.unitInterval = { lo := 0, hi := 1, le := LeanCert.Examples.Numerics.unitInterval._proof_1 }
Instances For
Example: Verified integration of constant function #
For the constant function 1 over [0,1], the integral is exactly 1. We can prove that our computed interval bound contains this value.
This uses the FULLY PROVED integrateInterval_correct_n1 theorem.
The computed interval bound for ∫₀¹ 1 dx
Equations
- One or more equations did not get rendered due to their size.
Instances For
Verified: the true integral ∫₀¹ 1 dx lies in our computed bound.
This theorem has NO SORRY - it's a direct application of the
fully-verified integrateInterval_correct_n1.
Example: Verified integration of x² #
For x² over [0,1], the true integral is 1/3. Our interval bound is guaranteed to contain this value.
The computed interval bound for ∫₀¹ x² dx
Equations
- One or more equations did not get rendered due to their size.
Instances For
Verified: the true integral ∫₀¹ x² dx lies in our computed bound.
Example: Verified integration with sin #
For sin(x) over [0, 1], we get verified bounds using the global [-1,1] bound.
The expression sin(x)
Equations
Instances For
Proof that sin(x) is supported
Equations
Instances For
The computed interval bound for ∫₀¹ sin(x) dx
Equations
- One or more equations did not get rendered due to their size.
Instances For
Verified: the true integral ∫₀¹ sin(x) dx lies in our computed bound.
Optimization examples #
The optimization module (LeanCert.Engine.Optimize) is fully verified
with theorems like minimizeInterval_correct for the ExprSupported subset.
The expression x² - 2x + 1 = (x-1)² with minimum at x = 1
Equations
- One or more equations did not get rendered due to their size.
Instances For
Root finding examples #
The root finding module (LeanCert.Engine.RootFinding.Main) is fully verified
with all theorems proved including newton_contraction_has_root and bisection correctness.
x² - 2 has root at √2 ≈ 1.414
Equations
Instances For
Search interval for √2
Equations
- LeanCert.Examples.Numerics.searchInterval = { lo := 1, hi := 2, le := LeanCert.Examples.Numerics.searchInterval._proof_1 }
Instances For
ExprSupported proof for x² - 2
Instances For
Bisection root finding example #
For x² - 2, we know the root is √2 ∈ [1, 2]. We demonstrate bisection
and prove that when it reports hasRoot, there truly exists a root.
Bisection result for x² - 2 on [1, 2] with 20 iterations and tol = 1/100
Equations
- One or more equations did not get rendered due to their size.
Instances For
x² - 2 evaluates to a polynomial in x, which is continuous
Correctness: every interval marked hasRoot in bisection result contains a true root.
This uses bisectRoot_hasRoot_correct from the verified bisection module.
Optimization example #
The quadratic (x-1)² = x² - 2x + 1 has minimum value 0 at x = 1. We demonstrate using minimizeInterval to get verified bounds.
ExprSupported proof for quadratic (x² - 2x + 1)
Equations
Instances For
Interval [0, 2] for optimization
Equations
- LeanCert.Examples.Numerics.I02 = { lo := 0, hi := 2, le := LeanCert.Examples.Numerics.I02._proof_1 }
Instances For
Minimization result for quadratic on [0, 2]
Equations
Instances For
UsesOnlyVar0 proof for quadratic
Equations
Instances For
Correctness: the computed lower bound is indeed a lower bound on the true minimum.
For all x in [0, 2], we have quad_min_result.valueBound.lo ≤ quadratic(x).
This uses minimizeInterval_correct from the verified optimization module.
Inverse function example #
The partial evaluator evalInterval? supports expressions with division (Expr.inv)
when the divisor interval excludes zero. This example demonstrates its usage.
The expression 1/x (inverse of x)
Equations
Instances For
ExprSupportedWithInv proof for 1/x
Equations
Instances For
Interval [1, 2] - excludes zero, so 1/x is safe to evaluate
Equations
- LeanCert.Examples.Numerics.I12 = { lo := 1, hi := 2, le := LeanCert.Examples.Numerics.searchInterval._proof_1 }
Instances For
The interval [1, 2] doesn't contain zero
Evaluation of 1/x on [1, 2] succeeds because the interval excludes zero
Evaluation succeeds
Get the bound result when evaluation succeeds
Equations
Instances For
Correctness: if evaluation succeeds, the result contains the true value.
For 1/x on [1, 2], we have 1/x ∈ [1/2, 1] (since x ∈ [1, 2] implies 1/x ∈ [1/2, 1]). The computed bound is guaranteed to contain this.
Refined evaluation example #
The refined evaluators use Taylor models for tighter bounds on transcendentals.
sin(x) on [0, 0.5] - the refined evaluator gives tighter bounds than [-1, 1]
Equations
- One or more equations did not get rendered due to their size.
Instances For
Correctness of refined evaluation