TorchLean API

NN.Floats.IEEEExec.DirectedRoundingSoundness.Positive

Directed rounding soundness for IEEE32Exec #

NN/Floats/IEEEExec/Exec32.lean defines executable directed rounding on the IEEE-754 binary32 grid:

This file proves (one core piece of) the enclosure direction (“golden theorem” style): the directed rounding down kernel for positive dyadics is a sound lower bound for the exact real value.

Scope (what is proved here):

Outside this file's scope:

References:

Basic helpers #

@[reducible, inline]
Instances For

    bpow e = 2^e is strictly positive.

    bpow e = 2^e is nonnegative.

    Exponent law for bpow: bpow (e₁+e₂) = bpow e₁ * bpow e₂.

    pow2 is monotone in the exponent, in the simple form pow2 k ≤ pow2 (k+1).

    We use this for small exponent-range arguments (e.g. 2^23 ≤ 2^24) without importing broader monotonicity machinery.

    Strict growth of pow2: pow2 k < pow2 (k+1).

    Commuted form of pow2_add: pow2 a * pow2 b = pow2 (a + b).

    Interpret bpow at a natural exponent in terms of pow2.

    Interpret bpow at a negative successor exponent as an inverse power of two.

    theorem TorchLean.Floats.IEEE754.IEEE32Exec.dyadicToReal_pos (mant : ) (exp : ) :
    dyadicToReal { sign := false, mant := mant, exp := exp } = mant * bpow exp

    Real semantics of a nonnegative dyadic (mant, exp) (sign bit false).

    theorem TorchLean.Floats.IEEE754.IEEE32Exec.dyadicToReal_signTrue (mant : ) (exp : ) :
    dyadicToReal { sign := true, mant := mant, exp := exp } = -(mant * bpow exp)

    Real semantics of a negative dyadic (mant, exp) (sign bit true).

    A few float32 constants as reals #

    Shift helpers (floor/ceil division by powers of two) #

    shiftRightCeilPow2 is also controlled from above by the corresponding floor quotient: ceil-division can overshoot by at most 1.

    Soundness: directed rounding on positive dyadics #

    theorem TorchLean.Floats.IEEE754.IEEE32Exec.toReal_roundDyadicPosDown_le (mant : ) (exp : ) (hm : mant 0) :
    (roundDyadicPosDown mant exp).toReal mant * bpow exp

    roundDyadicPosDown is a real lower bound for a positive dyadic.

    theorem TorchLean.Floats.IEEE754.IEEE32Exec.toEReal_roundDyadicPosUp_ge (mant : ) (exp : ) (hm : mant 0) :
    mant * (bpow exp) (roundDyadicPosUp mant exp).toEReal

    roundDyadicPosUp mant exp is an EReal upper bound for the positive dyadic (mant : ℝ) * 2^exp.

    This is the “ceil” counterpart to toReal_roundDyadicPosDown_le.