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.

  • ofUInt8 :: (
    • toUInt8 : UInt8

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

  • )
Instances For
structure Int32 :

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

  • ofUInt32 :: (
  • )
Instances For
structure ISize :

A ISize is a signed integer with the size of a word for the platform's architecture.

For example, if running on a 32-bit machine, ISize is equivalent to Int32. Or on a 64-bit machine, Int64.

  • ofUSize :: (
    • toUSize : USize

      Obtain the USize that is 2's complement equivalent to the ISize.

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

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

Equations
@[inline]

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

Equations
theorem Int8.toBitVec.inj {x y : Int8} :
x.toBitVec = y.toBitVecx = y
@[inline]

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

Equations
@[inline, deprecated UInt8.toInt8 (since := "2025-02-13")]
def Int8.mk (i : UInt8) :

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

Equations
@[extern lean_int8_of_int]
def Int8.ofInt (i : Int) :
Equations
@[extern lean_int8_of_nat]
def Int8.ofNat (n : Nat) :
Equations
@[reducible, inline]
abbrev Int.toInt8 (i : Int) :
Equations
@[reducible, inline]
abbrev Nat.toInt8 (n : Nat) :
Equations
@[extern lean_int8_to_int]
def Int8.toInt (i : Int8) :
Equations
@[inline]

This function has the same behavior as Int.toNat for negative numbers. If you want to obtain the 2's complement representation use toBitVec.

Equations
@[inline, deprecated Int8.toNatClampNeg (since := "2025-02-13")]
def Int8.toNat (i : Int8) :

This function has the same behavior as Int.toNat for negative numbers. If you want to obtain the 2's complement representation use toBitVec.

Equations
@[inline]

Obtains the Int8 whose 2's complement representation is the given BitVec 8.

Equations
@[extern lean_int8_neg]
def Int8.neg (i : Int8) :
Equations
Equations
Equations
Equations
instance Int8.instOfNat {n : Nat} :
Equations
Equations
@[reducible, inline]

The maximum value an Int8 may attain, that is, 2^7 - 1 = 127.

Equations
@[reducible, inline]

The minimum value an Int8 may attain, that is, -2^7 = -128.

Equations
@[inline]
def Int8.ofIntLE (i : Int) (_hl : minValue.toInt i) (_hr : i maxValue.toInt) :

Constructs an Int8 from an Int which is known to be in bounds.

Equations

Constructs an Int8 from an Int, clamping if the value is too small or too large.

Equations
@[extern lean_int8_add]
def Int8.add (a b : Int8) :
Equations
@[extern lean_int8_sub]
def Int8.sub (a b : Int8) :
Equations
@[extern lean_int8_mul]
def Int8.mul (a b : Int8) :
Equations
@[extern lean_int8_div]
def Int8.div (a b : Int8) :
Equations
@[extern lean_int8_mod]
def Int8.mod (a b : Int8) :
Equations
@[extern lean_int8_land]
def Int8.land (a b : Int8) :
Equations
@[extern lean_int8_lor]
def Int8.lor (a b : Int8) :
Equations
@[extern lean_int8_xor]
def Int8.xor (a b : Int8) :
Equations
@[extern lean_int8_shift_left]
def Int8.shiftLeft (a b : Int8) :
Equations
@[extern lean_int8_shift_right]
Equations
@[extern lean_int8_complement]
Equations
@[extern lean_int8_abs]
def Int8.abs (a : Int8) :

Computes the absolute value of the signed integer. This function is equivalent to if a < 0 then -a else a, so in particular Int8.minValue will be mapped to Int8.minValue.

Equations
@[extern lean_int8_dec_eq]
def Int8.decEq (a b : Int8) :
Decidable (a = b)
Equations
def Int8.lt (a b : Int8) :
Equations
def Int8.le (a b : Int8) :
Equations
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_bool_to_int8]
def Bool.toInt8 (b : Bool) :
Equations
@[extern lean_int8_dec_lt]
def Int8.decLt (a b : Int8) :
Decidable (a < b)
Equations
@[extern lean_int8_dec_le]
def Int8.decLe (a b : Int8) :
Equations
instance instDecidableLtInt8 (a b : Int8) :
Decidable (a < b)
Equations
instance instDecidableLeInt8 (a b : Int8) :
Equations
@[reducible, inline]
abbrev Int16.size :

