TorchLean API

NN.Floats.NeuralFloat.Rounding.Odd

Round to Odd #

For an inexact real input, neuralOddRound 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.

noncomputable def TorchLean.Floats.neuralOddRound (x : ) :

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 TorchLean.Floats.neuralOddRound_lt_even {x : } {n : } (hxn : x < n) (hn : Even n) :

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

    theorem TorchLean.Floats.even_lt_neuralOddRound {x : } {n : } (hnx : n < x) (hn : Even n) :

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

    Round-to-odd with at least two extra binary digits prevents nearest-even double rounding. This is the integer-scale core of the format-level theorem.

    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. The theorem is independent of any particular floating-point exponent format, so it also applies to fixed-point and affine-quantization grids.

    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. An exact input is unchanged. An inexact result is a directed neighbor and has an odd integer mantissa at an explicit radix exponent.

    Instances For

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