Remainder representability and exact value #
On the finer operand grid, either the dividend or the divisor has an original bounded coefficient. The integer remainder is no larger than either. Hence the exact result fits at the preferred quantum, including subnormal results.
theorem
FloatLib.Floats.Formats.DecimalInterchange.Arithmetic.remainder_coefficient_lt
(f : Format)
(cx cy : ℕ)
(qx qy : ℤ)
(hx : cx < f.coefficientBound)
(hy : cy < f.coefficientBound)
(hc : cy ≠ 0)
:
The exact remainder coefficient fits the original precision at the smaller quantum.
theorem
FloatLib.Floats.Formats.DecimalInterchange.Arithmetic.remainderFinite_valid
(f : Format)
(sx sy : Bool)
(cx cy : ℕ)
(qx qy : ℤ)
(hx : Datum.Valid f (Datum.finite sx cx qx))
(hy : Datum.Valid f (Datum.finite sy cy qy))
(hc : cy ≠ 0)
:
Datum.Valid f (remainderFinite sx cx qx cy qy)
theorem
FloatLib.Floats.Formats.DecimalInterchange.Arithmetic.remainder_valid
(f : Format)
(x y : Datum)
(hx : Datum.Valid f x)
(hy : Datum.Valid f y)
:
Datum.Valid f (remainder f x y).value
theorem
FloatLib.Floats.Formats.DecimalInterchange.Arithmetic.remainder_quantum
(f : Format)
(sx sy : Bool)
(cx cy : ℕ)
(qx qy : ℤ)
(hc : cy ≠ 0)
:
∃ (s : Bool) (c : ℕ), (remainder f (Datum.finite sx cx qx) (Datum.finite sy cy qy)).value = Datum.finite s c (min qx qy)
Every finite ordinary result uses exactly the preferred quantum.
theorem
FloatLib.Floats.Formats.DecimalInterchange.Arithmetic.remainder_value
(f : Format)
(sx sy : Bool)
(cx cy : ℕ)
(qx qy : ℤ)
(hc : cy ≠ 0)
:
(remainder f (Datum.finite sx cx qx) (Datum.finite sy cy qy)).value.toRat? = some (Datum.finiteValue sx cx qx - ↑(remainderInteger sx sy cx cy qx qy) * Datum.finiteValue sy cy qy)
theorem
FloatLib.Floats.Formats.DecimalInterchange.Arithmetic.remainder_zero_sign
(sx : Bool)
(cx cy : ℕ)
(qx qy : ℤ)
(hc : cy ≠ 0)
(s : Bool)
(q : ℤ)
(hz : remainderFinite sx cx qx cy qy = Datum.finite s 0 q)
:
A zero remainder retains the dividend's sign, for either sign of divisor.