doc-next-gen

Init.Data.SInt.Basic

Module docstring

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

Int8 structure
Full source
/--
Signed 8-bit integers.

This type has special support in the compiler so it can be represented by an unboxed 8-bit value.
-/
structure Int8 where
  private ofUInt8 ::
  /--
  Converts an 8-bit signed integer into the 8-bit unsigned integer that is its two's complement
  encoding.
  -/
  toUInt8 : UInt8
Signed 8-bit integers
Informal description
The structure representing signed 8-bit integers, which are stored as unboxed 8-bit values with special compiler support.
Int16 structure
Full source
/--
Signed 16-bit integers.

This type has special support in the compiler so it can be represented by an unboxed 16-bit value.
-/
structure Int16 where
  private ofUInt16 ::
  /--
  Converts an 16-bit signed integer into the 16-bit unsigned integer that is its two's complement
  encoding.
  -/
  toUInt16 : UInt16
Signed 16-bit integers
Informal description
The structure representing signed 16-bit integers, which are stored as unboxed 16-bit values with special compiler support.
Int32 structure
Full source
/--
Signed 32-bit integers.

This type has special support in the compiler so it can be represented by an unboxed 32-bit value.
-/
structure Int32 where
  private ofUInt32 ::
  /--
  Converts an 32-bit signed integer into the 32-bit unsigned integer that is its two's complement
  encoding.
  -/
  toUInt32 : UInt32
Signed 32-bit integers
Informal description
The structure representing signed 32-bit integers, which are stored as unboxed 32-bit values with special compiler support.
Int64 structure
Full source
/--
Signed 64-bit integers.

This type has special support in the compiler so it can be represented by an unboxed 64-bit value.
-/
structure Int64 where
  private ofUInt64 ::
  /--
  Converts an 64-bit signed integer into the 64-bit unsigned integer that is its two's complement
  encoding.
  -/
  toUInt64 : UInt64
Signed 64-bit integers
Informal description
The structure representing signed 64-bit integers. This type is specially supported by the compiler to be represented as an unboxed 64-bit value.
ISize structure
Full source
/--
Signed integers that are the size of a word on the platform's architecture.

On a 32-bit architecture, `ISize` is equivalent to `Int32`. On a 64-bit machine, it is equivalent to
`Int64`. This type has special support in the compiler so it can be represented by an unboxed value.
-/
structure ISize where
  private ofUSize ::
  /--
  Converts a word-sized signed integer into the word-sized unsigned integer that is its two's
  complement encoding.
  -/
  toUSize : USize
Platform-dependent signed integer type
Informal description
The structure `ISize` represents signed integers with a bit width matching the platform's word size. On a 32-bit architecture, this corresponds to 32-bit integers (equivalent to `Int32`), while on a 64-bit architecture it corresponds to 64-bit integers (equivalent to `Int64`). The compiler provides special support for this type, allowing it to be represented by unboxed values.
Int8.size abbrev
: Nat
Full source
/-- The number of distinct values representable by `Int8`, that is, `2^8 = 256`. -/
abbrev Int8.size : Nat := 256
Cardinality of 8-bit signed integers
Informal description
The size of the `Int8` type is $256$, representing the number of distinct values that can be stored in an 8-bit signed integer (from $-128$ to $127$ inclusive).
Int8.toBitVec definition
(x : Int8) : BitVec 8
Full source
/--
Obtain the `BitVec` that contains the 2's complement representation of the `Int8`.
-/
@[inline] def Int8.toBitVec (x : Int8) : BitVec 8 := x.toUInt8.toBitVec
2's complement representation of an 8-bit signed integer
Informal description
The function maps a signed 8-bit integer \( x \) to its 2's complement representation as a bitvector of width 8.
Int8.toBitVec.inj theorem
: {x y : Int8} → x.toBitVec = y.toBitVec → x = y
Full source
theorem Int8.toBitVec.inj : {x y : Int8} → x.toBitVec = y.toBitVec → x = y
  | ⟨⟨_⟩⟩, ⟨⟨_⟩⟩, rfl => rfl
Injective Property of 2's Complement Representation for 8-bit Integers
Informal description
For any two signed 8-bit integers $x$ and $y$, if their 2's complement bitvector representations (as 8-bit vectors) are equal, then $x = y$.
UInt8.toInt8 definition
(i : UInt8) : Int8
Full source
/-- Obtains the `Int8` that is 2's complement equivalent to the `UInt8`. -/
@[inline] def UInt8.toInt8 (i : UInt8) : Int8 := Int8.ofUInt8 i
Conversion from unsigned to signed 8-bit integer
Informal description
The function maps an unsigned 8-bit integer \( i \) to its corresponding signed 8-bit integer representation using 2's complement.
Int8.mk definition
(i : UInt8) : Int8
Full source
@[inline, deprecated UInt8.toInt8 (since := "2025-02-13"), inherit_doc UInt8.toInt8]
def Int8.mk (i : UInt8) : Int8 := UInt8.toInt8 i
Construction of signed 8-bit integer from unsigned 8-bit integer
Informal description
The function constructs a signed 8-bit integer from an unsigned 8-bit integer \( i \) using 2's complement representation.
Int8.ofInt definition
(i : @& Int) : Int8
Full source
/--
Converts an arbitrary-precision integer to an 8-bit integer, wrapping on overflow or underflow.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int8.ofInt 48 = 48`
 * `Int8.ofInt (-115) = -115`
 * `Int8.ofInt (-129) = 127`
 * `Int8.ofInt (128) = -128`
-/
@[extern "lean_int8_of_int"]
def Int8.ofInt (i : @& Int) : Int8 := ⟨⟨BitVec.ofInt 8 i⟩⟩
Conversion from integer to signed 8-bit integer with wrapping
Informal description
The function converts an arbitrary-precision integer \( i \) to a signed 8-bit integer using two's complement representation, wrapping around on overflow or underflow. Specifically: - For \(-128 \leq i \leq 127\), the result is \( i \) - For \( i = -129 \), the result is \( 127 \) - For \( i = 128 \), the result is \(-128\)
Int8.ofNat definition
(n : @& Nat) : Int8
Full source
/--
Converts a natural number to an 8-bit signed integer, wrapping around on overflow.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int8.ofNat 53 = 53`
 * `Int8.ofNat 127 = 127`
 * `Int8.ofNat 128 = -128`
 * `Int8.ofNat 255 = -1`
-/
@[extern "lean_int8_of_nat"]
def Int8.ofNat (n : @& Nat) : Int8 := ⟨⟨BitVec.ofNat 8 n⟩⟩
Conversion from natural number to signed 8-bit integer
Informal description
The function converts a natural number $n$ to an 8-bit signed integer using 2's complement representation, wrapping around on overflow. Specifically: - For $0 \leq n \leq 127$, the result is $n$ - For $n = 128$, the result is $-128$ - For $n = 255$, the result is $-1$ - For $n > 255$, the result is equivalent to $n \mod 256$ interpreted as a signed 8-bit integer.
Int.toInt8 abbrev
Full source
/--
Converts an arbitrary-precision integer to an 8-bit integer, wrapping on overflow or underflow.

Examples:
 * `Int.toInt8 48 = 48`
 * `Int.toInt8 (-115) = -115`
 * `Int.toInt8 (-129) = 127`
 * `Int.toInt8 (128) = -128`
-/
abbrev Int.toInt8 := Int8.ofInt
Conversion from Integer to 8-bit Signed Integer with Wrap-around
Informal description
The function $\mathrm{Int.toInt8}$ converts an arbitrary-precision integer $i$ to a signed 8-bit integer using two's complement representation, with wrap-around behavior on overflow or underflow. Specifically: - For $-128 \leq i \leq 127$, $\mathrm{Int.toInt8}(i) = i$ - For $i = -129$, $\mathrm{Int.toInt8}(-129) = 127$ - For $i = 128$, $\mathrm{Int.toInt8}(128) = -128$
Nat.toInt8 abbrev
Full source
/--
Converts a natural number to an 8-bit signed integer, wrapping around to negative numbers on
overflow.

Examples:
 * `Nat.toInt8 53 = 53`
 * `Nat.toInt8 127 = 127`
 * `Nat.toInt8 128 = -128`
 * `Nat.toInt8 255 = -1`
-/
abbrev Nat.toInt8 := Int8.ofNat
Natural Number to 8-bit Signed Integer Conversion with Wrap-around
Informal description
The function $\mathrm{Nat.toInt8}$ converts a natural number $n$ to an 8-bit signed integer using 2's complement representation, with wrap-around behavior on overflow. Specifically: - For $0 \leq n \leq 127$, $\mathrm{Nat.toInt8}(n) = n$ - For $n = 128$, $\mathrm{Nat.toInt8}(128) = -128$ - For $n = 255$, $\mathrm{Nat.toInt8}(255) = -1$ - For $n > 255$, $\mathrm{Nat.toInt8}(n) \equiv n \mod 256$ (interpreted as a signed 8-bit integer).
Int8.toInt definition
(i : Int8) : Int
Full source
/--
Converts an 8-bit signed integer to an arbitrary-precision integer that denotes the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_to_int"]
def Int8.toInt (i : Int8) : Int := i.toBitVec.toInt
Conversion from 8-bit signed integer to arbitrary-precision integer
Informal description
The function maps a signed 8-bit integer \( i \) to its corresponding arbitrary-precision integer by interpreting its 2's complement representation.
Int8.toNatClampNeg definition
(i : Int8) : Nat
Full source
/--
Converts an 8-bit signed integer to a natural number, mapping all negative numbers to `0`.

