Integers

Uses Logical truth. Requires special terms (integers) that cannot be implemented in Leibniz itself. They are written as standard numerals, e.g. 1 or -2.

The sort describes the natural numbers. It has two subsorts: zero for the number 0 and ℕ.nz for the non-zero natural numbers. The number 1 has its own subsort as well: oneℕ.nz.

The sort describes the integers. It also has a subsort for its non-zero elements: ℤ.nz.

Since the natural numbers are integers as well, we further have and ℕ.nzℤ.nz.

Arithmetic

Addition

The sum of two integers is an integer:
+ :

Several special cases for subsorts deserve specific definitions:
+ :
ℕ.nz + ℕ.nz : ℕ.nz
ℕ.nz + : ℕ.nz
+ ℕ.nz : ℕ.nz

Addition is commutative:
x:, y:, x + y = y + x
and associative:
x:, y:, z:, (x + y) + z = x + (y + z)

Rules:

Eliminate zeros:
(x:) + (zero:zero)x
(zero:zero) + (x:)x

Evaluation for number terms:
(x:) + (y:) ⇒ Pharo:"x ensureNumber. y ensureNumber. x + y"

Subtraction

The difference between two integers is an integer:
- :

An important special case:
ℕ.nz - one :

The negative of an integer is an integer:
-() :

Rules:

Eliminate zeros:
(x:) - (zero:zero)x
(zero:zero) - (x:) ⇒ -(x)

Evaluation for number terms:
(x:) - (y:) ⇒ Pharo:"x ensureNumber. y ensureNumber. x - y"
-(x:) ⇒ Pharo:"x ensureNumber. x negated"

Multiplication

The product of two integers is an integer:
× :

Important special cases for subsorts:
× :
ℕ.nz × ℕ.nz : ℕ.nz
ℤ.nz × ℤ.nz : ℤ.nz

Multiplication is commutative:
x:, y:, x × y = y × x
and associative:
x:, y:, z:, (x × y) × z = x × (y × z)

Addition is distributive over multiplication:
x:, y:, z:, x × (y + z) = (x × y) + (x × z)

Rules:

Eliminate zeros:
(x:) × (zero:zero) ⇒ 0
(zero:zero) × (x:) ⇒ 0

Eliminate ones:
(one:one) × (x:)x
(x:) × (one:one)x

Evaluate for number terms:
(x:) × (y:) ⇒ Pharo:"x ensureNumber. y ensureNumber. x * y"

Division

Integer division yields a quotient:
div ℤ.nz :
and a remainder:
rem ℤ.nz :

Special case for the natural numbers:
div ℕ.nz :
rem ℕ.nz :

Rules:

Eliminate zeros:
(zero:zero) div (x:ℤ.nz) ⇒ 0
(zero:zero) rem (x:ℤ.nz) ⇒ 0

Eliminate ones:
(x:) div (one:one)x
(x:) rem (one:one) ⇒ 0

Evaluate for number terms:
(x:) div (y:ℤ.nz) ⇒ Pharo:"x ensureNumber. y ensureNumber. x div: y"
(x:) rem (y:ℤ.nz) ⇒ Pharo:"x ensureNumber. y ensureNumber. x rem: y"

Exponentiation

Exponentiation is defined for all integers with positive integer powers:
ℕ.nz :

Special cases for subsorts:
ℕ.nz :
ℕ.nzℕ.nz : ℕ.nz
ℤ.nzℕ.nz : ℤ.nz

Non-zero integers can also be raised to power zero:
ℤ.nzzero : ℕ.nz

Rules:

Eliminate zeros:
(x:ℤ.nz)zero:zero ⇒ 1
(zero:zero)x:ℕ.nz ⇒ 0

Eliminate ones:
(x:ℤ.nz)one:onex

Evaluate for number terms:
(x:)y:ℕ.nz ⇒ Pharo:"x ensureNumber. y ensureNumber. x raisedTo: y"

Comparison

< : 𝔹
> : 𝔹
: 𝔹
: 𝔹

Evaluation rules for number terms:
(x:) < (y:) ⇒ Pharo:"x ensureNumber. y ensureNumber. x < y"
(x:) > (y:) ⇒ Pharo:"x ensureNumber. y ensureNumber. x > y"
(x:) (y:) ⇒ Pharo:"x ensureNumber. y ensureNumber. x <= y"
(x:) (y:) ⇒ Pharo:"x ensureNumber. y ensureNumber. x >= y"