Documentation

LeanCert.Examples.Numerics

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 #

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 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.

          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.

            Interval [0, 2] for optimization

            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.

              Interval [1, 2] - excludes zero, so 1/x is safe to evaluate

              Equations
              Instances For

                The interval [1, 2] doesn't contain zero

                Evaluation of 1/x on [1, 2] succeeds because the interval excludes zero

                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
                  theorem LeanCert.Examples.Numerics.sinSmall_refined_correct (x : ) (hx : x { lo := 0, hi := 1 / 2, le := }) :

                  Correctness of refined evaluation