14.4.Β Fixed-Precision Integer TypesπŸ”—

Lean's standard library includes the usual assortment of fixed-width integer types. From the perspective of formalization and proofs, these types are wrappers around bitvectors of the appropriate size; the wrappers ensure that the correct implementations of e.g. arithmetic operations are applied. In compiled code, they are represented efficiently: the compiler has special support for them, as it does for other fundamental types.

14.4.1.Β Logical Model

Fixed-width integers may be unsigned or signed. Furthermore, they are available in five sizes: 8, 16, 32, and 64 bits, along with the current architecture's word size. In their logical models, the unsigned integers are structures that wrap a BitVec of the appropriate width. Signed integers wrap the corresponding unsigned integers, and use a twos-complement representation.

14.4.1.1.Β Unsigned

πŸ”—structure
USize : Type

A USize is an unsigned integer with the size of a word for the platform's architecture.

For example, if running on a 32-bit machine, USize is equivalent to UInt32. Or on a 64-bit machine, UInt64.

Constructor

USize.ofBitVec

Create a USize from a BitVec System.Platform.numBits. This function is overridden with a native implementation.

Fields

toBitVec : BitVec System.Platform.numBits

Unpack a USize as a BitVec System.Platform.numBits. This function is overridden with a native implementation.

πŸ”—structure
UInt8 : Type

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

Constructor

UInt8.ofBitVec

Create a UInt8 from a BitVec 8. This function is overridden with a native implementation.

Fields

toBitVec : BitVec 8

Unpack a UInt8 as a BitVec 8. This function is overridden with a native implementation.

πŸ”—structure
UInt16 : Type

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

Constructor

UInt16.ofBitVec

Create a UInt16 from a BitVec 16. This function is overridden with a native implementation.

Fields

toBitVec : BitVec 16

Unpack a UInt16 as a BitVec 16. This function is overridden with a native implementation.

πŸ”—structure
UInt32 : Type

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

Constructor

UInt32.ofBitVec

Create a UInt32 from a BitVec 32. This function is overridden with a native implementation.

Fields

toBitVec : BitVec 32

Unpack a UInt32 as a BitVec 32. This function is overridden with a native implementation.

πŸ”—structure
UInt64 : Type

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

Constructor

UInt64.ofBitVec

Create a UInt64 from a BitVec 64. This function is overridden with a native implementation.

Fields

toBitVec : BitVec 64

Unpack a UInt64 as a BitVec 64. This function is overridden with a native implementation.

14.4.1.2.Β Signed

πŸ”—structure
ISize : Type

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

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

Constructor

ISize.ofUSize._@._hyg.0

Fields

toUSize : USize

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

πŸ”—structure
Int8 : Type

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

Constructor

Int8.ofUInt8._@._hyg.0

Fields

toUInt8 : UInt8

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

πŸ”—structure
Int16 : Type

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

Constructor

Int16.ofUInt16._@._hyg.0

Fields

toUInt16 : UInt16

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

πŸ”—structure
Int32 : Type

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

Constructor

Int32.ofUInt32._@._hyg.0

Fields

toUInt32 : UInt32

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

πŸ”—structure
Int64 : Type

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

Constructor

Int64.ofUInt64._@._hyg.0

Fields

toUInt64 : UInt64

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

14.4.2.Β Run-Time Representation

In compiled code, fixed-width integer types that fit in one less bit than the platform's pointer size are always represented unboxed, without additional allocations or indirections. This always includes Int8, UInt8, Int16, and UInt16. On 64-bit architectures, Int32 and UInt32 are also unboxed. On 32-bit architectures, Int32 and UInt32 are boxed, which means they may be represented by a pointer to an object on the heap. ISize, USize, Int64 and UInt64 are boxed on all architectures.

Even though some fixed-with integer types require boxing in general, the compiler is able to represent them without boxing in code paths that use only a specific fixed-width type rather than being polymorphic, potentially after a specialization pass. This applies in most practical situations where these types are used: their values are represented using the corresponding unsigned fixed-width C type when a constructor parameter, function parameter, function return value, or intermediate result is known to be a fixed-width integer type. The Lean run-time system includes primitives for storing fixed-width integers in constructors of inductive types, and the primitive operations are defined on the corresponding C types, so boxing tends to happen at the β€œedges” of integer calculations rather than for each intermediate result. In contexts where other types might occur, such as the contents of polymorphic containers like Array, these types are boxed, even if an array is statically known to contain only a single fixed-width integer type.The monomorphic array type ByteArray avoids boxing for arrays of UInt8. Lean does not specialize the representation of inductive types or arrays. Inspecting a function's type in Lean is not sufficient to determine how fixed-width integer values will be represented, because boxed values are not eagerly unboxedβ€”a function that projects an Int64 from an array returns a boxed integer value.

14.4.3.Β Syntax

All the fixed-width integer types have OfNat instances, which allow numerals to be used as literals, both in expression and in pattern contexts. The signed types additionally have Neg instances, allowing negation to be applied.

Fixed-Width Literals

Lean allows both decimal and hexadecimal literals to be used for types with OfNat instances. In this example, literal notation is used to define masks.

