TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Arithmetic.SignedSemantics.Core

Correctness of binary sign operations #

Negation usually changes only the stored sign bit. Formats with unsigned zero are the exception: their would-be negative-zero word is a reserved NaN, so semantic negation preserves both that NaN and the single zero encoding. This module separates raw sign toggling from policy-aware negation and transports the latter through dyadic decoding to the real semantics.

Reference #

@[simp]
theorem FloatLib.Floats.Formats.BinaryInterchange.Model.toggleSign_ofFields (fmt : FloatFormat) (sign : Bool) (exponent fraction : ) :
(ofFields fmt sign exponent fraction).toggleSign = ofFields fmt (!sign) exponent fraction

Toggling an explicitly packed value changes only its supplied sign field.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.neg_ofFields_of_supportsSignedZero (fmt : FloatFormat) (hfmt : fmt.supportsSignedZero = true) (sign : Bool) (exponent fraction : ) :
(ofFields fmt sign exponent fraction).neg = ofFields fmt (!sign) exponent fraction

Packed-field negation toggles the supplied sign when the format represents signed zero.

@[simp]
theorem FloatLib.Floats.Formats.BinaryInterchange.Model.fracField_copySign {fmt : FloatFormat} (magnitude signSource : Model fmt) :
(magnitude.copySign signSource).fracField = magnitude.fracField

Copying a sign never changes the fraction field.

@[simp]
theorem FloatLib.Floats.Formats.BinaryInterchange.Model.expField_copySign {fmt : FloatFormat} (magnitude signSource : Model fmt) :
(magnitude.copySign signSource).expField = magnitude.expField

Copying a sign never changes the exponent field.

theorem FloatLib.Floats.Formats.BinaryInterchange.Model.signBit_copySign_of_supportsSignedZero {fmt : FloatFormat} (magnitude signSource : Model fmt) (hfmt : fmt.supportsSignedZero = true) :
(magnitude.copySign signSource).signBit = signSource.signBit

In a signed-zero format, copySign gives the magnitude the source's sign.

@[simp]
theorem FloatLib.Floats.Formats.BinaryInterchange.Model.isNaN_copySign {fmt : FloatFormat} (magnitude signSource : Model fmt) :
(magnitude.copySign signSource).isNaN = magnitude.isNaN

Copying a sign preserves NaN classification under every format policy.

@[simp]
theorem FloatLib.Floats.Formats.BinaryInterchange.Model.isZero_copySign {fmt : FloatFormat} (magnitude signSource : Model fmt) :
(magnitude.copySign signSource).isZero = magnitude.isZero

Copying a sign preserves zero classification under every format policy.

@[simp]
theorem FloatLib.Floats.Formats.BinaryInterchange.Model.isInf_copySign {fmt : FloatFormat} (magnitude signSource : Model fmt) :
(magnitude.copySign signSource).isInf = magnitude.isInf

Copying a sign preserves infinity classification.

@[simp]
theorem FloatLib.Floats.Formats.BinaryInterchange.Model.isFinite_copySign {fmt : FloatFormat} (magnitude signSource : Model fmt) :
(magnitude.copySign signSource).isFinite = magnitude.isFinite

Copying a sign preserves finiteness.

@[simp]

Absolute value preserves NaN classification.

@[simp]

Absolute value preserves zero classification.

@[simp]

Absolute value preserves infinity classification.

@[simp]

Absolute value preserves finiteness.

In a signed-zero format, absolute value clears the stored sign.

@[simp]

Policy-aware negation is involutive for every supported encoding.

@[simp]

Negation maps positive zero to the format's policy-selected negative zero.

Negation maps negative zero to positive zero when negative zero is representable.

@[simp]

Negation exchanges the positive and negative IEEE infinity bit patterns in every encoding.

@[simp]

Negation maps the negative IEEE infinity bit pattern to the positive pattern.

@[simp]

The least positive subnormal has sign zero.

@[simp]

The least positive subnormal is finite in every supported encoding.

@[simp]

The least positive subnormal is nonzero.

@[simp]

The least positive subnormal is not a NaN.

@[simp]

The least positive subnormal is not an infinity.

The negative subnormal of least magnitude is explicit field packing with fraction one.

@[simp]

The negative subnormal of least magnitude has sign one.

@[simp]

The negative subnormal of least magnitude is finite in every supported encoding.

@[simp]

The negative subnormal of least magnitude is nonzero.

@[simp]

The negative subnormal of least magnitude is not a NaN.

@[simp]

The negative subnormal of least magnitude is not an infinity.

@[simp]

Negation maps the least positive subnormal to its negative counterpart.

@[simp]

Negation maps the negative subnormal of least magnitude to its positive counterpart.

@[simp]

The largest finite encoding carries exactly the requested sign.

@[simp]

A largest finite encoding is never zero.

@[simp]

A largest finite encoding is never a NaN.

@[simp]

A largest finite encoding is never an infinity.

@[simp]

Negation toggles the sign of the largest finite magnitude.

@[simp]

Negation maps the largest positive finite value to its negative counterpart.

@[simp]

Negation maps the most negative finite value to its positive counterpart.

@[simp]

Negation preserves NaN classification, including the reserved NaN of unsigned-zero formats.

@[simp]

Negation preserves infinity classification.

@[simp]

Negation preserves zero classification.

@[simp]

Negation preserves finiteness.

@[simp]

Flipping the sign flag of a dyadic negates its real value, including for zero significands.

Policy-aware negation decodes to exact dyadic negation with the format's zero convention.

@[simp]

Format-aware dyadic negation is real-number negation.

@[simp]

On finite values, executable policy negation is real-number negation.