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.

The double-rounding result below concerns a fixed binary grid. The corresponding theorem for floating-point formats also needs hypotheses relating their precision and minimum exponents.

References:

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.

      Flocq's round-to-odd point predicate, testing parity at the result's canonical exponent. Abrupt-underflow grids can give a different exponent to the input and output, so input-grid parity alone does not establish this predicate.

      Instances For
        theorem FloatLib.Floats.Formats.Flocq.round_odd_canonical_point_of_cexp_eq {β : Numerics.Radix} {fexp : ℤ → ℤ} [ValidExp fexp] (x : ℝ) (hexponent : cexp β fexp (round oddRound x) = cexp β fexp x) :

        Input-grid rounding satisfies canonical round-to-odd whenever the canonical exponent is preserved. Fixed-point grids always satisfy this condition.

        Fixed-point round-to-odd meets Flocq's canonical parity convention for every input.