TorchLean API

FloatLib.Floats.Formats.Flocq.Theory.Rounding.Nearest

Nearest Rounding with a Tie Choice #

nearestChoice 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 FloatLib.Floats.Formats.Flocq.nearestChoice (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 FloatLib.Floats.Formats.Flocq.nearestChoice_intCast (chooseUp : Bool) (n : ) :
    nearestChoice chooseUp n = n

    Choice-based nearest rounding fixes integers.

    theorem FloatLib.Floats.Formats.Flocq.nearestChoice_abs_sub_le_half (chooseUp : Bool) (x : ) :
    |(nearestChoice chooseUp x) - x| 1 / 2

    Every tie choice has absolute error at most one half.

    theorem FloatLib.Floats.Formats.Flocq.nearestChoice_mono (chooseUp : Bool) {x y : } (hxy : x y) :
    nearestChoice chooseUp x nearestChoice chooseUp y

    Choice-based nearest rounding is monotone.

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