TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Model.Fields.Optimized

Optimized field access for binary models #

The public field operations in Model.Carrier use exact-width bit vectors, which expose the storage layout cleanly to proofs. This module defines extensionally equal Nat implementations and registers their compiler substitutions. Each field decoder reads the natural-number storage pattern; packing constructs one natural-number pattern with an erased proof that it fits the width.

The theorems here are execution certificates: they justify erased bounds or compiler rewrites. Semantic facts about the public field operations belong in Model.Fields.Proof.

Masked sign, exponent, and fraction fields always fit their declared storage word.

@[inline]

Read the sign directly from the natural-number storage pattern.

Instances For
    @[inline]

    Decode the exponent after one conversion of the storage word to Nat.

    Instances For
      @[inline]

      Decode the fraction after one conversion of the storage word to Nat.

      Instances For

        The direct natural-number sign decoder agrees with the public bit-vector definition.

        @[csimp]

        The compiler reads the sign from the natural-number storage pattern.

        The direct natural-number exponent decoder agrees with the public bit-vector definition.

        @[csimp]

        The compiler decodes the exponent through one conversion to Nat.

        The direct natural-number fraction decoder agrees with the public bit-vector definition.

        @[csimp]

        The compiler decodes the fraction through one conversion to Nat.

        @[inline]

        Pack fields as one natural-number bit pattern known to fit the exact storage width.

        The bound passed to BitVec.ofNatLT is erased from compiled code. Unlike BitVec.ofNat, this avoids computing a redundant modulus after the masked fields have already established the width.

        Instances For
          theorem FloatLib.Floats.Formats.BinaryInterchange.Model.mkBits_eq_mkBitsImpl_apply (fmt : FloatFormat) (sign : Bool) (exponent fraction : ) :
          mkBits fmt sign exponent fraction = mkBitsImpl fmt sign exponent fraction

          The direct natural-number field packer agrees with the public mask-based definition.

          @[csimp]

          The compiler packs fields as one natural-number bit pattern.

          @[inline]

          Construct a Model through the direct natural-number field packer.

          Instances For
            @[csimp]

            The compiler constructs explicit fields through the direct natural-number packer.