TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.DirectedSemantics.Finite

Finite-operand helpers for directed arithmetic #

Finite-operand classification facts support the format-generic directed arithmetic proofs.

Unary NaN selection is inactive for a finite operand.

NaN selection is inactive when both operands are finite.

A finite nonzero value decodes to a dyadic with nonzero significand.

Exact intermediates of finite operands #

The exact dyadic sum of two finite values denotes their real sum.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.toReal_mulDyadic_of_toDyadic?_some {fmt : FloatFormat} {x y : Model fmt} {dx dy : Numerics.Dyadic} (hdx : x.toDyadic? = some dx) (hdy : y.toDyadic? = some dy) :
{ negative := dx.negative ^^ dy.negative, significand := dx.significand * dy.significand, exponent := dx.exponent + dy.exponent }.toReal = x.toReal * y.toReal

The exact dyadic product of two finite values denotes their real product.

Signed zero of an exactly cancelling sum #

@[simp]
theorem FloatLib.Floats.Formats.BinaryInterchange.Model.toReal_zeroForExactSum (fmt : FloatFormat) (mode : IEEERoundingMode) (leftSign rightSign : Bool) :
(zeroForExactSum fmt mode leftSign rightSign).toReal = 0

The signed zero chosen for an exactly cancelling sum denotes zero.

@[simp]

The signed zero chosen for an exactly cancelling sum is not a NaN.

@[simp]
theorem FloatLib.Floats.Formats.BinaryInterchange.Model.toEReal_zeroForExactSum (fmt : FloatFormat) (mode : IEEERoundingMode) (leftSign rightSign : Bool) :
(zeroForExactSum fmt mode leftSign rightSign).toEReal = 0

The signed zero chosen for an exactly cancelling sum denotes zero in the extended reals.

Directed operations on finite operands #

For modes other than nearest-even, finite addition and multiplication reduce to rounding an exact dyadic intermediate, and finite division with a nonzero divisor rounds an exact scaled rational. Exact cancellation has its own signed-zero rule. Square root in a directed mode instead rounds the appropriate endpoint of a dyadic bracket around the exact root, and both nearest modes use the nearest-even sqrt. These characterisations are shared by the enclosure, non-NaN, and finite-format proofs.

For finite operands, a directed addition is the directed rounding of the exact dyadic sum, or the rounding direction's signed zero when the sum cancels exactly.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.mul_eq_of_toDyadic?_some {fmt : FloatFormat} (mode : IEEERoundingMode) (hmode : mode ≠ IEEERoundingMode.nearest) {x y : Model fmt} {dx dy : Numerics.Dyadic} (hdx : x.toDyadic? = some dx) (hdy : y.toDyadic? = some dy) :
x.mul y mode = Internal.Directed.roundDyadic fmt mode { negative := dx.negative ^^ dy.negative, significand := dx.significand * dy.significand, exponent := dx.exponent + dy.exponent }

For finite operands, a directed multiplication rounds the exact dyadic product.

For a finite dividend and a finite nonzero divisor, a directed division rounds the exact scaled rational quotient.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.sqrt_of_isZero {fmt : FloatFormat} {mode : IEEERoundingMode} {x : Model fmt} (hfinite : x.isFinite = true) (hzero : x.isZero = true) :
x.sqrt mode = x

Square root fixes a finite zero of either sign in every rounding direction, for every descriptor.

On a finite positive operand, downward square root rounds the lower bracket downward.

On a finite positive operand, upward square root rounds the upper bracket upward.