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 serves every exponent width and both directed rounding modes, so division and conversion proofs share one rational lemma instead of repeating leading-bit arguments per format.
Executable power-of-two comparisons #
Numerics.RationalBinary.lessThanPowerOfTwo tests whether a natural quotient is below a binary
power.
Numerics.RationalBinary.atLeastPowerOfTwo 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 stays 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 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.
Comparison with an arbitrary dyadic #
The optimized comparison of a signed scaled rational with an arbitrary dyadic returns their real-number ordering whenever the denominator is nonzero.
Zero operands and opposite signs are decided from the signs alone. Two negative operands compare
their magnitudes in reverse order, which reduces to compareDyadicScaled?_false_eq_compare.