The size of type Int16, that is, 2^16 = 65536.

Equations
@[inline]

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

Equations
theorem Int16.toBitVec.inj {x y : Int16} :
x.toBitVec = y.toBitVecx = y
@[inline]

Obtains the Int16 that is 2's complement equivalent to the UInt16.

Equations
@[inline, deprecated UInt16.toInt16 (since := "2025-02-13")]
def Int16.mk (i : UInt16) :

Obtains the Int16 that is 2's complement equivalent to the UInt16.

Equations
@[extern lean_int16_of_int]
def Int16.ofInt (i : Int) :
Equations
@[extern lean_int16_of_nat]
def Int16.ofNat (n : Nat) :
Equations
@[reducible, inline]
abbrev Int.toInt16 (i : Int) :
Equations
@[reducible, inline]
abbrev Nat.toInt16 (n : Nat) :
Equations
@[extern lean_int16_to_int]
def Int16.toInt (i : Int16) :
Equations
@[inline]

This function has the same behavior as Int.toNat for negative numbers. If you want to obtain the 2's complement representation use toBitVec.

Equations
@[inline, deprecated Int16.toNatClampNeg (since := "2025-02-13")]
def Int16.toNat (i : Int16) :

This function has the same behavior as Int.toNat for negative numbers. If you want to obtain the 2's complement representation use toBitVec.

Equations
@[inline]

Obtains the Int16 whose 2's complement representation is the given BitVec 16.

Equations
@[extern lean_int16_to_int8]
Equations
@[extern lean_int8_to_int16]
Equations
@[extern lean_int16_neg]
def Int16.neg (i : Int16) :
Equations
Equations
Equations
Equations
instance Int16.instOfNat {n : Nat} :
Equations
Equations
@[reducible, inline]

The maximum value an Int16 may attain, that is, 2^15 - 1 = 32767.

Equations
@[reducible, inline]

The minimum value an Int16 may attain, that is, -2^15 = -32768.

Equations
@[inline]
def Int16.ofIntLE (i : Int) (_hl : minValue.toInt i) (_hr : i maxValue.toInt) :

Constructs an Int16 from an Int which is known to be in bounds.

Equations

Constructs an Int16 from an Int, clamping if the value is too small or too large.

Equations
@[extern lean_int16_add]
def Int16.add (a b : Int16) :
Equations
@[extern lean_int16_sub]
def Int16.sub (a b : Int16) :
Equations
@[extern lean_int16_mul]
def Int16.mul (a b : Int16) :
Equations
@[extern lean_int16_div]
def Int16.div (a b : Int16) :
Equations
@[extern lean_int16_mod]
def Int16.mod (a b : Int16) :
Equations
@[extern lean_int16_land]
def Int16.land (a b : Int16) :
Equations
@[extern lean_int16_lor]
def Int16.lor (a b : Int16) :
Equations
@[extern lean_int16_xor]
def Int16.xor (a b : Int16) :
Equations
@[extern lean_int16_shift_left]
Equations
@[extern lean_int16_shift_right]
Equations
@[extern lean_int16_complement]
Equations
@[extern lean_int16_abs]
def Int16.abs (a : Int16) :

Computes the absolute value of the signed integer. This function is equivalent to if a < 0 then -a else a, so in particular Int16.minValue will be mapped to Int16.minValue.

Equations
@[extern lean_int16_dec_eq]
def Int16.decEq (a b : Int16) :
Decidable (a = b)
Equations
def Int16.lt (a b : Int16) :
Equations
def Int16.le (a b : Int16) :
Equations
Equations
Equations
Equations
Equations
Equations
Equations
instance instLTInt16 :
Equations
instance instLEInt16 :
Equations
Equations
@[extern lean_bool_to_int16]
Equations
@[extern lean_int16_dec_lt]
def Int16.decLt (a b : Int16) :
Decidable (a < b)
Equations
@[extern lean_int16_dec_le]
def Int16.decLe (a b : Int16) :
Equations
instance instDecidableLtInt16 (a b : Int16) :
Decidable (a < b)
Equations
instance instDecidableLeInt16 (a b : Int16) :
Equations
@[reducible, inline]
abbrev Int32.size :

The size of type Int32, that is, 2^32 = 4294967296.

Equations
@[inline]

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

Equations
theorem Int32.toBitVec.inj {x y : Int32} :
x.toBitVec = y.toBitVecx = y
@[inline]

