Lean floating-point model bridge #
Model fmt retains the raw interchange bits, including noncanonical NaN payloads. Lean's
Float.Model.UnpackedFloat interprets those bits using the conventional IEEE bias and exceptional
encodings for their field widths. This module connects the two without selecting binary32 or any
other fixed format. Custom descriptor biases and encoding policies require separate semantic
agreement theorems.
The bridge is width preserving: FloatFormat.toModel has exactly fmt.bitWidth packed bits, so no
padding, truncation, or host Float conversion occurs. Packing a model value canonicalizes NaNs,
as Lean's model requires; unpacking arbitrary Model bits remains total.
References #
Init.Data.Float.Model, Lean 4's logical floating-point model.- IEEE Standard for Floating-Point Arithmetic, IEEE 754-2019. https://doi.org/10.1109/IEEESTD.2019.8766229
Translate the executable sign bit to Lean's logical floating-point sign.
Instances For
Translate Lean's logical floating-point sign back to an executable sign bit.
Instances For
Translating a clear executable sign bit produces Lean's positive sign.
Translating a set executable sign bit produces Lean's negative sign.
Lean's negative logical sign translates to a set executable sign bit.
Lean's positive logical sign translates to a clear executable sign bit.
Translating an executable sign bit to the logical model and back is the identity.
View executable bits at the exactly equal width expected by Lean's model.
Instances For
Wrap packed Lean-model bits as an executable value of the corresponding format.
Instances For
Wrapping Lean-model bits and viewing them again preserves every bit.
Viewing an executable value as Lean-model bits and wrapping them again is the identity.
Splitting and recombining Lean-model components preserves the packed bit vector.
Packing explicit fields agrees with Lean's sign/exponent/fraction concatenation. Inputs are reduced
to their declared field widths by the corresponding BitVec.ofNat.
Agreement of packed fields #
These lemmas are the representation boundary for the generic bridge. They show that the manual field extractors used by the executable kernel and the extractors used by Lean's logical model read the same raw bit vector. Arithmetic refinement proofs can therefore work with one decoded sign, exponent, and mantissa rather than repeat bit-layout arguments for each format.
Packing and then extracting the one-bit sign field returns the original model sign.
Lean's model and the executable decoder extract the same fraction field.
The decoded fraction field fits in exactly the number of bits declared by its format.
The all-ones exponent word of Lean's model is the executable all-ones exponent field.
Lean's model and the executable decoder extract the same biased exponent field.
The decoded biased exponent fits in exactly the number of bits declared by its format.
An exponent field that is neither endpoint lies strictly inside the encoded range.
Native normal-number kernels use this fact after checking zero and the all-ones pattern. Keeping the arithmetic here avoids repeating width-specific proofs for binary64, binary128, and future fixed-width backends.
Lean's one-bit sign field is exactly the most significant executable bit.
Lean's unpacked sign and the executable Boolean sign agree.
Packing explicit fields retains the low expWidth bits of the biased exponent.
Packing explicit fields preserves the requested sign bit.
Repacking the fields extracted from a Model reconstructs its exact bit pattern.
Packing three zero fields produces positive zero.
Packing only the sign bit produces the IEEE negative-zero bit pattern.
An in-range fraction is recovered exactly after field packing.
An in-range biased exponent is recovered exactly after field packing.
Interpret an arbitrary bit pattern using Lean's width-parameterized IEEE model.
Instances For
Encode a Lean logical value at fmt's field widths; NaNs use Lean's canonical payload.
Instances For
Whether the bits satisfy Lean's canonical-NaN invariant for packed model values.
Instances For
Every value produced by model packing satisfies the model's canonical-NaN invariant.
Repacking through Lean's model canonicalizes bit patterns it interprets as IEEE NaNs.
Instances For
Canonicalizing through Lean's model always establishes its packed-value invariant.