structure Permissions where readable : Bool writable : Bool executable : Bool def Permissions.encode (p : Permissions) : UInt8 := let r := if p.readable then 0x01 else 0 let w := if p.writable then 0x02 else 0 let x := if p.executable then 0x04 else 0 r ||| w ||| x def Permissions.decode (i : UInt8) : Permissions := ⟨i &&& 0x01 β‰  0, i &&& 0x02 β‰  0, i &&& 0x04 β‰  0⟩

Literals that overflow their types' precision are interpreted modulus the precision. Signed types, are interpreted according to the underlying twos-complement representation.

Overflowing Fixed-Width Literals

The following statements are all true:

example : (255 : UInt8) = 255 := ⊒ 255 = 255 All goals completed! πŸ™ example : (256 : UInt8) = 0 := ⊒ 256 = 0 All goals completed! πŸ™ example : (257 : UInt8) = 1 := ⊒ 257 = 1 All goals completed! πŸ™ example : (0x7f : Int8) = 127 := ⊒ 127 = 127 All goals completed! πŸ™ example : (0x8f : Int8) = -113 := ⊒ 143 = -113 All goals completed! πŸ™ example : (0xff : Int8) = -1 := ⊒ 255 = -1 All goals completed! πŸ™

14.4.4.Β API Reference

14.4.4.1.Β Sizes

Each fixed-width integer has a size, which is the number of distinct values that can be represented by the type. This is not equivalent to C's sizeof operator, which instead determines how many bytes the type occupies.

πŸ”—def
USize.size : Nat

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

πŸ”—def
ISize.size : Nat

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

πŸ”—def
UInt8.size : Nat

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

πŸ”—def
Int8.size : Nat

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

πŸ”—def
UInt16.size : Nat

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

πŸ”—def
Int16.size : Nat

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

πŸ”—def
UInt32.size : Nat

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

πŸ”—def
Int32.size : Nat

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

πŸ”—def
UInt64.size : Nat

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

πŸ”—def
Int64.size : Nat

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

14.4.4.2.Β Ranges

πŸ”—def
ISize.minValue : ISize

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

πŸ”—def
ISize.maxValue : ISize

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

πŸ”—def
Int8.minValue : Int8

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

πŸ”—def
Int8.maxValue : Int8

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

πŸ”—def
Int16.minValue : Int16

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

πŸ”—def
Int16.maxValue : Int16

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

πŸ”—def
Int32.minValue : Int32

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

πŸ”—def
Int32.maxValue : Int32

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

πŸ”—def
Int64.minValue : Int64

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

πŸ”—def
Int64.maxValue : Int64

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

14.4.4.3.Β Conversions

14.4.4.3.1.Β To and From Int

πŸ”—def
ISize.toInt (i : ISize) : Int
πŸ”—def
Int8.toInt (i : Int8) : Int
πŸ”—def
Int16.toInt (i : Int16) : Int
πŸ”—def
Int32.toInt (i : Int32) : Int
πŸ”—def
Int64.toInt (i : Int64) : Int
πŸ”—def
ISize.ofInt (i : Int) : ISize
πŸ”—def
Int8.ofInt (i : Int) : Int8
πŸ”—def
Int16.ofInt (i : Int) : Int16
πŸ”—def
Int32.ofInt (i : Int) : Int32
πŸ”—def
Int64.ofInt (i : Int) : Int64
πŸ”—def
ISize.ofIntTruncate (i : Int) : ISize

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

πŸ”—def
Int8.ofIntTruncate (i : Int) : Int8

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

πŸ”—def
Int16.ofIntTruncate (i : Int) : Int16

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

πŸ”—def
Int32.ofIntTruncate (i : Int) : Int32

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

πŸ”—def
Int64.ofIntTruncate (i : Int) : Int64

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

πŸ”—def
ISize.ofIntLE (i : Int)
  (_hl : ISize.minValue.toInt ≀ i)
  (_hr : i ≀ ISize.maxValue.toInt) : ISize

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

πŸ”—def
Int8.ofIntLE (i : Int)
  (_hl : Int8.minValue.toInt ≀ i)
  (_hr : i ≀ Int8.maxValue.toInt) : Int8

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

πŸ”—def
Int16.ofIntLE (i : Int)
  (_hl : Int16.minValue.toInt ≀ i)
  (_hr : i ≀ Int16.maxValue.toInt) : Int16

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

πŸ”—def
Int32.ofIntLE (i : Int)
  (_hl : Int32.minValue.toInt ≀ i)
  (_hr : i ≀ Int32.maxValue.toInt) : Int32

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

πŸ”—def
Int64.ofIntLE (i : Int)
  (_hl : Int64.minValue.toInt ≀ i)
  (_hr : i ≀ Int64.maxValue.toInt) : Int64

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

14.4.4.3.2.Β To and From Nat

πŸ”—def
USize.ofNat (n : Nat) : USize
πŸ”—def
ISize.ofNat (n : Nat) : ISize
πŸ”—def
UInt8.ofNat (n : Nat) : UInt8
πŸ”—def
Int8.ofNat (n : Nat) : Int8
πŸ”—def
UInt16.ofNat (n : Nat) : UInt16
πŸ”—def
Int16.ofNat (n : Nat) : Int16
πŸ”—def
UInt32.ofNat (n : Nat) : UInt32
πŸ”—def
Int32.ofNat (n : Nat) : Int32
πŸ”—def
UInt64.ofNat (n : Nat) : UInt64
πŸ”—def
Int64.ofNat (n : Nat) : Int64
πŸ”—def
USize.ofNat32 (n : Nat) (h : n < 4294967296) :
  USize