Obtains the Int32 that is 2's complement equivalent to the UInt32.

Equations
@[inline, deprecated UInt32.toInt32 (since := "2025-02-13")]
def Int32.mk (i : UInt32) :

Obtains the Int32 that is 2's complement equivalent to the UInt32.

Equations
@[extern lean_int32_of_int]
def Int32.ofInt (i : Int) :
Equations
@[extern lean_int32_of_nat]
def Int32.ofNat (n : Nat) :
Equations
@[reducible, inline]
abbrev Int.toInt32 (i : Int) :
Equations
@[reducible, inline]
abbrev Nat.toInt32 (n : Nat) :
Equations
@[extern lean_int32_to_int]
def Int32.toInt (i : Int32) :
Equations
@[inline]

This function has the same behavior as Int.toNat for negative numbers. If you want to obtain the 2's complement representation use toBitVec.

Equations
@[inline, deprecated Int32.toNatClampNeg (since := "2025-02-13")]
def Int32.toNat (i : Int32) :

This function has the same behavior as Int.toNat for negative numbers. If you want to obtain the 2's complement representation use toBitVec.

Equations
@[inline]

Obtains the Int32 whose 2's complement representation is the given BitVec 32.

Equations
@[extern lean_int32_to_int8]
Equations
@[extern lean_int32_to_int16]
Equations
@[extern lean_int8_to_int32]
Equations
@[extern lean_int16_to_int32]
Equations
@[extern lean_int32_neg]
def Int32.neg (i : Int32) :
Equations
Equations
Equations
Equations
instance Int32.instOfNat {n : Nat} :
Equations
Equations
@[reducible, inline]

The maximum value an Int32 may attain, that is, 2^31 - 1 = 2147483647.

Equations
@[reducible, inline]

The minimum value an Int32 may attain, that is, -2^31 = -2147483648.

Equations
@[inline]
def Int32.ofIntLE (i : Int) (_hl : minValue.toInt i) (_hr : i maxValue.toInt) :

Constructs an Int32 from an Int which is known to be in bounds.

Equations

Constructs an Int32 from an Int, clamping if the value is too small or too large.

Equations
@[extern lean_int32_add]
def Int32.add (a b : Int32) :
Equations
@[extern lean_int32_sub]
def Int32.sub (a b : Int32) :
Equations
@[extern lean_int32_mul]
def Int32.mul (a b : Int32) :
Equations
@[extern lean_int32_div]
def Int32.div (a b : Int32) :
Equations
@[extern lean_int32_mod]
def Int32.mod (a b : Int32) :
Equations
@[extern lean_int32_land]
def Int32.land (a b : Int32) :
Equations
@[extern lean_int32_lor]
def Int32.lor (a b : Int32) :
Equations
@[extern lean_int32_xor]
def Int32.xor (a b : Int32) :
Equations
@[extern lean_int32_shift_left]
Equations
@[extern lean_int32_shift_right]
Equations
@[extern lean_int32_complement]
Equations
@[extern lean_int32_abs]
def Int32.abs (a : Int32) :

Computes the absolute value of the signed integer. This function is equivalent to if a < 0 then -a else a, so in particular Int32.minValue will be mapped to Int32.minValue.

Equations
@[extern lean_int32_dec_eq]
def Int32.decEq (a b : Int32) :
Decidable (a = b)
Equations
def Int32.lt (a b : Int32) :
Equations
def Int32.le (a b : Int32) :
Equations
Equations
Equations
Equations
Equations
Equations
Equations
instance instLTInt32 :
Equations
instance instLEInt32 :
Equations
Equations
@[extern lean_bool_to_int32]
Equations
@[extern lean_int32_dec_lt]
def Int32.decLt (a b : Int32) :
Decidable (a < b)
Equations
@[extern lean_int32_dec_le]
def Int32.decLe (a b : Int32) :
Equations
instance instDecidableLtInt32 (a b : Int32) :
Decidable (a < b)
Equations
instance instDecidableLeInt32 (a b : Int32) :
Equations
@[reducible, inline]
abbrev Int64.size :

The size of type Int64, that is, 2^64 = 18446744073709551616.

Equations
@[inline]

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

Equations
theorem Int64.toBitVec.inj {x y : Int64} :
x.toBitVec = y.toBitVecx = y
@[inline]

Obtains the Int64 that is 2's complement equivalent to the UInt64.

