Documentation

Init.Data.SInt.Basic

This module contains the definition of signed fixed width integer types as well as basic arithmetic and bitwise operations on top of it.

structure Int8 :

The type of signed 8-bit integers. This type has special support in the compiler to make it actually 8 bits rather than wrapping a Nat.

  • toUInt8 : UInt8

    Obtain the UInt8 that is 2's complement equivalent to the Int8.

Instances For
    @[reducible, inline]
    abbrev Int8.size :

    The size of type Int8, that is, 2^8 = 256.

    Equations
    Instances For
      @[inline]

      Obtain the BitVec that contains the 2's complement representation of the Int8.

      Equations
      • x.toBitVec = x.toUInt8.toBitVec
      Instances For
        @[extern lean_int8_of_int]
        def Int8.ofInt (i : Int) :
        Equations
        Instances For
          @[extern lean_int8_of_int]
          def Int8.ofNat (n : Nat) :
          Equations
          Instances For
            @[reducible, inline]
            abbrev Int.toInt8 (i : Int) :
            Equations
            Instances For
              @[reducible, inline]
              abbrev Nat.toInt8 (n : Nat) :
              Equations
              Instances For
                @[extern lean_int8_to_int]
                def Int8.toInt (i : Int8) :
                Equations
                • i.toInt = i.toBitVec.toInt
                Instances For
                  @[inline]
                  def Int8.toNat (i : Int8) :
                  Equations
                  • i.toNat = i.toInt.toNat
                  Instances For
                    @[extern lean_int8_neg]
                    def Int8.neg (i : Int8) :
                    Equations
                    • i.neg = { toUInt8 := { toBitVec := -i.toBitVec } }
                    Instances For
                      Equations
                      instance instOfNatInt8 {n : Nat} :
                      Equations
                      instance instNegInt8 :
                      Equations
                      @[extern lean_int8_add]
                      def Int8.add (a b : Int8) :
                      Equations
                      • a.add b = { toUInt8 := { toBitVec := a.toBitVec + b.toBitVec } }
                      Instances For
                        @[extern lean_int8_sub]
                        def Int8.sub (a b : Int8) :
                        Equations
                        • a.sub b = { toUInt8 := { toBitVec := a.toBitVec - b.toBitVec } }
                        Instances For
                          @[extern lean_int8_mul]
                          def Int8.mul (a b : Int8) :
                          Equations
                          • a.mul b = { toUInt8 := { toBitVec := a.toBitVec * b.toBitVec } }
                          Instances For
                            @[extern lean_int8_div]
                            def Int8.div (a b : Int8) :
                            Equations
                            • a.div b = { toUInt8 := { toBitVec := a.toBitVec.sdiv b.toBitVec } }
                            Instances For
                              @[extern lean_int8_mod]
                              def Int8.mod (a b : Int8) :
                              Equations
                              • a.mod b = { toUInt8 := { toBitVec := a.toBitVec.smod b.toBitVec } }
                              Instances For
                                @[extern lean_int8_land]
                                def Int8.land (a b : Int8) :
                                Equations
                                • a.land b = { toUInt8 := { toBitVec := a.toBitVec &&& b.toBitVec } }
                                Instances For
                                  @[extern lean_int8_lor]
                                  def Int8.lor (a b : Int8) :
                                  Equations
                                  • a.lor b = { toUInt8 := { toBitVec := a.toBitVec ||| b.toBitVec } }
                                  Instances For
                                    @[extern lean_int8_xor]
                                    def Int8.xor (a b : Int8) :
                                    Equations
                                    • a.xor b = { toUInt8 := { toBitVec := a.toBitVec ^^^ b.toBitVec } }
                                    Instances For
                                      @[extern lean_int8_shift_left]
                                      def Int8.shiftLeft (a b : Int8) :
                                      Equations
                                      • a.shiftLeft b = { toUInt8 := { toBitVec := a.toBitVec <<< (b.mod 8).toBitVec } }
                                      Instances For
                                        @[extern lean_int8_shift_right]
                                        Equations
                                        • a.shiftRight b = { toUInt8 := { toBitVec := a.toBitVec.sshiftRight' (b.mod 8).toBitVec } }
                                        Instances For
                                          @[extern lean_int8_complement]
                                          Equations
                                          • a.complement = { toUInt8 := { toBitVec := ~~~a.toBitVec } }
                                          Instances For
                                            @[extern lean_int8_dec_eq]
                                            def Int8.decEq (a b : Int8) :
                                            Decidable (a = b)
                                            Equations
                                            • { toUInt8 := n }.decEq { toUInt8 := m } = if h : n = m then isTrue else isFalse
                                            Instances For
                                              def Int8.lt (a b : Int8) :
                                              Equations
                                              • a.lt b = (a.toBitVec.slt b.toBitVec = true)
                                              Instances For
                                                def Int8.le (a b : Int8) :
                                                Equations
                                                • a.le b = (a.toBitVec.sle b.toBitVec = true)
                                                Instances For
                                                  Equations
                                                  instance instAddInt8 :
                                                  Equations
                                                  instance instSubInt8 :
                                                  Equations
                                                  instance instMulInt8 :
                                                  Equations
                                                  instance instModInt8 :
                                                  Equations
                                                  instance instDivInt8 :
                                                  Equations
                                                  instance instLTInt8 :
                                                  Equations
                                                  instance instLEInt8 :
                                                  Equations
                                                  Equations
                                                  Equations
                                                  instance instXorInt8 :
                                                  Equations
                                                  @[extern lean_int8_dec_lt]
                                                  def Int8.decLt (a b : Int8) :
                                                  Decidable (a < b)
                                                  Equations
                                                  Instances For
                                                    @[extern lean_int8_dec_le]
                                                    def Int8.decLe (a b : Int8) :
                                                    Equations
                                                    Instances For
                                                      instance instDecidableLtInt8 (a b : Int8) :
                                                      Decidable (a < b)
                                                      Equations
                                                      instance instDecidableLeInt8 (a b : Int8) :
                                                      Equations
                                                      instance instMaxInt8 :
                                                      Equations
                                                      instance instMinInt8 :
                                                      Equations