Upcast a Nat less than 2^32 to a USize. This is lossless because USize.size is either 2^32 or 2^64. This function is overridden with a native implementation.

πŸ”—def
USize.ofNatLT (n : Nat) (h : n < USize.size) :
  USize

Pack a Nat less than USize.size into a USize. This function is overridden with a native implementation.

πŸ”—def
UInt8.ofNatLT (n : Nat) (h : n < UInt8.size) :
  UInt8

Pack a Nat less than 2^8 into a UInt8. This function is overridden with a native implementation.

πŸ”—def
UInt16.ofNatLT (n : Nat) (h : n < UInt16.size) :
  UInt16

Pack a Nat less than 2^16 into a UInt16. This function is overridden with a native implementation.

πŸ”—def
UInt32.ofNatLT (n : Nat) (h : n < UInt32.size) :
  UInt32

Pack a Nat less than 2^32 into a UInt32. This function is overridden with a native implementation.

πŸ”—def
UInt64.ofNatLT (n : Nat) (h : n < UInt64.size) :
  UInt64

Pack a Nat less than 2^64 into a UInt64. This function is overridden with a native implementation.

πŸ”—def
USize.ofNatTruncate (n : Nat) : USize

Converts the given natural number to USize, but returns USize.size - 1 (i.e., 2^64 - 1 or 2^32 - 1 depending on the platform) for natural numbers >= USize.size.

πŸ”—def
UInt8.ofNatTruncate (n : Nat) : UInt8

Converts the given natural number to UInt8, but returns 2^8 - 1 for natural numbers >= 2^8.

πŸ”—def
UInt16.ofNatTruncate (n : Nat) : UInt16

Converts the given natural number to UInt16, but returns 2^16 - 1 for natural numbers >= 2^16.

πŸ”—def
UInt32.ofNatTruncate (n : Nat) : UInt32

Converts the given natural number to UInt32, but returns 2^32 - 1 for natural numbers >= 2^32.

πŸ”—def
UInt64.ofNatTruncate (n : Nat) : UInt64

Converts the given natural number to UInt64, but returns 2^64 - 1 for natural numbers >= 2^64.

πŸ”—def
USize.toNat (n : USize) : Nat
πŸ”—def
ISize.toNatClampNeg (i : ISize) : Nat

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

πŸ”—def
UInt8.toNat (n : UInt8) : Nat
πŸ”—def
Int8.toNatClampNeg (i : Int8) : Nat

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

πŸ”—def
UInt16.toNat (n : UInt16) : Nat
πŸ”—def
Int16.toNatClampNeg (i : Int16) : Nat

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

πŸ”—def
UInt32.toNat (n : UInt32) : Nat

Unpack a UInt32 as a Nat. This function is overridden with a native implementation.

πŸ”—def
Int32.toNatClampNeg (i : Int32) : Nat

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

πŸ”—def
UInt64.toNat (n : UInt64) : Nat
πŸ”—def
Int64.toNatClampNeg (i : Int64) : Nat

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

14.4.4.3.3.Β To Other Fixed-Width Integers

πŸ”—def
ISize.toInt32 (a : ISize) : Int32
πŸ”—def
Int8.toInt32 (a : Int8) : Int32
πŸ”—def
Int16.toInt32 (a : Int16) : Int32
πŸ”—def
ISize.toInt64 (a : ISize) : Int64

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

πŸ”—def
USize.toUInt8 (a : USize) : UInt8
πŸ”—def
UInt8.toInt8 (i : UInt8) : Int8

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

πŸ”—def
UInt16.toUInt8 (a : UInt16) : UInt8
πŸ”—def
ISize.toInt8 (a : ISize) : Int8
πŸ”—def
Int16.toInt8 (a : Int16) : Int8
πŸ”—def
UInt32.toUInt8 (a : UInt32) : UInt8
πŸ”—def
Int32.toInt8 (a : Int32) : Int8
πŸ”—def
UInt64.toUInt8 (a : UInt64) : UInt8
πŸ”—def
Int64.toInt8 (a : Int64) : Int8
πŸ”—def
USize.toUInt16 (a : USize) : UInt16
πŸ”—def
UInt8.toUInt16 (a : UInt8) : UInt16
πŸ”—def
ISize.toInt16 (a : ISize) : Int16
πŸ”—def
Int8.toInt16 (a : Int8) : Int16
πŸ”—def
UInt16.toInt16 (i : UInt16) : Int16

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

πŸ”—def
UInt32.toUInt16 (a : UInt32) : UInt16
πŸ”—def
Int32.toInt16 (a : Int32) : Int16
πŸ”—def
UInt64.toUInt16 (a : UInt64) : UInt16
πŸ”—def
Int64.toInt16 (a : Int64) : Int16
πŸ”—def
USize.toUInt32 (a : USize) : UInt32
πŸ”—def
UInt8.toUInt32 (a : UInt8) : UInt32
πŸ”—def
Int8.toInt32 (a : Int8) : Int32
πŸ”—def
UInt16.toUInt32 (a : UInt16) : UInt32
πŸ”—def
Int16.toInt32 (a : Int16) : Int32
πŸ”—def
UInt32.toInt32 (i : UInt32) : Int32

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