Equations
@[inline, deprecated UInt64.toInt64 (since := "2025-02-13")]
def Int64.mk (i : UInt64) :

Obtains the Int64 that is 2's complement equivalent to the UInt64.

Equations
@[extern lean_int64_of_int]
def Int64.ofInt (i : Int) :
Equations
@[extern lean_int64_of_nat]
def Int64.ofNat (n : Nat) :
Equations
@[reducible, inline]
abbrev Int.toInt64 (i : Int) :
Equations
@[reducible, inline]
abbrev Nat.toInt64 (n : Nat) :
Equations
@[extern lean_int64_to_int_sint]
def Int64.toInt (i : Int64) :
Equations
@[inline]

This function has the same behavior as Int.toNat for negative numbers. If you want to obtain the 2's complement representation use toBitVec.

Equations
@[inline, deprecated Int64.toNatClampNeg (since := "2025-02-13")]
def Int64.toNat (i : Int64) :

This function has the same behavior as Int.toNat for negative numbers. If you want to obtain the 2's complement representation use toBitVec.

Equations
@[inline]

Obtains the Int64 whose 2's complement representation is the given BitVec 64.

Equations
@[extern lean_int64_to_int8]
Equations
@[extern lean_int64_to_int16]
Equations
@[extern lean_int64_to_int32]
Equations
@[extern lean_int8_to_int64]
Equations
@[extern lean_int16_to_int64]
Equations
@[extern lean_int32_to_int64]
Equations
@[extern lean_int64_neg]
def Int64.neg (i : Int64) :
Equations
Equations
Equations
Equations
instance Int64.instOfNat {n : Nat} :
Equations
Equations
@[reducible, inline]

The maximum value an Int64 may attain, that is, 2^63 - 1 = 9223372036854775807.

Equations
@[reducible, inline]

The minimum value an Int64 may attain, that is, -2^63 = -9223372036854775808.

Equations
@[inline]
def Int64.ofIntLE (i : Int) (_hl : minValue.toInt i) (_hr : i maxValue.toInt) :

Constructs an Int64 from an Int which is known to be in bounds.

Equations

Constructs an Int64 from an Int, clamping if the value is too small or too large.

Equations
@[extern lean_int64_add]
def Int64.add (a b : Int64) :
Equations
@[extern lean_int64_sub]
def Int64.sub (a b : Int64) :
Equations
@[extern lean_int64_mul]
def Int64.mul (a b : Int64) :
Equations
@[extern lean_int64_div]
def Int64.div (a b : Int64) :
Equations
@[extern lean_int64_mod]
def Int64.mod (a b : Int64) :
Equations
@[extern lean_int64_land]
def Int64.land (a b : Int64) :
Equations
@[extern lean_int64_lor]
def Int64.lor (a b : Int64) :
Equations
@[extern lean_int64_xor]
def Int64.xor (a b : Int64) :
Equations
@[extern lean_int64_shift_left]
Equations
@[extern lean_int64_shift_right]
Equations
@[extern lean_int64_complement]
Equations
@[extern lean_int64_abs]
def Int64.abs (a : Int64) :

Computes the absolute value of the signed integer. This function is equivalent to if a < 0 then -a else a, so in particular Int64.minValue will be mapped to Int64.minValue.

Equations
@[extern lean_int64_dec_eq]
def Int64.decEq (a b : Int64) :
Decidable (a = b)
Equations
def Int64.lt (a b : Int64) :
Equations
def Int64.le (a b : Int64) :
Equations
Equations
Equations
Equations
Equations
Equations
Equations
instance instLTInt64 :
Equations
instance instLEInt64 :
Equations
Equations
@[extern lean_bool_to_int64]
Equations
@[extern lean_int64_dec_lt]
def Int64.decLt (a b : Int64) :
Decidable (a < b)
Equations
@[extern lean_int64_dec_le]
def Int64.decLe (a b : Int64) :
Equations
instance instDecidableLtInt64 (a b : Int64) :
Decidable (a < b)
Equations
instance instDecidableLeInt64 (a b : Int64) :
Equations
@[reducible, inline]
abbrev ISize.size :

The size of type ISize, that is, 2^System.Platform.numBits.

Equations
@[inline]

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

Equations
theorem ISize.toBitVec.inj {x y : ISize} :
x.toBitVec = y.toBitVecx = y
@[inline]

