A journey to the world of Numbers

1 The natural numbers

Everything starts with the natural numbers. Since lean already has a type of natural numbers, we define our own copy, called \(\mathrm{MyNat}\), from scratch. To make sure we do not secretly use results that are already in mathlib, the file defining \(\mathrm{MyNat}\) does not import any mathematics.

1.1 Definition

Definition 1
#

We define \(\mathrm{MyNat}\) as the inductive type with two constructors:

  • a term \(0\) (called zero);

  • for every \(n \in \mathrm{MyNat}\), a term \(\mathrm{succ}(n)\) (the successor of \(n\)).

In other words, every natural number is obtained from \(0\) by applying the successor function a finite number of times. We write \(1\) for \(\mathrm{succ}(0)\).

Definition 2
#

We define addition on \(\mathrm{MyNat}\) by recursion on the second argument:

\[ a + 0 = a, \qquad a + \mathrm{succ}(b) = \mathrm{succ}(a + b). \]
Definition 3
#

We define multiplication on \(\mathrm{MyNat}\) by recursion on the second argument:

\[ a * 0 = 0, \qquad a * \mathrm{succ}(b) = a * b + a. \]

1.2 Commutative semiring structure

All the lemmas of this section are proved by induction, using the recursive definitions of addition and multiplication. Note that \(a + 0 = a\) and \(a * 0 = 0\) hold by definition, while the symmetric statements \(0 + a = a\) and \(0 * a = 0\) need a proof.

Lemma 4
#

For all \(a\) in \(\mathrm{MyNat}\) we have \(0 + a = a\).

Proof

By induction on \(a\).

Lemma 5
#

Addition on \(\mathrm{MyNat}\) is associative.

Proof

By induction on the last variable.

Lemma 6
#

Addition on \(\mathrm{MyNat}\) is commutative.

Proof

By induction.

Lemma 7
#

For all \(a\), \(b\) and \(c\) in \(\mathrm{MyNat}\) we have \(a * (b + c) = a * b + a * c\).

Proof

By induction on \(c\).

Lemma 8
#

For all \(a\), \(b\) and \(c\) in \(\mathrm{MyNat}\) we have \((a + b) * c = a * c + b * c\).

Proof

By induction on \(c\).

Lemma 9
#

Multiplication on \(\mathrm{MyNat}\) is associative.

Proof

By induction, using left distributivity.

Lemma 10
#

Multiplication on \(\mathrm{MyNat}\) is commutative.

Proof

By induction.

Lemma 11
#

For all \(a\) in \(\mathrm{MyNat}\) we have \(1 * a = a\).

Proof

By induction, recalling that \(1 = \mathrm{succ}(0)\).

Proposition 12
#

\(\mathrm{MyNat}\) with addition and multiplication is a commutative semiring.

Proof

We collect all the lemmas above: addition is associative and commutative with neutral element \(0\), multiplication is associative and commutative with neutral element \(1\), multiplication distributes over addition and \(0\) is absorbing for multiplication.

Lemma 13
#

In \(\mathrm{MyNat}\) we have \(0 \neq 1\).

Proof

The constructors \(\mathrm{zero}\) and \(\mathrm{succ}\) are distinct, and \(1 = \mathrm{succ}(0)\).

Lemma 14
#

Let \(a\) and \(b\) in \(\mathrm{MyNat}\) be such that \(a \neq 0\) and \(b \neq 0\). Then \(a * b \neq 0\).

Proof

If \(a \neq 0\) and \(b \neq 0\) we can write \(a = \mathrm{succ}(a')\) and \(b = \mathrm{succ}(b')\), and then \(a * b = \mathrm{succ}(a' * b' + a' + b')\) is a successor, hence nonzero.

1.3 The order

Definition 15
#

Let \(a\) and \(b\) in \(\mathrm{MyNat}\). We write \(a \leq b\) if there exists a natural number \(x\) such that

\[ b = a + x. \]
Lemma 16
#

The relation \(\leq \) on \(\mathrm{MyNat}\) is reflexive.

Proof

We can take \(x = 0\).

Lemma 17
#

The relation \(\leq \) on \(\mathrm{MyNat}\) is transitive.

Proof

If \(b = a + x\) and \(c = b + y\) then \(c = a + (x + y)\).

Lemma 18
#

The relation \(\leq \) on \(\mathrm{MyNat}\) is antisymmetric.

Proof

If \(b = a + x\) and \(a = b + y\) then \(a = a + (x + y)\), so \(x + y = 0\) and hence \(x = y = 0\), giving \(a = b\).

Lemma 19
#

The order \(\leq \) on \(\mathrm{MyNat}\) is total.

Proof

By induction one shows that for all \(a\) and \(b\) either \(a \leq b\) or \(b \leq a\).

Lemma 20
#

We have that \(\mathrm{MyNat}\) with \(\leq \) is a linear order.

Proof

Clear from the lemmas above.

1.4 Interaction between the order and the algebraic structure

Lemma 21
#

Let \(a\), \(b\) and \(c\) in \(\mathrm{MyNat}\) be such that \(a \leq b\). Then \(a + c \leq b + c\).

Proof

Let \(x\) be such that \(b = a + x\). The same \(x\) shows that \(a + c \leq b + c\).

Lemma 22
#

Let \(a\), \(b\) and \(c\) in \(\mathrm{MyNat}\) be such that \(0 {\lt} c\) and \(a {\lt} b\). Then \(c * a {\lt} c * b\).

Proof

Write \(b = a + x\) with \(x \neq 0\). Then \(c * b = c * a + c * x\) with \(c * x \neq 0\), so \(c * a {\lt} c * b\).

Lemma 23
#

Let \(a\), \(b\) and \(c\) in \(\mathrm{MyNat}\) be such that \(0 {\lt} c\) and \(a {\lt} b\). Then \(a * c {\lt} b * c\).

Proof

Identical to the previous lemma using commutativity of multiplication.