TorchLean API

FloatLib.Floats.Formats.IEEE754.Native.Model

Packed native floating-point models #

The conversions below connect the descriptor-indexed Model to Lean's packed binary32 and binary64 models. Converting from a native model retains every bit. Converting to one canonicalizes NaN signs and payloads, as required by Lean's packed-value invariant.

Lean 4.33 introduced these logical floating-point models. Lean 4.34 adds public nan and inf constants for Float32, Float, and their packed models, and strengthens the generic format invariant to require at least two exponent bits. These additions let both native widths share the representation and constant proofs below.

The generic representation lemmas imported here separate this normalization from arithmetic refinement. They concern Lean's logical definitions; they add no assumption about native machine instructions and do not select a floating-point backend.

Binary32 #

@[inline]

Read the exact canonical word stored by Lean's packed binary32 model.

Instances For
    @[inline]

    Pack binary32 bits into Lean's model, canonicalizing any NaN sign and payload.

    Instances For

      Native packed binary32 always satisfies the generic canonical-word invariant.

      @[simp]

      Unpacking the exact native binary32 word agrees with Lean's unpacked interpretation.

      @[simp]

      Packing an unpacked value agrees across the binary32 representation boundary.

      @[simp]

      Converting to a packed native model and back performs exactly NaN canonicalization.

      Reading the exact binary32 word loses no information from a native packed model.

      @[simp]

      Every native binary32 model round-trips exactly through FloatLib's representation.

      @[simp]

      Canonicalization does not change the unpacked interpretation of a binary32 conversion.

      @[simp]

      Packing already packed model output agrees with the direct binary32 model constructor.

      Equality of packed binary32 conversions is equality of their unpacked interpretations.

      Binary64 #

      @[inline]

      Read the exact canonical word stored by Lean's packed binary64 model.

      Instances For
        @[inline]

        Pack binary64 bits into Lean's model, canonicalizing any NaN sign and payload.

        Instances For

          Native packed binary64 always satisfies the generic canonical-word invariant.

          @[simp]

          Unpacking the exact native binary64 word agrees with Lean's unpacked interpretation.

          @[simp]

          Packing an unpacked value agrees across the binary64 representation boundary.

          @[simp]

          Converting to a packed native model and back performs exactly NaN canonicalization.

          Reading the exact binary64 word loses no information from a native packed model.

          @[simp]

          Every native binary64 model round-trips exactly through FloatLib's representation.

          @[simp]

          Canonicalization does not change the unpacked interpretation of a binary64 conversion.

          @[simp]

          Packing already packed model output agrees with the direct binary64 model constructor.

          Equality of packed binary64 conversions is equality of their unpacked interpretations.

          Native constants #

          @[simp]

          Lean's binary64 NaN has FloatLib's canonical IEEE quiet-NaN word.

          @[simp]

          Lean's positive binary32 infinity has the ordinary all-ones-exponent encoding.

          @[simp]

          Lean's positive binary64 infinity has the ordinary all-ones-exponent encoding.

          @[simp]

          The binary32 positive-infinity constant converts back to Lean's packed infinity.

          @[simp]

          The binary64 positive-infinity constant converts back to Lean's packed infinity.