πŸ”—def
UInt64.toUInt32 (a : UInt64) : UInt32
πŸ”—def
Int64.toInt32 (a : Int64) : Int32
πŸ”—def
USize.toUInt64 (a : USize) : UInt64

Upcast a USize to a UInt64. This is lossless because USize.size is either 2^32 or 2^64. This function is overridden with a native implementation.

πŸ”—def
UInt8.toUInt64 (a : UInt8) : UInt64
πŸ”—def
Int8.toInt64 (a : Int8) : Int64
πŸ”—def
UInt16.toUInt64 (a : UInt16) : UInt64
πŸ”—def
Int16.toInt64 (a : Int16) : Int64
πŸ”—def
UInt32.toUInt64 (a : UInt32) : UInt64
πŸ”—def
Int32.toInt64 (a : Int32) : Int64
πŸ”—def
UInt64.toInt64 (i : UInt64) : Int64

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

πŸ”—def
UInt8.toUSize (a : UInt8) : USize
πŸ”—def
UInt16.toUSize (a : UInt16) : USize
πŸ”—def
UInt32.toUSize (a : UInt32) : USize
πŸ”—def
UInt64.toUSize (a : UInt64) : USize

Converts a UInt64 to a USize by reducing modulo USize.size.

πŸ”—def
USize.toISize (i : USize) : ISize

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

πŸ”—def
Int8.toISize (a : Int8) : ISize
πŸ”—def
Int16.toISize (a : Int16) : ISize
πŸ”—def
Int32.toISize (a : Int32) : ISize

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

πŸ”—def
Int64.toISize (a : Int64) : ISize

14.4.4.3.4.Β To Floating-Point Numbers

πŸ”—opaque
ISize.toFloat (n : ISize) : Float

Obtains a Float whose value is near the given ISize. It will be exactly the value of the given ISize if such a Float exists. If no such Float exists, the returned value will either be the smallest Float this is larger than the given value, or the largest Float this is smaller than the given value.

πŸ”—opaque
ISize.toFloat32 (n : ISize) : Float32

Obtains a Float32 whose value is near the given ISize. It will be exactly the value of the given ISize if such a Float32 exists. If no such Float32 exists, the returned value will either be the smallest Float32 this is larger than the given value, or the largest Float32 this is smaller than the given value.

πŸ”—opaque
Int8.toFloat (n : Int8) : Float

Obtains the Float whose value is the same as the given Int8.

πŸ”—opaque
Int8.toFloat32 (n : Int8) : Float32

Obtains the Float32 whose value is the same as the given Int8.

πŸ”—opaque
Int16.toFloat (n : Int16) : Float

Obtains the Float whose value is the same as the given Int16.

πŸ”—opaque
Int16.toFloat32 (n : Int16) : Float32

Obtains the Float32 whose value is the same as the given Int16.

πŸ”—opaque
Int32.toFloat (n : Int32) : Float

Obtains the Float whose value is the same as the given Int32.

πŸ”—opaque
Int32.toFloat32 (n : Int32) : Float32

Obtains a Float32 whose value is near the given Int32. It will be exactly the value of the given Int32 if such a Float32 exists. If no such Float32 exists, the returned value will either be the smallest Float32 this is larger than the given value, or the largest Float32 this is smaller than the given value.

πŸ”—opaque
Int64.toFloat (n : Int64) : Float

Obtains a Float whose value is near the given Int64. It will be exactly the value of the given Int64 if such a Float exists. If no such Float exists, the returned value will either be the smallest Float this is larger than the given value, or the largest Float this is smaller than the given value.

πŸ”—opaque
Int64.toFloat32 (n : Int64) : Float32

Obtains a Float32 whose value is near the given Int64. It will be exactly the value of the given Int64 if such a Float32 exists. If no such Float32 exists, the returned value will either be the smallest Float32 this is larger than the given value, or the largest Float32 this is smaller than the given value.

πŸ”—opaque
USize.toFloat (n : USize) : Float

Obtains a Float whose value is near the given USize. It will be exactly the value of the given USize if such a Float exists. If no such Float exists, the returned value will either be the smallest Float this is larger than the given value, or the largest Float this is smaller than the given value.

πŸ”—opaque
USize.toFloat32 (n : USize) : Float32

Obtains a Float32 whose value is near the given USize. It will be exactly the value of the given USize if such a Float32 exists. If no such Float32 exists, the returned value will either be the smallest Float32 this is larger than the given value, or the largest Float32 this is smaller than the given value.

πŸ”—opaque
UInt8.toFloat (n : UInt8) : Float

Obtains the Float whose value is the same as the given UInt8.

πŸ”—opaque
UInt8.toFloat32 (n : UInt8) : Float32

Obtains the Float32 whose value is the same as the given UInt8.

πŸ”—opaque
UInt16.toFloat (n : UInt16) : Float

Obtains the Float whose value is the same as the given UInt16.

πŸ”—opaque
UInt16.toFloat32 (n : UInt16) : Float32

Obtains the Float32 whose value is the same as the given UInt16.

πŸ”—opaque
UInt32.toFloat (n : UInt32) : Float

Obtains the Float whose value is the same as the given UInt32.

πŸ”—opaque
UInt32.toFloat32 (n : UInt32) : Float32

