Correctness of nearest-even real rounding #
For conventional IEEE descriptors, Model.roundDyadic delegates normalization to Lean's generic
logical float model. This module relates that executable result to the independent Flocq-style
rounded-real semantics in FloatLib.Floats.Formats.Flocq.FloatRep. Exponent and fraction widths
remain symbolic. The grid membership and preservation results also cover custom biases and
encoding policies, but the executable rounding refinement requires fmt.isIEEE = true.
The rounded-real model has gradual underflow but no infinities. So refinement theorems assume that the executable result is finite, since an overflowing IEEE result cannot equal a real-valued rounding function.
References #
- IEEE Standard for Floating-Point Arithmetic, IEEE 754-2019, Section 4.3.1.
- S. Boldo and G. Melquiond, "Flocq: A Unified Library for Proving Floating-Point Algorithms in Coq," ARITH 2011. https://doi.org/10.1109/ARITH.2011.40
- Lean 4,
Init.Data.Float.Model.Unpacked.Round.
Precision and gradual-underflow grid using the descriptor’s declared exponent bias.
Instances For
Rounding of a real onto the precision and gradual-underflow grid of fmt, with the descriptor's
bias, in the direction mode, nearest-even by default.
The real grid has no upper exponent bound. Overflow and exceptional encodings belong to the
executable operation, and its equality to roundAt needs the corresponding refinement hypotheses.
Nearest-even rounding and the two infinity directions unfold to Flocq's round with
nearestEven, ceilRound, and floorRound, and every direction is
round (roundingFunction mode) (roundAt_eq_round).
Instances For
Rounding in every direction is Flocq's rounding with the direction's integer rule.
Every rounding direction fixes zero.
Rounding a negated real gives the negation of rounding the real in the mirrored direction
mode.negate, which exchanges the two infinity directions and fixes the other four. Nearest-even
rounding commutes with negation.
Every rounding direction is monotone in the real input.
Every finite decoded word belongs to its descriptor's precision and gradual-underflow grid. The result includes custom biases, FNUZ, and finite-only encodings.
The absolute value of a dyadic ignores its stored sign bit.
A nonzero dyadic has the leading exponent predicted by its integer mantissa.
Lean's model and the rounded-real format choose the same exponent for a nonzero dyadic.
The canonical scaled mantissa of a dyadic is its signed magnitude at the target exponent.
Nearest-even rounding of a nonnegative dyadic agrees with executable shift-and-round.
Nearest-even rounding commutes with the sign stored in a dyadic value.
The executable natural power of two has the same real value as the binary radix power.
Rounded-real semantics of a nonzero dyadic at a conventional IEEE descriptor.
The integer on the right is computed entirely by shifts and nearest-even rounding. The exponent is
chosen by Lean's generic logical float model and independently characterized by fexpOf.
Real value of a finished rounded mantissa on the subnormal grid.
The mantissa may be zero, in which case the packed value is a signed zero, or reach
2 ^ fracWidth, in which case it is the least normal value. Both have the stated real value.
Real value of a finished normalized rounded mantissa with leading bit at unbiased exponent k.
The mantissa lies in [2 ^ fracWidth, 2 ^ (fracWidth + 1)]. The upper endpoint is the carry that
finishRoundedMantissa renormalizes to exponent k + 1. The finiteness hypothesis excludes IEEE
overflow, which has no value in ℝ.
Executable dyadic rounding refines the rounded-real semantics for conventional IEEE descriptors.
The finiteness hypothesis excludes the one case that has no value in ℝ: IEEE overflow to
infinity. Custom widths are allowed when they satisfy the IEEE-descriptor condition.