TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Dyadic.Decode

Correctness of exact IEEE decoding #

Binary arithmetic proofs need an exact value that is cheaper and more concrete than a real number. toDyadic? decodes every finite encoding to that value and rejects exceptional encodings. Conventional IEEE descriptors reuse the established unpacked model; configurable descriptors follow their declared bias and exceptional-value policy.

The central theorem proves that executable field decoding agrees with Lean's logical floating model. Later lemmas recover finiteness, sign, zero, and sign-toggle facts from successful decoding. This direction is deliberate: optimized kernels may inspect fields, while their proofs can immediately move to one canonical exact dyadic semantics.

Complete-format decoding #

@[inline]

Decode a finite Model into an exact dyadic under its complete format descriptor.

The conventional IEEE case delegates to the established decoder. Other encodings use their declared exponent bias and exceptional-value policy directly.

Instances For

    Exact rational value of a finite executable float; returns none for NaN or infinity.

    Instances For

      The IEEE field decoder agrees with Lean's logical IEEE model.

      The theorem is width-generic. Both sides use the conventional IEEE interpretation of the layout; the descriptor's custom bias and exceptional-value policy are handled separately by toDyadic?.

      theorem FloatLib.Floats.Formats.BinaryInterchange.Model.toModel_eq_finite_of_ieeeToDyadic?_eq_some {fmt : FloatFormat} (x : Model fmt) (sign : Bool) (mantissa : ) (exponent : ) (hmantissa : mantissa 0) (hdecode : x.ieeeToDyadic? = some { negative := sign, significand := mantissa, exponent := exponent }) :
      x.toModel = Float.Model.UnpackedFloat.finite (modelSign sign) mantissa exponent

      A nonzero successful dyadic decode determines the corresponding finite logical model value.

      theorem FloatLib.Floats.Formats.BinaryInterchange.Model.toModel_eq_zero_of_ieeeToDyadic?_eq_some {fmt : FloatFormat} (x : Model fmt) (sign : Bool) (exponent : ) (hdecode : x.ieeeToDyadic? = some { negative := sign, significand := 0, exponent := exponent }) :

      A zero dyadic decode determines the corresponding signed model zero.

      Decoding and finiteness #

      IEEE decoding preserves magnitude and exponent when the storage sign bit is toggled.

      IEEE dyadic decoding preserves the stored sign bit.

      A decoded dyadic has zero mantissa only when the source is an IEEE signed zero.

      A successful dyadic decode certifies that the source bit pattern is finite.

      Every bit pattern that is neither NaN nor infinity has an exact dyadic decode.

      Every bit pattern classified as finite by IEEE rules has an exact dyadic decode.

      IEEE dyadic decoding succeeds exactly on bit patterns classified as finite by IEEE rules.