Obtains a Float32 whose value is near the given UInt32. It will be exactly the value of the given UInt32 if such a Float32 exists. If no such Float32 exists, the returned value will either be the smallest Float32 this is larger than the given value, or the largest Float32 this is smaller than the given value.

πŸ”—opaque
UInt64.toFloat (n : UInt64) : Float

Obtains a Float whose value is near the given UInt64. It will be exactly the value of the given UInt64 if such a Float exists. If no such Float exists, the returned value will either be the smallest Float this is larger than the given value, or the largest Float this is smaller than the given value.

πŸ”—opaque
UInt64.toFloat32 (n : UInt64) : Float32

Obtains a Float32 whose value is near the given UInt64. It will be exactly the value of the given UInt64 if such a Float32 exists. If no such Float32 exists, the returned value will either be the smallest Float32 this is larger than the given value, or the largest Float32 this is smaller than the given value.

14.4.4.3.5.Β To and From Bitvectors

πŸ”—def
ISize.toBitVec (x : ISize) :
  BitVec System.Platform.numBits

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

πŸ”—def
ISize.ofBitVec
  (b : BitVec System.Platform.numBits) : ISize

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

πŸ”—def
Int8.toBitVec (x : Int8) : BitVec 8

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

πŸ”—def
Int8.ofBitVec (b : BitVec 8) : Int8

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

πŸ”—def
Int16.toBitVec (x : Int16) : BitVec 16

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

πŸ”—def
Int16.ofBitVec (b : BitVec 16) : Int16

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

πŸ”—def
Int32.toBitVec (x : Int32) : BitVec 32

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

πŸ”—def
Int32.ofBitVec (b : BitVec 32) : Int32

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

πŸ”—def
Int64.toBitVec (x : Int64) : BitVec 64

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

πŸ”—def
Int64.ofBitVec (b : BitVec 64) : Int64

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

14.4.4.3.6.Β To and From Finite Numbers

πŸ”—def
USize.toFin (x : USize) : Fin USize.size

Converts a USize into the corresponding Fin USize.size.

πŸ”—def
UInt8.toFin (x : UInt8) : Fin UInt8.size

Converts a UInt8 into the corresponding Fin UInt8.size.

πŸ”—def
UInt16.toFin (x : UInt16) : Fin UInt16.size

Converts a UInt16 into the corresponding Fin UInt16.size.

πŸ”—def
UInt32.toFin (x : UInt32) : Fin UInt32.size

Converts a UInt32 into the corresponding Fin UInt32.size.

πŸ”—def
UInt64.toFin (x : UInt64) : Fin UInt64.size

Converts a UInt64 into the corresponding Fin UInt64.size.

πŸ”—def
USize.ofFin (a : Fin USize.size) : USize

Converts a Fin USize.size into the corresponding USize.

πŸ”—def
UInt8.ofFin (a : Fin UInt8.size) : UInt8

Converts a Fin UInt8.size into the corresponding UInt8.

πŸ”—def
UInt16.ofFin (a : Fin UInt16.size) : UInt16

Converts a Fin UInt16.size into the corresponding UInt16.

πŸ”—def
UInt32.ofFin (a : Fin UInt32.size) : UInt32

Converts a Fin UInt32.size into the corresponding UInt32.

πŸ”—def
UInt64.ofFin (a : Fin UInt64.size) : UInt64

Converts a Fin UInt64.size into the corresponding UInt64.

πŸ”—def
USize.repr (n : USize) : String

14.4.4.3.7.Β To Characters

The Char type is a wrapper around UInt32 that requires a proof that the wrapped integer represents a Unicode code point. This predicate is part of the UInt32 API.

πŸ”—def
UInt32.isValidChar (n : UInt32) : Prop

A UInt32 denotes a valid unicode codepoint if it is less than 0x110000, and it is also not a "surrogate" character (the range 0xd800 to 0xdfff inclusive).

14.4.4.4.Β ComparisonsπŸ”—

The operators in this section are rarely invoked by name. Typically, comparisons operations on fixed-width integers should use the decidability of the corresponding relations, which consist of the equality type Eq and those implemented in instances of LE, LT.

πŸ”—def
USize.le (a b : USize) : Prop
πŸ”—def
ISize.le (a b : ISize) : Prop
πŸ”—def
UInt8.le (a b : UInt8) : Prop
πŸ”—def
Int8.le (a b : Int8) : Prop
πŸ”—def
UInt16.le (a b : UInt16) : Prop
πŸ”—def
Int16.le (a b : Int16) : Prop
πŸ”—def
UInt32.le (a b : UInt32) : Prop
πŸ”—def
Int32.le (a b : Int32) : Prop
πŸ”—def
UInt64.le (a b : UInt64) : Prop
πŸ”—def
Int64.le (a b : Int64) : Prop
πŸ”—def
USize.lt (a b : USize) : Prop
πŸ”—def
ISize.lt (a b : ISize) : Prop
πŸ”—def
UInt8.lt (a b : UInt8) : Prop
πŸ”—def
Int8.lt (a b : Int8) : Prop
πŸ”—def
UInt16.lt (a b : UInt16) : Prop
πŸ”—def
Int16.lt (a b : Int16) : Prop
πŸ”—def
UInt32.lt (a b : UInt32) : Prop
πŸ”—def
Int32.lt (a b : Int32) : Prop
πŸ”—def
UInt64.lt (a b : UInt64) : Prop
πŸ”—def
Int64.lt (a b : Int64) : Prop
πŸ”—def
USize.decEq (a b : USize) : Decidable (a = b)

