NLA-lib Explorer

Rounding to a binary floating-point grid

Library · Source module

Rounding to a binary floating-point grid

The binary floating-point numbers with t significant bits and unbounded exponent, Real.floatGrid t (the numbers m 2^e with integers \lvert m \rvert < 2^t and e), and rounding to nearest onto it, Real.roundNearest t x: scale \mathbf{x} by the power of two that puts \lvert \mathbf{x} \rvert in [2^{t-1}, 2^t) (through Int.log), round to an integer with Mathlib's round (ties upward) and scale back. The relative error is at most u = 2^{-t} [Higham2002, Theorem 2.2]. Mathlib's FP (Mathlib.Data.FP.Basic) is an experimental implementation of floating-point numbers with no theorems about rounding; nothing here reuses it. Upstream candidate for Mathlib.Algebra.Order.Round.

Main definitions

* Real.floatGrid: the grid of t-bit binary floating-point numbers. * Real.roundNearest: rounding to nearest onto it.

Main results

* Real.abs_sub_roundNearest_le: \lvert \mathbf{x} - \mathrm{fl}(\mathbf{x}) \rvert \le 2^{-t} \lvert \mathbf{x} \rvert. * Real.roundNearest_mem_floatGrid: rounding lands on the grid, for t \ge 1. * Real.roundNearest_eq_self_of_mem_floatGrid: rounding fixes the grid. * Real.roundNearest_roundNearest: rounding is idempotent, for t \ge 1. * Real.neg_mem_floatGrid: the grid is symmetric. * Real.roundNearest_zero, Real.roundNearest_one, Real.roundNearest_two_inv_pow: points of the grid that rounding fixes. * Real.abs_roundNearest_le_of_mem_floatGrid: rounding does not leave the modulus of a grid point. * Real.countable_range_roundNearest: rounding has countable range.

Declarations