The type of integers. It is defined as an inductive type based on the
natural number type Nat
featuring two constructors: "a natural
number is an integer", and "the negation of a successor of a natural
number is an integer". The former represents integers between 0
(inclusive) and ∞
, and the latter integers between -∞
and -1
(inclusive).
This type is special-cased by the compiler. The runtime has a special
representation for Int
which stores "small" signed numbers directly,
and larger numbers use an arbitrary precision "bignum" library
(usually GMP). A "small number" is an integer
that can be encoded with 63 bits (31 bits on 32-bits architectures).
- ofNat: Nat → Int
A natural number is an integer (
0
to∞
). - negSucc: Nat → Int
The negation of the successor of a natural number is an integer (
-1
to-∞
).
Instances For
Coercions #
Negation of an integer.
Implemented by efficient native code.
Equations
- (Int.ofNat n_2).neg = Int.negOfNat n_2
- (Int.negSucc n_2).neg = ↑n_2.succ
Instances For
Equations
- Int.instNegInt = { neg := Int.neg }
Subtraction of two natural numbers.
Equations
- Int.subNatNat m n = match n - m with | 0 => Int.ofNat (m - n) | k.succ => Int.negSucc k
Instances For
Multiplication of two integers.
#eval (63 : Int) * (6 : Int) -- 378
#eval (6 : Int) * (-6 : Int) -- -36
#eval (7 : Int) * (0 : Int) -- 0
Implemented by efficient native code.
Equations
- (Int.ofNat m_2).mul (Int.ofNat n_2) = Int.ofNat (m_2 * n_2)
- (Int.ofNat m_2).mul (Int.negSucc n_2) = Int.negOfNat (m_2 * n_2.succ)
- (Int.negSucc m_2).mul (Int.ofNat n_2) = Int.negOfNat (m_2.succ * n_2)
- (Int.negSucc m_2).mul (Int.negSucc n_2) = Int.ofNat (m_2.succ * n_2.succ)
Instances For
sign #
Conversion #
divisibility #
Divisibility of integers. a ∣ b
(typed as \|
) says that
there is some c
such that b = a * c
.