11.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.

11.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.

11.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.mk

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.mk

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.mk

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.mk

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.mk

Fields

toBitVec : BitVec 64

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

11.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.mk

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.mk

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.mk

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.mk

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.mk

Fields

toUInt64 : UInt64

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

11.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 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.

Fixed-width integer types that take at least as many bits as the platform's pointer type are represented the same way as Nat: if they are sufficiently small, then they are represented unboxed; if they are larger, then they are represented by a heap-allocated number value. Int64, UInt64, ISize, and USize are always represented this way, as are Int32 and UInt32 on 32-bit architectures.

11.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! πŸ™

11.4.4.Β API Reference

11.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.

11.4.4.2.Β Conversions

11.4.4.2.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

11.4.4.2.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
UInt32.ofNat' (n : Nat) (h : n < UInt32.size)
    : UInt32
πŸ”—def
UInt32.ofNatTruncate (n : Nat) : UInt32

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

πŸ”—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.ofNatCore (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.ofNatCore (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.ofNatCore (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.ofNatCore (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.ofNatCore (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.toNat (n : USize) : Nat
πŸ”—def
ISize.toNat (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.toNat (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.toNat (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.toNat (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.toNat (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.

11.4.4.2.3.Β To Other Fixed-Width Integers

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

Upcast Int32 to ISize. This function is losless as ISize is either Int32 or Int64.

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

Upcast ISize to Int64. This function is losless as ISize is either Int32 or Int64.

πŸ”—def
USize.toUInt8 (a : USize) : UInt8
πŸ”—def
UInt16.toUInt8 (a : UInt16) : UInt8
πŸ”—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
Int8.toInt16 (a : Int8) : Int16
πŸ”—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
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
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.

11.4.4.2.4.Β To Floating-Point Numbers

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

11.4.4.2.5.Β To Bitvectors

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

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

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

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

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

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

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

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

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

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

11.4.4.2.6.Β To Finite Numbers

πŸ”—def
USize.val (x : USize) : Fin USize.size
πŸ”—def
UInt8.val (x : UInt8) : Fin UInt8.size
πŸ”—def
UInt16.val (x : UInt16) : Fin UInt16.size
πŸ”—def
UInt32.val (x : UInt32) : Fin UInt32.size
πŸ”—def
UInt64.val (x : UInt64) : Fin UInt64.size
πŸ”—def
USize.repr (n : USize) : String

11.4.4.2.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).

11.4.4.3.Β 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

{docstring UInt32.le}

πŸ”—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

{docstring UInt32.lt}

πŸ”—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)

11.4.4.4.Β 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

11.4.4.5.Β 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

11.4.4.6.Β 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.reduceOfNatCore : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt16.reduceOfNatCore : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt32.reduceOfNatCore : Lean.Meta.Simp.DSimproc
πŸ”—def
UInt64.reduceOfNatCore : 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