Use `Int8.toBitVec` to obtain the two's complement representation.
-/
@[inline] def Int8.toNatClampNeg (i : Int8) : Nat := i.toInt.toNat
Conversion from 8-bit signed integer to natural number (negative clamped to zero)
Informal description
The function converts a signed 8-bit integer \( i \) to a natural number by first converting it to an arbitrary-precision integer and then mapping negative values to zero. Specifically: - If \( i \) is non-negative (interpreted in two's complement), returns the corresponding natural number - If \( i \) is negative, returns 0
Int8.toNat definition
(i : Int8) : Nat
Full source
@[inline, deprecated Int8.toNatClampNeg (since := "2025-02-13"), inherit_doc Int8.toNatClampNeg]
def Int8.toNat (i : Int8) : Nat := i.toInt.toNat
Conversion from 8-bit signed integer to natural number (negative to zero)
Informal description
The function converts a signed 8-bit integer \( i \) to a natural number by first converting it to an arbitrary-precision integer and then mapping non-negative integers to their natural number counterpart while mapping negative integers to zero.
Int8.ofBitVec definition
(b : BitVec 8) : Int8
Full source
/-- Obtains the `Int8` whose 2's complement representation is the given `BitVec 8`. -/
@[inline] def Int8.ofBitVec (b : BitVec 8) : Int8 := ⟨⟨b⟩⟩
Conversion from bitvector to 8-bit signed integer
Informal description
Given a bitvector $b$ of width 8, the function returns the corresponding 8-bit signed integer obtained by interpreting $b$ as a two's complement representation.
Int8.neg definition
(i : Int8) : Int8
Full source
/--
Negates 8-bit signed integers. Usually accessed via the `-` prefix operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_neg"]
def Int8.neg (i : Int8) : Int8 := ⟨⟨-i.toBitVec⟩⟩
Negation of 8-bit signed integers
Informal description
The function negates an 8-bit signed integer \( i \) by computing its two's complement negation. This is implemented by interpreting \( i \) as a bitvector of width 8, negating it, and converting the result back to an 8-bit signed integer.
instToStringInt8 instance
: ToString Int8
Full source
instance : ToString Int8 where
  toString i := toString i.toInt
String Representation of 8-bit Signed Integers
Informal description
The signed 8-bit integers $\text{Int8}$ have a string representation.
instReprInt8 instance
: Repr Int8
Full source
instance : Repr Int8 where
  reprPrec i prec := reprPrec i.toInt prec
Decimal Representation of 8-bit Signed Integers
Informal description
The signed 8-bit integers $\text{Int8}$ have a standard string representation in decimal format.
instReprAtomInt8 instance
: ReprAtom Int8
Full source
instance : ReprAtom Int8 := ⟨⟩
Atomic Representation Marker for 8-bit Integers
Informal description
The type `Int8` of signed 8-bit integers is marked as an atomic type for representation purposes.
instHashableInt8 instance
: Hashable Int8
Full source
instance : Hashable Int8 where
  hash i := i.toUInt8.toUInt64
Hashability of Signed 8-bit Integers
Informal description
The type `Int8` of signed 8-bit integers can be hashed into a 64-bit unsigned integer.
Int8.instOfNat instance
: OfNat Int8 n
Full source
instance Int8.instOfNat : OfNat Int8 n := ⟨Int8.ofNat n⟩
Natural Number Literals as Signed 8-bit Integers
Informal description
For any natural number $n$, there is a canonical interpretation of $n$ as a signed 8-bit integer, using 2's complement representation with wrap-around behavior for overflow.
Int8.instNeg instance
: Neg Int8
Full source
instance Int8.instNeg : Neg Int8 where
  neg := Int8.neg
Negation Operation on 8-bit Signed Integers
Informal description
The type `Int8` of signed 8-bit integers is equipped with a negation operation, where each element is negated using two's complement arithmetic.
Int8.maxValue abbrev
: Int8
Full source
/-- The largest number that `Int8` can represent: `2^7 - 1 = 127`. -/
abbrev Int8.maxValue : Int8 := 127
Maximum Value of 8-bit Signed Integer: $127$
Informal description
The largest representable value in the `Int8` type is $127$, which equals $2^7 - 1$.
Int8.minValue abbrev
: Int8
Full source
/-- The smallest number that `Int8` can represent: `-2^7 = -128`. -/
abbrev Int8.minValue : Int8 := -128
Minimum Value of 8-bit Signed Integer: $-128$
Informal description
The smallest representable value in the `Int8` type is $-128$, which equals $-2^7$.
Int8.ofIntLE definition
(i : Int) (_hl : Int8.minValue.toInt ≤ i) (_hr : i ≤ Int8.maxValue.toInt) : Int8
Full source
/-- Constructs an `Int8` from an `Int` that is known to be in bounds. -/
@[inline]
def Int8.ofIntLE (i : Int) (_hl : Int8.minValue.toInt ≤ i) (_hr : i ≤ Int8.maxValue.toInt) : Int8 :=
  Int8.ofInt i
Conversion from bounded integer to signed 8-bit integer
Informal description
The function constructs a signed 8-bit integer from an integer \( i \) that is known to satisfy \(-128 \leq i \leq 127\), where \(-128\) and \(127\) are the minimum and maximum representable values in the `Int8` type, respectively. The function uses the underlying `Int8.ofInt` conversion, which is safe in this range.
Int8.ofIntTruncate definition
(i : Int) : Int8
Full source
/-- Constructs an `Int8` from an `Int`, clamping if the value is too small or too large. -/
def Int8.ofIntTruncate (i : Int) : Int8 :=
  if hl : Int8.minValue.toInt ≤ i then
    if hr : i ≤ Int8.maxValue.toInt then
      Int8.ofIntLE i hl hr
    else
      Int8.minValue
  else
    Int8.minValue
Conversion from integer to signed 8-bit integer with clamping
Informal description
The function constructs a signed 8-bit integer from an arbitrary integer \( i \). If \( i \) is within the range \([-128, 127]\), it is converted directly to an `Int8`. If \( i \) is greater than 127, it is clamped to 127 (the maximum value). If \( i \) is less than -128, it is clamped to -128 (the minimum value).
Int8.add definition
(a b : Int8) : Int8
Full source
/--
Adds two 8-bit signed integers, wrapping around on over- or underflow. Usually accessed via the `+`
operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_add"]
protected def Int8.add (a b : Int8) : Int8 := ⟨⟨a.toBitVec + b.toBitVec⟩⟩
Addition of signed 8-bit integers with wrap-around
Informal description
The function takes two signed 8-bit integers \( a \) and \( b \) and returns their sum as another signed 8-bit integer, with overflow behavior wrapping around using 2's complement arithmetic.
Int8.sub definition
(a b : Int8) : Int8
Full source
/--
Subtracts one 8-bit signed integer from another, wrapping around on over- or underflow. Usually
accessed via the `-` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_sub"]
protected def Int8.sub (a b : Int8) : Int8 := ⟨⟨a.toBitVec - b.toBitVec⟩⟩
Subtraction of signed 8-bit integers with wrap-around
Informal description
The function subtracts two signed 8-bit integers \( a \) and \( b \), wrapping around on overflow or underflow, and returns the result as a signed 8-bit integer. The operation is performed by converting the integers to their 2's complement bitvector representations, subtracting them as bitvectors, and converting the result back to a signed 8-bit integer.
Int8.mul definition
(a b : Int8) : Int8
Full source
/--
Multiplies two 8-bit signed integers, wrapping around on over- or underflow.  Usually accessed via
the `*` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_mul"]
protected def Int8.mul (a b : Int8) : Int8 := ⟨⟨a.toBitVec * b.toBitVec⟩⟩
Multiplication of signed 8-bit integers with wrap-around
Informal description
The function multiplies two signed 8-bit integers $a$ and $b$, wrapping around on overflow or underflow, and returns the result as another signed 8-bit integer. The multiplication is performed by first converting the integers to their 2's complement bitvector representations of width 8, multiplying these bitvectors modulo $2^8$, and then converting the result back to a signed 8-bit integer.
Int8.div definition
(a b : Int8) : Int8
Full source
/--
Truncating division for 8-bit signed integers, rounding towards zero. Usually accessed via the `/`
operator.

Division by zero is defined to be zero.

This function is overridden at runtime with an efficient implementation.

Examples:
* `Int8.div 10 3 = 3`
* `Int8.div 10 (-3) = (-3)`
* `Int8.div (-10) (-3) = 3`
* `Int8.div (-10) 3 = (-3)`
* `Int8.div 10 0 = 0`
-/
@[extern "lean_int8_div"]
protected def Int8.div (a b : Int8) : Int8 := ⟨⟨BitVec.sdiv a.toBitVec b.toBitVec⟩⟩
Truncating division for signed 8-bit integers
Informal description
The function performs truncating division for signed 8-bit integers $a$ and $b$, rounding towards zero. Division by zero is defined to return zero. Specifically: - If $a$ and $b$ are both positive or both negative, it returns the quotient of their absolute values with the appropriate sign. - If one is positive and the other negative, it returns the negation of the quotient of their absolute values. Examples: - $10 / 3 = 3$ - $10 / (-3) = -3$ - $-10 / (-3) = 3$ - $-10 / 3 = -3$ - $10 / 0 = 0$
Int8.mod definition
(a b : Int8) : Int8
Full source
/--
The modulo operator for 8-bit signed integers, which computes the remainder when dividing one
integer by another with the T-rounding convention used by `Int8.div`. Usually accessed via the `%`
operator.

When the divisor is `0`, the result is the dividend rather than an error.

This function is overridden at runtime with an efficient implementation.

Examples:
* `Int8.mod 5 2 = 1`
* `Int8.mod 5 (-2) = 1`
* `Int8.mod (-5) 2 = (-1)`
* `Int8.mod (-5) (-2) = (-1)`
* `Int8.mod 4 2 = 0`
* `Int8.mod 4 (-2) = 0`
* `Int8.mod 4 0 = 4`
* `Int8.mod (-4) 0 = (-4)`
-/
@[extern "lean_int8_mod"]
protected def Int8.mod (a b : Int8) : Int8 := ⟨⟨BitVec.srem a.toBitVec b.toBitVec⟩⟩
Signed 8-bit integer modulo operation (T-rounding)
Informal description
The modulo operation for signed 8-bit integers, which computes the remainder of the division of $a$ by $b$ using the T-rounding convention (rounding towards zero). If $b = 0$, the result is $a$ (rather than an error). The operation is implemented via the signed remainder operation on the 2's complement bitvector representations of the inputs. Examples: * $5 \mod 2 = 1$ * $5 \mod (-2) = 1$ * $-5 \mod 2 = -1$ * $-5 \mod (-2) = -1$ * $4 \mod 2 = 0$ * $4 \mod (-2) = 0$ * $4 \mod 0 = 4$ * $-4 \mod 0 = -4$
Int8.land definition
(a b : Int8) : Int8
Full source
/--
Bitwise and for 8-bit signed integers. Usually accessed via the `&&&` operator.

Each bit of the resulting integer is set if the corresponding bits of both input integers are set,
according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_land"]
protected def Int8.land (a b : Int8) : Int8 := ⟨⟨a.toBitVec &&& b.toBitVec⟩⟩
Bitwise AND for signed 8-bit integers
Informal description
The function takes two signed 8-bit integers \( a \) and \( b \) and returns their bitwise AND as another signed 8-bit integer. Each bit of the result is set if and only if the corresponding bits of both \( a \) and \( b \) are set, according to the two's complement representation.
Int8.lor definition
(a b : Int8) : Int8
Full source
/--
Bitwise or for 8-bit signed integers. Usually accessed via the `|||` operator.

Each bit of the resulting integer is set if at least one of the corresponding bits of the input
integers is set, according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_lor"]
protected def Int8.lor (a b : Int8) : Int8 := ⟨⟨a.toBitVec ||| b.toBitVec⟩⟩
Bitwise OR for signed 8-bit integers
Informal description
The function takes two signed 8-bit integers \( a \) and \( b \) and returns their bitwise OR as another signed 8-bit integer. Each bit of the result is set if at least one of the corresponding bits in \( a \) or \( b \) is set, using the two's complement representation. The operation is implemented by first converting the integers to their 8-bit bitvector representations, performing the bitwise OR on the bitvectors, and then converting the result back to a signed 8-bit integer.
Int8.xor definition
(a b : Int8) : Int8
Full source
/--
Bitwise exclusive or for 8-bit signed integers. Usually accessed via the `^^^` operator.

Each bit of the resulting integer is set if exactly one of the corresponding bits of the input
integers is set, according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_xor"]
protected def Int8.xor (a b : Int8) : Int8 := ⟨⟨a.toBitVec ^^^ b.toBitVec⟩⟩
Bitwise XOR for signed 8-bit integers
Informal description
The function computes the bitwise exclusive OR (XOR) of two signed 8-bit integers $a$ and $b$, returning another signed 8-bit integer. Each bit of the result is set if exactly one of the corresponding bits in $a$ and $b$ is set, using the two's complement representation.
Int8.shiftLeft definition
(a b : Int8) : Int8
Full source
/--
Bitwise left shift for 8-bit signed integers. Usually accessed via the `<<<` operator.

Signed integers are interpreted as bitvectors according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_shift_left"]
protected def Int8.shiftLeft (a b : Int8) : Int8 := ⟨⟨a.toBitVec <<< (b.toBitVec.smod 8)⟩⟩
Left shift for signed 8-bit integers
Informal description
The function takes two signed 8-bit integers \( a \) and \( b \) and returns the result of left-shifting \( a \) by \( b \mod 8 \) bits, interpreted in two's complement representation. The shift amount \( b \) is taken modulo 8 to ensure it fits within the bit width. The operation is implemented by first converting the integers to their 8-bit bitvector representations, performing the left shift on the bitvectors, and then converting the result back to a signed 8-bit integer.
Int8.shiftRight definition
(a b : Int8) : Int8
Full source
/--
Arithmetic right shift for 8-bit signed integers. Usually accessed via the `<<<` operator.

The high bits are filled with the value of the most significant bit.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_shift_right"]
protected def Int8.shiftRight (a b : Int8) : Int8 := ⟨⟨BitVec.sshiftRight' a.toBitVec (b.toBitVec.smod 8)⟩⟩
Arithmetic right shift for signed 8-bit integers
Informal description
The arithmetic right shift operation for signed 8-bit integers \( a \) and \( b \), where \( a \) is shifted right by \( b \mod 8 \) positions. The high bits are filled with the value of the most significant bit (sign extension), preserving the sign of the original number.
Int8.complement definition
(a : Int8) : Int8
Full source
/--
Bitwise complement, also known as bitwise negation, for 8-bit signed integers. Usually accessed via
the `~~~` prefix operator.

Each bit of the resulting integer is the opposite of the corresponding bit of the input integer.
Integers use the two's complement representation, so `Int8.complement a = -(a + 1)`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_complement"]
protected def Int8.complement (a : Int8) : Int8 := ⟨⟨~~~a.toBitVec⟩⟩
Bitwise complement of an 8-bit signed integer
Informal description
The bitwise complement (negation) of an 8-bit signed integer \( a \), denoted \( \texttt{~~~}a \), is defined as the integer whose bits are the negation of the corresponding bits in \( a \). In two's complement representation, this operation satisfies \( \texttt{~~~}a = -(a + 1) \).
Int8.abs definition
(a : Int8) : Int8
Full source
/--
Computes the absolute value of an 8-bit 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`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_abs"]
protected def Int8.abs (a : Int8) : Int8 := ⟨⟨a.toBitVec.abs⟩⟩
Absolute value of an 8-bit signed integer
Informal description
The absolute value of an 8-bit signed integer \( a \), defined as \( -a \) if \( a \) is negative and \( a \) otherwise. Note that for the minimal value `Int8.minValue`, the result remains `Int8.minValue` due to overflow in two's complement representation.
Int8.decEq definition
(a b : Int8) : Decidable (a = b)
Full source
/--
Decides whether two 8-bit signed integers are equal. Usually accessed via the `DecidableEq Int8`
instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int8.decEq 123 123 = .isTrue rfl`
 * `(if ((-7) : Int8) = 7 then "yes" else "no") = "no"`
 * `show (7 : Int8) = 7 by decide`
-/
@[extern "lean_int8_dec_eq"]
def Int8.decEq (a b : Int8) : Decidable (a = b) :=
  match a, b with
  | ⟨n⟩, ⟨m⟩ =>
    if h : n = m then
      isTrue <| h ▸ rfl
    else
      isFalse (fun h' => Int8.noConfusion h' (fun h' => absurd h' h))
Decidable equality for 8-bit signed integers
Informal description
The function `Int8.decEq` decides whether two 8-bit signed integers `a` and `b` are equal, returning a constructive proof of either `a = b` or `¬(a = b`. This is typically accessed via the `DecidableEq Int8` instance.
Int8.lt definition
(a b : Int8) : Prop
Full source
/--
Strict inequality of 8-bit signed integers, defined as inequality of the corresponding integers.
Usually accessed via the `<` operator.
-/
protected def Int8.lt (a b : Int8) : Prop := a.toBitVec.slt b.toBitVec
Strict inequality for 8-bit signed integers
Informal description
The strict inequality relation on 8-bit signed integers, defined by comparing their two's complement representations as bitvectors. For any two 8-bit signed integers $a$ and $b$, $a < b$ holds if and only if the signed interpretation of $a$'s bitvector representation is strictly less than that of $b$'s.
Int8.le definition
(a b : Int8) : Prop
Full source
/--
Non-strict inequality of 8-bit signed integers, defined as inequality of the corresponding integers.
Usually accessed via the `≤` operator.
-/
protected def Int8.le (a b : Int8) : Prop := a.toBitVec.sle b.toBitVec
Signed 8-bit integer less-than-or-equal relation
Informal description
The relation defines the non-strict inequality between two signed 8-bit integers $a$ and $b$, interpreted as their two's complement signed integer representations. Specifically, $a \leq b$ holds if and only if the signed interpretation of $a$'s bitvector representation is less than or equal to that of $b$'s bitvector representation.
instInhabitedInt8 instance
: Inhabited Int8
Full source
instance : Inhabited Int8 where
  default := 0
Inhabited Type for Signed 8-bit Integers
Informal description
The type of signed 8-bit integers `Int8` is inhabited, meaning it has a default element.
instAddInt8 instance
: Add Int8
Full source
instance : Add Int8         := ⟨Int8.add⟩
Addition on 8-bit Integers
Informal description
The type of signed 8-bit integers `Int8` has an addition operation defined by 2's complement arithmetic with wrap-around behavior.
instSubInt8 instance
: Sub Int8
Full source
instance : Sub Int8         := ⟨Int8.sub⟩
Subtraction Operation on 8-bit Integers with Wrap-around
Informal description
The type of signed 8-bit integers `Int8` is equipped with a subtraction operation that wraps around on overflow or underflow.
instMulInt8 instance
: Mul Int8
Full source
instance : Mul Int8         := ⟨Int8.mul⟩
Multiplication Operation on 8-bit Integers with Wrap-around
Informal description
The type of signed 8-bit integers `Int8` is equipped with a multiplication operation that performs wrap-around arithmetic.
instModInt8 instance
: Mod Int8
Full source
instance : Mod Int8         := ⟨Int8.mod⟩
Modulo Operation on 8-bit Signed Integers with T-rounding
Informal description
The type of signed 8-bit integers `Int8` is equipped with a modulo operation that computes the remainder of division using T-rounding (rounding towards zero). For any two 8-bit integers $a$ and $b$, $a \mod b$ returns the remainder when $a$ is divided by $b$, with the convention that the result has the same sign as $a$. If $b = 0$, the result is $a$.
instDivInt8 instance
: Div Int8
Full source
instance : Div Int8         := ⟨Int8.div⟩
Truncating Division for Signed 8-bit Integers
Informal description
The type of signed 8-bit integers `Int8` is equipped with a division operation that performs truncating division, rounding towards zero. Division by zero is defined to return zero.
instLTInt8 instance
: LT Int8
Full source
instance : LT Int8          := ⟨Int8.lt⟩
Strict Order on 8-bit Signed Integers
Informal description
The type of signed 8-bit integers `Int8` is equipped with a strict order relation `<`, defined by comparing their two's complement representations as bitvectors. For any two 8-bit signed integers $a$ and $b$, $a < b$ holds if and only if the signed interpretation of $a$'s bitvector representation is strictly less than that of $b$'s.
instLEInt8 instance
: LE Int8
Full source
instance : LE Int8          := ⟨Int8.le⟩
The Less-Than-or-Equal Relation on Signed 8-bit Integers
Informal description
The type of signed 8-bit integers `Int8` is equipped with a canonical less-than-or-equal relation, where for any two integers `a` and `b` in `Int8`, the relation `a ≤ b` holds if and only if the signed interpretation of `a`'s bitvector representation is less than or equal to that of `b`'s bitvector representation.
instComplementInt8 instance
: Complement Int8
Full source
instance : Complement Int8  := ⟨Int8.complement⟩
Bitwise Complement Operation on 8-bit Integers
Informal description
The signed 8-bit integers $\text{Int8}$ are equipped with a bitwise complement operation, where for any integer $a \in \text{Int8}$, the operation $\texttt{~~~}a$ returns the bitwise complement of $a$ as another $\text{Int8}$.
instAndOpInt8 instance
: AndOp Int8
Full source
instance : AndOp Int8       := ⟨Int8.land⟩
Bitwise AND Operation on 8-bit Integers
Informal description
The signed 8-bit integers $\text{Int8}$ can be equipped with a bitwise AND operation, where for any two integers $a, b \in \text{Int8}$, the operation $a \&\& b$ returns their bitwise AND as another $\text{Int8}$.
instOrOpInt8 instance
: OrOp Int8
Full source
instance : OrOp Int8        := ⟨Int8.lor⟩
Bitwise OR Operation on 8-bit Integers
Informal description
The signed 8-bit integers $\text{Int8}$ are equipped with a bitwise OR operation $\|$, which takes two $\text{Int8}$ values and returns their bitwise OR as another $\text{Int8}$ value.
instXorInt8 instance
: Xor Int8
Full source
instance : Xor Int8         := ⟨Int8.xor⟩
Bitwise XOR Operation on 8-bit Integers
Informal description
The signed 8-bit integers $\text{Int8}$ have a bitwise exclusive OR (XOR) operation, where for any two integers $a$ and $b$ in $\text{Int8}$, the result $a \oplus b$ is computed by applying XOR to each corresponding pair of bits in $a$ and $b$.
instShiftLeftInt8 instance
: ShiftLeft Int8
Full source
instance : ShiftLeft Int8   := ⟨Int8.shiftLeft⟩
Left Shift Operation on 8-bit Integers
Informal description
The signed 8-bit integers $\text{Int8}$ are equipped with a left shift operation, where for any two integers $a$ and $b$ in $\text{Int8}$, the result $a \ll b$ is computed by left-shifting $a$ by $b \mod 8$ bits in two's complement representation.
instShiftRightInt8 instance
: ShiftRight Int8
Full source
instance : ShiftRight Int8  := ⟨Int8.shiftRight⟩
Right Shift Operation on 8-bit Signed Integers
Informal description
The signed 8-bit integers $\text{Int8}$ have a right shift operation, where for any two integers $a$ and $b$ in $\text{Int8}$, the result $a \gg b$ is computed by shifting $a$ right by $b \mod 8$ positions with sign extension.
instDecidableEqInt8 instance
: DecidableEq Int8
Full source
instance : DecidableEq Int8 := Int8.decEq
Decidable Equality for 8-bit Signed Integers
Informal description
The type of signed 8-bit integers has decidable equality. That is, for any two elements $a, b \in \text{Int8}$, the proposition $a = b$ is decidable.
Bool.toInt8 definition
(b : Bool) : Int8
Full source
/--
Converts `true` to `1` and `false` to `0`.
-/
@[extern "lean_bool_to_int8"]
def Bool.toInt8 (b : Bool) : Int8 := if b then 1 else 0
Boolean to signed 8-bit integer conversion
Informal description
The function converts a boolean value `b` to a signed 8-bit integer, returning `1` if `b` is `true` and `0` if `b` is `false`.
Int8.decLt definition
(a b : Int8) : Decidable (a < b)
Full source
/--
Decides whether one 8-bit signed integer is strictly less than another. Usually accessed via the
`DecidableLT Int8` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `(if ((-7) : Int8) < 7 then "yes" else "no") = "yes"`
 * `(if (5 : Int8) < 5 then "yes" else "no") = "no"`
 * `show ¬((7 : Int8) < 7) by decide`
-/
@[extern "lean_int8_dec_lt"]
def Int8.decLt (a b : Int8) : Decidable (a < b) :=
  inferInstanceAs (Decidable (a.toBitVec.slt b.toBitVec))
Decidability of strict less-than for signed 8-bit integers
Informal description
The function `Int8.decLt` takes two signed 8-bit integers `a` and `b` and returns a constructive proof that the proposition `a < b` is decidable. This is implemented by converting both integers to their 2's complement bitvector representations and using the signed less-than comparison (`slt`) on these bitvectors. The result is a `Decidable` instance that can be used in `if`-expressions or with the `decide` tactic.
Int8.decLe definition
(a b : Int8) : Decidable (a ≤ b)
Full source
/--
Decides whether one 8-bit signed integer is less than or equal to another. Usually accessed via the
`DecidableLE Int8` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `(if ((-7) : Int8) ≤ 7 then "yes" else "no") = "yes"`
 * `(if (15 : Int8) ≤ 15 then "yes" else "no") = "yes"`
 * `(if (15 : Int8) ≤ 5 then "yes" else "no") = "no"`
 * `show (7 : Int8) ≤ 7 by decide`
-/
@[extern "lean_int8_dec_le"]
def Int8.decLe (a b : Int8) : Decidable (a ≤ b) :=
  inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
Decidability of less-than-or-equal for signed 8-bit integers
Informal description
The function `Int8.decLe` takes two signed 8-bit integers `a` and `b` and returns a constructive proof that the proposition `a ≤ b` is decidable. This is implemented by converting both integers to their 2's complement bitvector representations and using the signed less-than-or-equal comparison (`sle`) on these bitvectors. The result is a `Decidable` instance that can be used in `if`-expressions or with the `decide` tactic.
instDecidableLtInt8 instance
(a b : Int8) : Decidable (a < b)
Full source
instance (a b : Int8) : Decidable (a < b) := Int8.decLt a b
Decidability of Strict Order on 8-bit Signed Integers
Informal description
For any two signed 8-bit integers $a$ and $b$, the proposition $a < b$ is decidable. This means there exists a constructive procedure to determine whether $a$ is strictly less than $b$ based on their two's complement representations.
instDecidableLeInt8 instance
(a b : Int8) : Decidable (a ≤ b)
Full source
instance (a b : Int8) : Decidable (a ≤ b) := Int8.decLe a b
Decidability of the less-than-or-equal relation on 8-bit integers
Informal description
For any two signed 8-bit integers $a$ and $b$, the proposition $a \leq b$ is decidable.
instMaxInt8 instance
: Max Int8
Full source
instance : Max Int8 := maxOfLe
Maximum Operation on Signed 8-bit Integers
Informal description
The type of signed 8-bit integers `Int8` is equipped with a canonical maximum operation, where for any two integers `a` and `b` in `Int8`, the maximum `max(a, b)` returns the larger of the two integers based on their signed interpretation.
instMinInt8 instance
: Min Int8
Full source
instance : Min Int8 := minOfLe
Minimum Operation on Signed 8-bit Integers
Informal description
The type of signed 8-bit integers `Int8` is equipped with a minimum operation, where for any two integers `a` and `b` in `Int8`, the minimum is defined as `a` if `a ≤ b` and `b` otherwise.
Int16.size abbrev
: Nat
Full source
/-- The number of distinct values representable by `Int16`, that is, `2^16 = 65536`. -/
abbrev Int16.size : Nat := 65536
Cardinality of Int16: $2^{16} = 65536$
Informal description
The size of the `Int16` type is $2^{16} = 65536$, representing the number of distinct values it can hold.
Int16.toBitVec definition
(x : Int16) : BitVec 16
Full source
/--
Obtain the `BitVec` that contains the 2's complement representation of the `Int16`.
-/
@[inline] def Int16.toBitVec (x : Int16) : BitVec 16 := x.toUInt16.toBitVec
2's complement representation of a signed 16-bit integer
Informal description
The function maps a signed 16-bit integer \( x \) to its 2's complement representation as a bitvector of width 16.
Int16.toBitVec.inj theorem
: {x y : Int16} → x.toBitVec = y.toBitVec → x = y
Full source
theorem Int16.toBitVec.inj : {x y : Int16} → x.toBitVec = y.toBitVec → x = y
  | ⟨⟨_⟩⟩, ⟨⟨_⟩⟩, rfl => rfl
Injectivity of 2's Complement Representation for Signed 16-bit Integers
Informal description
For any two signed 16-bit integers $x$ and $y$, if their 2's complement bitvector representations (as bitvectors of width 16) are equal, then $x = y$.
UInt16.toInt16 definition
(i : UInt16) : Int16
Full source
/-- Obtains the `Int16` that is 2's complement equivalent to the `UInt16`. -/
@[inline] def UInt16.toInt16 (i : UInt16) : Int16 := Int16.ofUInt16 i
Conversion from unsigned to signed 16-bit integer
Informal description
The function converts an unsigned 16-bit integer $i$ to its corresponding signed 16-bit integer representation using 2's complement.
Int16.mk definition
(i : UInt16) : Int16
Full source
@[inline, deprecated UInt16.toInt16 (since := "2025-02-13"), inherit_doc UInt16.toInt16]
def Int16.mk (i : UInt16) : Int16 := UInt16.toInt16 i
Construction of signed 16-bit integer from unsigned 16-bit integer
Informal description
The function constructs a signed 16-bit integer from an unsigned 16-bit integer $i$ using 2's complement representation.
Int16.ofInt definition
(i : @& Int) : Int16
Full source
/--
Converts an arbitrary-precision integer to a 16-bit signed integer, wrapping on overflow or underflow.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int16.ofInt 48 = 48`
 * `Int16.ofInt (-129) = -129`
 * `Int16.ofInt (128) = 128`
 * `Int16.ofInt 70000 = 4464`
 * `Int16.ofInt (-40000) = 25536`
-/
@[extern "lean_int16_of_int"]
def Int16.ofInt (i : @& Int) : Int16 := ⟨⟨BitVec.ofInt 16 i⟩⟩
Conversion from integer to signed 16-bit integer with wrap-around
Informal description
The function converts an arbitrary-precision integer \( i \) to a signed 16-bit integer by interpreting \( i \mod 2^{16} \) in two's complement representation. This ensures proper handling of overflow and underflow, with values wrapping around within the range \(-32768\) to \(32767\).
Int16.ofNat definition
(n : @& Nat) : Int16
Full source
/--
Converts a natural number to a 16-bit signed integer, wrapping around on overflow.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int16.ofNat 127 = 127`
 * `Int16.ofNat 32767 = 32767`
 * `Int16.ofNat 32768 = -32768`
 * `Int16.ofNat 32770 = -32766`
-/
@[extern "lean_int16_of_nat"]
def Int16.ofNat (n : @& Nat) : Int16 := ⟨⟨BitVec.ofNat 16 n⟩⟩
Conversion from natural number to signed 16-bit integer with wrap-around
Informal description
The function converts a natural number $n$ to a signed 16-bit integer by taking $n \mod 2^{16}$ and interpreting the result in 2's complement representation. This means values from $0$ to $32767$ map directly, while values from $32768$ to $65535$ wrap around to $-32768$ to $-1$ respectively.
Int.toInt16 abbrev
Full source
/--
Converts an arbitrary-precision integer to a 16-bit integer, wrapping on overflow or underflow.

Examples:
 * `Int.toInt16 48 = 48`
 * `Int.toInt16 (-129) = -129`
 * `Int.toInt16 (128) = 128`
 * `Int.toInt16 70000 = 4464`
 * `Int.toInt16 (-40000) = 25536`
-/
abbrev Int.toInt16 := Int16.ofInt
Wrap-around conversion from integer to 16-bit signed integer
Informal description
The function $\mathrm{Int.toInt16}$ converts an arbitrary-precision integer $i$ to a 16-bit signed integer by interpreting $i \mod 2^{16}$ in two's complement representation. This results in wrap-around behavior for values outside the range $-32768$ to $32767$.
Nat.toInt16 abbrev
Full source
/--
Converts a natural number to a 16-bit signed integer, wrapping around to negative numbers on
overflow.

Examples:
 * `Nat.toInt16 127 = 127`
 * `Nat.toInt16 32767 = 32767`
 * `Nat.toInt16 32768 = -32768`
 * `Nat.toInt16 32770 = -32766`
-/
abbrev Nat.toInt16 := Int16.ofNat
Natural number to 16-bit signed integer conversion with wrap-around
Informal description
The function $\mathrm{Nat.toInt16}$ converts a natural number $n$ to a 16-bit signed integer using 2's complement representation, with wrap-around behavior for values exceeding the 16-bit range. Specifically: - For $0 \leq n \leq 32767$, the result is $n$ - For $n \geq 32768$, the result is $-32768 + (n \mod 32768)$
Int16.toInt definition
(i : Int16) : Int
Full source
/--
Converts a 16-bit signed integer to an arbitrary-precision integer that denotes the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_to_int"]
def Int16.toInt (i : Int16) : Int := i.toBitVec.toInt
Conversion from signed 16-bit integer to arbitrary-precision integer
Informal description
The function maps a signed 16-bit integer \( i \) to its corresponding arbitrary-precision integer by first converting \( i \) to its 2's complement bitvector representation and then interpreting this bitvector as a two's complement signed integer.
Int16.toNatClampNeg definition
(i : Int16) : Nat
Full source
/--
Converts a 16-bit signed integer to a natural number, mapping all negative numbers to `0`.

Use `Int16.toBitVec` to obtain the two's complement representation.
-/
@[inline] def Int16.toNatClampNeg (i : Int16) : Nat := i.toInt.toNat
Conversion from signed 16-bit integer to natural number (negative clamped to zero)
Informal description
The function converts a signed 16-bit integer \( i \) to a natural number by first converting \( i \) to an arbitrary-precision integer and then mapping negative values to zero while preserving non-negative values.
Int16.toNat definition
(i : Int16) : Nat
Full source
@[inline, deprecated Int16.toNatClampNeg (since := "2025-02-13"), inherit_doc Int16.toNatClampNeg]
def Int16.toNat (i : Int16) : Nat := i.toInt.toNat
Conversion from signed 16-bit integer to natural number (negative to zero)
Informal description
The function maps a signed 16-bit integer \( i \) to a natural number by first converting \( i \) to an arbitrary-precision integer and then converting that integer to a natural number (with negative values mapping to zero).
Int16.ofBitVec definition
(b : BitVec 16) : Int16
Full source
/-- Obtains the `Int16` whose 2's complement representation is the given `BitVec 16`. -/
@[inline] def Int16.ofBitVec (b : BitVec 16) : Int16 := ⟨⟨b⟩⟩
Conversion from bitvector to signed 16-bit integer
Informal description
The function maps a bitvector \( b \) of width 16 to the corresponding signed 16-bit integer represented by its 2's complement encoding.
Int16.toInt8 definition
(a : Int16) : Int8
Full source
/--
Converts 16-bit signed integers to 8-bit signed integers by truncating their bitvector
representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_to_int8"]
def Int16.toInt8 (a : Int16) : Int8 := ⟨⟨a.toBitVec.signExtend 8⟩⟩
Truncation of 16-bit signed integer to 8-bit signed integer
Informal description
The function converts a signed 16-bit integer $a$ to a signed 8-bit integer by truncating its 2's complement bitvector representation to 8 bits (with sign extension).
Int8.toInt16 definition
(a : Int8) : Int16
Full source
/--
Converts 8-bit signed integers to 16-bit signed integers that denote the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_to_int16"]
def Int8.toInt16 (a : Int8) : Int16 := ⟨⟨a.toBitVec.signExtend 16⟩⟩
Sign extension from 8-bit to 16-bit signed integer
Informal description
The function converts an 8-bit signed integer \( a \) to a 16-bit signed integer by sign-extending its 2's complement representation to 16 bits.
Int16.neg definition
(i : Int16) : Int16
Full source
/--
Negates 16-bit signed integers. Usually accessed via the `-` prefix operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_neg"]
def Int16.neg (i : Int16) : Int16 := ⟨⟨-i.toBitVec⟩⟩
Negation of signed 16-bit integers
Informal description
The function negates a signed 16-bit integer \( i \) by computing its 2's complement representation as a bitvector of width 16 and then negating that bitvector. The result is converted back to a signed 16-bit integer.
instToStringInt16 instance
: ToString Int16
Full source
instance : ToString Int16 where
  toString i := toString i.toInt
String Representation of 16-bit Integers
Informal description
The signed 16-bit integers $\text{Int16}$ have a string representation.
instReprInt16 instance
: Repr Int16
Full source
instance : Repr Int16 where
  reprPrec i prec := reprPrec i.toInt prec
Decimal Representation of 16-bit Signed Integers
Informal description
The signed 16-bit integers $\text{Int16}$ have a standard string representation in decimal format.
instReprAtomInt16 instance
: ReprAtom Int16
Full source
instance : ReprAtom Int16 := ⟨⟩
Atomic Representation Marker for 16-bit Integers
Informal description
The type of signed 16-bit integers `Int16` is marked as an atomic type for representation methods.
instHashableInt16 instance
: Hashable Int16
Full source
instance : Hashable Int16 where
  hash i := i.toUInt16.toUInt64
Hashable 16-bit Signed Integers
Informal description
The type of signed 16-bit integers `Int16` can be hashed into a 64-bit unsigned integer.
Int16.instOfNat instance
: OfNat Int16 n
Full source
instance Int16.instOfNat : OfNat Int16 n := ⟨Int16.ofNat n⟩
Numeric Literal Interpretation for Signed 16-bit Integers
Informal description
For any natural number $n$, there is a canonical interpretation of $n$ as a signed 16-bit integer, obtained by taking $n \mod 2^{16}$ and interpreting the result in 2's complement representation.
Int16.instNeg instance
: Neg Int16
Full source
instance Int16.instNeg : Neg Int16 where
  neg := Int16.neg
Negation Operation on 16-bit Signed Integers
Informal description
The type of signed 16-bit integers `Int16` has a negation operation, where each integer is negated using 2's complement representation.
Int16.maxValue abbrev
: Int16
Full source
/-- The largest number that `Int16` can represent: `2^15 - 1 = 32767`. -/
abbrev Int16.maxValue : Int16 := 32767
Maximum Value of 16-bit Signed Integer: $32767$
Informal description
The largest representable value in the `Int16` type is $2^{15} - 1 = 32767$.
Int16.minValue abbrev
: Int16
Full source
/-- The smallest number that `Int16` can represent: `-2^15 = -32768`. -/
abbrev Int16.minValue : Int16 := -32768
Minimum Value of 16-bit Signed Integer: $-32768$
Informal description
The smallest representable value in the `Int16` type is $-2^{15} = -32768$.
Int16.ofIntLE definition
(i : Int) (_hl : Int16.minValue.toInt ≤ i) (_hr : i ≤ Int16.maxValue.toInt) : Int16
Full source
/-- Constructs an `Int16` from an `Int` that is known to be in bounds. -/
@[inline]
def Int16.ofIntLE (i : Int) (_hl : Int16.minValue.toInt ≤ i) (_hr : i ≤ Int16.maxValue.toInt) : Int16 :=
  Int16.ofInt i
Construction of signed 16-bit integer from bounded integer
Informal description
The function constructs a signed 16-bit integer from an integer \( i \) that is known to satisfy \( -32768 \leq i \leq 32767 \). This is implemented by directly converting \( i \) to a 16-bit integer using the `Int16.ofInt` function.
Int16.ofIntTruncate definition
(i : Int) : Int16
Full source
/-- Constructs an `Int16` from an `Int`, clamping if the value is too small or too large. -/
def Int16.ofIntTruncate (i : Int) : Int16 :=
  if hl : Int16.minValue.toInt ≤ i then
    if hr : i ≤ Int16.maxValue.toInt then
      Int16.ofIntLE i hl hr
    else
      Int16.minValue
  else
    Int16.minValue
Clamped conversion from integer to 16-bit signed integer
Informal description
The function constructs a signed 16-bit integer from an arbitrary integer \( i \). If \( i \) is within the range \([-32768, 32767]\), it is directly converted to an `Int16`. Otherwise, the result is clamped to the minimum value \(-32768\).
Int16.add definition
(a b : Int16) : Int16
Full source
/--
Adds two 16-bit signed integers, wrapping around on over- or underflow.  Usually accessed via the `+`
operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_add"]
protected def Int16.add (a b : Int16) : Int16 := ⟨⟨a.toBitVec + b.toBitVec⟩⟩
Addition of signed 16-bit integers with wrap-around
Informal description
The function takes two signed 16-bit integers \( a \) and \( b \) and returns their sum, represented as a signed 16-bit integer. The addition is performed by converting the integers to their 2's complement bitvector representations of width 16, adding these bitvectors (with wrap-around on overflow or underflow), and converting the result back to a signed 16-bit integer.
Int16.sub definition
(a b : Int16) : Int16
Full source
/--
Subtracts one 16-bit signed integer from another, wrapping around on over- or underflow. Usually
accessed via the `-` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_sub"]
protected def Int16.sub (a b : Int16) : Int16 := ⟨⟨a.toBitVec - b.toBitVec⟩⟩
Subtraction of signed 16-bit integers with wrap-around
Informal description
The function subtracts two signed 16-bit integers $a$ and $b$, wrapping around on overflow or underflow, and returns the result as a signed 16-bit integer. The subtraction is performed using the 2's complement representation of the integers as bitvectors of width 16.
Int16.mul definition
(a b : Int16) : Int16
Full source
/--
Multiplies two 16-bit signed integers, wrapping around on over- or underflow.  Usually accessed via
the `*` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_mul"]
protected def Int16.mul (a b : Int16) : Int16 := ⟨⟨a.toBitVec * b.toBitVec⟩⟩
Multiplication of signed 16-bit integers with wrap-around
Informal description
The function multiplies two signed 16-bit integers $a$ and $b$, returning their product as another signed 16-bit integer. The multiplication is performed by converting the integers to their 2's complement bitvector representations of width 16, multiplying these bitvectors (which wraps around on overflow/underflow modulo $2^{16}$), and then converting the result back to a signed 16-bit integer.
Int16.div definition
(a b : Int16) : Int16
Full source
/--
Truncating division for 16-bit signed integers, rounding towards zero. Usually accessed via the `/`
operator.

Division by zero is defined to be zero.

This function is overridden at runtime with an efficient implementation.

Examples:
* `Int16.div 10 3 = 3`
* `Int16.div 10 (-3) = (-3)`
* `Int16.div (-10) (-3) = 3`
* `Int16.div (-10) 3 = (-3)`
* `Int16.div 10 0 = 0`
-/
@[extern "lean_int16_div"]
protected def Int16.div (a b : Int16) : Int16 := ⟨⟨BitVec.sdiv a.toBitVec b.toBitVec⟩⟩
Truncating division for signed 16-bit integers
Informal description
The function computes the truncating division of two signed 16-bit integers $a$ and $b$, rounding towards zero. Division by zero is defined to return zero. Specifically: - If $a \geq 0$ and $b \geq 0$, returns $\lfloor a / b \rfloor$ - If $a \geq 0$ and $b < 0$, returns $-\lfloor a / (-b) \rfloor$ - If $a < 0$ and $b \geq 0$, returns $-\lfloor (-a) / b \rfloor$ - If $a < 0$ and $b < 0$, returns $\lfloor (-a) / (-b) \rfloor$
Int16.mod definition
(a b : Int16) : Int16
Full source
/--
The modulo operator for 16-bit signed integers, which computes the remainder when dividing one
integer by another with the T-rounding convention used by `Int16.div`. Usually accessed via the `%`
operator.

When the divisor is `0`, the result is the dividend rather than an error.

This function is overridden at runtime with an efficient implementation.

Examples:
* `Int16.mod 5 2 = 1`
* `Int16.mod 5 (-2) = 1`
* `Int16.mod (-5) 2 = (-1)`
* `Int16.mod (-5) (-2) = (-1)`
* `Int16.mod 4 2 = 0`
* `Int16.mod 4 (-2) = 0`
* `Int16.mod 4 0 = 4`
* `Int16.mod (-4) 0 = (-4)`
-/
@[extern "lean_int16_mod"]
protected def Int16.mod (a b : Int16) : Int16 := ⟨⟨BitVec.srem a.toBitVec b.toBitVec⟩⟩
Modulo operation for signed 16-bit integers
Informal description
The modulo operation for signed 16-bit integers, which computes the remainder when dividing $a$ by $b$ using the same rounding convention as `Int16.div`. Specifically: - If $b \neq 0$, the result has the same sign as $a$ and magnitude less than $|b|$. - If $b = 0$, the result is $a$ (rather than causing an error). This operation corresponds to the `%` operator in many programming languages.
Int16.land definition
(a b : Int16) : Int16
Full source
/--
Bitwise and for 16-bit signed integers. Usually accessed via the `&&&` operator.

Each bit of the resulting integer is set if the corresponding bits of both input integers are set,
according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_land"]
protected def Int16.land (a b : Int16) : Int16 := ⟨⟨a.toBitVec &&& b.toBitVec⟩⟩
Bitwise AND for signed 16-bit integers
Informal description
The function computes the bitwise AND of two signed 16-bit integers \( a \) and \( b \), where each bit of the result is set if and only if the corresponding bits of both \( a \) and \( b \) are set, using their two's complement representation.
Int16.lor definition
(a b : Int16) : Int16
Full source
/--
Bitwise or for 16-bit signed integers. Usually accessed via the `|||` operator.

Each bit of the resulting integer is set if at least one of the corresponding bits of the input
integers is set, according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_lor"]
protected def Int16.lor (a b : Int16) : Int16 := ⟨⟨a.toBitVec ||| b.toBitVec⟩⟩
Bitwise OR for 16-bit integers
Informal description
The bitwise OR operation for signed 16-bit integers. Given two 16-bit integers $a$ and $b$, it returns a new 16-bit integer where each bit is set if at least one of the corresponding bits in $a$ or $b$ is set, according to their two's complement representations.
Int16.xor definition
(a b : Int16) : Int16
Full source
/--
Bitwise exclusive or for 16-bit signed integers. Usually accessed via the `^^^` operator.

Each bit of the resulting integer is set if exactly one of the corresponding bits of the input
integers is set, according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_xor"]
protected def Int16.xor (a b : Int16) : Int16 := ⟨⟨a.toBitVec ^^^ b.toBitVec⟩⟩
Bitwise XOR of signed 16-bit integers
Informal description
The function computes the bitwise exclusive or (XOR) of two signed 16-bit integers \( a \) and \( b \), where each bit of the result is set if exactly one of the corresponding bits in \( a \) or \( b \) is set, according to their two's complement representation. The result is returned as a signed 16-bit integer.
Int16.shiftLeft definition
(a b : Int16) : Int16
Full source
/--
Bitwise left shift for 16-bit signed integers. Usually accessed via the `<<<` operator.

Signed integers are interpreted as bitvectors according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_shift_left"]
protected def Int16.shiftLeft (a b : Int16) : Int16 := ⟨⟨a.toBitVec <<< (b.toBitVec.smod 16)⟩⟩
Bitwise left shift for signed 16-bit integers
Informal description
The function computes the bitwise left shift of a signed 16-bit integer $a$ by the amount specified by another signed 16-bit integer $b$, interpreted modulo 16. The operation is performed using the two's complement representation of the integers, where the bits of $a$ are shifted left by the value of $b \mod 16$, filling the low bits with zeros.
Int16.shiftRight definition
(a b : Int16) : Int16
Full source
/--
Arithmetic right shift for 16-bit signed integers. Usually accessed via the `<<<` operator.

The high bits are filled with the value of the most significant bit.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_shift_right"]
protected def Int16.shiftRight (a b : Int16) : Int16 := ⟨⟨BitVec.sshiftRight' a.toBitVec (b.toBitVec.smod 16)⟩⟩
Arithmetic right shift for signed 16-bit integers
Informal description
The function performs an arithmetic right shift on a signed 16-bit integer \( a \) by \( b \) positions, where \( b \) is taken modulo 16. The high bits are filled with the value of the most significant bit (sign extension), preserving the sign of the original number.
Int16.complement definition
(a : Int16) : Int16
Full source
/--
Bitwise complement, also known as bitwise negation, for 16-bit signed integers. Usually accessed via
the `~~~` prefix operator.

Each bit of the resulting integer is the opposite of the corresponding bit of the input integer.
Integers use the two's complement representation, so `Int16.complement a = -(a + 1)`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_complement"]
protected def Int16.complement (a : Int16) : Int16 := ⟨⟨~~~a.toBitVec⟩⟩
Bitwise complement of a 16-bit signed integer
Informal description
The bitwise complement (negation) of a 16-bit signed integer $a$, denoted $\sim a$, is defined as the integer whose binary representation has each bit flipped compared to $a$'s two's complement representation. This operation satisfies $\text{Int16.complement}\,a = -(a + 1)$.
Int16.abs definition
(a : Int16) : Int16
Full source
/--
Computes the absolute value of a 16-bit 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`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_abs"]
protected def Int16.abs (a : Int16) : Int16 := ⟨⟨a.toBitVec.abs⟩⟩
Absolute value of a 16-bit signed integer
Informal description
The function computes the absolute value of a 16-bit signed integer $a$ as follows: if $a$ is negative (i.e., its most significant bit is set in its two's complement representation), it returns $-a$; otherwise, it returns $a$ itself. Note that for the most negative value (`Int16.minValue`), the result remains `Int16.minValue` due to overflow in the two's complement representation.
Int16.decEq definition
(a b : Int16) : Decidable (a = b)
Full source
/--
Decides whether two 16-bit signed integers are equal. Usually accessed via the `DecidableEq Int16`
instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int16.decEq 123 123 = .isTrue rfl`
 * `(if ((-7) : Int16) = 7 then "yes" else "no") = "no"`
 * `show (7 : Int16) = 7 by decide`
-/
@[extern "lean_int16_dec_eq"]
def Int16.decEq (a b : Int16) : Decidable (a = b) :=
  match a, b with
  | ⟨n⟩, ⟨m⟩ =>
    if h : n = m then
      isTrue <| h ▸ rfl
    else
      isFalse (fun h' => Int16.noConfusion h' (fun h' => absurd h' h))
Decidable equality for 16-bit signed integers
Informal description
The function `Int16.decEq` takes two 16-bit signed integers `a` and `b` and returns a constructive proof that their equality is decidable. Specifically, it returns either a proof that `a = b` (`isTrue`) or a proof that `¬(a = b)` (`isFalse`). This function is typically accessed via the `DecidableEq Int16` instance and is overridden at runtime with an efficient implementation.
Int16.lt definition
(a b : Int16) : Prop
Full source
/--
Strict inequality of 16-bit signed integers, defined as inequality of the corresponding integers.
Usually accessed via the `<` operator.
-/
protected def Int16.lt (a b : Int16) : Prop := a.toBitVec.slt b.toBitVec
Strict inequality for 16-bit signed integers
Informal description
The strict inequality relation on 16-bit signed integers, defined by comparing their two's complement representations as bitvectors. For any two 16-bit signed integers $a$ and $b$, $a < b$ holds if and only if the signed interpretation of $a$'s bitvector representation is strictly less than that of $b$'s.
Int16.le definition
(a b : Int16) : Prop
Full source
/--
Non-strict inequality of 16-bit signed integers, defined as inequality of the corresponding
integers. Usually accessed via the `≤` operator.
-/
protected def Int16.le (a b : Int16) : Prop := a.toBitVec.sle b.toBitVec
Non-strict inequality for 16-bit signed integers
Informal description
The non-strict inequality relation on 16-bit signed integers, defined by comparing their two's complement representations as bitvectors. For any two 16-bit signed integers $a$ and $b$, $a \leq b$ holds if and only if the signed interpretation of $a$'s bitvector representation is less than or equal to that of $b$'s.
instInhabitedInt16 instance
: Inhabited Int16
Full source
instance : Inhabited Int16 where
  default := 0
Inhabited Type for Signed 16-bit Integers
Informal description
The type of signed 16-bit integers `Int16` is inhabited, meaning it has a default element.
instAddInt16 instance
: Add Int16
Full source
instance : Add Int16         := ⟨Int16.add⟩
Addition Operation on 16-bit Signed Integers with Wrap-around
Informal description
The type of signed 16-bit integers `Int16` is equipped with an addition operation that performs wrap-around arithmetic on overflow or underflow.
instSubInt16 instance
: Sub Int16
Full source
instance : Sub Int16         := ⟨Int16.sub⟩
Subtraction Operation on 16-bit Integers
Informal description
The type of signed 16-bit integers `Int16` is equipped with a subtraction operation.
instMulInt16 instance
: Mul Int16
Full source
instance : Mul Int16         := ⟨Int16.mul⟩
Multiplication Structure on 16-bit Integers
Informal description
The signed 16-bit integers $\text{Int16}$ form a multiplicative structure, where multiplication is defined as the 2's complement multiplication with wrap-around modulo $2^{16}$.
instModInt16 instance
: Mod Int16
Full source
instance : Mod Int16         := ⟨Int16.mod⟩
Modulo Operation on 16-bit Signed Integers
Informal description
The signed 16-bit integers $\text{Int16}$ are equipped with a modulo operation that computes the remainder of division, following the same rounding convention as integer division. For any $a, b \in \text{Int16}$ with $b \neq 0$, the result $a \mod b$ has the same sign as $a$ and magnitude less than $|b|$. If $b = 0$, the result is $a$.
instDivInt16 instance
: Div Int16
Full source
instance : Div Int16         := ⟨Int16.div⟩
Truncating Division for 16-bit Signed Integers
Informal description
The signed 16-bit integers $\text{Int16}$ are equipped with a division operation that performs truncating division, rounding towards zero. Division by zero is defined to return zero.
instLTInt16 instance
: LT Int16
Full source
instance : LT Int16          := ⟨Int16.lt⟩
Strict Order on 16-bit Signed Integers
Informal description
The type of signed 16-bit integers `Int16` is equipped with a strict inequality relation `<`, defined by comparing their two's complement representations as bitvectors.
instLEInt16 instance
: LE Int16
Full source
instance : LE Int16          := ⟨Int16.le⟩
The Non-Strict Inequality Relation on 16-bit Signed Integers
Informal description
The type of 16-bit signed integers $\text{Int16}$ is equipped with a canonical non-strict inequality relation $\leq$, defined by comparing their two's complement representations as bitvectors.
instComplementInt16 instance
: Complement Int16
Full source
instance : Complement Int16  := ⟨Int16.complement⟩
Bitwise Complement Operation on 16-bit Signed Integers
Informal description
The type of 16-bit signed integers $\text{Int16}$ is equipped with a bitwise complement operation, where for any integer $a \in \text{Int16}$, the operation $\sim a$ flips all bits in $a$'s two's complement representation.
instAndOpInt16 instance
: AndOp Int16
Full source
instance : AndOp Int16       := ⟨Int16.land⟩
Bitwise AND Operation on 16-bit Integers
Informal description
The signed 16-bit integers $\text{Int16}$ can be equipped with a bitwise AND operation, where for any two integers $a$ and $b$ in $\text{Int16}$, the operation $a \&\& b$ computes their bitwise AND.
instOrOpInt16 instance
: OrOp Int16
Full source
instance : OrOp Int16        := ⟨Int16.lor⟩
Bitwise OR Operation on 16-bit Integers
Informal description
The signed 16-bit integers $\text{Int16}$ are equipped with a bitwise OR operation $\|$, which takes two 16-bit integers and returns a new 16-bit integer where each bit is set if at least one of the corresponding bits in the input integers is set.
instXorInt16 instance
: Xor Int16
Full source
instance : Xor Int16         := ⟨Int16.xor⟩
Bitwise XOR Operation on 16-bit Integers
Informal description
The signed 16-bit integers $\text{Int16}$ are equipped with a bitwise exclusive or (XOR) operation, where for any two integers $a$ and $b$ in $\text{Int16}$, the operation computes the bitwise XOR of $a$ and $b$ according to their two's complement representation.
instShiftLeftInt16 instance
: ShiftLeft Int16
Full source
instance : ShiftLeft Int16   := ⟨Int16.shiftLeft⟩
Bitwise Left Shift Operation on 16-bit Integers
Informal description
The signed 16-bit integers $\text{Int16}$ are equipped with a bitwise left shift operation $<<<$, where for any two integers $a$ and $b$ in $\text{Int16}$, the operation computes the bitwise left shift of $a$ by $b \mod 16$ bits, filling the low bits with zeros.
instShiftRightInt16 instance
: ShiftRight Int16
Full source
instance : ShiftRight Int16  := ⟨Int16.shiftRight⟩
Arithmetic Right Shift Operation on 16-bit Integers
Informal description
The signed 16-bit integers $\text{Int16}$ are equipped with a right shift operation, where for any two integers $a$ and $b$ in $\text{Int16}$, the operation computes the arithmetic right shift of $a$ by $b$ positions (modulo 16), preserving the sign of $a$.
instDecidableEqInt16 instance
: DecidableEq Int16
Full source
instance : DecidableEq Int16 := Int16.decEq
Decidable Equality for Signed 16-bit Integers
Informal description
The type of signed 16-bit integers has decidable equality, meaning that for any two elements $a, b \in \text{Int16}$, the equality $a = b$ can be constructively decided.
Bool.toInt16 definition
(b : Bool) : Int16
Full source
/--
Converts `true` to `1` and `false` to `0`.
-/
@[extern "lean_bool_to_int16"]
def Bool.toInt16 (b : Bool) : Int16 := if b then 1 else 0
Boolean to signed 16-bit integer conversion
Informal description
The function converts a boolean value `b` to a signed 16-bit integer, returning `1` if `b` is `true` and `0` if `b` is `false`.
Int16.decLt definition
(a b : Int16) : Decidable (a < b)
Full source
/--
Decides whether one 16-bit signed integer is strictly less than another. Usually accessed via the
`DecidableLT Int16` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `(if ((-7) : Int16) < 7 then "yes" else "no") = "yes"`
 * `(if (5 : Int16) < 5 then "yes" else "no") = "no"`
 * `show ¬((7 : Int16) < 7) by decide`
-/
@[extern "lean_int16_dec_lt"]
def Int16.decLt (a b : Int16) : Decidable (a < b) :=
  inferInstanceAs (Decidable (a.toBitVec.slt b.toBitVec))
Decidable strict inequality for signed 16-bit integers
Informal description
The function takes two signed 16-bit integers \( a \) and \( b \) and returns a constructive proof that the strict inequality \( a < b \) is decidable. This is implemented by converting the integers to their 2's complement bitvector representations and using the signed less-than comparison for bitvectors.
Int16.decLe definition
(a b : Int16) : Decidable (a ≤ b)
Full source
/--
Decides whether one 16-bit signed integer is less than or equal to another. Usually accessed via the
`DecidableLE Int16` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `(if ((-7) : Int16) ≤ 7 then "yes" else "no") = "yes"`
 * `(if (15 : Int16) ≤ 15 then "yes" else "no") = "yes"`
 * `(if (15 : Int16) ≤ 5 then "yes" else "no") = "no"`
 * `show (7 : Int16) ≤ 7 by decide`
-/
@[extern "lean_int16_dec_le"]
def Int16.decLe (a b : Int16) : Decidable (a ≤ b) :=
  inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
Decidable less-than-or-equal-to for 16-bit signed integers
Informal description
The function decides whether a 16-bit signed integer $a$ is less than or equal to another 16-bit signed integer $b$ by comparing their two's complement representations as bitvectors. This is used to provide a `Decidable` instance for the inequality $a \leq b$ on `Int16`.
instDecidableLtInt16 instance
(a b : Int16) : Decidable (a < b)
Full source
instance (a b : Int16) : Decidable (a < b) := Int16.decLt a b
Decidability of strict inequality on 16-bit signed integers
Informal description
For any two signed 16-bit integers $a$ and $b$, the strict inequality $a < b$ is decidable.
instDecidableLeInt16 instance
(a b : Int16) : Decidable (a ≤ b)
Full source
instance (a b : Int16) : Decidable (a ≤ b) := Int16.decLe a b
Decidability of Inequality for 16-bit Signed Integers
Informal description
For any two 16-bit signed integers $a$ and $b$, the inequality $a \leq b$ is decidable by comparing their two's complement representations.
instMaxInt16 instance
: Max Int16
Full source
instance : Max Int16 := maxOfLe
The Maximum Operation on 16-bit Signed Integers
Informal description
The type of 16-bit signed integers $\text{Int16}$ is equipped with a canonical maximum operation $\max$, defined by comparing their two's complement representations as bitvectors.
instMinInt16 instance
: Min Int16
Full source
instance : Min Int16 := minOfLe
Minimum Operation on 16-bit Signed Integers
Informal description
The type of 16-bit signed integers $\text{Int16}$ is equipped with a canonical minimum operation, where the minimum of two integers $a$ and $b$ is defined to be $a$ if $a \leq b$ and $b$ otherwise, based on their two's complement representations.
Int32.size abbrev
: Nat
Full source
/-- The number of distinct values representable by `Int32`, that is, `2^32 = 4294967296`. -/
abbrev Int32.size : Nat := 4294967296
Cardinality of 32-bit Integers: $2^{32}$
Informal description
The size of the `Int32` type is $2^{32} = 4294967296$, representing the number of distinct values that can be stored in a 32-bit signed integer.
Int32.toBitVec definition
(x : Int32) : BitVec 32
Full source
/--
Obtain the `BitVec` that contains the 2's complement representation of the `Int32`.
-/
@[inline] def Int32.toBitVec (x : Int32) : BitVec 32 := x.toUInt32.toBitVec
2's complement representation of a 32-bit integer
Informal description
The function maps a signed 32-bit integer \( x \) to its 2's complement representation as a bitvector of width 32.
Int32.toBitVec.inj theorem
: {x y : Int32} → x.toBitVec = y.toBitVec → x = y
Full source
theorem Int32.toBitVec.inj : {x y : Int32} → x.toBitVec = y.toBitVec → x = y
  | ⟨⟨_⟩⟩, ⟨⟨_⟩⟩, rfl => rfl
Injectivity of 2's Complement Representation for 32-bit Integers
Informal description
For any two signed 32-bit integers $x$ and $y$, if their 2's complement bitvector representations are equal (i.e., $\text{toBitVec}(x) = \text{toBitVec}(y)$), then $x = y$.
UInt32.toInt32 definition
(i : UInt32) : Int32
Full source
/-- Obtains the `Int32` that is 2's complement equivalent to the `UInt32`. -/
@[inline] def UInt32.toInt32 (i : UInt32) : Int32 := Int32.ofUInt32 i
Conversion from unsigned to signed 32-bit integer
Informal description
The function converts an unsigned 32-bit integer `i` to a signed 32-bit integer using 2's complement representation.
Int32.mk definition
(i : UInt32) : Int32
Full source
@[inline, deprecated UInt32.toInt32 (since := "2025-02-13"), inherit_doc UInt32.toInt32]
def Int32.mk (i : UInt32) : Int32 := UInt32.toInt32 i
Construction of signed 32-bit integer from unsigned 32-bit integer
Informal description
The function constructs a signed 32-bit integer from an unsigned 32-bit integer `i` using 2's complement representation.
Int32.ofInt definition
(i : @& Int) : Int32
Full source
/--
Converts an arbitrary-precision integer to a 32-bit integer, wrapping on overflow or underflow.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int32.ofInt 48 = 48`
 * `Int32.ofInt (-129) = -129`
 * `Int32.ofInt 70000 = 70000`
 * `Int32.ofInt (-40000) = -40000`
 * `Int32.ofInt 2147483648 = -2147483648`
 * `Int32.ofInt (-2147483649) = 2147483647`
-/
@[extern "lean_int32_of_int"]
def Int32.ofInt (i : @& Int) : Int32 := ⟨⟨BitVec.ofInt 32 i⟩⟩
Conversion from integer to 32-bit signed integer with overflow wrapping
Informal description
The function converts an arbitrary-precision integer $i$ to a 32-bit signed integer using two's complement representation, wrapping around on overflow or underflow. Specifically, the result is computed as $(2^{32} + (i \bmod 2^{32})) \bmod 2^{32}$ interpreted in two's complement form. Examples: - $\text{Int32.ofInt } 48 = 48$ - $\text{Int32.ofInt } (-129) = -129$ - $\text{Int32.ofInt } 2147483648 = -2147483648$ - $\text{Int32.ofInt } (-2147483649) = 2147483647$
Int32.ofNat definition
(n : @& Nat) : Int32
Full source
/--
Converts a natural number to a 32-bit signed integer, wrapping around on overflow.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int32.ofNat 127 = 127`
 * `Int32.ofNat 32770 = 32770`
 * `Int32.ofNat 2_147_483_647 = 2_147_483_647`
 * `Int32.ofNat 2_147_483_648 = -2_147_483_648`
-/
@[extern "lean_int32_of_nat"]
def Int32.ofNat (n : @& Nat) : Int32 := ⟨⟨BitVec.ofNat 32 n⟩⟩
Conversion from natural number to 32-bit signed integer with overflow wrapping
Informal description
The function converts a natural number \( n \) to a 32-bit signed integer, using 2's complement representation. If \( n \) exceeds the maximum value representable in 32 bits (\( 2^{31} - 1 \)), it wraps around to negative values starting from \(-2^{31}\). For example: - \( \text{Int32.ofNat } 127 = 127 \) - \( \text{Int32.ofNat } 32770 = 32770 \) - \( \text{Int32.ofNat } 2,147,483,647 = 2,147,483,647 \) - \( \text{Int32.ofNat } 2,147,483,648 = -2,147,483,648 \)
Int.toInt32 abbrev
Full source
/--
Converts an arbitrary-precision integer to a 32-bit integer, wrapping on overflow or underflow.

Examples:
 * `Int.toInt32 48 = 48`
 * `Int.toInt32 (-129) = -129`
 * `Int.toInt32 70000 = 70000`
 * `Int.toInt32 (-40000) = -40000`
 * `Int.toInt32 2147483648 = -2147483648`
 * `Int.toInt32 (-2147483649) = 2147483647`
-/
abbrev Int.toInt32 := Int32.ofInt
Conversion from arbitrary-precision integer to 32-bit signed integer with overflow wrapping
Informal description
The function $\text{Int.toInt32}$ converts an arbitrary-precision integer $i$ to a 32-bit signed integer using two's complement representation, wrapping around on overflow or underflow. Specifically, the result is computed as $(2^{32} + (i \bmod 2^{32})) \bmod 2^{32}$ interpreted in two's complement form. Examples: - $\text{Int.toInt32}(48) = 48$ - $\text{Int.toInt32}(-129) = -129$ - $\text{Int.toInt32}(2147483648) = -2147483648$ - $\text{Int.toInt32}(-2147483649) = 2147483647$
Nat.toInt32 abbrev
Full source
/--
Converts a natural number to a 32-bit signed integer, wrapping around to negative numbers on
overflow.

Examples:
 * `Nat.toInt32 127 = 127`
 * `Nat.toInt32 32770 = 32770`
 * `Nat.toInt32 2_147_483_647 = 2_147_483_647`
 * `Nat.toInt32 2_147_483_648 = -2_147_483_648`
-/
abbrev Nat.toInt32 := Int32.ofNat
Natural Number to 32-bit Signed Integer Conversion with Overflow Wrapping
Informal description
The function $\text{Nat.toInt32}$ converts a natural number $n$ to a 32-bit signed integer using 2's complement representation. If $n$ exceeds the maximum positive value representable in 32 bits ($2^{31} - 1$), it wraps around to negative values starting from $-2^{31}$. For example: - $\text{Nat.toInt32}(127) = 127$ - $\text{Nat.toInt32}(32770) = 32770$ - $\text{Nat.toInt32}(2,147,483,647) = 2,147,483,647$ - $\text{Nat.toInt32}(2,147,483,648) = -2,147,483,648$
Int32.toInt definition
(i : Int32) : Int
Full source
/--
Converts a 32-bit signed integer to an arbitrary-precision integer that denotes the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_to_int"]
def Int32.toInt (i : Int32) : Int := i.toBitVec.toInt
Conversion from 32-bit integer to arbitrary-precision integer
Informal description
The function converts a signed 32-bit integer \( i \) to an arbitrary-precision integer by interpreting its 2's complement representation as a signed integer.
Int32.toNatClampNeg definition
(i : Int32) : Nat
Full source
/--
Converts a 32-bit signed integer to a natural number, mapping all negative numbers to `0`.

Use `Int32.toBitVec` to obtain the two's complement representation.
-/
@[inline] def Int32.toNatClampNeg (i : Int32) : Nat := i.toInt.toNat
Conversion from 32-bit integer to natural number (negative clamped to zero)
Informal description
The function converts a signed 32-bit integer \( i \) to a natural number by first converting it to an arbitrary-precision integer and then mapping negative values to zero. Specifically: - If \( i \) is non-negative, returns the corresponding natural number. - If \( i \) is negative, returns zero.
Int32.toNat definition
(i : Int32) : Nat
Full source
@[inline, deprecated Int32.toNatClampNeg (since := "2025-02-13"), inherit_doc Int32.toNatClampNeg]
def Int32.toNat (i : Int32) : Nat := i.toInt.toNat
Conversion from 32-bit integer to natural number (negative to zero)
Informal description
The function converts a signed 32-bit integer \( i \) to a natural number by first converting \( i \) to an arbitrary-precision integer (via `Int32.toInt`) and then converting that integer to a natural number (via `Int.toNat`), where negative integers are mapped to zero.
Int32.ofBitVec definition
(b : BitVec 32) : Int32
Full source
/-- Obtains the `Int32` whose 2's complement representation is the given `BitVec 32`. -/
@[inline] def Int32.ofBitVec (b : BitVec 32) : Int32 := ⟨⟨b⟩⟩
Conversion from bitvector to signed 32-bit integer
Informal description
The function takes a bitvector `b` of width 32 and returns the corresponding signed 32-bit integer obtained by interpreting `b` as a 2's complement representation.
Int32.toInt8 definition
(a : Int32) : Int8
Full source
/--
Converts a 32-bit signed integer to an 8-bit signed integer by truncating its bitvector
representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_to_int8"]
def Int32.toInt8 (a : Int32) : Int8 := ⟨⟨a.toBitVec.signExtend 8⟩⟩
Truncation from 32-bit to 8-bit signed integer
Informal description
The function converts a signed 32-bit integer \( a \) to a signed 8-bit integer by truncating its 2's complement bitvector representation to 8 bits (with sign extension).
Int32.toInt16 definition
(a : Int32) : Int16
Full source
/--
Converts a 32-bit signed integer to an 16-bit signed integer by truncating its bitvector
representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_to_int16"]
def Int32.toInt16 (a : Int32) : Int16 := ⟨⟨a.toBitVec.signExtend 16⟩⟩
Conversion from 32-bit to 16-bit signed integer via truncation
Informal description
The function converts a signed 32-bit integer \( a \) to a signed 16-bit integer by truncating its 2's complement bitvector representation to 16 bits (using sign extension to preserve the sign bit).
Int8.toInt32 definition
(a : Int8) : Int32
Full source
/--
Converts 8-bit signed integers to 32-bit signed integers that denote the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_to_int32"]
def Int8.toInt32 (a : Int8) : Int32 := ⟨⟨a.toBitVec.signExtend 32⟩⟩
Sign extension from 8-bit to 32-bit integers
Informal description
The function converts a signed 8-bit integer \( a \) to a signed 32-bit integer by sign-extending its 2's complement representation to 32 bits.
Int16.toInt32 definition
(a : Int16) : Int32
Full source
/--
Converts 8-bit signed integers to 32-bit signed integers that denote the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_to_int32"]
def Int16.toInt32 (a : Int16) : Int32 := ⟨⟨a.toBitVec.signExtend 32⟩⟩
Conversion from 16-bit to 32-bit signed integer
Informal description
The function maps a signed 16-bit integer \( a \) to a signed 32-bit integer that represents the same numerical value. This is implemented by first converting \( a \) to its 2's complement bitvector representation of width 16, then sign-extending this bitvector to width 32, and finally interpreting the result as a 32-bit signed integer.
Int32.neg definition
(i : Int32) : Int32
Full source
/--
Negates 32-bit signed integers. Usually accessed via the `-` prefix operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_neg"]
def Int32.neg (i : Int32) : Int32 := ⟨⟨-i.toBitVec⟩⟩
Negation of 32-bit signed integers
Informal description
The function negates a signed 32-bit integer \( i \) by computing its 2's complement negation, which is implemented by negating its underlying bitvector representation and interpreting the result as a 32-bit signed integer.
instToStringInt32 instance
: ToString Int32
Full source
instance : ToString Int32 where
  toString i := toString i.toInt
String Representation of 32-bit Integers
Informal description
The signed 32-bit integers $\text{Int32}$ have a string representation.
instReprInt32 instance
: Repr Int32
Full source
instance : Repr Int32 where
  reprPrec i prec := reprPrec i.toInt prec
Decimal Representation of 32-bit Integers
Informal description
The signed 32-bit integers `Int32` have a standard string representation in decimal format.
instReprAtomInt32 instance
: ReprAtom Int32
Full source
instance : ReprAtom Int32 := ⟨⟩
Atomic Representation Marker for 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` is marked as an atomic type for representation purposes.
instHashableInt32 instance
: Hashable Int32
Full source
instance : Hashable Int32 where
  hash i := i.toUInt32.toUInt64
Hashability of 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` can be hashed into a 64-bit unsigned integer.
Int32.instOfNat instance
: OfNat Int32 n
Full source
instance Int32.instOfNat : OfNat Int32 n := ⟨Int32.ofNat n⟩
Numeric Literal Interpretation for 32-bit Integers
Informal description
For any natural number $n$, there is a canonical interpretation of $n$ as a signed 32-bit integer via the `OfNat` typeclass. This conversion wraps around using 2's complement representation if $n$ exceeds the maximum value representable in 32 bits.
Int32.instNeg instance
: Neg Int32
Full source
instance Int32.instNeg : Neg Int32 where
  neg := Int32.neg
Negation Operation on 32-bit Signed Integers
Informal description
The type of signed 32-bit integers `Int32` has a negation operation, where for any `i : Int32`, the negation `-i` is computed using 2's complement arithmetic.
Int32.maxValue abbrev
: Int32
Full source
/-- The largest number that `Int32` can represent: `2^31 - 1 = 2147483647`. -/
abbrev Int32.maxValue : Int32 := 2147483647
Maximum Value of 32-bit Signed Integer: $2^{31} - 1$
Informal description
The maximum value representable by a signed 32-bit integer is $2^{31} - 1 = 2147483647$.
Int32.minValue abbrev
: Int32
Full source
/-- The smallest number that `Int32` can represent: `-2^31 = -2147483648`. -/
abbrev Int32.minValue : Int32 := -2147483648
Minimum Value of 32-bit Signed Integer: $-2^{31}$
Informal description
The smallest value representable by a 32-bit signed integer is $-2^{31} = -2147483648$.
Int32.ofIntLE definition
(i : Int) (_hl : Int32.minValue.toInt ≤ i) (_hr : i ≤ Int32.maxValue.toInt) : Int32
Full source
/-- Constructs an `Int32` from an `Int` that is known to be in bounds. -/
@[inline]
def Int32.ofIntLE (i : Int) (_hl : Int32.minValue.toInt ≤ i) (_hr : i ≤ Int32.maxValue.toInt) : Int32 :=
  Int32.ofInt i
Bounded conversion from integer to 32-bit signed integer
Informal description
Given an integer \( i \) with \( -2^{31} \leq i \leq 2^{31} - 1 \), the function constructs a signed 32-bit integer from \( i \). This function is guaranteed to succeed without overflow since \( i \) is within the bounds of a 32-bit signed integer.
Int32.ofIntTruncate definition
(i : Int) : Int32
Full source
/-- Constructs an `Int32` from an `Int`, clamping if the value is too small or too large. -/
def Int32.ofIntTruncate (i : Int) : Int32 :=
  if hl : Int32.minValue.toInt ≤ i then
    if hr : i ≤ Int32.maxValue.toInt then
      Int32.ofIntLE i hl hr
    else
      Int32.minValue
  else
    Int32.minValue
Clamped conversion from integer to 32-bit signed integer
Informal description
The function constructs a signed 32-bit integer from an arbitrary-precision integer \( i \). If \( i \) is within the range \([-2^{31}, 2^{31} - 1]\), it returns the corresponding 32-bit integer. Otherwise, it clamps the value to the minimum 32-bit integer value \(-2^{31}\).
Int32.add definition
(a b : Int32) : Int32
Full source
/--
Adds two 32-bit signed integers, wrapping around on over- or underflow.  Usually accessed via the
`+` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_add"]
protected def Int32.add (a b : Int32) : Int32 := ⟨⟨a.toBitVec + b.toBitVec⟩⟩
Addition of signed 32-bit integers with wrap-around
Informal description
The function adds two signed 32-bit integers \( a \) and \( b \), wrapping around on overflow or underflow. The addition is performed by converting the integers to their 2's complement bitvector representations, adding them as bitvectors modulo \( 2^{32} \), and converting the result back to a signed 32-bit integer.
Int32.sub definition
(a b : Int32) : Int32
Full source
/--
Subtracts one 32-bit signed integer from another, wrapping around on over- or underflow. Usually
accessed via the `-` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_sub"]
protected def Int32.sub (a b : Int32) : Int32 := ⟨⟨a.toBitVec - b.toBitVec⟩⟩
Subtraction of signed 32-bit integers with wrap-around
Informal description
The function subtracts two signed 32-bit integers \( a \) and \( b \), wrapping around on overflow or underflow, and returns the result as a signed 32-bit integer. The operation is performed by converting the integers to their 2's complement bitvector representations, subtracting them as bitvectors (modulo \( 2^{32} \)), and converting the result back to a signed 32-bit integer.
Int32.mul definition
(a b : Int32) : Int32
Full source
/--
Multiplies two 32-bit signed integers, wrapping around on over- or underflow.  Usually accessed via
the `*` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_mul"]
protected def Int32.mul (a b : Int32) : Int32 := ⟨⟨a.toBitVec * b.toBitVec⟩⟩
Multiplication of signed 32-bit integers with wrap-around
Informal description
The function multiplies two signed 32-bit integers \( a \) and \( b \), returning their product as a signed 32-bit integer with wrap-around behavior on overflow or underflow. The multiplication is performed by converting the integers to their 2's complement bitvector representations, multiplying them modulo \( 2^{32} \), and converting the result back to a signed 32-bit integer.
Int32.div definition
(a b : Int32) : Int32
Full source
/--
Truncating division for 32-bit signed integers, rounding towards zero. Usually accessed via the `/`
operator.

Division by zero is defined to be zero.

This function is overridden at runtime with an efficient implementation.

Examples:
* `Int32.div 10 3 = 3`
* `Int32.div 10 (-3) = (-3)`
* `Int32.div (-10) (-3) = 3`
* `Int32.div (-10) 3 = (-3)`
* `Int32.div 10 0 = 0`
-/
@[extern "lean_int32_div"]
protected def Int32.div (a b : Int32) : Int32 := ⟨⟨BitVec.sdiv a.toBitVec b.toBitVec⟩⟩
Truncating division for signed 32-bit integers
Informal description
The function divides two signed 32-bit integers $a$ and $b$, rounding towards zero (truncating division). Division by zero is defined to return zero. Specifically: - If $a \geq 0$ and $b \geq 0$, returns $\lfloor a / b \rfloor$. - If $a \geq 0$ and $b < 0$, returns $-\lfloor a / |b| \rfloor$. - If $a < 0$ and $b \geq 0$, returns $-\lfloor |a| / b \rfloor$. - If $a < 0$ and $b < 0$, returns $\lfloor |a| / |b| \rfloor$.
Int32.mod definition
(a b : Int32) : Int32
Full source
/--
The modulo operator for 32-bit signed integers, which computes the remainder when dividing one
integer by another with the T-rounding convention used by `Int32.div`. Usually accessed via the `%`
operator.

When the divisor is `0`, the result is the dividend rather than an error.

This function is overridden at runtime with an efficient implementation.

Examples:
* `Int32.mod 5 2 = 1`
* `Int32.mod 5 (-2) = 1`
* `Int32.mod (-5) 2 = (-1)`
* `Int32.mod (-5) (-2) = (-1)`
* `Int32.mod 4 2 = 0`
* `Int32.mod 4 (-2) = 0`
* `Int32.mod 4 0 = 4`
* `Int32.mod (-4) 0 = (-4)`
-/
@[extern "lean_int32_mod"]
protected def Int32.mod (a b : Int32) : Int32 := ⟨⟨BitVec.srem a.toBitVec b.toBitVec⟩⟩
Signed 32-bit integer modulo operation
Informal description
The modulo operation for signed 32-bit integers, which computes the remainder when dividing $a$ by $b$ using the same rounding convention as `Int32.div`. If $b = 0$, the result is $a$ (rather than an error). The operation is implemented via signed remainder on the 2's complement bitvector representations of the inputs.
Int32.land definition
(a b : Int32) : Int32
Full source
/--
Bitwise and for 32-bit signed integers. Usually accessed via the `&&&` operator.

Each bit of the resulting integer is set if the corresponding bits of both input integers are set,
according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_land"]
protected def Int32.land (a b : Int32) : Int32 := ⟨⟨a.toBitVec &&& b.toBitVec⟩⟩
Bitwise AND for signed 32-bit integers
Informal description
The function takes two signed 32-bit integers \( a \) and \( b \), converts them to their 2's complement representation as bitvectors of width 32, performs a bitwise AND operation on these bitvectors (where each bit of the result is set if both corresponding bits of the inputs are set), and returns the result as a signed 32-bit integer.
Int32.lor definition
(a b : Int32) : Int32
Full source
/--
Bitwise or for 32-bit signed integers. Usually accessed via the `|||` operator.

Each bit of the resulting integer is set if at least one of the corresponding bits of the input
integers is set, according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_lor"]
protected def Int32.lor (a b : Int32) : Int32 := ⟨⟨a.toBitVec ||| b.toBitVec⟩⟩
Bitwise OR for 32-bit integers
Informal description
The function takes two signed 32-bit integers \( a \) and \( b \) and returns their bitwise OR, where each bit of the result is set if at least one of the corresponding bits in \( a \) or \( b \) is set, according to the two's complement representation.
Int32.xor definition
(a b : Int32) : Int32
Full source
/--
Bitwise exclusive or for 32-bit signed integers. Usually accessed via the `^^^` operator.

Each bit of the resulting integer is set if exactly one of the corresponding bits of the input
integers is set, according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_xor"]
protected def Int32.xor (a b : Int32) : Int32 := ⟨⟨a.toBitVec ^^^ b.toBitVec⟩⟩
Bitwise XOR of 32-bit integers
Informal description
The function computes the bitwise exclusive or (XOR) of two signed 32-bit integers \( a \) and \( b \), where each bit of the result is set if exactly one of the corresponding bits in \( a \) or \( b \) is set, according to the two's complement representation. The operation is implemented by converting the integers to their 32-bit bitvector representations, performing the XOR operation on the bitvectors, and then converting the result back to a signed 32-bit integer.
Int32.shiftLeft definition
(a b : Int32) : Int32
Full source
/--
Bitwise left shift for 32-bit signed integers. Usually accessed via the `<<<` operator.

Signed integers are interpreted as bitvectors according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_shift_left"]
protected def Int32.shiftLeft (a b : Int32) : Int32 := ⟨⟨a.toBitVec <<< (b.toBitVec.smod 32)⟩⟩
Left shift for 32-bit integers
Informal description
The function takes two signed 32-bit integers \( a \) and \( b \), and returns the result of left-shifting the bits of \( a \) by the value of \( b \) modulo 32, filling the low bits with zeros. The operation is performed using the two's complement representation of the integers.
Int32.shiftRight definition
(a b : Int32) : Int32
Full source
/--
Arithmetic right shift for 32-bit signed integers. Usually accessed via the `<<<` operator.

The high bits are filled with the value of the most significant bit.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_shift_right"]
protected def Int32.shiftRight (a b : Int32) : Int32 := ⟨⟨BitVec.sshiftRight' a.toBitVec (b.toBitVec.smod 32)⟩⟩
Arithmetic right shift for 32-bit integers
Informal description
The function performs an arithmetic right shift on a signed 32-bit integer \( a \) by \( b \) positions, where \( b \) is taken modulo 32. The high bits are filled with the value of the most significant bit (sign extension). Numerically, this operation is equivalent to the two's complement interpretation of \( a \) right-shifted by \( b \) positions, i.e., \( \lfloor a / 2^b \rfloor \) where \( a \) is treated as a signed integer.
Int32.complement definition
(a : Int32) : Int32
Full source
/--
Bitwise complement, also known as bitwise negation, for 32-bit signed integers. Usually accessed via
the `~~~` prefix operator.

Each bit of the resulting integer is the opposite of the corresponding bit of the input integer.
Integers use the two's complement representation, so `Int32.complement a = -(a + 1)`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_complement"]
protected def Int32.complement (a : Int32) : Int32 := ⟨⟨~~~a.toBitVec⟩⟩
Bitwise complement of a signed 32-bit integer
Informal description
The bitwise complement (negation) of a signed 32-bit integer \( a \), denoted \( \text{Int32.complement}\,a \), is defined as \( -(a + 1) \) in two's complement representation. This operation flips each bit of \( a \), and the result is another signed 32-bit integer.
Int32.abs definition
(a : Int32) : Int32
Full source
/--
Computes the absolute value of a 32-bit 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`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_abs"]
protected def Int32.abs (a : Int32) : Int32 := ⟨⟨a.toBitVec.abs⟩⟩
Absolute value of a 32-bit signed integer
Informal description
The function computes the absolute value of a signed 32-bit integer $a$. For $a \geq 0$, it returns $a$; for $a < 0$, it returns $-a$. Note that for the minimal value `Int32.minValue`, the result remains `Int32.minValue` due to overflow in two's complement representation.
Int32.decEq definition
(a b : Int32) : Decidable (a = b)
Full source
/--
Decides whether two 32-bit signed integers are equal. Usually accessed via the `DecidableEq Int32`
instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int32.decEq 123 123 = .isTrue rfl`
 * `(if ((-7) : Int32) = 7 then "yes" else "no") = "no"`
 * `show (7 : Int32) = 7 by decide`
-/
@[extern "lean_int32_dec_eq"]
def Int32.decEq (a b : Int32) : Decidable (a = b) :=
  match a, b with
  | ⟨n⟩, ⟨m⟩ =>
    if h : n = m then
      isTrue <| h ▸ rfl
    else
      isFalse (fun h' => Int32.noConfusion h' (fun h' => absurd h' h))
Decidable equality for signed 32-bit integers
Informal description
The function `Int32.decEq` decides whether two signed 32-bit integers `a` and `b` are equal, returning a constructive proof of either `a = b` or `¬(a = b)`. This is used to provide decidable equality for the `Int32` type.
Int32.lt definition
(a b : Int32) : Prop
Full source
/--
Strict inequality of 32-bit signed integers, defined as inequality of the corresponding integers.
Usually accessed via the `<` operator.
-/
protected def Int32.lt (a b : Int32) : Prop := a.toBitVec.slt b.toBitVec
Signed less-than for 32-bit integers
Informal description
The strict inequality relation on signed 32-bit integers, defined as the signed less-than comparison of their 2's complement bitvector representations. For any two 32-bit integers $a$ and $b$, $a < b$ holds if and only if the signed interpretation of $a$'s bitvector representation is strictly less than that of $b$'s.
Int32.le definition
(a b : Int32) : Prop
Full source
/--
Non-strict inequality of 32-bit signed integers, defined as inequality of the corresponding integers.
Usually accessed via the `≤` operator.
-/
protected def Int32.le (a b : Int32) : Prop := a.toBitVec.sle b.toBitVec
Signed 32-bit integer less-than-or-equal-to relation
Informal description
The relation `Int32.le` defines the non-strict inequality between two signed 32-bit integers $a$ and $b$, interpreted as their two's complement signed integer representations. Specifically, $a \leq b$ holds if and only if the signed comparison of their 32-bit two's complement representations evaluates to true.
instInhabitedInt32 instance
: Inhabited Int32
Full source
instance : Inhabited Int32 where
  default := 0
Inhabitedness of 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` is inhabited, meaning it has a default element.
instAddInt32 instance
: Add Int32
Full source
instance : Add Int32         := ⟨Int32.add⟩
Addition Operation on 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` is equipped with a homogeneous addition operation, where the sum of any two `Int32` elements is computed using 2's complement arithmetic with wrap-around on overflow or underflow.
instSubInt32 instance
: Sub Int32
Full source
instance : Sub Int32         := ⟨Int32.sub⟩
Subtraction Operation on 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` is equipped with a subtraction operation, where for any two elements `a` and `b` in `Int32`, their difference `a - b` is computed as a signed 32-bit integer with wrap-around behavior on overflow or underflow.
instMulInt32 instance
: Mul Int32
Full source
instance : Mul Int32         := ⟨Int32.mul⟩
Multiplication Operation on 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` is equipped with a multiplication operation `*` that performs multiplication modulo \(2^{32}\) with wrap-around behavior on overflow or underflow.
instModInt32 instance
: Mod Int32
Full source
instance : Mod Int32         := ⟨Int32.mod⟩
Modulo Operation on 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` is equipped with a modulo operation `%` that computes the remainder when dividing one integer by another, following the same rounding convention as `Int32.div`. If the divisor is zero, the result is the dividend.
instDivInt32 instance
: Div Int32
Full source
instance : Div Int32         := ⟨Int32.div⟩
Division Operation on 32-bit Integers with Truncation
Informal description
The type of signed 32-bit integers `Int32` is equipped with a division operation `/` that performs truncating division (rounding towards zero). Division by zero is defined to return zero.
instLTInt32 instance
: LT Int32
Full source
instance : LT Int32          := ⟨Int32.lt⟩
Strict Order on 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` is equipped with a canonical strict order relation `<` defined via the signed comparison of their 2's complement bitvector representations.
instLEInt32 instance
: LE Int32
Full source
instance : LE Int32          := ⟨Int32.le⟩
Non-strict Order on 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` is equipped with a canonical non-strict order relation `≤` defined via the signed comparison of their 2's complement bitvector representations.
instComplementInt32 instance
: Complement Int32
Full source
instance : Complement Int32  := ⟨Int32.complement⟩
Bitwise Complement Operation on 32-bit Integers
Informal description
The signed 32-bit integers $\text{Int32}$ are equipped with a bitwise complement operation, where for any integer $a$ in $\text{Int32}$, the operation $\sim a$ flips all bits of $a$ in its 32-bit two's complement representation.
instAndOpInt32 instance
: AndOp Int32
Full source
instance : AndOp Int32       := ⟨Int32.land⟩
Bitwise AND Operation on 32-bit Integers
Informal description
The signed 32-bit integers $\text{Int32}$ are equipped with a bitwise AND operation, where for any two integers $a$ and $b$ in $\text{Int32}$, the operation $a \&\&\& b$ performs a bitwise AND on their 32-bit representations and returns the result as a signed 32-bit integer.
instOrOpInt32 instance
: OrOp Int32
Full source
instance : OrOp Int32        := ⟨Int32.lor⟩
Bitwise OR Operation on 32-bit Integers
Informal description
The signed 32-bit integers $\text{Int32}$ are equipped with a bitwise OR operation, where for any two integers $a$ and $b$, the operation $a \lor b$ computes the bitwise OR of $a$ and $b$.
instXorInt32 instance
: Xor Int32
Full source
instance : Xor Int32         := ⟨Int32.xor⟩
Bitwise XOR Operation on 32-bit Integers
Informal description
The signed 32-bit integers $\text{Int32}$ are equipped with a bitwise exclusive or (XOR) operation, where for any two integers $a$ and $b$, the result is the integer whose bits are set to 1 in positions where exactly one of $a$ or $b$ has a 1, and 0 otherwise.
instShiftLeftInt32 instance
: ShiftLeft Int32
Full source
instance : ShiftLeft Int32   := ⟨Int32.shiftLeft⟩
Left Shift Operation on 32-bit Integers
Informal description
The signed 32-bit integers $\text{Int32}$ are equipped with a left shift operation, where for any two integers $a$ and $b$, the operation $a \ll b$ shifts the bits of $a$ left by $b$ positions, filling the low bits with zeros.
instShiftRightInt32 instance
: ShiftRight Int32
Full source
instance : ShiftRight Int32  := ⟨Int32.shiftRight⟩
Arithmetic Right Shift Operation on 32-bit Integers
Informal description
The signed 32-bit integers $\text{Int32}$ are equipped with an arithmetic right shift operation, where for any two integers $a$ and $b$, the result is the integer obtained by shifting $a$ right by $b$ positions (modulo 32), with sign extension.
instDecidableEqInt32 instance
: DecidableEq Int32
Full source
instance : DecidableEq Int32 := Int32.decEq
Decidable Equality for Signed 32-bit Integers
Informal description
The type of signed 32-bit integers has decidable equality, meaning that for any two elements `a` and `b` in `Int32`, the equality `a = b` can be constructively decided.
Bool.toInt32 definition
(b : Bool) : Int32
Full source
/--
Converts `true` to `1` and `false` to `0`.
-/
@[extern "lean_bool_to_int32"]
def Bool.toInt32 (b : Bool) : Int32 := if b then 1 else 0
Boolean to 32-bit integer conversion
Informal description
The function converts a boolean value `b` to a 32-bit integer, returning `1` if `b` is `true` and `0` if `b` is `false`.
Int32.decLt definition
(a b : Int32) : Decidable (a < b)
Full source
/--
Decides whether one 32-bit signed integer is strictly less than another. Usually accessed via the
`DecidableLT Int32` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `(if ((-7) : Int32) < 7 then "yes" else "no") = "yes"`
 * `(if (5 : Int32) < 5 then "yes" else "no") = "no"`
 * `show ¬((7 : Int32) < 7) by decide`
-/
@[extern "lean_int32_dec_lt"]
def Int32.decLt (a b : Int32) : Decidable (a < b) :=
  inferInstanceAs (Decidable (a.toBitVec.slt b.toBitVec))
Decidability of strict order on 32-bit integers
Informal description
The function decides whether one 32-bit signed integer `a` is strictly less than another `b` by comparing their two's complement bitvector representations. This is used to constructively prove the decidability of the proposition `a < b`.
Int32.decLe definition
(a b : Int32) : Decidable (a ≤ b)
Full source
/--
Decides whether one 32-bit signed integer is less than or equal to another. Usually accessed via the
`DecidableLE Int32` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `(if ((-7) : Int32) ≤ 7 then "yes" else "no") = "yes"`
 * `(if (15 : Int32) ≤ 15 then "yes" else "no") = "yes"`
 * `(if (15 : Int32) ≤ 5 then "yes" else "no") = "no"`
 * `show (7 : Int32) ≤ 7 by decide`
-/
@[extern "lean_int32_dec_le"]
def Int32.decLe (a b : Int32) : Decidable (a ≤ b) :=
  inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
Decidable less-than-or-equal for 32-bit integers
Informal description
The function takes two signed 32-bit integers $a$ and $b$ and returns a constructive proof that either $a \leq b$ or $\neg(a \leq b)$. The decision is made by comparing the 2's complement bitvector representations of $a$ and $b$ using signed less-than-or-equal comparison.
instDecidableLtInt32 instance
(a b : Int32) : Decidable (a < b)
Full source
instance (a b : Int32) : Decidable (a < b) := Int32.decLt a b
Decidability of Strict Order on 32-bit Integers
Informal description
For any two signed 32-bit integers $a$ and $b$, the proposition $a < b$ is decidable. This means there exists a constructive procedure to determine whether $a$ is strictly less than $b$ based on their two's complement bitvector representations.
instDecidableLeInt32 instance
(a b : Int32) : Decidable (a ≤ b)
Full source
instance (a b : Int32) : Decidable (a ≤ b) := Int32.decLe a b
Decidability of the Non-strict Order on 32-bit Integers
Informal description
For any two signed 32-bit integers $a$ and $b$, the proposition $a \leq b$ is decidable. This means there exists a constructive procedure to determine whether $a$ is less than or equal to $b$ based on their 2's complement bitvector representations.
instMaxInt32 instance
: Max Int32
Full source
instance : Max Int32 := maxOfLe
Maximum Operation on 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` is equipped with a canonical maximum operation, where for any two integers `x` and `y`, `max(x, y)` returns `y` if `x ≤ y` and `x` otherwise, using the decidable order on `Int32`.
instMinInt32 instance
: Min Int32
Full source
instance : Min Int32 := minOfLe
Minimum Operation on 32-bit Integers
Informal description
The type of signed 32-bit integers `Int32` is equipped with a minimum operation, where for any two integers `a` and `b`, the minimum is defined to be `a` if `a ≤ b` and `b` otherwise, using the canonical order on 32-bit integers.
Int64.size abbrev
: Nat
Full source
/-- The number of distinct values representable by `Int64`, that is, `2^64 = 18446744073709551616`. -/
abbrev Int64.size : Nat := 18446744073709551616
Cardinality of `Int64`: $2^{64}$
Informal description
The size of the `Int64` type is $2^{64} = 18446744073709551616$, representing the number of distinct values it can hold.
Int64.toBitVec definition
(x : Int64) : BitVec 64
Full source
/--
Obtain the `BitVec` that contains the 2's complement representation of the `Int64`.
-/
@[inline] def Int64.toBitVec (x : Int64) : BitVec 64 := x.toUInt64.toBitVec
Conversion from signed 64-bit integer to 64-bit bitvector (2's complement)
Informal description
The function converts a signed 64-bit integer \( x \) to a bitvector of width 64, representing its 2's complement form.
Int64.toBitVec.inj theorem
: {x y : Int64} → x.toBitVec = y.toBitVec → x = y
Full source
theorem Int64.toBitVec.inj : {x y : Int64} → x.toBitVec = y.toBitVec → x = y
  | ⟨⟨_⟩⟩, ⟨⟨_⟩⟩, rfl => rfl
Injective Conversion from Signed 64-bit Integers to Bitvectors
Informal description
For any two signed 64-bit integers $x$ and $y$, if their corresponding 64-bit bitvector representations (in 2's complement form) are equal, then $x$ and $y$ are equal.
UInt64.toInt64 definition
(i : UInt64) : Int64
Full source
/-- Obtains the `Int64` that is 2's complement equivalent to the `UInt64`. -/
@[inline] def UInt64.toInt64 (i : UInt64) : Int64 := Int64.ofUInt64 i
Conversion from unsigned to signed 64-bit integer
Informal description
The function converts an unsigned 64-bit integer `i` to a signed 64-bit integer using 2's complement representation.
Int64.mk definition
(i : UInt64) : Int64
Full source
@[inline, deprecated UInt64.toInt64 (since := "2025-02-13"), inherit_doc UInt64.toInt64]
def Int64.mk (i : UInt64) : Int64 := UInt64.toInt64 i
Construction of signed 64-bit integer from unsigned 64-bit integer
Informal description
The function constructs a signed 64-bit integer from an unsigned 64-bit integer `i` using 2's complement representation.
Int64.ofInt definition
(i : @& Int) : Int64
Full source
/--
Converts an arbitrary-precision integer to a 64-bit integer, wrapping on overflow or underflow.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int64.ofInt 48 = 48`
 * `Int64.ofInt (-40_000) = -40_000`
 * `Int64.ofInt 2_147_483_648 = 2_147_483_648`
 * `Int64.ofInt (-2_147_483_649) = -2_147_483_649`
 * `Int64.ofInt 9_223_372_036_854_775_808 = -9_223_372_036_854_775_808`
 * `Int64.ofInt (-9_223_372_036_854_775_809) = 9_223_372_036_854_775_807`
-/
@[extern "lean_int64_of_int"]
def Int64.ofInt (i : @& Int) : Int64 := ⟨⟨BitVec.ofInt 64 i⟩⟩
Conversion from integer to signed 64-bit integer with wrapping
Informal description
The function converts an arbitrary-precision integer \( i \) to a signed 64-bit integer using two's complement representation, wrapping around on overflow or underflow. Specifically, the result is \( i \mod 2^{64} \) interpreted as a signed 64-bit integer, where values \( \geq 2^{63} \) are represented as negative numbers.
Int64.ofNat definition
(n : @& Nat) : Int64
Full source
/--
Converts a natural number to a 64-bit signed integer, wrapping around to negative numbers on
overflow.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int64.ofNat 127 = 127`
 * `Int64.ofNat 2_147_483_648 = 2_147_483_648`
 * `Int64.ofNat 9_223_372_036_854_775_807 = 9_223_372_036_854_775_807`
 * `Int64.ofNat 9_223_372_036_854_775_808 = -9_223_372_036_854_775_808`
 * `Int64.ofNat 18_446_744_073_709_551_618 = 0`
-/
@[extern "lean_int64_of_nat"]
def Int64.ofNat (n : @& Nat) : Int64 := ⟨⟨BitVec.ofNat 64 n⟩⟩
Conversion from natural number to signed 64-bit integer with overflow wrapping
Informal description
The function converts a natural number \( n \) to a signed 64-bit integer by interpreting \( n \) modulo \( 2^{64} \) and wrapping around to negative numbers on overflow. Specifically, if \( n \geq 2^{63} \), the result is \( n - 2^{64} \).
Int.toInt64 abbrev
Full source
/--
Converts an arbitrary-precision integer to a 64-bit integer, wrapping on overflow or underflow.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int.toInt64 48 = 48`
 * `Int.toInt64 (-40_000) = -40_000`
 * `Int.toInt64 2_147_483_648 = 2_147_483_648`
 * `Int.toInt64 (-2_147_483_649) = -2_147_483_649`
 * `Int.toInt64 9_223_372_036_854_775_808 = -9_223_372_036_854_775_808`
 * `Int.toInt64 (-9_223_372_036_854_775_809) = 9_223_372_036_854_775_807`
-/
abbrev Int.toInt64 := Int64.ofInt
64-bit Integer Conversion with Wrapping Behavior
Informal description
The function $\mathrm{Int.toInt64}$ converts an arbitrary-precision integer $i$ to a 64-bit signed integer using two's complement representation, wrapping around on overflow or underflow. Specifically, the result is $i \mod 2^{64}$ interpreted as a signed 64-bit integer, where values $\geq 2^{63}$ are represented as negative numbers. **Examples:** - $\mathrm{Int.toInt64}(48) = 48$ - $\mathrm{Int.toInt64}(-40000) = -40000$ - $\mathrm{Int.toInt64}(2147483648) = 2147483648$ - $\mathrm{Int.toInt64}(-2147483649) = -2147483649$ - $\mathrm{Int.toInt64}(9223372036854775808) = -9223372036854775808$ - $\mathrm{Int.toInt64}(-9223372036854775809) = 9223372036854775807$
Nat.toInt64 abbrev
Full source
/--
Converts a natural number to a 64-bit signed integer, wrapping around to negative numbers on
overflow.

Examples:
 * `Nat.toInt64 127 = 127`
 * `Nat.toInt64 2_147_483_648 = 2_147_483_648`
 * `Nat.toInt64 9_223_372_036_854_775_807 = 9_223_372_036_854_775_807`
 * `Nat.toInt64 9_223_372_036_854_775_808 = -9_223_372_036_854_775_808`
 * `Nat.toInt64 18_446_744_073_709_551_618 = 0`
-/
abbrev Nat.toInt64 := Int64.ofNat
Natural number to 64-bit signed integer conversion with overflow wrapping
Informal description
The function $\mathrm{Nat.toInt64}$ converts a natural number $n$ to a 64-bit signed integer by interpreting $n \mod 2^{64}$ and wrapping around to negative numbers when $n \geq 2^{63}$. Specifically: - For $n < 2^{63}$, $\mathrm{Nat.toInt64}(n) = n$ - For $2^{63} \leq n < 2^{64}$, $\mathrm{Nat.toInt64}(n) = n - 2^{64}$ - For $n \geq 2^{64}$, the result wraps around modulo $2^{64}$
Int64.toInt definition
(i : Int64) : Int
Full source
/--
Converts a 64-bit signed integer to an arbitrary-precision integer that denotes the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_to_int_sint"]
def Int64.toInt (i : Int64) : Int := i.toBitVec.toInt
Conversion from signed 64-bit integer to arbitrary-precision integer
Informal description
The function converts a signed 64-bit integer \( i \) to an arbitrary-precision integer by interpreting its 64-bit two's complement representation.
Int64.toNatClampNeg definition
(i : Int64) : Nat
Full source
/--
Converts a 64-bit signed integer to a natural number, mapping all negative numbers to `0`.

Use `Int64.toBitVec` to obtain the two's complement representation.
-/
@[inline] def Int64.toNatClampNeg (i : Int64) : Nat := i.toInt.toNat
Conversion from signed 64-bit integer to natural number (negative clamped to zero)
Informal description
The function converts a signed 64-bit integer \( i \) to a natural number by first converting it to an arbitrary-precision integer and then mapping negative values to zero. Specifically: - If \( i \) is non-negative, returns the corresponding natural number - If \( i \) is negative, returns zero
Int64.toNat definition
(i : Int64) : Nat
Full source
@[inline, deprecated Int64.toNatClampNeg (since := "2025-02-13"), inherit_doc Int64.toNatClampNeg]
def Int64.toNat (i : Int64) : Nat := i.toInt.toNat
Conversion from signed 64-bit integer to natural number (negative to zero)
Informal description
The function converts a signed 64-bit integer \( i \) to a natural number by first converting \( i \) to an arbitrary-precision integer (via `Int64.toInt`) and then converting that integer to a natural number (via `Int.toNat`), where negative integers are mapped to zero.
Int64.ofBitVec definition
(b : BitVec 64) : Int64
Full source
/-- Obtains the `Int64` whose 2's complement representation is the given `BitVec 64`. -/
@[inline] def Int64.ofBitVec (b : BitVec 64) : Int64 := ⟨⟨b⟩⟩
Conversion from bitvector to Int64
Informal description
The function takes a bitvector $b$ of width 64 and returns the corresponding signed 64-bit integer represented by $b$ in two's complement form.
Int64.toInt8 definition
(a : Int64) : Int8
Full source
/--
Converts a 64-bit signed integer to an 8-bit signed integer by truncating its bitvector
representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_to_int8"]
def Int64.toInt8 (a : Int64) : Int8 := ⟨⟨a.toBitVec.signExtend 8⟩⟩
Conversion from 64-bit to 8-bit signed integer with sign extension
Informal description
The function converts a signed 64-bit integer \( a \) to a signed 8-bit integer by truncating its bitvector representation to 8 bits (using sign extension to preserve the two's complement interpretation).
Int64.toInt16 definition
(a : Int64) : Int16
Full source
/--
Converts a 64-bit signed integer to a 16-bit signed integer by truncating its bitvector
representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_to_int16"]
def Int64.toInt16 (a : Int64) : Int16 := ⟨⟨a.toBitVec.signExtend 16⟩⟩
Conversion from 64-bit to 16-bit signed integer (with sign extension)
Informal description
The function converts a signed 64-bit integer \( a \) to a signed 16-bit integer by truncating its 64-bit two's complement representation to 16 bits (using sign extension to preserve the value's sign).
Int64.toInt32 definition
(a : Int64) : Int32
Full source
/--
Converts a 64-bit signed integer to a 32-bit signed integer by truncating its bitvector
representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_to_int32"]
def Int64.toInt32 (a : Int64) : Int32 := ⟨⟨a.toBitVec.signExtend 32⟩⟩
Conversion from 64-bit to 32-bit signed integer with sign extension
Informal description
The function converts a signed 64-bit integer \( a \) to a signed 32-bit integer by truncating its 64-bit two's complement representation to 32 bits and then sign-extending it to maintain the correct numerical value.
Int8.toInt64 definition
(a : Int8) : Int64
Full source
/--
Converts 8-bit signed integers to 64-bit signed integers that denote the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_to_int64"]
def Int8.toInt64 (a : Int8) : Int64 := ⟨⟨a.toBitVec.signExtend 64⟩⟩
Sign extension from 8-bit to 64-bit integers
Informal description
The function converts a signed 8-bit integer \( a \) to a signed 64-bit integer by sign-extending its 2's complement representation to 64 bits, preserving the numerical value.
Int16.toInt64 definition
(a : Int16) : Int64
Full source
/--
Converts 16-bit signed integers to 64-bit signed integers that denote the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_to_int64"]
def Int16.toInt64 (a : Int16) : Int64 := ⟨⟨a.toBitVec.signExtend 64⟩⟩
Sign extension from 16-bit to 64-bit integers
Informal description
The function converts a signed 16-bit integer \( a \) to a signed 64-bit integer by sign-extending its 2's complement representation to 64 bits, preserving the numerical value.
Int32.toInt64 definition
(a : Int32) : Int64
Full source
/--
Converts 32-bit signed integers to 64-bit signed integers that denote the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_to_int64"]
def Int32.toInt64 (a : Int32) : Int64 := ⟨⟨a.toBitVec.signExtend 64⟩⟩
Sign extension from 32-bit to 64-bit integers
Informal description
The function converts a signed 32-bit integer \( a \) to a signed 64-bit integer by sign-extending its 2's complement representation to 64 bits, preserving the numerical value.
Int64.neg definition
(i : Int64) : Int64
Full source
/--
Negates 64-bit signed integers. Usually accessed via the `-` prefix operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_neg"]
def Int64.neg (i : Int64) : Int64 := ⟨⟨-i.toBitVec⟩⟩
Negation of signed 64-bit integers
Informal description
The function negates a signed 64-bit integer \( i \) by first converting it to its 2's complement bitvector representation, negating the bitvector, and then converting back to a signed 64-bit integer.
instToStringInt64 instance
: ToString Int64
Full source
instance : ToString Int64 where
  toString i := toString i.toInt
String Representation of 64-bit Integers
Informal description
The signed 64-bit integers $\text{Int64}$ have a string representation.
instReprInt64 instance
: Repr Int64
Full source
instance : Repr Int64 where
  reprPrec i prec := reprPrec i.toInt prec
Decimal Representation of 64-bit Integers
Informal description
The signed 64-bit integers have a standard string representation in decimal format.
instReprAtomInt64 instance
: ReprAtom Int64
Full source
instance : ReprAtom Int64 := ⟨⟩
Atomic Representation Marker for 64-bit Integers
Informal description
The type `Int64` of signed 64-bit integers is marked as an atomic type for representation methods.
instHashableInt64 instance
: Hashable Int64
Full source
instance : Hashable Int64 where
  hash i := i.toUInt64
Hashable 64-bit Integers
Informal description
The type `Int64` of signed 64-bit integers can be hashed into a 64-bit unsigned integer.
Int64.instOfNat instance
: OfNat Int64 n
Full source
instance Int64.instOfNat : OfNat Int64 n := ⟨Int64.ofNat n⟩
Natural Number Literals as Signed 64-bit Integers
Informal description
For any natural number `n`, there is a canonical interpretation of `n` as a signed 64-bit integer, where the value is obtained by interpreting `n` modulo \(2^{64}\) with overflow wrapping.
Int64.instNeg instance
: Neg Int64
Full source
instance Int64.instNeg : Neg Int64 where
  neg := Int64.neg
Negation Operation on Signed 64-bit Integers
Informal description
The type `Int64` of signed 64-bit integers has a negation operation, where the negation of an integer is computed by taking the two's complement of its bit representation.
Int64.maxValue abbrev
: Int64
Full source
/-- The largest number that `Int64` can represent: `2^63 - 1 = 9223372036854775807`. -/
abbrev Int64.maxValue : Int64 := 9223372036854775807
Maximum Value of Signed 64-bit Integer: $2^{63} - 1$
Informal description
The largest value representable by a signed 64-bit integer is $2^{63} - 1 = 9223372036854775807$.
Int64.minValue abbrev
: Int64
Full source
/-- The smallest number that `Int64` can represent: `-2^63 = -9223372036854775808`. -/
abbrev Int64.minValue : Int64 := -9223372036854775808
Minimum value of 64-bit integers: $-2^{63}$
Informal description
The smallest representable value in the `Int64` type is $-2^{63} = -9223372036854775808$.
Int64.ofIntLE definition
(i : Int) (_hl : Int64.minValue.toInt ≤ i) (_hr : i ≤ Int64.maxValue.toInt) : Int64
Full source
/-- Constructs an `Int64` from an `Int` that is known to be in bounds. -/
@[inline]
def Int64.ofIntLE (i : Int) (_hl : Int64.minValue.toInt ≤ i) (_hr : i ≤ Int64.maxValue.toInt) : Int64 :=
  Int64.ofInt i
Conversion from bounded integer to signed 64-bit integer
Informal description
The function constructs a signed 64-bit integer from an arbitrary-precision integer \( i \), given proofs that \( i \) is within the bounds of the `Int64` type (i.e., \( -2^{63} \leq i \leq 2^{63} - 1 \)). The result is equivalent to `Int64.ofInt i`, but this definition provides a type-safe way to ensure the input is within valid range.
Int64.ofIntTruncate definition
(i : Int) : Int64
Full source
/-- Constructs an `Int64` from an `Int`, clamping if the value is too small or too large. -/
def Int64.ofIntTruncate (i : Int) : Int64 :=
  if hl : Int64.minValue.toInt ≤ i then
    if hr : i ≤ Int64.maxValue.toInt then
      Int64.ofIntLE i hl hr
    else
      Int64.minValue
  else
    Int64.minValue
Conversion from integer to signed 64-bit integer with clamping
Informal description
The function converts an arbitrary-precision integer \( i \) to a signed 64-bit integer by clamping it to the range \([-2^{63}, 2^{63} - 1]\). If \( i \) is less than \(-2^{63}\), it returns \(-2^{63}\). If \( i \) is greater than \(2^{63} - 1\), it returns \(2^{63} - 1\). Otherwise, it returns \( i \) as a 64-bit integer.
Int64.add definition
(a b : Int64) : Int64
Full source
/--
Adds two 64-bit signed integers, wrapping around on over- or underflow.  Usually accessed via the
`+` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_add"]
protected def Int64.add (a b : Int64) : Int64 := ⟨⟨a.toBitVec + b.toBitVec⟩⟩
Addition of signed 64-bit integers with wrap-around
Informal description
The function adds two signed 64-bit integers $a$ and $b$, with the result wrapping around on overflow or underflow. The addition is performed by converting the integers to their 2's complement bitvector representation of width 64, adding them as bitvectors (which is equivalent to addition modulo $2^{64}$), and converting the result back to a signed 64-bit integer.
Int64.sub definition
(a b : Int64) : Int64
Full source
/--
Subtracts one 64-bit signed integer from another, wrapping around on over- or underflow. Usually
accessed via the `-` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_sub"]
protected def Int64.sub (a b : Int64) : Int64 := ⟨⟨a.toBitVec - b.toBitVec⟩⟩
Subtraction of signed 64-bit integers with wrap-around
Informal description
The function subtracts two signed 64-bit integers \( a \) and \( b \), wrapping around on overflow or underflow. The result is computed by converting the integers to 64-bit bitvectors (in 2's complement representation), performing subtraction modulo \( 2^{64} \), and converting back to a signed 64-bit integer.
Int64.mul definition
(a b : Int64) : Int64
Full source
/--
Multiplies two 64-bit signed integers, wrapping around on over- or underflow.  Usually accessed via
the `*` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_mul"]
protected def Int64.mul (a b : Int64) : Int64 := ⟨⟨a.toBitVec * b.toBitVec⟩⟩
Multiplication of signed 64-bit integers with wrap-around
Informal description
The function multiplies two signed 64-bit integers \( a \) and \( b \), wrapping around on overflow or underflow, and returns the result as a signed 64-bit integer. The multiplication is performed by converting the integers to 64-bit bitvectors (in 2's complement form), multiplying them modulo \( 2^{64} \), and converting the result back to a signed 64-bit integer.
Int64.div definition
(a b : Int64) : Int64
Full source
/--
Truncating division for 64-bit signed integers, rounding towards zero. Usually accessed via the `/`
operator.

Division by zero is defined to be zero.

This function is overridden at runtime with an efficient implementation.

Examples:
* `Int64.div 10 3 = 3`
* `Int64.div 10 (-3) = (-3)`
* `Int64.div (-10) (-3) = 3`
* `Int64.div (-10) 3 = (-3)`
* `Int64.div 10 0 = 0`
-/
@[extern "lean_int64_div"]
protected def Int64.div (a b : Int64) : Int64 := ⟨⟨BitVec.sdiv a.toBitVec b.toBitVec⟩⟩
Truncating division for signed 64-bit integers
Informal description
The function computes the truncating division of two signed 64-bit integers $a$ and $b$, rounding towards zero. Division by zero is defined to return zero. Specifically: - If $a$ and $b$ are both non-negative, it returns $\lfloor a / b \rfloor$. - If $a$ is negative and $b$ is positive, it returns $-\lfloor |a| / b \rfloor$. - If $a$ is positive and $b$ is negative, it returns $-\lfloor a / |b| \rfloor$. - If both $a$ and $b$ are negative, it returns $\lfloor |a| / |b| \rfloor$.
Int64.mod definition
(a b : Int64) : Int64
Full source
/--
The modulo operator for 64-bit signed integers, which computes the remainder when dividing one
integer by another with the T-rounding convention used by `Int64.div`. Usually accessed via the `%`
operator.

When the divisor is `0`, the result is the dividend rather than an error.

This function is overridden at runtime with an efficient implementation.

Examples:
* `Int64.mod 5 2 = 1`
* `Int64.mod 5 (-2) = 1`
* `Int64.mod (-5) 2 = (-1)`
* `Int64.mod (-5) (-2) = (-1)`
* `Int64.mod 4 2 = 0`
* `Int64.mod 4 (-2) = 0`
* `Int64.mod 4 0 = 4`
* `Int64.mod (-4) 0 = (-4)`
-/
@[extern "lean_int64_mod"]
protected def Int64.mod (a b : Int64) : Int64 := ⟨⟨BitVec.srem a.toBitVec b.toBitVec⟩⟩
Signed 64-bit integer modulo operation (T-rounding)
Informal description
The modulo operation for signed 64-bit integers, which computes the remainder when dividing $a$ by $b$ using the T-rounding convention (rounding towards zero). When $b = 0$, the result is $a$ rather than an error. The operation is implemented via signed remainder on bitvectors.
Int64.land definition
(a b : Int64) : Int64
Full source
/--
Bitwise and for 64-bit signed integers. Usually accessed via the `&&&` operator.

Each bit of the resulting integer is set if the corresponding bits of both input integers are set,
according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_land"]
protected def Int64.land (a b : Int64) : Int64 := ⟨⟨a.toBitVec &&& b.toBitVec⟩⟩
Bitwise AND for signed 64-bit integers
Informal description
The function computes the bitwise AND of two signed 64-bit integers $a$ and $b$, where each bit of the result is set to 1 if and only if the corresponding bits of both $a$ and $b$ are 1. The operation is performed using the two's complement representation of the integers.
Int64.lor definition
(a b : Int64) : Int64
Full source
/--
Bitwise or for 64-bit signed integers. Usually accessed via the `|||` operator.

Each bit of the resulting integer is set if at least one of the corresponding bits of the input
integers is set, according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_lor"]
protected def Int64.lor (a b : Int64) : Int64 := ⟨⟨a.toBitVec ||| b.toBitVec⟩⟩
Bitwise OR for signed 64-bit integers
Informal description
The function computes the bitwise OR of two signed 64-bit integers \( a \) and \( b \), where each bit of the result is set if at least one of the corresponding bits in \( a \) or \( b \) is set, according to the two's complement representation. The operation is implemented by first converting the integers to 64-bit bitvectors, performing the bitwise OR, and then converting back to a signed 64-bit integer.
Int64.xor definition
(a b : Int64) : Int64
Full source
/--
Bitwise exclusive or for 64-bit signed integers. Usually accessed via the `^^^` operator.

Each bit of the resulting integer is set if exactly one of the corresponding bits of the input
integers is set, according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_xor"]
protected def Int64.xor (a b : Int64) : Int64 := ⟨⟨a.toBitVec ^^^ b.toBitVec⟩⟩
Bitwise XOR of signed 64-bit integers
Informal description
The function computes the bitwise exclusive OR (XOR) of two signed 64-bit integers $a$ and $b$, where each bit of the result is set if exactly one of the corresponding bits in $a$ and $b$ is set, according to the two's complement representation. The operation is implemented by converting the integers to 64-bit bitvectors, performing the XOR operation on the bitvectors, and converting the result back to a signed 64-bit integer.
Int64.shiftLeft definition
(a b : Int64) : Int64
Full source
/--
Bitwise left shift for 64-bit signed integers. Usually accessed via the `<<<` operator.

Signed integers are interpreted as bitvectors according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_shift_left"]
protected def Int64.shiftLeft (a b : Int64) : Int64 := ⟨⟨a.toBitVec <<< (b.toBitVec.smod 64)⟩⟩
Bitwise left shift for signed 64-bit integers
Informal description
The function computes the bitwise left shift of a signed 64-bit integer $a$ by $b$ positions, where $b$ is interpreted modulo 64. The operation is implemented by converting both integers to 64-bit bitvectors, performing the left shift on the bitvector representation of $a$ by the value of $b \bmod 64$, and converting the result back to a signed 64-bit integer.
Int64.shiftRight definition
(a b : Int64) : Int64
Full source
/--
Arithmetic right shift for 64-bit signed integers. Usually accessed via the `<<<` operator.

The high bits are filled with the value of the most significant bit.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_shift_right"]
protected def Int64.shiftRight (a b : Int64) : Int64 := ⟨⟨BitVec.sshiftRight' a.toBitVec (b.toBitVec.smod 64)⟩⟩
Arithmetic right shift for signed 64-bit integers
Informal description
The function performs an arithmetic right shift on a signed 64-bit integer $a$ by $b$ positions, where $b$ is also a signed 64-bit integer. The shift amount $b$ is taken modulo 64 (using signed modulo operation). The high bits are filled with the value of the most significant bit (sign extension), preserving the sign of the original number. Numerically, this operation is equivalent to $\lfloor a / 2^{b \bmod 64} \rfloor$ where $a$ is treated as a signed integer in two's complement representation.
Int64.complement definition
(a : Int64) : Int64
Full source
/--
Bitwise complement, also known as bitwise negation, for 64-bit signed integers. Usually accessed via
the `~~~` prefix operator.

Each bit of the resulting integer is the opposite of the corresponding bit of the input integer.
Integers use the two's complement representation, so `Int64.complement a = -(a + 1)`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_complement"]
protected def Int64.complement (a : Int64) : Int64 := ⟨⟨~~~a.toBitVec⟩⟩
Bitwise complement for signed 64-bit integers
Informal description
The bitwise complement (negation) operation for signed 64-bit integers. For a given integer $a$, this operation returns an integer where each bit is the opposite of the corresponding bit in $a$. In two's complement representation, this operation satisfies $\text{Int64.complement}\,a = -(a + 1)$.
Int64.abs definition
(a : Int64) : Int64
Full source
/--
Computes the absolute value of a 64-bit 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`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_abs"]
protected def Int64.abs (a : Int64) : Int64 := ⟨⟨a.toBitVec.abs⟩⟩
Absolute value of a signed 64-bit integer
Informal description
The absolute value of a signed 64-bit integer \( a \) is defined as \( -a \) if \( a \) is negative (i.e., \( a < 0 \)), and \( a \) otherwise. Note that for the minimum value `Int64.minValue`, the result remains `Int64.minValue` due to overflow in two's complement representation.
Int64.decEq definition
(a b : Int64) : Decidable (a = b)
Full source
/--
Decides whether two 64-bit signed integers are equal. Usually accessed via the `DecidableEq Int64`
instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `Int64.decEq 123 123 = .isTrue rfl`
 * `(if ((-7) : Int64) = 7 then "yes" else "no") = "no"`
 * `show (7 : Int64) = 7 by decide`
-/
@[extern "lean_int64_dec_eq"]
def Int64.decEq (a b : Int64) : Decidable (a = b) :=
  match a, b with
  | ⟨n⟩, ⟨m⟩ =>
    if h : n = m then
      isTrue <| h ▸ rfl
    else
      isFalse (fun h' => Int64.noConfusion h' (fun h' => absurd h' h))
Decidable equality for signed 64-bit integers
Informal description
The function `Int64.decEq` takes two signed 64-bit integers `a` and `b` and returns a constructive proof that their equality is decidable, i.e., it either provides a proof that `a = b` or a proof that `¬(a = b)`. This is typically accessed via the `DecidableEq Int64` instance.
Int64.lt definition
(a b : Int64) : Prop
Full source
/--
Strict inequality of 64-bit signed integers, defined as inequality of the corresponding integers.
Usually accessed via the `<` operator.
-/
protected def Int64.lt (a b : Int64) : Prop := a.toBitVec.slt b.toBitVec
Signed less-than for 64-bit integers
Informal description
The strict inequality relation on signed 64-bit integers, defined by converting the integers to their 64-bit two's complement bitvector representations and comparing them using signed less-than (`slt`). For any two signed 64-bit integers $a$ and $b$, $a < b$ holds if and only if the signed interpretation of $a$'s bitvector representation is strictly less than that of $b$'s.
Int64.le definition
(a b : Int64) : Prop
Full source
/--
Non-strict inequality of 64-bit signed integers, defined as inequality of the corresponding integers.
Usually accessed via the `≤` operator.
-/
protected def Int64.le (a b : Int64) : Prop := a.toBitVec.sle b.toBitVec
Signed 64-bit integer inequality ($\leq$)
Informal description
The non-strict inequality relation for signed 64-bit integers, defined as the signed less-than-or-equal-to comparison of their corresponding 64-bit bitvector representations in two's complement form. For any two signed 64-bit integers $a$ and $b$, $a \leq b$ holds if and only if the two's complement representation of $a$ is less than or equal to that of $b$ when interpreted as signed integers.
instInhabitedInt64 instance
: Inhabited Int64
Full source
instance : Inhabited Int64 where
  default := 0
Inhabited Type for Signed 64-bit Integers
Informal description
The type of signed 64-bit integers `Int64` is inhabited, meaning it has a designated default element.
instAddInt64 instance
: Add Int64
Full source
instance : Add Int64         := ⟨Int64.add⟩
Addition Operation for Signed 64-bit Integers with Wrap-around
Informal description
The type of signed 64-bit integers `Int64` is equipped with an addition operation that performs wrap-around arithmetic on overflow or underflow.
instSubInt64 instance
: Sub Int64
Full source
instance : Sub Int64         := ⟨Int64.sub⟩
Subtraction Operation on 64-bit Integers
Informal description
The type of signed 64-bit integers `Int64` is equipped with a subtraction operation that computes the difference of two integers modulo $2^{64}$, wrapping around on overflow or underflow.
instMulInt64 instance
: Mul Int64
Full source
instance : Mul Int64         := ⟨Int64.mul⟩
Multiplication Operation on 64-bit Integers
Informal description
The signed 64-bit integers $\text{Int64}$ are equipped with a multiplication operation that performs multiplication modulo $2^{64}$ with wrap-around behavior.
instModInt64 instance
: Mod Int64
Full source
instance : Mod Int64         := ⟨Int64.mod⟩
Modulo Operation on 64-bit Integers
Informal description
The signed 64-bit integers $\text{Int64}$ are equipped with a modulo operation that computes the remainder when dividing one integer by another using the T-rounding convention (rounding towards zero).
instDivInt64 instance
: Div Int64
Full source
instance : Div Int64         := ⟨Int64.div⟩
Truncating Division Operation on 64-bit Integers
Informal description
The signed 64-bit integers $\text{Int64}$ are equipped with a truncating division operation that rounds towards zero. Division by zero is defined to return zero.
instLTInt64 instance
: LT Int64
Full source
instance : LT Int64          := ⟨Int64.lt⟩
The Less Than Relation on 64-bit Integers
Informal description
The type of signed 64-bit integers has a canonical "less than" relation, defined by comparing their two's complement bitvector representations using signed less-than.
instLEInt64 instance
: LE Int64
Full source
instance : LE Int64          := ⟨Int64.le⟩
The Less-Than-Or-Equal Relation on 64-bit Integers
Informal description
The type of signed 64-bit integers `Int64` is equipped with a canonical less-than-or-equal-to relation `≤`, defined via two's complement comparison.
instComplementInt64 instance
: Complement Int64
Full source
instance : Complement Int64  := ⟨Int64.complement⟩
Bitwise Complement Operation on 64-bit Integers
Informal description
The signed 64-bit integer type `Int64` is equipped with a bitwise complement operation, where for any integer `a : Int64`, the operation `~~~a` flips all bits of `a` (equivalent to `-(a + 1)` in two's complement representation).
instAndOpInt64 instance
: AndOp Int64
Full source
instance : AndOp Int64       := ⟨Int64.land⟩
Bitwise AND Operation on 64-bit Integers
Informal description
The signed 64-bit integers $\text{Int64}$ are equipped with a bitwise AND operation, where for any two integers $a$ and $b$ in $\text{Int64}$, the operation $a \&\& b$ computes their bitwise AND.
instOrOpInt64 instance
: OrOp Int64
Full source
instance : OrOp Int64        := ⟨Int64.lor⟩
Bitwise OR Operation on 64-bit Integers
Informal description
The signed 64-bit integer type `Int64` is equipped with a bitwise OR operation `|||`, where for any two integers `a` and `b`, the result is the bitwise OR of `a` and `b` (i.e., each bit in the result is set if at least one of the corresponding bits in `a` or `b` is set).
instXorInt64 instance
: Xor Int64
Full source
instance : Xor Int64         := ⟨Int64.xor⟩
Bitwise XOR Operation on 64-bit Integers
Informal description
The type of signed 64-bit integers `Int64` is equipped with a bitwise exclusive OR (XOR) operation, where for any two integers `a` and `b`, the result is computed by performing a bitwise XOR on their binary representations.
instShiftLeftInt64 instance
: ShiftLeft Int64
Full source
instance : ShiftLeft Int64   := ⟨Int64.shiftLeft⟩
Left Shift Operation on 64-bit Integers
Informal description
The signed 64-bit integer type `Int64` is equipped with a left shift operation `<<<`, where for any two integers `a` and `b`, the result is the bitwise left shift of `a` by `b` positions (with `b` interpreted modulo 64).
instShiftRightInt64 instance
: ShiftRight Int64
Full source
instance : ShiftRight Int64  := ⟨Int64.shiftRight⟩
Arithmetic Right Shift Operation on 64-bit Integers
Informal description
The type of signed 64-bit integers `Int64` is equipped with a homogeneous right shift operation `>>>`, where for any two integers `a` and `b` in `Int64`, the operation performs an arithmetic right shift on `a` by `b` positions, filling the high bits with the sign bit (sign extension).
instDecidableEqInt64 instance
: DecidableEq Int64
Full source
instance : DecidableEq Int64 := Int64.decEq
Decidable Equality for 64-bit Integers
Informal description
The type of signed 64-bit integers has decidable equality, meaning for any two elements $a$ and $b$ in `Int64`, the equality $a = b$ can be constructively determined.
Bool.toInt64 definition
(b : Bool) : Int64
Full source
/--
Converts `true` to `1` and `false` to `0`.
-/
@[extern "lean_bool_to_int64"]
def Bool.toInt64 (b : Bool) : Int64 := if b then 1 else 0
Boolean to 64-bit integer conversion
Informal description
The function maps a boolean value $b$ to the integer $1$ if $b$ is true and to $0$ if $b$ is false, represented as a 64-bit signed integer.
Int64.decLt definition
(a b : Int64) : Decidable (a < b)
Full source
/--
Decides whether one 8-bit signed integer is strictly less than another. Usually accessed via the
`DecidableLT Int64` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `(if ((-7) : Int64) < 7 then "yes" else "no") = "yes"`
 * `(if (5 : Int64) < 5 then "yes" else "no") = "no"`
 * `show ¬((7 : Int64) < 7) by decide`
-/
@[extern "lean_int64_dec_lt"]
def Int64.decLt (a b : Int64) : Decidable (a < b) :=
  inferInstanceAs (Decidable (a.toBitVec.slt b.toBitVec))
Decidability of less-than for signed 64-bit integers
Informal description
The function `Int64.decLt` takes two signed 64-bit integers `a` and `b` and returns a constructive proof that the proposition `a < b` is decidable. This is implemented by converting both integers to their 64-bit two's complement bitvector representations and using the signed less-than comparison (`slt`) on these bitvectors.
Int64.decLe definition
(a b : Int64) : Decidable (a ≤ b)
Full source
/--
Decides whether one 8-bit signed integer is less than or equal to another. Usually accessed via the
`DecidableLE Int64` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `(if ((-7) : Int64) ≤ 7 then "yes" else "no") = "yes"`
 * `(if (15 : Int64) ≤ 15 then "yes" else "no") = "yes"`
 * `(if (15 : Int64) ≤ 5 then "yes" else "no") = "no"`
 * `show (7 : Int64) ≤ 7 by decide`
-/
@[extern "lean_int64_dec_le"]
def Int64.decLe (a b : Int64) : Decidable (a ≤ b) :=
  inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
Decidable less-than-or-equal for signed 64-bit integers
Informal description
The function decides whether a signed 64-bit integer \( a \) is less than or equal to another signed 64-bit integer \( b \), using their two's complement bitvector representations. This is typically accessed via the `DecidableLE Int64` instance and is optimized at runtime for efficiency.
instDecidableLtInt64 instance
(a b : Int64) : Decidable (a < b)
Full source
instance (a b : Int64) : Decidable (a < b) := Int64.decLt a b
Decidability of Less-Than for 64-bit Integers
Informal description
For any two signed 64-bit integers $a$ and $b$, the proposition $a < b$ is decidable. This is implemented by comparing their two's complement bitvector representations using signed less-than.
instDecidableLeInt64 instance
(a b : Int64) : Decidable (a ≤ b)
Full source
instance (a b : Int64) : Decidable (a ≤ b) := Int64.decLe a b
Decidability of $\leq$ on 64-bit integers
Informal description
For any two signed 64-bit integers $a$ and $b$, the proposition $a \leq b$ is decidable.
instMaxInt64 instance
: Max Int64
Full source
instance : Max Int64 := maxOfLe
Maximum Operation on 64-bit Integers
Informal description
The type of signed 64-bit integers `Int64` is equipped with a canonical maximum operation, where for any two integers `a` and `b`, `max(a, b)` returns the larger of the two according to the two's complement comparison.
instMinInt64 instance
: Min Int64
Full source
instance : Min Int64 := minOfLe
Minimum Operation on 64-bit Integers
Informal description
The type of signed 64-bit integers `Int64` is equipped with a minimum operation, where for any two integers `x` and `y`, the minimum is defined to be `x` if `x ≤ y` and `y` otherwise.
ISize.size abbrev
: Nat
Full source
/-- The number of distinct values representable by `ISize`, that is, `2^System.Platform.numBits`. -/
abbrev ISize.size : Nat := 2^System.Platform.numBits
Cardinality of `ISize` Values
Informal description
The size of the `ISize` type, which represents the number of distinct values it can hold, is given by $2^{\text{System.Platform.numBits}}$, where `System.Platform.numBits` is the platform's word size (32 or 64 bits).
ISize.toBitVec definition
(x : ISize) : BitVec System.Platform.numBits
Full source
/--
Obtain the `BitVec` that contains the 2's complement representation of the `ISize`.
-/
@[inline] def ISize.toBitVec (x : ISize) : BitVec System.Platform.numBits := x.toUSize.toBitVec
Two's complement representation of a signed integer
Informal description
The function maps a signed integer `x` of platform-dependent word size to its two's complement representation as a bitvector of width equal to the platform's word size (32 or 64 bits).
ISize.toBitVec.inj theorem
: {x y : ISize} → x.toBitVec = y.toBitVec → x = y
Full source
theorem ISize.toBitVec.inj : {x y : ISize} → x.toBitVec = y.toBitVec → x = y
  | ⟨⟨_⟩⟩, ⟨⟨_⟩⟩, rfl => rfl
Injectivity of Two's Complement Representation for Signed Integers
Informal description
For any two signed integers $x$ and $y$ of platform-dependent word size, if their two's complement representations as bitvectors are equal, then $x = y$.
USize.toISize definition
(i : USize) : ISize
Full source
/-- Obtains the `ISize` that is 2's complement equivalent to the `USize`. -/
@[inline] def USize.toISize (i : USize) : ISize := ISize.ofUSize i
Conversion from unsigned to signed platform-dependent integer
Informal description
The function converts an unsigned integer `i` of platform-dependent word size to a signed integer of the same word size using two's complement representation.
ISize.mk definition
(i : USize) : ISize
Full source
@[inline, deprecated USize.toISize (since := "2025-02-13"), inherit_doc USize.toISize]
def ISize.mk (i : USize) : ISize := USize.toISize i
Construction of signed platform-dependent integer from unsigned integer
Informal description
The function constructs a signed integer of platform-dependent word size from an unsigned integer `i` of the same word size, using the conversion function `USize.toISize`.
ISize.ofInt definition
(i : @& Int) : ISize
Full source
/--
Converts an arbitrary-precision integer to a word-sized signed integer, wrapping around on over- or
underflow.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_of_int"]
def ISize.ofInt (i : @& Int) : ISize := ⟨⟨BitVec.ofInt System.Platform.numBits i⟩⟩
Conversion from arbitrary-precision integer to platform-dependent signed integer (with wrap-around)
Informal description
The function converts an arbitrary-precision integer \( i \) to a signed integer of platform-dependent word size (either 32 or 64 bits), wrapping around on overflow or underflow. The conversion is performed by interpreting \( i \) modulo \( 2^w \) (where \( w \) is the platform's word size) as a two's complement signed integer.
ISize.ofNat definition
(n : @& Nat) : ISize
Full source
/--
Converts an arbitrary-precision natural number to a word-sized signed integer, wrapping around on
overflow.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_of_nat"]
def ISize.ofNat (n : @& Nat) : ISize := ⟨⟨BitVec.ofNat System.Platform.numBits n⟩⟩
Natural number to platform-dependent signed integer conversion (with wrap-around)
Informal description
The function converts a natural number \( n \) to a signed integer of platform-dependent word size (either 32 or 64 bits), wrapping around on overflow. The result is obtained by taking \( n \) modulo \( 2^w \), where \( w \) is the platform's word size (32 or 64), and interpreting it as a signed integer.
Int.toISize abbrev
Full source
@[inherit_doc ISize.ofInt]
abbrev Int.toISize := ISize.ofInt
Conversion from arbitrary-precision integer to platform-dependent signed integer (with wrap-around)
Informal description
The function converts an arbitrary-precision integer to a signed integer of platform-dependent word size (either 32 or 64 bits), wrapping around on overflow or underflow. The conversion is performed by interpreting the input integer modulo $2^w$ (where $w$ is the platform's word size) as a two's complement signed integer.
Nat.toISize abbrev
Full source
@[inherit_doc ISize.ofNat] abbrev Nat.toISize := ISize.ofNat
Natural number to platform-dependent signed integer conversion (with wrap-around)
Informal description
The function converts a natural number $n$ to a signed integer of platform-dependent word size (either 32 or 64 bits), wrapping around on overflow. The result is obtained by taking $n \bmod 2^w$, where $w$ is the platform's word size (32 or 64), and interpreting it as a signed integer.
ISize.toInt definition
(i : ISize) : Int
Full source
/--
Converts a word-sized signed integer to an arbitrary-precision integer that denotes the same number.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_to_int"]
def ISize.toInt (i : ISize) : Int := i.toBitVec.toInt
Conversion from platform-dependent signed integer to arbitrary-precision integer
Informal description
The function maps a signed integer `i` of platform-dependent word size to its corresponding arbitrary-precision integer, preserving the numerical value. This is implemented by first converting `i` to its two's complement bitvector representation (using `ISize.toBitVec`) and then interpreting this bitvector as a signed integer (using `BitVec.toInt`).
ISize.toNatClampNeg definition
(i : ISize) : Nat
Full source
/--
Converts a word-sized signed integer to a natural number, mapping all negative numbers to `0`.

Use `ISize.toBitVec` to obtain the two's complement representation.
-/
@[inline] def ISize.toNatClampNeg (i : ISize) : Nat := i.toInt.toNat
Conversion from platform-dependent signed integer to natural number (negative to zero)
Informal description
The function converts a platform-dependent signed integer `i` to a natural number, mapping all negative integers to `0`. This is implemented by first converting `i` to an arbitrary-precision integer (using `ISize.toInt`) and then applying the standard integer-to-natural conversion (using `Int.toNat`), which clamps negative values to zero.
ISize.toNat definition
(i : ISize) : Nat
Full source
@[inline, deprecated ISize.toNatClampNeg (since := "2025-02-13"), inherit_doc ISize.toNatClampNeg]
def ISize.toNat (i : ISize) : Nat := i.toInt.toNat
Conversion from platform-dependent signed integer to natural number (negative to zero)
Informal description
The function converts a platform-dependent signed integer `i` to a natural number by first converting it to an arbitrary-precision integer (via `toInt`) and then mapping non-negative values to their natural number counterpart while converting negative values to zero.
ISize.ofBitVec definition
(b : BitVec System.Platform.numBits) : ISize
Full source
/-- Obtains the `ISize` whose 2's complement representation is the given `BitVec`. -/
@[inline] def ISize.ofBitVec (b : BitVec System.Platform.numBits) : ISize := ⟨⟨b⟩⟩
Conversion from bitvector to platform-dependent signed integer
Informal description
Given a bitvector `b` of width equal to the platform's word size (32 or 64 bits), the function returns the corresponding platform-dependent signed integer (`ISize`) by interpreting the bitvector as a 2's complement representation.
ISize.toInt8 definition
(a : ISize) : Int8
Full source
/--
Converts a word-sized signed integer to an 8-bit signed integer by truncating its bitvector representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_to_int8"]
def ISize.toInt8 (a : ISize) : Int8 := ⟨⟨a.toBitVec.signExtend 8⟩⟩
Conversion from platform-dependent signed integer to 8-bit signed integer
Informal description
The function converts a platform-dependent signed integer `a` (represented as an `ISize`) to an 8-bit signed integer by truncating its two's complement bitvector representation to 8 bits. This operation preserves the sign by extending the most significant bit when necessary.
ISize.toInt16 definition
(a : ISize) : Int16
Full source
/--
Converts a word-sized integer to a 16-bit integer by truncating its bitvector representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_to_int16"]
def ISize.toInt16 (a : ISize) : Int16 := ⟨⟨a.toBitVec.signExtend 16⟩⟩
Conversion from platform-dependent signed integer to 16-bit integer
Informal description
The function converts a platform-dependent signed integer `a` to a signed 16-bit integer by first obtaining its two's complement bitvector representation (with width equal to the platform's word size) and then sign-extending this bitvector to 16 bits.
ISize.toInt32 definition
(a : ISize) : Int32
Full source
/--
Converts a word-sized signed integer to a 32-bit signed integer.

On 32-bit platforms, this conversion is lossless. On 64-bit platforms, the integer's bitvector
representation is truncated to 32 bits. This function is overridden at runtime with an efficient
implementation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_to_int32"]
def ISize.toInt32 (a : ISize) : Int32 := ⟨⟨a.toBitVec.signExtend 32⟩⟩
Conversion from platform-dependent signed integer to 32-bit signed integer
Informal description
The function converts a platform-dependent signed integer `a` to a 32-bit signed integer by sign-extending its two's complement representation to 32 bits. On 32-bit platforms, this conversion is lossless, while on 64-bit platforms, the integer's bitvector representation is truncated to 32 bits.
ISize.toInt64 definition
(a : ISize) : Int64
Full source
/--
Converts word-sized signed integers to 64-bit signed integers that denote the same number. This
conversion is lossless, because `ISize` is either `Int32` or `Int64`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_to_int64"]
def ISize.toInt64 (a : ISize) : Int64 := ⟨⟨a.toBitVec.signExtend 64⟩⟩
Conversion from platform-dependent signed integer to 64-bit signed integer
Informal description
The function converts a signed integer `a` of platform-dependent word size to a 64-bit signed integer by sign-extending its two's complement representation to 64 bits. This conversion is lossless as it preserves the numeric value of the integer.
Int8.toISize definition
(a : Int8) : ISize
Full source
/--
Converts 8-bit signed integers to word-sized signed integers that denote the same number. This
conversion is lossless, because `ISize` is either `Int32` or `Int64`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int8_to_isize"]
def Int8.toISize (a : Int8) : ISize := ⟨⟨a.toBitVec.signExtend System.Platform.numBits⟩⟩
Conversion from 8-bit signed integer to platform-dependent signed integer
Informal description
The function converts a signed 8-bit integer \( a \) to a platform-dependent signed integer (either 32-bit or 64-bit) by first representing \( a \) as an 8-bit two's complement bitvector, then sign-extending it to the platform's word size (32 or 64 bits). This conversion preserves the numeric value of \( a \).
Int16.toISize definition
(a : Int16) : ISize
Full source
/--
Converts 16-bit signed integers to word-sized signed integers that denote the same number. This conversion is lossless, because
`ISize` is either `Int32` or `Int64`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int16_to_isize"]
def Int16.toISize (a : Int16) : ISize := ⟨⟨a.toBitVec.signExtend System.Platform.numBits⟩⟩
Conversion from 16-bit to platform-dependent signed integer
Informal description
The function converts a signed 16-bit integer $a$ to a platform-dependent signed integer (either 32-bit or 64-bit depending on the platform) by sign-extending its 2's complement representation to match the platform's word size. This conversion preserves the numeric value of $a$.
Int32.toISize definition
(a : Int32) : ISize
Full source
/--
Converts 32-bit signed integers to word-sized signed integers that denote the same number. This
conversion is lossless, because `ISize` is either `Int32` or `Int64`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int32_to_isize"]
def Int32.toISize (a : Int32) : ISize := ⟨⟨a.toBitVec.signExtend System.Platform.numBits⟩⟩
Conversion from 32-bit to platform-dependent signed integer
Informal description
The function converts a signed 32-bit integer \( a \) to a platform-dependent signed integer (`ISize`) by first converting \( a \) to its 2's complement bitvector representation of width 32, then sign-extending it to the platform's word size (either 32 or 64 bits), and finally constructing an `ISize` from the resulting bitvector. This conversion is lossless as it preserves the numerical value of \( a \).
Int64.toISize definition
(a : Int64) : ISize
Full source
/--
Converts 64-bit signed integers to word-sized signed integers, truncating the bitvector
representation on 32-bit platforms. This conversion is lossless on 64-bit platforms.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_int64_to_isize"]
def Int64.toISize (a : Int64) : ISize := ⟨⟨a.toBitVec.signExtend System.Platform.numBits⟩⟩
Conversion from signed 64-bit integer to platform-dependent signed integer
Informal description
The function converts a signed 64-bit integer \( a \) to a platform-dependent signed integer (`ISize`) by first converting \( a \) to its 2's complement bitvector representation of width 64, then sign-extending it to the platform's word size (either 32 or 64 bits), and finally constructing an `ISize` from the resulting bitvector. This conversion is lossless on 64-bit platforms but truncates the value on 32-bit platforms.
ISize.neg definition
(i : ISize) : ISize
Full source
/--
Negates word-sized signed integers. Usually accessed via the `-` prefix operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_neg"]
protected def ISize.neg (i : ISize) : ISize := ⟨⟨-i.toBitVec⟩⟩
Negation of platform-dependent signed integer
Informal description
The function negates a platform-dependent signed integer `i` by first converting it to its two's complement bitvector representation, negating the bitvector, and then converting back to an `ISize`. The negation is implemented as `-i.toBitVec` modulo `2^n`, where `n` is the platform's word size (32 or 64 bits).
instToStringISize instance
: ToString ISize
Full source
instance : ToString ISize where
  toString i := toString i.toInt
String Representation of Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` has a string representation.
instReprISize instance
: Repr ISize
Full source
instance : Repr ISize where
  reprPrec i prec := reprPrec i.toInt prec
String Representation of Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` has a standard string representation that matches its two's complement bitvector interpretation.
instReprAtomISize instance
: ReprAtom ISize
Full source
instance : ReprAtom ISize := ⟨⟩
Atomic Representation Marker for Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is marked as an atomic type for representation purposes.
instHashableISize instance
: Hashable ISize
Full source
instance : Hashable ISize where
  hash i := i.toUSize.toUInt64
Hashability of Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` can be hashed into a 64-bit unsigned integer.
ISize.instOfNat instance
: OfNat ISize n
Full source
instance ISize.instOfNat : OfNat ISize n := ⟨ISize.ofNat n⟩
Natural Number Literals as Platform-Dependent Signed Integers
Informal description
For any natural number `n`, there is a canonical interpretation of `n` as a platform-dependent signed integer `ISize`, obtained by converting `n` modulo `2^w` (where `w` is the platform's word size) and interpreting the result as a signed integer.
ISize.instNeg instance
: Neg ISize
Full source
instance ISize.instNeg : Neg ISize where
  neg := ISize.neg
Negation Operation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` has a negation operation, where for any `i : ISize`, the negation `-i` is computed by taking the two's complement of its bitvector representation modulo `2^w` (with `w` being the platform's word size).
ISize.maxValue abbrev
: ISize
Full source
/-- The largest number that `ISize` can represent: `2^(System.Platform.numBits - 1) - 1`. -/
abbrev ISize.maxValue : ISize := .ofInt (2 ^ (System.Platform.numBits - 1) - 1)
Maximum Value of Platform-Dependent Signed Integer Type
Informal description
The largest representable value of the platform-dependent signed integer type `ISize` is given by $2^{w-1} - 1$, where $w$ is the platform's word size (32 or 64 bits).
ISize.minValue abbrev
: ISize
Full source
/-- The smallest number that `ISize` can represent: `-2^(System.Platform.numBits - 1)`. -/
abbrev ISize.minValue : ISize := .ofInt (-2 ^ (System.Platform.numBits - 1))
Minimum value of platform-dependent signed integer type: $-2^{w-1}$
Informal description
The smallest representable value of the platform-dependent signed integer type `ISize` is $-2^{w-1}$, where $w$ is the platform's word size (either 32 or 64 bits).
ISize.ofIntLE definition
(i : Int) (_hl : ISize.minValue.toInt ≤ i) (_hr : i ≤ ISize.maxValue.toInt) : ISize
Full source
/-- Constructs an `ISize` from an `Int` that is known to be in bounds. -/
@[inline]
def ISize.ofIntLE (i : Int) (_hl : ISize.minValue.toInt ≤ i) (_hr : i ≤ ISize.maxValue.toInt) : ISize :=
  ISize.ofInt i
Bounded conversion from integer to platform-dependent signed integer
Informal description
Given an integer \( i \) and proofs that \( i \) lies within the bounds of the platform-dependent signed integer type (i.e., \( \text{ISize.minValue} \leq i \leq \text{ISize.maxValue} \)), the function constructs an `ISize` from \( i \).
ISize.ofIntTruncate definition
(i : Int) : ISize
Full source
/-- Constructs an `ISize` from an `Int`, clamping if the value is too small or too large. -/
def ISize.ofIntTruncate (i : Int) : ISize :=
  if hl : ISize.minValue.toInt ≤ i then
    if hr : i ≤ ISize.maxValue.toInt then
      ISize.ofIntLE i hl hr
    else
      ISize.minValue
  else
    ISize.minValue
Clamping conversion from integer to platform-dependent signed integer
Informal description
The function constructs an `ISize` from an integer `i`, clamping the value to `ISize.minValue` if `i` is outside the representable range of the platform-dependent signed integer type. Specifically, if `i` is less than `ISize.minValue`, it returns `ISize.minValue`; if `i` is greater than `ISize.maxValue`, it also returns `ISize.minValue`; otherwise, it returns the exact value of `i` as an `ISize`.
ISize.add definition
(a b : ISize) : ISize
Full source
/--
Adds two word-sized signed integers, wrapping around on over- or underflow.  Usually accessed via
the `+` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_add"]
protected def ISize.add (a b : ISize) : ISize := ⟨⟨a.toBitVec + b.toBitVec⟩⟩
Addition of platform-dependent signed integers with wrap-around
Informal description
The function adds two platform-dependent signed integers `a` and `b`, wrapping around on overflow or underflow. The addition is performed by converting the integers to their two's complement bitvector representations of width equal to the platform's word size, adding them as bitvectors (which inherently wraps around modulo $2^n$ where $n$ is the word size), and converting the result back to a signed integer.
ISize.sub definition
(a b : ISize) : ISize
Full source
/--
Subtracts one word-sized signed integer from another, wrapping around on over- or underflow. Usually
accessed via the `-` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_sub"]
protected def ISize.sub (a b : ISize) : ISize := ⟨⟨a.toBitVec - b.toBitVec⟩⟩
Subtraction of platform-dependent signed integers with wrap-around
Informal description
The function subtracts two platform-dependent signed integers `a` and `b`, wrapping around on overflow or underflow. The result is computed by converting both integers to their two's complement bitvector representation (with width equal to the platform's word size), performing subtraction modulo $2^n$ (where $n$ is the platform's word size), and converting back to a signed integer.
ISize.mul definition
(a b : ISize) : ISize
Full source
/--
Multiplies two word-sized signed integers, wrapping around on over- or underflow.  Usually accessed
via the `*` operator.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_mul"]
protected def ISize.mul (a b : ISize) : ISize := ⟨⟨a.toBitVec * b.toBitVec⟩⟩
Multiplication of platform-dependent signed integers with wrap-around
Informal description
The function multiplies two signed integers `a` and `b` of platform-dependent word size, wrapping around on overflow or underflow. The result is obtained by converting the integers to their two's complement bitvector representations, performing multiplication modulo \(2^n\) (where \(n\) is the platform's word size), and converting back to a signed integer.
ISize.div definition
(a b : ISize) : ISize
Full source
/--
Truncating division for word-sized signed integers, rounding towards zero. Usually accessed via the
`/` operator.

Division by zero is defined to be zero.

This function is overridden at runtime with an efficient implementation.

Examples:
* `ISize.div 10 3 = 3`
* `ISize.div 10 (-3) = (-3)`
* `ISize.div (-10) (-3) = 3`
* `ISize.div (-10) 3 = (-3)`
* `ISize.div 10 0 = 0`
-/
@[extern "lean_isize_div"]
protected def ISize.div (a b : ISize) : ISize := ⟨⟨BitVec.sdiv a.toBitVec b.toBitVec⟩⟩
Truncating division for platform-dependent signed integers
Informal description
The function performs truncating division for platform-dependent signed integers, rounding towards zero. Given two signed integers `a` and `b` of platform-dependent word size, it returns: - `a` divided by `b` when both `a` and `b` are non-negative, - the negation of `a` divided by the negation of `b` when both `a` and `b` are negative, - the negation of `a` divided by `b` when `a` is negative and `b` is non-negative, - the negation of `a` divided by the negation of `b` when `a` is non-negative and `b` is negative. If `b` is zero, the result is zero. The function is implemented by converting the integers to their two's complement bitvector representations, performing signed division on these bitvectors, and converting the result back to a signed integer.
ISize.mod definition
(a b : ISize) : ISize
Full source
/--
The modulo operator for word-sized signed integers, which computes the remainder when dividing one
integer by another with the T-rounding convention used by `ISize.div`. Usually accessed via the `%`
operator.

When the divisor is `0`, the result is the dividend rather than an error.

This function is overridden at runtime with an efficient implementation.

Examples:
* `ISize.mod 5 2 = 1`
* `ISize.mod 5 (-2) = 1`
* `ISize.mod (-5) 2 = (-1)`
* `ISize.mod (-5) (-2) = (-1)`
* `ISize.mod 4 2 = 0`
* `ISize.mod 4 (-2) = 0`
* `ISize.mod 4 0 = 4`
* `ISize.mod (-4) 0 = (-4)`
-/
@[extern "lean_isize_mod"]
protected def ISize.mod (a b : ISize) : ISize := ⟨⟨BitVec.srem a.toBitVec b.toBitVec⟩⟩
Signed modulo operation for platform-dependent integers
Informal description
The modulo operation for platform-dependent signed integers, which computes the remainder when dividing integer $a$ by integer $b$ using the T-rounding convention (rounding towards zero). When $b = 0$, the result is $a$ rather than an error. The operation is implemented via signed remainder on the two's complement bitvector representations of the integers.
ISize.land definition
(a b : ISize) : ISize
Full source
/--
Bitwise and for word-sized signed integers. Usually accessed via the `&&&` operator.

Each bit of the resulting integer is set if the corresponding bits of both input integers are set,
according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_land"]
protected def ISize.land (a b : ISize) : ISize := ⟨⟨a.toBitVec &&& b.toBitVec⟩⟩
Bitwise AND operation on platform-dependent signed integers
Informal description
The function takes two signed integers `a` and `b` of platform-dependent word size and returns their bitwise AND operation, computed by converting each integer to its two's complement representation as a bitvector, performing the bitwise AND operation on these bitvectors, and converting the result back to a signed integer.
ISize.lor definition
(a b : ISize) : ISize
Full source
/--
Bitwise or for word-sized signed integers. Usually accessed via the `|||` operator.

Each bit of the resulting integer is set if at least one of the corresponding bits of the input
integers is set, according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_lor"]
protected def ISize.lor (a b : ISize) : ISize := ⟨⟨a.toBitVec ||| b.toBitVec⟩⟩
Bitwise OR on platform-dependent signed integers
Informal description
The bitwise OR operation on two signed integers `a` and `b` of platform-dependent word size, returning a new signed integer where each bit is set if at least one of the corresponding bits in `a` or `b` is set, according to the two's complement representation. The operation is implemented by converting the integers to bitvectors of the platform's word size, performing the bitwise OR, and converting back to a signed integer.
ISize.xor definition
(a b : ISize) : ISize
Full source
/--
Bitwise exclusive or for word-sized signed integers. Usually accessed via the `^^^` operator.

Each bit of the resulting integer is set if exactly one of the corresponding bits of the input
integers is set, according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_xor"]
protected def ISize.xor (a b : ISize) : ISize := ⟨⟨a.toBitVec ^^^ b.toBitVec⟩⟩
Bitwise XOR for platform-dependent signed integers
Informal description
The function takes two signed integers `a` and `b` of platform-dependent word size and returns their bitwise exclusive or (XOR) as another signed integer of the same word size. The operation is performed by converting the integers to their two's complement bitvector representations, applying bitwise XOR, and converting back to a signed integer.
ISize.shiftLeft definition
(a b : ISize) : ISize
Full source
/--
Bitwise left shift for word-sized signed integers. Usually accessed via the `<<<` operator.

Signed integers are interpreted as bitvectors according to the two's complement representation.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_shift_left"]
protected def ISize.shiftLeft (a b : ISize) : ISize := ⟨⟨a.toBitVec <<< (b.toBitVec.smod System.Platform.numBits)⟩⟩
Left shift for platform-dependent signed integers
Informal description
The left shift operation for platform-dependent signed integers, where the bits of `a` are shifted left by the value of `b` (interpreted as a signed integer modulo the platform's word size), filling the low bits with zeros. The shift amount is computed as the signed modulo of `b` by the platform's word size to ensure it is within bounds. The operation is performed using the two's complement representation of the integers.
ISize.shiftRight definition
(a b : ISize) : ISize
Full source
/--
Arithmetic right shift for word-sized signed integers. Usually accessed via the `<<<` operator.

The high bits are filled with the value of
the most significant bit.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_shift_right"]
protected def ISize.shiftRight (a b : ISize) : ISize := ⟨⟨BitVec.sshiftRight' a.toBitVec (b.toBitVec.smod System.Platform.numBits)⟩⟩
Arithmetic right shift for platform-dependent signed integers
Informal description
The arithmetic right shift operation for platform-dependent signed integers, where the bits of `a` are shifted right by the value of `b` (interpreted as a signed integer modulo the platform's word size), filling the high bits with the value of the most significant bit (sign extension). The shift amount is computed as the signed modulo of `b` by the platform's word size to ensure it is within bounds. The operation is performed using the two's complement representation of the integers.
ISize.complement definition
(a : ISize) : ISize
Full source
/--
Bitwise complement, also known as bitwise negation, for word-sized signed integers. Usually accessed
via the `~~~` prefix operator.

Each bit of the resulting integer is the opposite of the corresponding bit of the input integer.
Integers use the two's complement representation, so `ISize.complement a = -(a + 1)`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_complement"]
protected def ISize.complement (a : ISize) : ISize := ⟨⟨~~~a.toBitVec⟩⟩
Bitwise complement of a signed integer
Informal description
The bitwise complement (negation) of a signed integer `a` of platform-dependent word size, where each bit of the result is the opposite of the corresponding bit in `a`. In two's complement representation, this operation satisfies $\text{ISize.complement}\,a = -(a + 1)$.
ISize.abs definition
(a : ISize) : ISize
Full source
/--
Computes the absolute value of a word-sized 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`.

This function is overridden at runtime with an efficient implementation.
-/
@[extern "lean_isize_abs"]
protected def ISize.abs (a : ISize) : ISize := ⟨⟨a.toBitVec.abs⟩⟩
Absolute value of a platform-dependent signed integer
Informal description
The absolute value of a platform-dependent signed integer \( a \) is defined as follows: if \( a \) is negative (in two's complement representation), return \( -a \); otherwise, return \( a \) itself. Note that for the minimum value `ISize.minValue`, the absolute value remains `ISize.minValue` due to overflow in two's complement arithmetic.
ISize.decEq definition
(a b : ISize) : Decidable (a = b)
Full source
/--
Decides whether two word-sized signed integers are equal. Usually accessed via the
`DecidableEq ISize` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `ISize.decEq 123 123 = .isTrue rfl`
 * `(if ((-7) : ISize) = 7 then "yes" else "no") = "no"`
 * `show (7 : ISize) = 7 by decide`
-/
@[extern "lean_isize_dec_eq"]
def ISize.decEq (a b : ISize) : Decidable (a = b) :=
  match a, b with
  | ⟨n⟩, ⟨m⟩ =>
    if h : n = m then
      isTrue <| h ▸ rfl
    else
      isFalse (fun h' => ISize.noConfusion h' (fun h' => absurd h' h))
Decidable equality for platform-dependent signed integers
Informal description
The function `ISize.decEq` decides whether two signed integers `a` and `b` of platform word size are equal, returning a constructive proof of either `a = b` or `¬(a = b)`. This is implemented by comparing the underlying two's complement representations of the integers.
ISize.lt definition
(a b : ISize) : Prop
Full source
/--
Strict inequality of word-sized signed integers, defined as inequality of the corresponding
integers. Usually accessed via the `<` operator.
-/
protected def ISize.lt (a b : ISize) : Prop := a.toBitVec.slt b.toBitVec
Signed less-than for platform integers
Informal description
The strict inequality relation on platform-dependent signed integers, defined as the signed less-than comparison of their two's complement bitvector representations. For two signed integers $a$ and $b$ of platform word size, $a < b$ holds if and only if the two's complement representation of $a$ is strictly less than that of $b$ when interpreted as signed integers.
ISize.le definition
(a b : ISize) : Prop
Full source
/--
Non-strict inequality of word-sized signed integers, defined as inequality of the corresponding
integers. Usually accessed via the `≤` operator.
-/
protected def ISize.le (a b : ISize) : Prop := a.toBitVec.sle b.toBitVec
Signed integer inequality (platform-dependent)
Informal description
The non-strict inequality relation on platform-dependent signed integers, defined as the signed less-than-or-equal-to comparison (`bvsle`) of their two's complement bitvector representations. For any two signed integers `a` and `b` of platform word size, `a ≤ b` holds if and only if the two's complement representation of `a` is less than or equal to that of `b` when interpreted as signed integers.
instInhabitedISize instance
: Inhabited ISize
Full source
instance : Inhabited ISize where
  default := 0
Inhabited Instance for Platform-Dependent Signed Integers
Informal description
The type of platform-dependent signed integers `ISize` is inhabited, meaning it has a default element.
instAddISize instance
: Add ISize
Full source
instance : Add ISize         := ⟨ISize.add⟩
Addition Operation for Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` has an addition operation defined by wrapping around on overflow or underflow.
instSubISize instance
: Sub ISize
Full source
instance : Sub ISize         := ⟨ISize.sub⟩
Subtraction Operation for Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a subtraction operation that performs two's complement arithmetic with wrap-around behavior.
instMulISize instance
: Mul ISize
Full source
instance : Mul ISize         := ⟨ISize.mul⟩
Multiplication Operation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a multiplication operation that performs wrap-around arithmetic.
instModISize instance
: Mod ISize
Full source
instance : Mod ISize         := ⟨ISize.mod⟩
Modulo Operation for Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a modulo operation that computes the remainder of division using the T-rounding convention (rounding towards zero). When the divisor is zero, the operation returns the dividend rather than raising an error.
instDivISize instance
: Div ISize
Full source
instance : Div ISize         := ⟨ISize.div⟩
Truncating Division for Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a division operation that performs truncating division, rounding towards zero. For any two `ISize` values `a` and `b`, the division `a / b` is computed as follows: - If both `a` and `b` are non-negative, it returns `a` divided by `b`. - If both `a` and `b` are negative, it returns the negation of `a` divided by the negation of `b`. - If `a` is negative and `b` is non-negative, it returns the negation of `a` divided by `b`. - If `a` is non-negative and `b` is negative, it returns the negation of `a` divided by the negation of `b`. If `b` is zero, the result is zero. The operation is implemented using two's complement arithmetic on the underlying bitvector representation.
instLTISize instance
: LT ISize
Full source
instance : LT ISize          := ⟨ISize.lt⟩
Strict Order on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a canonical strict order relation `<`, defined by comparing their two's complement bitvector representations as signed integers.
instLEISize instance
: LE ISize
Full source
instance : LE ISize          := ⟨ISize.le⟩
The ≤ Relation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a canonical "less than or equal to" relation, defined via signed comparison of their two's complement representations.
instComplementISize instance
: Complement ISize
Full source
instance : Complement ISize  := ⟨ISize.complement⟩
Bitwise Complement Operation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a bitwise complement operation, where for any integer `a` of type `ISize`, the operation `~~~a` performs a bitwise NOT on its two's complement representation.
instAndOpISize instance
: AndOp ISize
Full source
instance : AndOp ISize       := ⟨ISize.land⟩
Bitwise AND Operation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a bitwise AND operation, where for any two integers `a` and `b` of type `ISize`, the operation `a &&& b` performs a bitwise AND on their two's complement representations.
instOrOpISize instance
: OrOp ISize
Full source
instance : OrOp ISize        := ⟨ISize.lor⟩
Bitwise OR Operation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a bitwise OR operation `|||`, which performs a bitwise OR on two `ISize` values and returns another `ISize` value.
instXorISize instance
: Xor ISize
Full source
instance : Xor ISize         := ⟨ISize.xor⟩
Bitwise XOR Operation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a bitwise XOR operation, where for any two `ISize` values `a` and `b`, their XOR is computed by performing bitwise exclusive or on their two's complement representations.
instShiftLeftISize instance
: ShiftLeft ISize
Full source
instance : ShiftLeft ISize   := ⟨ISize.shiftLeft⟩
Left Shift Operation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a left shift operation `<<<`, where for any two `ISize` values `a` and `b`, the operation shifts the bits of `a` left by the value of `b` (interpreted modulo the platform's word size), filling the low bits with zeros.
instShiftRightISize instance
: ShiftRight ISize
Full source
instance : ShiftRight ISize  := ⟨ISize.shiftRight⟩
Arithmetic Right Shift Operation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a homogeneous right shift operation `>>>`, where for any two `ISize` values `a` and `b`, the operation `a >>> b` performs an arithmetic right shift of `a` by `b` bits (with sign extension).
instDecidableEqISize instance
: DecidableEq ISize
Full source
instance : DecidableEq ISize := ISize.decEq
Decidable Equality for Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` has decidable equality, meaning that for any two elements `a` and `b` of type `ISize`, the proposition `a = b` can be constructively decided.
Bool.toISize definition
(b : Bool) : ISize
Full source
/--
Converts `true` to `1` and `false` to `0`.
-/
@[extern "lean_bool_to_isize"]
def Bool.toISize (b : Bool) : ISize := if b then 1 else 0
Conversion from boolean to platform-dependent signed integer
Informal description
The function converts a boolean value `b` to a platform-dependent signed integer, returning `1` if `b` is `true` and `0` if `b` is `false`.
ISize.decLt definition
(a b : ISize) : Decidable (a < b)
Full source
/--
Decides whether one word-sized signed integer is strictly less than another. Usually accessed via the
`DecidableLT ISize` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `(if ((-7) : ISize) < 7 then "yes" else "no") = "yes"`
 * `(if (5 : ISize) < 5 then "yes" else "no") = "no"`
 * `show ¬((7 : ISize) < 7) by decide`
-/
@[extern "lean_isize_dec_lt"]
def ISize.decLt (a b : ISize) : Decidable (a < b) :=
  inferInstanceAs (Decidable (a.toBitVec.slt b.toBitVec))
Decidable strict order on platform-dependent signed integers
Informal description
The function decides whether one platform-dependent signed integer `a` is strictly less than another `b` by comparing their two's complement bitvector representations as signed integers. This is used to provide a `Decidable` instance for the strict order relation `<` on `ISize`.
ISize.decLe definition
(a b : ISize) : Decidable (a ≤ b)
Full source
/--
Decides whether one word-sized signed integer is less than or equal to another. Usually accessed via
the `DecidableLE ISize` instance.

This function is overridden at runtime with an efficient implementation.

Examples:
 * `(if ((-7) : ISize) ≤ 7 then "yes" else "no") = "yes"`
 * `(if (15 : ISize) ≤ 15 then "yes" else "no") = "yes"`
 * `(if (15 : ISize) ≤ 5 then "yes" else "no") = "no"`
 * `show (7 : ISize) ≤ 7 by decide`
-/
@[extern "lean_isize_dec_le"]
def ISize.decLe (a b : ISize) : Decidable (a ≤ b) :=
  inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
Decidable less-than-or-equal-to for platform-dependent signed integers
Informal description
Given two signed integers `a` and `b` of platform-dependent word size, the function `ISize.decLe` constructively decides whether `a` is less than or equal to `b` by comparing their two's complement representations as bitvectors. This is implemented via runtime-efficient signed comparison.
instDecidableLtISize instance
(a b : ISize) : Decidable (a < b)
Full source
instance (a b : ISize) : Decidable (a < b) := ISize.decLt a b
Decidability of Strict Order on Platform-Dependent Signed Integers
Informal description
For any two platform-dependent signed integers `a` and `b`, the strict order relation `a < b` is decidable.
instDecidableLeISize instance
(a b : ISize) : Decidable (a ≤ b)
Full source
instance (a b : ISize) : Decidable (a ≤ b) := ISize.decLe a b
Decidability of the ≤ Relation on Platform-Dependent Signed Integers
Informal description
For any two platform-dependent signed integers $a$ and $b$ of type `ISize`, the relation $a \leq b$ is decidable.
instMaxISize instance
: Max ISize
Full source
instance : Max ISize := maxOfLe
Maximum Operation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a maximum operation, where for any two integers `a` and `b` of type `ISize`, the maximum is computed using their signed comparison.
instMinISize instance
: Min ISize
Full source
instance : Min ISize := minOfLe
Minimum Operation on Platform-Dependent Signed Integers
Informal description
The platform-dependent signed integer type `ISize` is equipped with a minimum operation, where for any two elements $a$ and $b$ of type `ISize`, the minimum is defined to be $a$ if $a \leq b$ and $b$ otherwise.