TorchLean API

FloatLib.Floats.Formats.Posit.Model.Fields

Tapered posit field decoding #

Posit field decoding recovers the variable-length regime, tapered exponent, fraction, significand, and binary scale from a model word. The resulting DecodedFields structure is the common proof-facing boundary for exact semantics and optimized arithmetic.

@[inline]

Count a leading run in exactly width low bits of value, starting at bit width - 1.

Instances For
    theorem FloatLib.Floats.Formats.Posit.Model.countLeadingRun_le (value width : ) (bit : Bool) :
    countLeadingRun value width bit width

    A leading run cannot consume more bits than the width being inspected.

    theorem FloatLib.Floats.Formats.Posit.Model.countLeadingRun_self_pos (value width : ) (hwidth : 0 < width) :
    0 < countLeadingRun value width (value.testBit (width - 1))

    Inspecting a nonempty word from its actual first bit finds a nonempty run.

    @[inline]

    First regime bit in the magnitude payload.

    Instances For
      @[inline]

      Number of equal leading regime bits.

      Instances For

        The tapered regime consumes at most the complete payload.

        Every posit word has a nonempty leading regime run.

        @[inline]

        Whether an opposite regime-terminator bit is present.

        Instances For
          @[inline]

          Bits available after the regime and its optional terminator.

          Instances For

            Regime and trailing fields together fit inside the payload.

            @[inline]

            Number of exponent bits actually present in this tapered encoding.

            Instances For
              @[inline]

              Number of explicit fraction bits present in this tapered encoding.

              Instances For

                The explicit fraction is a subfield of the trailing payload.

                Regime and explicit fraction together never exceed the payload.

                @[inline]

                Low explicit fraction field.

                Instances For
                  @[inline]

                  Exponent bits physically present between the regime and fraction.

                  Instances For
                    @[inline]

                    Full exponent value after restoring unavailable low bits as zeros.

                    Exponent bits are consumed most-significant first. Tapering therefore removes low exponent bits, which is represented by this left shift.

                    Instances For

                      At most the descriptor's two standard exponent bits are physically present.

                      The restored standard exponent field is always below four.

                      @[inline]

                      Signed regime value k.

                      Instances For
                        @[inline]

                        Exact binary scale after accounting for the explicit fraction denominator.

                        Instances For

                          Every decoded posit scale is no smaller than -4 times its payload width.

                          theorem FloatLib.Floats.Formats.Posit.Model.scale_lt_four_bits {format : Format} (value : Model format) :
                          value.scale < 4 * Int.ofNat format.bits

                          Every decoded posit scale is strictly below four times its total encoded width.

                          theorem FloatLib.Floats.Formats.Posit.Model.zero_or_nar_or_scale_eq_zero_of_bits_eq_two {format : Format} (value : Model format) (hbits : format.bits = 2) :
                          value = zero format value = nar format value.scale = 0

                          At the minimum standard width, every word is zero, NaR, or one of the two encodings of unit magnitude. The latter therefore has dyadic scale zero.

                          This boundary case complements the uniform payload bound used in quire proofs for widths of at least three.

                          Complete decoded fields of a nonzero finite posit.

                          • negative : Bool

                            Sign of the represented finite value.

                          • regimeBit : Bool

                            First bit of the variable-length regime.

                          • regimeRunLength :

                            Number of repeated regime bits.

                          • regimeValue :

                            Signed regime value.

                          • usedExponentBits :

                            Number of exponent bits physically present.

                          • exponentField :

                            Exponent after omitted low bits are restored as zero.

                          • fractionBits :

                            Number of explicit fraction bits.

                          • fractionField :

                            Explicit fraction field.

                          • significand :

                            Positive integer significand, including its implicit leading bit.

                          • scale :

                            Binary exponent applied to significand.

                          Instances For
                            Instances For
                              @[instance_reducible]
                              @[inline]

                              Decode all fields of a nonzero finite posit word.

                              Instances For

                                A decoded posit significand fits within the complete posit word's width.

                                A decoded posit significand fits in the format payload.

                                The regime always consumes at least one payload bit, so the implicit leading significand bit together with every explicit fraction bit occupies at most payloadBits positions.

                                @[inline]

                                Signed integer significand before applying the binary scale.

                                Instances For
                                  @[inline]

                                  Format-independent exact dyadic value represented by these decoded fields.

                                  Integer kernels use this value after the posit decoder recovers the tapered fields. Other radix-two families use the same exact-number representation.

                                  Instances For
                                    @[inline]

                                    Exact dyadic rational represented by these decoded fields.

                                    Instances For
                                      @[simp]
                                      theorem FloatLib.Floats.Formats.Posit.Model.DecodedFields.toDyadic_fields {format : Format} (fields : DecodedFields format) :
                                      fields.toDyadic = { negative := fields.negative, significand := fields.significand, exponent := fields.scale }

                                      Expanding toDyadic exposes the decoded sign, significand, and binary scale unchanged.