TorchLean API

FloatLib.Floats.Interval.Rounders

Directed rounding (down/up) for Flocq-style formats #

For interval propagation under a discrete numeric grid (float, fixed-point, quantization), one typically wants directed rounding at interval endpoints:

In IEEE-754 hardware this corresponds to the rounding modes toward $-\infty$ and toward $+\infty$. FloatLib represents these directions with Flocq-style rounding on $\mathbb{R}$ via round together with the floor/ceil rounding functions from FloatLib/Floats/Formats/Flocq/Theory/Rounding/Core.lean.

The rounders work for any radix $\beta$ and exponent selection function fexp satisfying ValidExp.

References:

noncomputable def FloatLib.Floats.Interval.roundDown {β : Numerics.Radix} {fexp : } [Formats.Flocq.ValidExp fexp] (x : ) :

Round down to the $(\beta,\mathtt{fexp})$ grid by taking the floor of the scaled mantissa.

Instances For
    noncomputable def FloatLib.Floats.Interval.roundUp {β : Numerics.Radix} {fexp : } [Formats.Flocq.ValidExp fexp] (x : ) :

    Round up to the $(\beta,\mathtt{fexp})$ grid by taking the ceiling of the scaled mantissa.

    Instances For

      Correctness of directed rounding down: roundDown x is an enclosure lower bound.

      This is the format-generic analogue of the IEEE-754 fact that rounding toward $-\infty$ never exceeds the exact real value.

      Correctness of directed rounding up: roundUp x is an enclosure upper bound.

      This is the format-generic analogue of the IEEE-754 fact that rounding toward $+\infty$ is never below the exact real value.

      A pair of real maps bracketing every real number from below and above.

      This is the only interface the enclosure proofs need: they use $\operatorname{down}(x)\le x\le\operatorname{up}(x)$ and nothing else. In particular the structure does not require down x or up x to lie on any representable grid, nor does it require monotonicity; the identity maps satisfy both bounds. Representability is a property of a particular instance such as formatRounder, whose outputs lie on the $(\beta,\mathtt{fexp})$ grid by construction.

      • down :

        A lower bound for an exact real value.

      • up :

        An upper bound for an exact real value.

      • down_le (x : ) : self.down x x

        Rounding down never exceeds the exact value.

      • le_up (x : ) : x self.up x

        Rounding up never falls below the exact value.

      Instances For

        Canonical rounder for the $(\beta,\mathtt{fexp})$ format via roundDown/roundUp.

        The outputs are values of the Flocq generic format, which has an unbounded exponent range: there is no overflow to infinity and no largest finite value, so this rounder models a binary format's finite grid extended past its exponent limits rather than the encoded format itself.

        Instances For