Binary exponent bounds for positive rational numbers #
The executable rational rounder locates a positive quotient between consecutive powers of two
using Numerics.RationalBinary.floorLog2. This module proves that format-independent
characterization, including the asymmetric numerator and denominator cases that make quotient
normalization easy to get wrong.
The result is shared by arbitrary exponent widths and both directed rounding modes. Division and conversion proofs can therefore reuse one rational lemma instead of duplicating leading-bit arguments for each concrete format.
Executable power-of-two comparisons #
Numerics.RationalBinary.lessThanPowerOfTwo exactly tests whether a natural quotient is below a
binary power.
Numerics.RationalBinary.atLeastPowerOfTwo exactly tests whether a binary power is at most the
real quotient of two natural numbers with nonzero denominator.
Coarse logarithm bounds #
The difference of the numerator and denominator leading-bit positions locates a positive quotient within one binary exponent.
Exact floor-logarithm characterization #
Two intervals of the form [2^e, 2^(e+1)) containing the same value have equal exponents.
Numerics.RationalBinary.floorLog2 places a positive quotient between consecutive powers of two.
The shift-based rational logarithm agrees with Mathlib's integer logarithm on positive inputs.
Viewing a positive natural number as a quotient by one preserves its floor binary logarithm.
A binary interval characterization determines Numerics.RationalBinary.floorLog2.
Exact binary scaling adds its exponent to the rational floor logarithm.
The leading exponent of a scaled positive rational bounds its exact real value between consecutive binary powers.
After moving an external binary exponent into a positive rational, its quotient remains between the binary powers determined by the original leading exponent plus that scale.
Comparison with a positive dyadic #
The optimized comparison of a nonnegative scaled rational with a positive dyadic returns exactly their real-number ordering.
The comparison first uses the leading exponent of the ratio to the dyadic. Only when that exponent is zero does it compare the scaled numerator and denominator.
Nonnegative scaled-rational comparison returns .lt exactly for strict real order.
Nonnegative scaled-rational comparison returns .eq exactly for real equality.
Nonnegative scaled-rational comparison returns .gt exactly for reverse strict real order.