Nearest-even rounding of positive rational numbers #
Lean's logical floating-point model represents an inexact quotient by its integer quotient and an
Accuracy value computed from the remainder. Model.roundRatScaled rounds the same rational
after moving a binary exponent into its numerator or denominator. This module proves that those
representations remain equivalent through model normalization.
All results are independent of a particular floating-point format.
Quotient bounds #
Nearest-even quotient rounding lies between the directed floor and ceiling rounders.
The nonzero-denominator premise is essential: at denominator zero and positive numerator, both directed rounders return zero but nearest-even quotient rounding returns one.
Nearest-even normal-path rounding stays within the normalized mantissa interval.
The integer quotient and remainder accuracy used to round numerator / denominator.
Instances For
Multiplying the remainder and denominator by a common nonzero factor preserves accuracy.
A common nonzero scale factor does not change a quotient's extended mantissa.
Nearest-even quotient rounding depends only on the represented nonnegative rational.
Successive exact binary scalings may be combined before nearest-even rounding.
Scaling a denominator by 2 ^ shift is exact binary scaling by 2 ^ (-shift).
Round a quotient at a chosen binary exponent either directly or by first restoring the quotient's exact external exponent.
Shifting a quotient right by shift bits scales its denominator by 2 ^ shift.
Adding quotient bits by shifting left is undone by the matching right shift.
Nearest-even rounding after shifting a quotient agrees with rounding the rational number whose denominator has been scaled by the same power of two.
After choosing the format's target exponent, model quotient rounding reduces to one
roundQuotientEven call on the correspondingly scaled denominator.