Decides equality on USize. This function is overridden with a native implementation.

πŸ”—def
ISize.decEq (a b : ISize) : Decidable (a = b)
πŸ”—def
UInt8.decEq (a b : UInt8) : Decidable (a = b)

Decides equality on UInt8. This function is overridden with a native implementation.

πŸ”—def
Int8.decEq (a b : Int8) : Decidable (a = b)
πŸ”—def
UInt16.decEq (a b : UInt16) : Decidable (a = b)

Decides equality on UInt16. This function is overridden with a native implementation.

πŸ”—def
Int16.decEq (a b : Int16) : Decidable (a = b)
πŸ”—def
UInt32.decEq (a b : UInt32) : Decidable (a = b)

Decides equality on UInt32. This function is overridden with a native implementation.

πŸ”—def
Int32.decEq (a b : Int32) : Decidable (a = b)
πŸ”—def
UInt64.decEq (a b : UInt64) : Decidable (a = b)

Decides equality on UInt64. This function is overridden with a native implementation.

πŸ”—def
Int64.decEq (a b : Int64) : Decidable (a = b)
πŸ”—def
USize.decLe (a b : USize) : Decidable (a ≀ b)
πŸ”—def
ISize.decLe (a b : ISize) : Decidable (a ≀ b)
πŸ”—def
UInt8.decLe (a b : UInt8) : Decidable (a ≀ b)
πŸ”—def
Int8.decLe (a b : Int8) : Decidable (a ≀ b)
πŸ”—def
UInt16.decLe (a b : UInt16) : Decidable (a ≀ b)
πŸ”—def
Int16.decLe (a b : Int16) : Decidable (a ≀ b)
πŸ”—def
UInt32.decLe (a b : UInt32) : Decidable (a ≀ b)

Decides less-than on UInt32. This function is overridden with a native implementation.

πŸ”—def
Int32.decLe (a b : Int32) : Decidable (a ≀ b)
πŸ”—def
UInt64.decLe (a b : UInt64) : Decidable (a ≀ b)
πŸ”—def
Int64.decLe (a b : Int64) : Decidable (a ≀ b)
πŸ”—def
USize.decLt (a b : USize) : Decidable (a < b)
πŸ”—def
ISize.decLt (a b : ISize) : Decidable (a < b)
πŸ”—def
UInt8.decLt (a b : UInt8) : Decidable (a < b)
πŸ”—def
Int8.decLt (a b : Int8) : Decidable (a < b)
πŸ”—def
UInt16.decLt (a b : UInt16) : Decidable (a < b)
πŸ”—def
Int16.decLt (a b : Int16) : Decidable (a < b)
πŸ”—def
UInt32.decLt (a b : UInt32) : Decidable (a < b)

Decides less-equal on UInt32. This function is overridden with a native implementation.

πŸ”—def
Int32.decLt (a b : Int32) : Decidable (a < b)
πŸ”—def
UInt64.decLt (a b : UInt64) : Decidable (a < b)
πŸ”—def
Int64.decLt (a b : Int64) : Decidable (a < b)

14.4.4.5.Β ArithmeticπŸ”—

Typically, arithmetic operations on fixed-width integers should be accessed using Lean's overloaded arithmetic notation, particularly their instances of Add, Sub, Mul, Div, and Mod, as well as Neg for signed types.

