Rational semantics of exact-dyadic order #
Dyadic stores a signed natural significand and an integral power of two. Its executable
comparison routines avoid constructing rationals: they align powers of two, compare natural
magnitudes, and account for signs. This module proves that those decisions are exactly the
ordering decisions made by Dyadic.toRat.
The correctness arguments are separate from execution. Field-level comparisons avoid temporary
Dyadic records, while format proofs can use rational inequalities. The later lemmas show that
the leading-position comparator agrees with full exponent alignment.
Basic rational denotations #
Canonical exact zero denotes rational zero.
The scaled-integer constructor has exactly its expected rational denotation.
A nonzero dyadic whose sign field is clear has a strictly positive rational denotation.
Format-specific exact rounders share this fact when they reduce signed inputs to positive magnitudes. Keeping it on the common carrier avoids duplicating sign-and-scale arguments in every radix-two format.
A dyadic has zero rational value exactly when its integer significand is zero.
Exponent alignment and comparison #
The executable comparator is the ordinary linear-order comparator on rational denotations.
This is the proof boundary that lets format-specific rounders use aligned integers while their specifications remain stated in mathlib's ordered rational field. Proving the three-way result once also keeps the strict and equality corollaries below from repeating exponent alignment.
The integer comparator reports lt exactly when rational denotation is smaller.
The integer comparator reports gt exactly when rational denotation is greater.
Keeping both strict directions at the comparator boundary lets nearest-even rounders inspect one three-way comparison instead of evaluating two independently aligned dyadic comparisons.
The integer comparator reports eq exactly for equal rational denotations.
Field-level scalable comparison #
Optimized rounders often hold the sign, significand, and exponent in local variables rather than
in a constructed Dyadic. These lemmas connect that execution path to the same rational order
without requiring runtime record construction.
Leading-position magnitude comparison equals ordinary exact nonnegative comparison.
The optimized branch avoids exponent-gap allocation; this theorem keeps the existing exact dyadic comparator as its mathematical specification.
Exponent-scalable field comparison has exactly the ordinary exact-dyadic result.
Kernels can use this equality to justify comparisons over large exponent ranges without materializing an integer whose width is the exponent gap.
Record-based scalable comparison equals ordinary exact-dyadic comparison.
Boolean comparison API #
Boolean non-strict comparison agrees with rational order.