TorchLean API

FloatLib.Floats.Formats.Flocq.Theory.Rounding.Odd

Round to Odd #

For an inexact real input, oddRound selects the odd member of the two adjacent integers. Exact integers are unchanged. Applied to a binary scaled mantissa, this is the usual round-to-odd or jamming rule: discarded information is recorded by setting the least-significant retained bit.

Preserve integers; otherwise select the odd integer among floor x and floor x + 1.

Instances For

    Round-to-odd always selects one of the two adjacent integers.

    @[simp]

    Exact integers are fixed by round-to-odd.

    An inexact input receives an odd integer result.

    Round-to-odd is monotone and fixes every integer.

    theorem FloatLib.Floats.Formats.Flocq.oddRound_lt_even {x : } {n : } (hxn : x < n) (hn : Even n) :

    An input below an even integer rounds to an integer strictly below it.

    theorem FloatLib.Floats.Formats.Flocq.even_lt_oddRound {x : } {n : } (hnx : n < x) (hn : Even n) :

    An input above an even integer rounds to an integer strictly above it.

    theorem FloatLib.Floats.Formats.Flocq.nearestEven_roundOdd_binary_extra (extra : ) (x : ) :
    nearestEven ((oddRound (x * 2 ^ (extra + 2))) / 2 ^ (extra + 2)) = nearestEven x

    Round-to-odd with at least two extra binary digits prevents nearest-even double rounding on the integer grid. roundAtScale_nearestEven_after_odd_binary_extra transports this to any fixed grid; no floating-point (exponent-dependent) version is proved in this library.

    theorem FloatLib.Floats.Formats.Flocq.roundAtScale_nearestEven_after_odd_binary_extra (extra : ) (step x : ) (hstep : 0 < step) :
    roundAtScale nearestEven step hstep (roundAtScale oddRound (step / 2 ^ (extra + 2)) x) = roundAtScale nearestEven step hstep x

    Round-to-odd on a finer binary grid prevents nearest-even double rounding on a coarser grid.

    The coarse grid has positive spacing step; the intermediate grid is finer by extra + 2 binary digits. Both grids are fixed, so the theorem applies to fixed-point and affine-quantization grids. It does not cover floating-point formats, whose spacing depends on the exponent of the value.

    If x is not representable, round-to-odd selects an odd scaled integer mantissa.

    Round-to-odd produces a value in the selected generic format.

    Semantic round-to-odd specification at the grid exponent selected for the input.

    An exact input is unchanged. An inexact result is a directed neighbor whose integer mantissa is odd at exponent. Fixing this exponent matters: every nonzero binary dyadic has an odd mantissa at some exponent, which alone would not characterize round-to-odd.

    Instances For
      theorem FloatLib.Floats.Formats.Flocq.round_odd_point {β : Numerics.Radix} {fexp : } [ValidExp fexp] (x : ) :
      RoundOddPoint β (genericFormat β fexp) (cexp β fexp x) x (round oddRound x)

      Generic rounding with oddRound satisfies the round-to-odd point specification.