TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Configured.Instances

Ordinary Lean instances for configured binary values #

Configured binary values ExecFloat (Configured.Family format code plan) receive the ordinary Lean interfaces here, generically in the storage codec, so byte, machine-word, and wide carriers share one set of instances. Numerical literals are rounded once from exact rationals. Display, comparison, equality, and hashing operate on the exact-width model, independently of the packed carrier.

Two different notions of equality are installed:

These instances do not provide LawfulBEq. Using configured values as Std.HashMap or Std.HashSet keys requires an equality and hashing convention that satisfies their laws.

< and ≤ use IEEE numerical comparisons: a < b holds exactly when the numerical comparison returns some .lt, and a ≤ b when it returns some .lt or some .eq. Every comparison involving a NaN is false, so a ≤ a fails for NaN and these relations are not a Preorder. max and min are IEEE maximum and minimum: they propagate NaN and order -0 below +0, so max a b = if a ≤ b then b else a fails on NaN inputs.

@[instance_reducible]

Configured binary comparison follows the descriptor's IEEE-style numerical order.

NaNs are unordered, signed zeros compare equal, and every other pair is ordered by exact value.

@[simp]

The stored word determines the value, so decoding to the model is injective.

Comparison on configured values is comparison of their exact-width models.

@[instance_reducible]

The default configured binary value is positive zero.

@[simp]

The default configured binary value is positive zero.

@[instance_reducible]

Structural equality of the stored interchange word.

This differs from ==: distinct signed-zero encodings are unequal and a NaN equals itself. Deciding equality on the exact-width model keeps the instance independent of the packed carrier.

@[instance_reducible]

Hash of the complete interchange word.

Structural equality = guarantees equal hashes. Numerical equality == alone does not, since distinct signed-zero encodings compare numerically equal.

The hash of a configured binary value is the hash of its interchange word.

@[instance_reducible]

IEEE strict order: a < b holds when the numerical comparison returns some .lt.

@[instance_reducible]

IEEE weak order: a ≤ b holds when the comparison returns some .lt or some .eq.

@[instance_reducible]

< is decided by the executable comparison.

@[instance_reducible]

≤ is decided by the executable comparison.

@[instance_reducible]

IEEE maximum: NaN operands propagate as a quiet NaN and max (-0) (+0) = +0.

This is not the order-theoretic maximum of ≤, since NaNs are unordered by ≤.

@[instance_reducible]

IEEE minimum: NaN operands propagate as a quiet NaN and min (-0) (+0) = -0.

This is not the order-theoretic minimum of ≤, since NaNs are unordered by ≤.

@[simp]

max decodes to IEEE maximum on the exact-width models.

@[simp]

min decodes to IEEE minimum on the exact-width models.

< holds exactly when the model comparison returns some .lt.

< on configured values is Model.lt on their models.

≤ holds exactly when the model comparison returns some .lt or some .eq.

≤ on configured values is Model.le on their models.

Nothing is strictly below or above a NaN.

Nothing is weakly below or above a NaN.

Strict order is irreflexive, for NaN because it is unordered and otherwise by equality.

≤ is reflexive exactly on non-NaN values.

@[instance_reducible]

Configured binary values print their mathematical value rather than their packed carrier.

@[instance_reducible]

Numeral literals are rounded once from the exact natural number into the destination format.

@[instance_reducible]

Scientific and decimal literals are rounded once from their exact rational value into the destination format.

@[instance_reducible]

Negation follows the destination format's signed-zero and exceptional-value policy.