πŸ”—def
ISize.neg (i : ISize) : ISize
πŸ”—def
Int8.neg (i : Int8) : Int8
πŸ”—def
Int16.neg (i : Int16) : Int16
πŸ”—def
Int32.neg (i : Int32) : Int32
πŸ”—def
Int64.neg (i : Int64) : Int64
πŸ”—def
USize.add (a b : USize) : USize
πŸ”—def
ISize.add (a b : ISize) : ISize
πŸ”—def
UInt8.add (a b : UInt8) : UInt8
πŸ”—def
Int8.add (a b : Int8) : Int8
πŸ”—def
UInt16.add (a b : UInt16) : UInt16
πŸ”—def
Int16.add (a b : Int16) : Int16
πŸ”—def
UInt32.add (a b : UInt32) : UInt32
πŸ”—def
Int32.add (a b : Int32) : Int32
πŸ”—def
UInt64.add (a b : UInt64) : UInt64
πŸ”—def
Int64.add (a b : Int64) : Int64
πŸ”—def
USize.sub (a b : USize) : USize
πŸ”—def
ISize.sub (a b : ISize) : ISize
πŸ”—def
UInt8.sub (a b : UInt8) : UInt8
πŸ”—def
Int8.sub (a b : Int8) : Int8
πŸ”—def
UInt16.sub (a b : UInt16) : UInt16
πŸ”—def
Int16.sub (a b : Int16) : Int16
πŸ”—def
UInt32.sub (a b : UInt32) : UInt32
πŸ”—def
Int32.sub (a b : Int32) : Int32
πŸ”—def
UInt64.sub (a b : UInt64) : UInt64
πŸ”—def
Int64.sub (a b : Int64) : Int64
πŸ”—def
USize.mul (a b : USize) : USize
πŸ”—def
ISize.mul (a b : ISize) : ISize
πŸ”—def
UInt8.mul (a b : UInt8) : UInt8
πŸ”—def
Int8.mul (a b : Int8) : Int8
πŸ”—def
UInt16.mul (a b : UInt16) : UInt16
πŸ”—def
Int16.mul (a b : Int16) : Int16
πŸ”—def
UInt32.mul (a b : UInt32) : UInt32
πŸ”—def
Int32.mul (a b : Int32) : Int32
πŸ”—def
UInt64.mul (a b : UInt64) : UInt64
πŸ”—def
Int64.mul (a b : Int64) : Int64
πŸ”—def
USize.div (a b : USize) : USize
πŸ”—def
ISize.div (a b : ISize) : ISize
πŸ”—def
UInt8.div (a b : UInt8) : UInt8
πŸ”—def
Int8.div (a b : Int8) : Int8
πŸ”—def
UInt16.div (a b : UInt16) : UInt16
πŸ”—def
Int16.div (a b : Int16) : Int16
πŸ”—def
UInt32.div (a b : UInt32) : UInt32
πŸ”—def
Int32.div (a b : Int32) : Int32
πŸ”—def
UInt64.div (a b : UInt64) : UInt64
πŸ”—def
Int64.div (a b : Int64) : Int64
πŸ”—def
USize.mod (a b : USize) : USize
πŸ”—def
ISize.mod (a b : ISize) : ISize
πŸ”—def
UInt8.mod (a b : UInt8) : UInt8
πŸ”—def
Int8.mod (a b : Int8) : Int8
πŸ”—def
UInt16.mod (a b : UInt16) : UInt16
πŸ”—def
Int16.mod (a b : Int16) : Int16
πŸ”—def
UInt32.mod (a b : UInt32) : UInt32
πŸ”—def
Int32.mod (a b : Int32) : Int32
πŸ”—def
UInt64.mod (a b : UInt64) : UInt64
πŸ”—def
Int64.mod (a b : Int64) : Int64
πŸ”—def
USize.log2 (a : USize) : USize
πŸ”—def
UInt8.log2 (a : UInt8) : UInt8
πŸ”—def
UInt16.log2 (a : UInt16) : UInt16
πŸ”—def
UInt32.log2 (a : UInt32) : UInt32
πŸ”—def
UInt64.log2 (a : UInt64) : UInt64
πŸ”—def
ISize.abs (a : ISize) : ISize

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

πŸ”—def
Int8.abs (a : Int8) : Int8

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

πŸ”—def
Int16.abs (a : Int16) : Int16

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

πŸ”—def
Int32.abs (a : Int32) : Int32

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

πŸ”—def
Int64.abs (a : Int64) : Int64

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

14.4.4.6.Β Bitwise Operations

Typically, bitwise operations on fixed-width integers should be accessed using Lean's overloaded operators, particularly their instances of ShiftLeft, ShiftRight, AndOp, OrOp, and Xor.

πŸ”—def
USize.land (a b : USize) : USize
πŸ”—def
ISize.land (a b : ISize) : ISize
πŸ”—def
UInt8.land (a b : UInt8) : UInt8
πŸ”—def
Int8.land (a b : Int8) : Int8
πŸ”—def
UInt16.land (a b : UInt16) : UInt16
πŸ”—def
Int16.land (a b : Int16) : Int16
πŸ”—def
UInt32.land (a b : UInt32) : UInt32
πŸ”—def
Int32.land (a b : Int32) : Int32
πŸ”—def
UInt64.land (a b : UInt64) : UInt64
πŸ”—def
Int64.land (a b : Int64) : Int64
πŸ”—def
USize.lor (a b : USize) : USize
πŸ”—def
ISize.lor (a b : ISize) : ISize
πŸ”—def
UInt8.lor (a b : UInt8) : UInt8
πŸ”—def
Int8.lor (a b : Int8) : Int8
πŸ”—def
UInt16.lor (a b : UInt16) : UInt16
πŸ”—def
Int16.lor (a b : Int16) : Int16
πŸ”—def
UInt32.lor (a b : UInt32) : UInt32
πŸ”—def
Int32.lor (a b : Int32) : Int32
πŸ”—def
UInt64.lor (a b : UInt64) : UInt64
πŸ”—def
Int64.lor (a b : Int64) : Int64
πŸ”—def
USize.xor (a b : USize) : USize
πŸ”—def
ISize.xor (a b : ISize) : ISize
πŸ”—def
UInt8.xor (a b : UInt8) : UInt8
πŸ”—def
Int8.xor (a b : Int8) : Int8
πŸ”—def
UInt16.xor (a b : UInt16) : UInt16
πŸ”—def
Int16.xor (a b : Int16) : Int16
πŸ”—def
UInt32.xor (a b : UInt32) : UInt32
πŸ”—def
Int32.xor (a b : Int32) : Int32
πŸ”—def
UInt64.xor (a b : UInt64) : UInt64
πŸ”—def
Int64.xor (a b : Int64) : Int64
πŸ”—def
USize.complement (a : USize) : USize
πŸ”—def
ISize.complement (a : ISize) : ISize
πŸ”—def
UInt8.complement (a : UInt8) : UInt8
πŸ”—def
Int8.complement (a : Int8) : Int8
πŸ”—def
UInt16.complement (a : UInt16) : UInt16
πŸ”—def
Int16.complement (a : Int16) : Int16
πŸ”—def
UInt32.complement (a : UInt32) : UInt32
πŸ”—def
Int32.complement (a : Int32) : Int32
πŸ”—def
UInt64.complement (a : UInt64) : UInt64
πŸ”—def
Int64.complement (a : Int64) : Int64
πŸ”—def
USize.shiftLeft (a b : USize) : USize
πŸ”—def
ISize.shiftLeft (a b : ISize) : ISize
πŸ”—def
UInt8.shiftLeft (a b : UInt8) : UInt8
πŸ”—def
Int8.shiftLeft (a b : Int8) : Int8
πŸ”—def
UInt16.shiftLeft (a b : UInt16) : UInt16
πŸ”—def
Int16.shiftLeft (a b : Int16) : Int16
πŸ”—def
UInt32.shiftLeft (a b : UInt32) : UInt32
πŸ”—def
Int32.shiftLeft (a b : Int32) : Int32
πŸ”—def
UInt64.shiftLeft (a b : UInt64) : UInt64
πŸ”—def
Int64.shiftLeft (a b : Int64) : Int64
πŸ”—def
USize.shiftRight (a b : USize) : USize
πŸ”—def
ISize.shiftRight (a b : ISize) : ISize
πŸ”—def
UInt8.shiftRight (a b : UInt8) : UInt8
πŸ”—def
Int8.shiftRight (a b : Int8) : Int8
πŸ”—def
UInt16.shiftRight (a b : UInt16) : UInt16
πŸ”—def
Int16.shiftRight (a b : Int16) : Int16
πŸ”—def
UInt32.shiftRight (a b : UInt32) : UInt32
πŸ”—def
Int32.shiftRight (a b : Int32) : Int32
πŸ”—def
UInt64.shiftRight (a b : UInt64) : UInt64
πŸ”—def
Int64.shiftRight (a b : Int64) : Int64

