TorchLean API

FloatLib.Numerics.Representations.FixedInt.Core

Fixed-width signed integers #

FixedInt width stores a two's-complement integer in exactly width bits. The policy is explicit in every arithmetic name:

The wrapping kernels operate directly on BitVec. Checked operations use Lean's signed-overflow tests. Saturating operations compute the exact Int result, clamp it to the signed range, and encode it.

A two's-complement integer stored in exactly width bits.

  • bits : BitVec width

    Complete two's-complement bit pattern.

Instances For
    @[instance_reducible]
    def FloatLib.Numerics.Representations.instDecidableEqFixedInt.decEq {width✝ : } (x✝ x✝¹ : FixedInt width✝) :
    Decidable (x✝ = x✝¹)
    Instances For
      @[instance_reducible]
      @[inline]

      Construct a fixed-width integer from the low width bits of a natural number.

      Instances For
        @[inline]

        Extract the unsigned bit pattern.

        Instances For

          Every exact-width word lies below its unsigned modulus.

          @[simp]

          Re-encoding a fixed integer's complete bit pattern preserves it.

          @[simp]
          theorem FloatLib.Numerics.Representations.FixedInt.toNatBits_ofNatBits_of_lt {width : } (bits : ) (bits_lt : bits < 2 ^ width) :
          (ofNatBits bits).toNatBits = bits

          An in-range unsigned bit pattern is unchanged by exact-width encoding.

          @[inline]

          Interpret a word as a signed two's-complement integer.

          Instances For
            @[inline]

            Encode an integer modulo 2^width.

            Instances For
              @[inline]

              Least signed integer representable at width.

              Instances For
                @[inline]

                Greatest signed integer representable at width.

                Instances For

                  Whether an integer lies in the signed range of width bits.

                  Instances For
                    @[instance_reducible]
                    @[inline]

                    Clamp an integer to the signed range of width bits, the shared Saturating.clamp applied to the range endpoints.

                    Instances For
                      @[inline]

                      The least representable word, denoting minValue width.

                      Instances For
                        @[inline]

                        The greatest representable word, denoting maxValue width.

                        Instances For
                          @[inline]

                          Two's-complement addition modulo 2^width.

                          Instances For
                            @[inline]

                            Two's-complement subtraction modulo 2^width.

                            Instances For
                              @[inline]

                              Two's-complement multiplication modulo 2^width.

                              Instances For
                                @[inline]

                                Return the exact sum when it fits in width signed bits.

                                Instances For
                                  @[inline]

                                  Return the exact difference when it fits in width signed bits.

                                  Instances For
                                    @[inline]

                                    Return the exact product when it fits in width signed bits.

                                    Instances For
                                      @[inline]

                                      Encode an exact integer, clamping it to the signed range when necessary.

                                      Instances For
                                        @[inline]

                                        Signed addition with saturation at the destination bounds.

                                        Instances For
                                          @[inline]

                                          Signed subtraction with saturation at the destination bounds.

                                          Instances For
                                            @[inline]

                                            Signed multiplication with saturation at the destination bounds.

                                            Instances For