Correctness of unsigned-scale exact addition #
For conventional IEEE descriptors, roundSum_eq identifies unsigned-scale alignment and rounding
with exact dyadic addition followed by roundDyadic. The proof includes zero operands and the
signed-zero result of cancellation. The roundOffset parameter accommodates both addition scales
and the product scales used by FMA.
theorem
FloatLib.Floats.Formats.BinaryInterchange.Model.FiniteScaleAdd.roundMagnitude_eq
(fmt : FloatFormat)
(hfmt : fmt.isIEEE = true)
(roundOffset : ℕ)
(sign : Bool)
(mantissa scale : ℕ)
:
roundMagnitude fmt roundOffset sign mantissa scale = roundDyadic fmt { negative := sign, significand := mantissa, exponent := exponent fmt scale roundOffset }
Unsigned-scale rounding is the corresponding exact dyadic rounding.
theorem
FloatLib.Floats.Formats.BinaryInterchange.Model.FiniteScaleAdd.roundMagnitudes_eq
(fmt : FloatFormat)
(hfmt : fmt.isIEEE = true)
(roundOffset : ℕ)
(leftSign rightSign : Bool)
(left right scale : ℕ)
:
roundMagnitudes fmt roundOffset leftSign rightSign left right scale = roundDyadic fmt (addDyadicMagnitudes leftSign rightSign left right (exponent fmt scale roundOffset))
The signed-magnitude helper rounds the exact dyadic magnitude sum.
theorem
FloatLib.Floats.Formats.BinaryInterchange.Model.FiniteScaleAdd.roundSum_eq
(fmt : FloatFormat)
(hfmt : fmt.isIEEE = true)
(roundOffset : ℕ)
(leftSign rightSign : Bool)
(leftMantissa leftScale rightMantissa rightScale : ℕ)
:
roundSum fmt roundOffset leftSign rightSign leftMantissa leftScale rightMantissa rightScale = roundDyadic fmt
(addDyadic { negative := leftSign, significand := leftMantissa, exponent := exponent fmt leftScale roundOffset }
{ negative := rightSign, significand := rightMantissa, exponent := exponent fmt rightScale roundOffset })
roundSum is exactly dyadic addition followed by one IEEE rounding step.