TorchLean API

NN.Floats.NeuralFloat.Rounding.Nearest

Nearest Rounding with a Tie Choice #

neuralNearestChoice chooseUp rounds to a nearest integer. At an exact midpoint, chooseUp f decides whether the lower integer f or the upper integer f + 1 is selected. This is the native Lean counterpart of Flocq's Znearest choice.

noncomputable def TorchLean.Floats.neuralNearestChoice (chooseUp : Bool) (x : ) :

Round to a nearest integer, resolving a midpoint according to its lower integer.

Instances For

    Choice-based nearest rounding always selects floor or ceiling.

    Choice-based nearest rounding lies between floor and floor plus one.

    @[simp]
    theorem TorchLean.Floats.neuralNearestChoice_intCast (chooseUp : Bool) (n : ) :
    neuralNearestChoice chooseUp n = n

    Choice-based nearest rounding fixes integers.

    theorem TorchLean.Floats.neuralNearestChoice_abs_sub_le_half (chooseUp : Bool) (x : ) :
    |(neuralNearestChoice chooseUp x) - x| 1 / 2

    Every tie choice has absolute error at most one half.

    theorem TorchLean.Floats.neuralNearestChoice_mono (chooseUp : Bool) {x y : } (hxy : x y) :

    Choice-based nearest rounding is monotone.

    Every tie-choice nearest mode is a valid nearest rounding mode.