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

        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

                Midpoint of an interval (approximate, using larger exponent)

                Equations
                Instances For

                  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

                              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

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