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. nearestAwayChoice is the tie rule of IEEE 754-2019 roundTiesToAway.

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.

    Tie choice of rounding to nearest with ties away from zero.

    A midpoint f + 1/2 above a nonnegative integer f is positive and goes up to f + 1. A midpoint above a negative integer is negative and stays at f. Either way the tie goes to the neighbor of larger magnitude.

    Instances For