Documentation

LeanCert.Core.IntervalDyadic

Dyadic Intervals #

Intervals with Dyadic endpoints. These support "Outward Rounding", ensuring mathematical soundness even when we limit numerical precision.

Main definitions #

Design notes #

The key feature is roundOut: after each operation, we can enforce a minimum exponent to prevent precision explosion. When rounding:

This maintains the containment invariant: the rounded interval always contains the original interval, which contains the true mathematical value.

Performance #

In v1.0, Rat multiplication of 1/3 * 1/3 * ... * 1/3 (10 times) creates a denominator of 3^10 = 59049. Each operation requires GCD computation.

In v1.1, with precision = -10, the denominator stays fixed at 2^10 = 1024. The result is slightly less tight but computed significantly faster.

An interval with Dyadic endpoints.

Maintains invariant: lo.toRat ≤ hi.toRat

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      Membership and Sets #

      The set of reals contained in this interval

      Equations
      Instances For
        @[instance_reducible]

        Membership in a Dyadic interval

        Equations

        Conversion to IntervalRat #

        Convert to IntervalRat for verification with existing theorems

        Equations
        Instances For

          Membership is preserved by conversion to IntervalRat

          Construction #

          Create a singleton interval from a Dyadic

          Equations
          Instances For

            A Dyadic value is in its singleton interval

            Create an interval, checking the invariant

            Equations
            Instances For

              The width of an interval

              Equations
              Instances For
                @[simp]

                The dyadic width denotes endpoint subtraction exactly.

                Exact midpoint of a dyadic interval.

                Dyadics are closed under division by two, so midpoint construction must lower the exponent rather than shift (and potentially round) the mantissa.

                Equations
                Instances For
                  @[simp]

                  The dyadic midpoint denotes the ordinary rational midpoint exactly.

                  The lower endpoint is at most the exact midpoint.

                  The exact midpoint is at most the upper endpoint.

                  Split a dyadic interval into two exact closed halves.

                  Equations
                  Instances For
                    theorem LeanCert.Core.IntervalDyadic.mem_bisect_left {x : ℝ} {I : IntervalDyadic} (hx : x ∈ I) (hm : x ≤ ↑I.midpoint.toRat) :
                    x ∈ I.bisect.1

                    A point in the original interval and left of the midpoint is in the left half.

                    theorem LeanCert.Core.IntervalDyadic.mem_bisect_right {x : ℝ} {I : IntervalDyadic} (hx : x ∈ I) (hm : ↑I.midpoint.toRat ≤ x) :
                    x ∈ I.bisect.2

                    A point in the original interval and right of the midpoint is in the right half.

                    Membership in the left half implies membership in the original interval.

                    Membership in the right half implies membership in the original interval.

                    The two closed halves cover the original interval, including their shared seam.

                    Both closed halves contain the midpoint seam.

                    The overlap of the two closed children is exactly their midpoint seam.

                    The left child has exactly half the semantic width of its parent.

                    The right child has exactly half the semantic width of its parent.

                    Outward Rounding #

                    Outward rounding: enforces a maximum precision (minimum exponent).

                    This is the key operation for preventing precision explosion. minExp is the minimum allowed exponent (higher = coarser precision).

                    For example, minExp = -10 ensures all values are multiples of 2^(-10) ≈ 0.001.

                    Equations
                    Instances For
                      theorem LeanCert.Core.IntervalDyadic.roundOut_contains {x : ℝ} {I : IntervalDyadic} (hx : x ∈ I) (minExp : ℤ) :
                      x ∈ I.roundOut minExp

                      roundOut produces an interval containing the original

                      Interval Negation #

                      Negate an interval

                      Equations
                      Instances For

                        FTIA for negation

                        Interval Addition #

                        Add two intervals

                        Equations
                        Instances For
                          theorem LeanCert.Core.IntervalDyadic.mem_add {x y : ℝ} {I J : IntervalDyadic} (hx : x ∈ I) (hy : y ∈ J) :
                          x + y ∈ I.add J

                          FTIA for addition

                          Add with precision control

                          Equations
                          Instances For

                            Interval Subtraction #

                            Subtract two intervals

                            Equations
                            Instances For
                              theorem LeanCert.Core.IntervalDyadic.mem_sub {x y : ℝ} {I J : IntervalDyadic} (hx : x ∈ I) (hy : y ∈ J) :
                              x - y ∈ I.sub J

                              FTIA for subtraction

                              Interval Multiplication #

                              Multiply two intervals.

                              Uses min/max of all four endpoint products to handle signs correctly. This is the exact multiplication - mantissas may grow. Use mulRounded or mulNormalized for controlled precision.

                              Correctness: For x ∈ [a,b] and y ∈ [c,d], the product x*y lies in the interval [min(ac,ad,bc,bd), max(ac,ad,bc,bd)].

                              Equations
                              Instances For
                                theorem LeanCert.Core.IntervalDyadic.mem_mul {x y : ℝ} {I J : IntervalDyadic} (hx : x ∈ I) (hy : y ∈ J) :
                                x * y ∈ I.mul J

                                FTIA for multiplication

                                mulFast preserves the containment property of mul. This is retained as documentation and a future audited optimization hook; production certificate checking currently uses mul directly.

                                Multiply with precision control (outward rounding)

                                Equations
                                Instances For

                                  Multiply with mantissa normalization (prevents bit explosion)

                                  Equations
                                  Instances For

                                    Interval Scaling #

                                    Scale an interval by a constant Dyadic

                                    Equations
                                    Instances For

                                      Scale by a power of 2 (very efficient: just adjusts exponents)

                                      Equations
                                      Instances For

                                        Square Root #

                                        Square root of an interval. Returns a conservative bound [0, max(hi, 1)]. This is sound because:

                                        • sqrt(x) = 0 for x < 0 (by definition in Mathlib)
                                        • sqrt(x) ≥ 0 for all x
                                        • sqrt(x) ≤ max(x, 1) for x ≥ 0 Therefore for any x ∈ [lo, hi], sqrt(x) ∈ [0, max(hi, 1)].
                                        Equations
                                        Instances For
                                          theorem LeanCert.Core.IntervalDyadic.mem_sqrt {x : ℝ} {I : IntervalDyadic} (hx : x ∈ I) (hx_nn : 0 ≤ x) (prec : ℤ) :
                                          √x ∈ I.sqrt prec

                                          Soundness of interval sqrt: if x ∈ I, x ≥ 0, then Real.sqrt x ∈ sqrt I

                                          theorem LeanCert.Core.IntervalDyadic.mem_sqrt' {x : ℝ} {I : IntervalDyadic} (hx : x ∈ I) (prec : ℤ) :
                                          √x ∈ I.sqrt prec

                                          General soundness of interval sqrt for any real input. Handles both non-negative inputs and negative inputs (where Real.sqrt returns 0).

                                          Comparison and Containment #

                                          Check if entire interval is positive

                                          Equations
                                          Instances For

                                            Check if entire interval is negative

                                            Equations
                                            Instances For

                                              Check if I ⊆ J

                                              Equations
                                              Instances For

                                                Check if the upper bound is ≤ a rational

                                                Equations
                                                Instances For

                                                  Check if a rational is ≤ the lower bound

                                                  Equations
                                                  Instances For

                                                    Upper bound extraction from membership

                                                    Lower bound extraction from membership

                                                    What upperBoundedBy means: the interval's hi endpoint is ≤ q

                                                    What lowerBoundedBy means: q is ≤ the interval's lo endpoint

                                                    Helper for Transcendentals #

                                                    Convert from IntervalRat (for transcendental results)

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For
                                                      theorem LeanCert.Core.IntervalDyadic.mem_ofIntervalRat {x : ℝ} {I : IntervalRat} (hx : x ∈ I) (prec : ℤ) (hprec : prec ≤ 0 := by norm_num) :

                                                      If x ∈ IntervalRat I, then x ∈ ofIntervalRat I prec (outward rounding preserves membership). Requires precision ≤ 0 (e.g. -53).