TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Model.Carrier

Descriptor-indexed binary-interchange proof model #

Model fmt is the bit-exact specification carrier for the binary-interchange family. Statically declared formats use FloatLib.Floats.ExecFloat F, whose runtime representation is selected by EncodedFormat F.

This model stores BitVec fmt.bitWidth so descriptor-generic specifications and refinement proofs can quantify over a runtime-selected layout. Concrete format packages bridge their direct runtime codes to this model at the proof boundary.

References #

Descriptor-indexed bit-level proof model for format fmt.

The carrier is BitVec fmt.bitWidth; every stored bit is part of the format.

  • bits : fmt.ExecWord

    Raw binary storage pattern.

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

      Wrap a storage word as a Model.

      Instances For
        @[inline]

        Wrap a Nat pattern, reduced to the format's exact bit width.

        Instances For
          @[inline]

          Extract the raw storage word.

          Instances For
            @[inline]

            Return the encoded bit pattern as a natural number.

            Instances For

              Every encoded word lies below the radix determined by its stored width.

              @[inline]

              Wrap a UInt32 pattern, truncating it when the destination has fewer than 32 bits.

              Instances For
                @[simp]

                Re-encoding the exact natural-number bit pattern preserves a binary value.

                @[simp]

                An in-range natural-number pattern is not changed by fixed-width encoding.

                @[simp]

                Wrapping a storage word and reading it back is the identity.

                @[simp]

                Rewrapping the storage word of a value is the identity.

                Field extraction and classification #

                @[inline]

                Whether the sign bit is set.

                Instances For

                  The executable sign test is the most significant bit of the storage word.

                  @[inline]

                  The biased exponent field as a natural number.

                  Instances For
                    @[inline]

                    The low fracWidth bits of the fraction field.

                    Instances For
                      @[inline]

                      Whether x has an IEEE NaN bit pattern.

                      Instances For
                        @[inline]

                        Whether x has an IEEE quiet-NaN bit pattern.

                        Instances For
                          @[inline]

                          Whether x has an IEEE signaling-NaN bit pattern.

                          Instances For
                            @[inline]

                            Whether x has an IEEE infinity bit pattern.

                            Instances For
                              @[inline]

                              Whether x has an IEEE signed-zero bit pattern.

                              Instances For
                                @[inline]

                                Whether x has an IEEE finite bit pattern.

                                Instances For

                                  Policy-aware classification #

                                  @[inline]

                                  Whether x is one of the NaN encodings selected by its complete format.

                                  Instances For
                                    @[inline]

                                    Whether x is a quiet NaN.

                                    The non-IEEE policies represented by FloatFormat.Encoding do not distinguish signaling from quiet NaNs, so every NaN in those formats is classified as quiet.

                                    Instances For
                                      @[inline]

                                      Whether x is a signaling NaN. Only the IEEE encoding has signaling NaNs.

                                      Instances For

                                        A value that is not a NaN cannot be a signaling NaN.

                                        @[inline]

                                        Whether x is an infinity. Only the IEEE encoding contains infinities.

                                        Instances For
                                          @[inline]

                                          Whether x denotes zero under its complete format.

                                          Instances For
                                            @[inline]

                                            Whether x denotes a finite value under its complete format.

                                            Instances For
                                              @[inline]

                                              Whether x is a finite subnormal under its complete format.

                                              Instances For

                                                Encoding and constants #

                                                @[inline]

                                                Pack a sign, biased exponent, and fraction into one exact-width storage word.

                                                Instances For
                                                  @[inline]

                                                  Construct a value from its sign, exponent, and fraction fields.

                                                  Instances For
                                                    @[inline]

                                                    Positive zero.

                                                    Instances For
                                                      @[inline]

                                                      The negative-zero bit pattern; it denotes NaN in FNUZ formats.

                                                      Instances For
                                                        @[inline]

                                                        Positive one.

                                                        Instances For
                                                          @[inline]

                                                          Negative one.

                                                          Instances For
                                                            @[inline]

                                                            The positive-infinity IEEE bit pattern; use infinity? for policy-aware construction.

                                                            Instances For
                                                              @[inline]

                                                              The negative-infinity IEEE bit pattern; use infinity? for policy-aware construction.

                                                              Instances For
                                                                @[inline]

                                                                Finite value of greatest magnitude with the requested sign.

                                                                Instances For
                                                                  @[inline]

                                                                  Largest finite positive value.

                                                                  Instances For
                                                                    @[inline]

                                                                    Finite value with the largest negative magnitude.

                                                                    Instances For
                                                                      @[inline]

                                                                      The canonical IEEE quiet-NaN bit pattern; use canonicalNaN? for other encodings.

                                                                      Instances For

                                                                        Policy-aware constants #

                                                                        @[inline]

                                                                        Signed zero, canonicalizing negative zero when the format has only one zero.

                                                                        Instances For
                                                                          @[inline]

                                                                          Signed infinity when the format supports it.

                                                                          Instances For
                                                                            @[inline]

                                                                            A canonical NaN when the format has a NaN encoding.

                                                                            Instances For
                                                                              @[inline]

                                                                              Total result for an invalid operation in the complete format descriptor.

                                                                              Formats with a NaN encoding use their canonical NaN. A format whose every bit pattern is numeric uses positive zero because it has no exceptional result to encode.

                                                                              Instances For
                                                                                @[inline]

                                                                                Signed infinity when the format supports it, otherwise the same-sign largest finite value.

                                                                                This constructs a range boundary for saturation and interval endpoints. Nonsaturating conversion, arithmetic, and exact reductions use nativeOverflow, which may return NaN when the format reserves an exceptional encoding.

                                                                                Instances For
                                                                                  @[simp]

                                                                                  Conventional IEEE policy zero is the usual signed zero.

                                                                                  @[simp]

                                                                                  Conventional IEEE invalid operations return the canonical NaN.

                                                                                  NaN propagation #

                                                                                  @[inline]

                                                                                  Set the quiet bit of a NaN, leaving non-NaN values unchanged.

                                                                                  Instances For
                                                                                    @[inline]

                                                                                    Return x quieted when it is a NaN.

                                                                                    Instances For
                                                                                      @[inline]

                                                                                      Select signaling NaNs before quiet NaNs, breaking ties from left to right.

                                                                                      Instances For
                                                                                        @[inline]

                                                                                        Ternary NaN selection used by fused multiply-add.

                                                                                        Instances For
                                                                                          @[inline]
                                                                                          def FloatLib.Floats.Formats.BinaryInterchange.Model.withNaNSelection {fmt : FloatFormat} (selected : Option (Model fmt)) (otherwise : selected = noneModel fmt) :
                                                                                          Model fmt

                                                                                          Return a selected NaN, or continue with evidence that NaN selection produced no result.

                                                                                          The continuation proof is erased. Keeping this dependent boundary beside the NaN selectors lets operations rule out impossible ordinary branches without duplicating selection logic.

                                                                                          Instances For
                                                                                            @[simp]
                                                                                            theorem FloatLib.Floats.Formats.BinaryInterchange.Model.withNaNSelection_of_none {fmt : FloatFormat} (selected : Option (Model fmt)) (otherwise : selected = noneModel fmt) (hselected : selected = none) :
                                                                                            withNaNSelection selected otherwise = otherwise hselected

                                                                                            A failed NaN selection enters the ordinary operation.

                                                                                            @[simp]
                                                                                            theorem FloatLib.Floats.Formats.BinaryInterchange.Model.withNaNSelection_of_some {fmt : FloatFormat} (selected : Option (Model fmt)) (otherwise : selected = noneModel fmt) (nan : Model fmt) (hselected : selected = some nan) :
                                                                                            withNaNSelection selected otherwise = nan

                                                                                            A successful NaN selection returns the selected NaN.

                                                                                            Sign and adjacency #

                                                                                            @[inline]

                                                                                            Flip only the stored sign bit, without interpreting the format's encoding policy.

                                                                                            Instances For
                                                                                              @[simp]

                                                                                              Toggling the stored sign bit preserves the fraction field.

                                                                                              @[simp]

                                                                                              Toggling the stored sign bit preserves the exponent field.

                                                                                              @[simp]

                                                                                              Toggling the stored sign bit complements the decoded sign.

                                                                                              @[simp]

                                                                                              Toggling the stored sign bit twice restores the original word.

                                                                                              @[simp]

                                                                                              Toggling the stored sign bit preserves IEEE NaN classification.

                                                                                              @[simp]

                                                                                              Toggling the stored sign bit preserves IEEE infinity classification.

                                                                                              @[simp]

                                                                                              Toggling the stored sign bit preserves IEEE zero classification.

                                                                                              @[simp]

                                                                                              Toggling the stored sign bit preserves IEEE finiteness.

                                                                                              @[inline]

                                                                                              Negate an encoded value according to its format.

                                                                                              Formats with signed zero use the flat sign-bit operation. An unsigned-zero format preserves its single zero and reserved NaN encodings instead of exchanging them.

                                                                                              Instances For

                                                                                                Formats with signed zero implement negation as a flat stored-sign toggle.

                                                                                                An unsigned-zero format preserves a NaN under negation.

                                                                                                An unsigned-zero format preserves its single zero under negation.

                                                                                                A value that is neither NaN nor zero is negated by the raw stored-sign toggle.

                                                                                                @[simp]

                                                                                                Negation preserves the fraction field of every encoded value, including NaNs.

                                                                                                @[simp]

                                                                                                Negation preserves the exponent field of every encoded value, including infinities and NaNs.

                                                                                                @[simp]

                                                                                                Negation toggles the sign unless an unsigned-zero format preserves zero or NaN.

                                                                                                @[simp]

                                                                                                Negation preserves IEEE NaN classification.

                                                                                                @[simp]

                                                                                                Negation preserves IEEE infinity classification.

                                                                                                @[simp]

                                                                                                Negation preserves IEEE zero classification.

                                                                                                @[simp]

                                                                                                Negation preserves IEEE finiteness.

                                                                                                @[inline]

                                                                                                Copy the numerical sign of signSource onto magnitude.

                                                                                                For formats with signed zero, this is the usual quiet sign-bit operation. An unsigned-zero format uses its sign-bit word as the NaN encoding, so zero and NaN are preserved instead of being changed into one another. Every other finite value still receives the requested stored sign.

                                                                                                Instances For
                                                                                                  @[simp]
                                                                                                  theorem FloatLib.Floats.Formats.BinaryInterchange.Model.copySign_eq_self_of_signBit_eq {fmt : FloatFormat} (magnitude signSource : Model fmt) (hsign : magnitude.signBit = signSource.signBit) :
                                                                                                  magnitude.copySign signSource = magnitude

                                                                                                  Copying an already equal sign leaves the complete encoded word unchanged.

                                                                                                  theorem FloatLib.Floats.Formats.BinaryInterchange.Model.copySign_eq_self_of_not_supportsSignedZero_of_isZero {fmt : FloatFormat} (magnitude signSource : Model fmt) (hfmt : fmt.supportsSignedZero = false) (hzero : magnitude.isZero = true) :
                                                                                                  magnitude.copySign signSource = magnitude

                                                                                                  An unsigned-zero format preserves its zero when a sign is copied onto it.

                                                                                                  theorem FloatLib.Floats.Formats.BinaryInterchange.Model.copySign_eq_self_of_not_supportsSignedZero_of_isNaN {fmt : FloatFormat} (magnitude signSource : Model fmt) (hfmt : fmt.supportsSignedZero = false) (hnan : magnitude.isNaN = true) :
                                                                                                  magnitude.copySign signSource = magnitude

                                                                                                  An unsigned-zero format preserves its reserved NaN word when a sign is copied onto it.

                                                                                                  @[inline]

                                                                                                  Absolute value under the complete format policy.

                                                                                                  This clears an ordinary stored sign. In an unsigned-zero encoding it leaves the unique zero and reserved NaN word intact, avoiding the raw-bit alias between those two encodings.

                                                                                                  Instances For
                                                                                                    @[inline]

                                                                                                    The smallest positive subnormal encoding.

                                                                                                    Instances For
                                                                                                      @[inline]

                                                                                                      The negative subnormal of smallest magnitude.

                                                                                                      Instances For
                                                                                                        @[inline]

                                                                                                        The next representable value strictly greater than x.

                                                                                                        A quiet NaN and the positive endpoint are fixed. A signaling NaN becomes the corresponding quiet NaN; since this value-only operation carries no status, the invalid signal IEEE 754-2019 §5.3.1 owes to a signaling operand is reported by nextUpWithStatus in Operations.Runtime. Formats without infinity saturate at their largest finite value. In an unsigned-zero encoding, the word immediately below the negative minimum subnormal is reserved for NaN, so that transition goes directly to the format's unique zero.

                                                                                                        Instances For
                                                                                                          @[inline]

                                                                                                          The next representable value strictly less than x.

                                                                                                          A quiet NaN and the negative endpoint are fixed. A signaling NaN becomes the corresponding quiet NaN; the invalid signal it owes is reported by nextDownWithStatus in Operations.Runtime. Formats without infinity saturate at their most negative finite value.

                                                                                                          Instances For