Dyadic Intervals #
Intervals with Dyadic endpoints. These support "Outward Rounding", ensuring mathematical soundness even when we limit numerical precision.
Main definitions #
IntervalDyadic- Interval with Dyadic endpointsIntervalDyadic.add,mul,neg- Interval arithmetic operationsIntervalDyadic.roundOut- Outward rounding to control precisionIntervalDyadic.toIntervalRat- Convert to rational interval for verification
Design notes #
The key feature is roundOut: after each operation, we can enforce a minimum
exponent to prevent precision explosion. When rounding:
- Lower bounds are shifted down (toward -∞)
- Upper bounds are shifted up (toward +∞)
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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Membership and Sets #
Membership in a Dyadic interval
Conversion to IntervalRat #
Convert to IntervalRat for verification with existing theorems
Instances For
Membership is preserved by conversion to IntervalRat
Construction #
Create a singleton interval from a Dyadic
Equations
- LeanCert.Core.IntervalDyadic.singleton d = { lo := d, hi := d, le := ⋯ }
Instances For
Default interval [0, 0]
Create an interval, checking the invariant
Equations
Instances For
The width of an interval
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.
Instances For
roundOut produces an interval containing the original
Interval Negation #
Negate an interval
Instances For
FTIA for negation
Interval Addition #
Add two intervals
Instances For
FTIA for addition
Add with precision control
Equations
- I.addRounded J prec = (I.add J).roundOut prec
Instances For
Interval Subtraction #
Subtract two intervals
Instances For
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
FTIA for multiplication
Multiply with precision control (outward rounding)
Equations
- I.mulRounded J prec = (I.mul J).roundOut prec
Instances For
Multiply with mantissa normalization (prevents bit explosion)
Equations
- I.mulNormalized J maxBits = { lo := (I.mul J).lo.normalizeDown maxBits, hi := (I.mul J).hi.normalizeUp maxBits, le := ⋯ }
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)
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
- I.sqrt _prec = { lo := LeanCert.Core.Dyadic.zero, hi := I.hi.max (LeanCert.Core.Dyadic.ofInt 1), le := ⋯ }
Instances For
Soundness of interval sqrt: if x ∈ I, x ≥ 0, then Real.sqrt x ∈ sqrt I
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 interval contains zero
Equations
Instances For
Check if entire interval is positive
Equations
Instances For
Check if entire interval is negative
Equations
Instances For
Check if the upper bound is ≤ a rational
Instances For
Check if a rational is ≤ the lower bound
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
If x ∈ IntervalRat I, then x ∈ ofIntervalRat I prec (outward rounding preserves membership). Requires precision ≤ 0 (e.g. -53).