Obtains the ISize that is 2's complement equivalent to the USize.

Equations
@[inline, deprecated USize.toISize (since := "2025-02-13")]
def ISize.mk (i : USize) :

Obtains the ISize that is 2's complement equivalent to the USize.

Equations
@[extern lean_isize_of_int]
def ISize.ofInt (i : Int) :
Equations
@[extern lean_isize_of_nat]
def ISize.ofNat (n : Nat) :
Equations
@[reducible, inline]
abbrev Int.toISize (i : Int) :
Equations
@[reducible, inline]
abbrev Nat.toISize (n : Nat) :
Equations
@[extern lean_isize_to_int]
def ISize.toInt (i : ISize) :
Equations
@[inline]

This function has the same behavior as Int.toNat for negative numbers. If you want to obtain the 2's complement representation use toBitVec.

Equations
@[inline, deprecated ISize.toNatClampNeg (since := "2025-02-13")]
def ISize.toNat (i : ISize) :

This function has the same behavior as Int.toNat for negative numbers. If you want to obtain the 2's complement representation use toBitVec.

Equations
@[inline]

Obtains the ISize whose 2's complement representation is the given BitVec.

Equations
@[extern lean_isize_to_int8]
Equations
@[extern lean_isize_to_int16]
Equations
@[extern lean_isize_to_int32]
Equations
@[extern lean_isize_to_int64]

Upcasts ISize to Int64. This function is lossless as ISize is either Int32 or Int64.

Equations
@[extern lean_int8_to_isize]
Equations
@[extern lean_int16_to_isize]
Equations
@[extern lean_int32_to_isize]

Upcasts Int32 to ISize. This function is lossless as ISize is either Int32 or Int64.

Equations
@[extern lean_int64_to_isize]
Equations
@[extern lean_isize_neg]
def ISize.neg (i : ISize) :
Equations
Equations
Equations
Equations
instance ISize.instOfNat {n : Nat} :
Equations
Equations
@[reducible, inline]

The maximum value an ISize may attain, that is, 2^(System.Platform.numBits - 1) - 1.

Equations
@[reducible, inline]

The minimum value an ISize may attain, that is, -2^(System.Platform.numBits - 1).

Equations
@[inline]
def ISize.ofIntLE (i : Int) (_hl : minValue.toInt i) (_hr : i maxValue.toInt) :

Constructs an ISize from an Int which is known to be in bounds.

Equations

Constructs an ISize from an Int, clamping if the value is too small or too large.

Equations
@[extern lean_isize_add]
def ISize.add (a b : ISize) :
Equations
@[extern lean_isize_sub]
def ISize.sub (a b : ISize) :
Equations
@[extern lean_isize_mul]
def ISize.mul (a b : ISize) :
Equations
@[extern lean_isize_div]
def ISize.div (a b : ISize) :
Equations
@[extern lean_isize_mod]
def ISize.mod (a b : ISize) :
Equations
@[extern lean_isize_land]
def ISize.land (a b : ISize) :
Equations
@[extern lean_isize_lor]
def ISize.lor (a b : ISize) :
Equations
@[extern lean_isize_xor]
def ISize.xor (a b : ISize) :
Equations
@[extern lean_isize_shift_left]
Equations
@[extern lean_isize_shift_right]
Equations
@[extern lean_isize_complement]
Equations
@[extern lean_isize_abs]
def ISize.abs (a : ISize) :

Computes the absolute value of the signed integer. This function is equivalent to if a < 0 then -a else a, so in particular ISize.minValue will be mapped to ISize.minValue.

Equations
@[extern lean_isize_dec_eq]
def ISize.decEq (a b : ISize) :
Decidable (a = b)
Equations
def ISize.lt (a b : ISize) :
Equations
def ISize.le (a b : ISize) :
Equations
Equations
Equations
Equations
Equations
Equations
Equations
instance instLTISize :
Equations
instance instLEISize :
Equations
Equations
@[extern lean_bool_to_isize]
Equations
@[extern lean_isize_dec_lt]
def ISize.decLt (a b : ISize) :
Decidable (a < b)
Equations
@[extern lean_isize_dec_le]
def ISize.decLe (a b : ISize) :
Equations
instance instDecidableLtISize (a b : ISize) :
Decidable (a < b)
Equations
instance instDecidableLeISize (a b : ISize) :
Equations