14.4.4.7.Β Proof Automation

The functions in this section are primarily parts of the implementation of simplification rules employed by simp. They are probably only of interest to users who are implementing custom proof automation that involves fixed-precision integers.

πŸ”—def
USize.fromExpr (e : Lean.Expr) :
  Lean.Meta.SimpM (Option USize)
πŸ”—def
UInt8.fromExpr :
  Lean.Expr β†’ Lean.Meta.SimpM (Option UInt8)
πŸ”—def
UInt16.fromExpr :
  Lean.Expr β†’ Lean.Meta.SimpM (Option UInt16)
πŸ”—def
UInt32.fromExpr :
  Lean.Expr β†’ Lean.Meta.SimpM (Option UInt32)
πŸ”—def
UInt64.fromExpr :
  Lean.Expr β†’ Lean.Meta.SimpM (Option UInt64)
πŸ”—def
UInt8.reduceAdd : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt16.reduceAdd : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt32.reduceAdd : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt64.reduceAdd : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt8.reduceDiv : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt16.reduceDiv : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt32.reduceDiv : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt64.reduceDiv : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt8.reduceGE : Lean.Meta.Simp.Simproc
πŸ”—def
UInt16.reduceGE : Lean.Meta.Simp.Simproc
πŸ”—def
UInt32.reduceGE : Lean.Meta.Simp.Simproc
πŸ”—def
UInt64.reduceGE : Lean.Meta.Simp.Simproc
πŸ”—def
UInt8.reduceGT : Lean.Meta.Simp.Simproc
πŸ”—def
UInt16.reduceGT : Lean.Meta.Simp.Simproc
πŸ”—def
UInt32.reduceGT : Lean.Meta.Simp.Simproc
πŸ”—def
UInt64.reduceGT : Lean.Meta.Simp.Simproc
πŸ”—def
UInt8.reduceLE : Lean.Meta.Simp.Simproc
πŸ”—def
UInt16.reduceLE : Lean.Meta.Simp.Simproc
πŸ”—def
UInt32.reduceLE : Lean.Meta.Simp.Simproc
πŸ”—def
UInt64.reduceLE : Lean.Meta.Simp.Simproc
πŸ”—def
UInt8.reduceLT : Lean.Meta.Simp.Simproc
πŸ”—def
UInt16.reduceLT : Lean.Meta.Simp.Simproc
πŸ”—def
UInt32.reduceLT : Lean.Meta.Simp.Simproc
πŸ”—def
UInt64.reduceLT : Lean.Meta.Simp.Simproc
πŸ”—def
UInt8.reduceMod : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt16.reduceMod : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt32.reduceMod : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt64.reduceMod : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt8.reduceMul : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt16.reduceMul : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt32.reduceMul : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt64.reduceMul : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt8.reduceOfNat : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt16.reduceOfNat : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt32.reduceOfNat : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt64.reduceOfNat : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt8.reduceOfNatLT : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt16.reduceOfNatLT : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt32.reduceOfNatLT : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt64.reduceOfNatLT : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt8.reduceSub : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt16.reduceSub : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt32.reduceSub : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt64.reduceSub : Lean.Meta.Simp.DSimproc
πŸ”—def
USize.reduceToNat : Lean.Meta.Simp.Simproc
πŸ”—def
UInt8.reduceToNat : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt16.reduceToNat : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt32.reduceToNat : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt64.reduceToNat : Lean.Meta.Simp.DSimproc