A journey to the world of Numbers

1 The integers

We construct the integers starting from the natural numbers \(\mathbb {N}\). Since lean already has a type called \(\mathbb {Z}\), we define a new type called \(\mathrm{MyInt}\) that will be another definition of the integers.

1.1 The preintegers

\(\mathrm{MyInt}\) will be a quotient of a type called \(\mathrm{MyPreint}\).

Definition 1
#

Let \(\mathrm{MyPreint}\) be \(\mathbb {N}\times \mathbb {N}\).

Definition 2
#

We define a relation \(R\) on \(\mathrm{MyPreint}\) as follows: \((a,b)\) and \((c, d)\) are related if and only if

\[ a + d = b + c \]
Lemma 3
#

\(R\) is a reflexive relation.

Proof

This follows by commutativity of addition in \(\mathbb {N}\).

Lemma 4
#

\(R\) is a symmetric relation.

Proof

This follows by commutativity of addition in \(\mathbb {N}\).

Lemma 5
#

\(R\) is a transitive relation.

Proof

Let \(x\), \(y\) and \(z\) in \(\mathrm{MyPreint}\) such that \(x R y\) and \(y R z\). We can write \(x = (a,b)\) and similarly for \(y = (c,d)\) and \(z = (e,f)\). By assumption we have \(a+d=b+c\) and \(c+f=d+e\). Adding these equalities we get

\[ a+d+c+f=b+c+d+e \]

Since addition on \(\mathbb {N}\) is cancellative we get

\[ a+f = b + e \]

as wanted.

Lemma 6
#

We have that \(R\) is an equivalence relation. From now on, we will write \(x \approx y\) for \(x R y\).

Proof

Clear from Lemma 3, Lemma 4 and Lemma 5.

Definition 7
#

We define an operation, called negation on \(\mathrm{MyPreint}\) as follows: the negation of \(x = (a,b)\) is \((b,a)\):

\[ -x = -(a,b) = (b,a) \]
Lemma 8
#

If \(x \approx x'\), then \(-x \approx -x'\).

Proof

Let \(x = (a,b)\) and \(x' = (a',b')\), so by assumption \(a + b' = b + a'\). By definition we have

\[ -x=-(a,b)=(b,a) \mbox{ and } -x'=-(a',b')=(b',a') \]

We need to show \(b+a'=b'+a\), which follows immediately from \(a + b' = b + a'\).

Definition 9
#

We define an operation, called addition on \(\mathrm{MyPreint}\) as follows: the addition of \(x = (a,b)\) and \(y = (b, c)\) is

\[ x + y = (a,b) + (c,d) = (a+c, b + d) \]
Lemma 10
#

If \(x \approx x'\) and \(y \approx y'\), then \(x + y \approx x' + y'\).

Proof

Let \(x = (a,b)\), \(y = (c,d)\), \(x' = (a',b')\) and \(y' = (c',d')\) such that \(x \approx x'\) and \(y \approx y'\). by assumption we have

\[ a + b' = b + a' \mbox{ and } c + d' = d + c' \]

Adding these two equalities we get

\[ a+b'+c+d'=b+a'+d+c' \]

and hence

\[ a+c+b'+d'=b+d+a'+c' \]

that is \(x + y = (a+c,b+d) \approx (a'+c',b'+d') = x'+y'\).

Definition 11
#

We define an operation, called multiplication on \(\mathrm{MyPreint}\) as follows: the multiplication of \(x = (a,b)\) and \(y = (b, c)\) is

\[ x * y = (a,b) * (c,d) = (a*c+b*d, a*d+b*c) \]
Lemma 12
#

If \(x \approx x'\) and \(y \approx y'\), then \(x * y \approx x' * y'\).

Proof

Let \(x = (a,b)\), \(y = (c,d)\), \(x' = (a',b')\) and \(y' = (c',d')\) such that \(x \approx x'\) and \(y \approx y'\). by assumption we have

\[ a + b' = b + a' \mbox{ and } c + d' = d + c' \]

Multiplying the first equality by \(c'\) and by \(d'\) we get

\begin{equation} \label{H1} a * c' + b' * c' = b * c' + a' * c' \end{equation}
1

and

\begin{equation} \label{H2} b * d' + a' * d' = a * d' + b' * d' \end{equation}
2

Multiplying the second equality by \(a\) and by \(b\) we get

\begin{equation} \label{H3} a * c + a * d' = a * d + a * c' \end{equation}
3

and

\begin{equation} \label{H4} b * d + b * c' = b * c + b * d' \end{equation}
4

Adding 1 and 4 we get

\[ a * c' + b' * c' + b * d + b * c' = b * c' + a' * c' + b * c + b * d' \]

Adding 3 and 2 we get

\[ a * c + a * d' + b * d' + a' * d' = a * d + a * c' + a * d' + b' * d' \]

Adding the last two equations and cancelling the terms appearing on both sides we finally have

\[ b' * c' + b * d + a * c + a' * d' = a' * c' + b * c + a * d + b' * d' \]

that is \(x * y \approx x'*y'\).

1.2 The integers

1.2.1 Definitions

Definition 13
#

We define our integers \(\mathrm{MyInt}\) as

\[ \mathrm{MyInt}= \mathrm{MyPreint}\, / \approx \]

We will write \(⟦ (a, b) ⟧\) for the class of \((a,b)\).

Definition 14
#

We define the zero of \(\mathrm{MyInt}\), denoted \(0\) as the class of \((0,0)\).

Definition 15
#

We define the one of \(\mathrm{MyInt}\), denoted \(1\) as the class of \((1,0)\).

1.2.2 Commutative ring structure

Definition 16
#

We define the negation of \(x = ⟦ (a, b) ⟧\) in \(\mathrm{MyInt}\) as

\[ -x = ⟦ -(a, b) ⟧ \]

Thanks to Lemma 8 this is well defined.

Definition 17
#

We define the addition of \(x = ⟦ (a, b) ⟧\) and \(y = ⟦ (c, d) ⟧\) in \(\mathrm{MyInt}\) as

\[ x + y = ⟦ (a, b)+(c,d) ⟧ \]

Thanks to Lemma 10 this is well defined.

Definition 18
#

We define the multiplication of \(x = ⟦ (a, b) ⟧\) and \(y = ⟦ (c, d) ⟧\) in \(\mathrm{MyInt}\) as

\[ x * y = ⟦ (a, b)*(c,d) ⟧ \]

Thanks to Lemma 12 this is well defined.

Lemma 19
#

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

Proof

To prove the lemma it is enough to prove that, for all \(a\), \(b\), \(c\), \(d\), \(e\) and \(f\) in \(\mathbb {N}\), we have

\[ (⟦ (a, b) ⟧+ ⟦ (c, d) ⟧) + ⟦ (e, f) ⟧ = ⟦ (a, b) ⟧ + (⟦ (c, d) ⟧ + ⟦ (e, f) ⟧) \]

Unravelling the definitions this is

\[ a + c + e + (b + (d + f)) = b + d + f + (a + (c + e)) \]

that is true by associativity and commutativity in \(\mathbb {N}\).

Proposition 20
#

\(\mathrm{MyInt}\) with addition and multiplication is a commutative ring.

Proof

We have to prove various properties, namely:

  • addition is associative (already done in Lemma 19)

  • \(0\) works as neutral element for addition (on both sides)

  • existence of an inverse for addition (we prove that \(x + (-x) = (-x) + x = 0\))

  • addition is commutative

  • left and right distributivity of multiplication with respect to addition

  • associativity of multiplication

  • \(1\) works as neutral element for multiplication (on both sides)

All the proofs are essentially identical to the proof of Lemma 19 above.

Lemma 21
#

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

Proof

If \(0 = 1\) by definition we would have \(⟦ (0,0) ⟧ = ⟦ (1,0) ⟧\) so \(0+1=0+0\) in \(\mathbb {N}\), that is absurd.

Lemma 22
#

Let \(x\) and \(y\) in \(\mathrm{MyInt}\) such that \(x \neq 0\) and \(y \neq 0\). Then \(x*y \neq 0\).

Proof

It is enough to prove that, for all \(a\), \(b\), \(c\) and \(d\) in \(\mathbb {N}\) such that \(a \neq b\) and \(c \neq d\) we have \(a*c+b*d\neq a*d+b*c\). If this is not the case we must have \(a = b\) or \(c = d\). (Can you see how to prove this in \(\mathbb {N}\)? You cannot use subtraction!) and we are done.

Lemma 23
#

Let \(x\), \(y\) and \(z\) in \(\mathrm{MyInt}\) such that \(x \neq 0\) and \(y * x = z * x\). Then \(y = z\).

Proof

We have \(0 = y*x-z*x=(y-z)*x\). Since \(x \neq 0\) we have by Lemma 22 that \(y-z=0\) and hence \(y=z\).

1.2.3 The inclusion \(i \colon \mathbb {N}\to \mathrm{MyInt}\)

Definition 24
#

We define a map

\begin{gather*} i \colon \mathbb {N}\to \mathrm{MyInt}\\ n \mapsto ⟦ (n,0) ⟧ \end{gather*}
Lemma 25
#

We have that \(i(0) = 0\).

Proof

Clear from the definition.

Lemma 26
#

We have that \(i(1) = 1\).

Proof

Clear from the definition.

Lemma 27
#

For all \(a\) and \(b\) in \(\mathbb {N}\) we have that

\[ i(a+b) = i(a) + i(b) \]
Proof

We have \(i(a+b) = ⟦ (a+b, 0) ⟧\), \(i(a) = ⟦ (a, 0) ⟧\) and \(i(b) = ⟦ (b, 0) ⟧\), so we need to prove that

\[ ⟦ (a+b, 0) ⟧ = ⟦ (a, 0) ⟧ + ⟦ (b, 0) ⟧ \]

that is obvious from the definition.

Lemma 28
#

For all \(a\) and \(b\) in \(\mathbb {N}\) we have that

\[ i(a*b) = i(a) * i(b) \]
Proof

We have \(i(a*b) = ⟦ (a*b, 0) ⟧\), \(i(a) = ⟦ (a, 0) ⟧\) and \(i(b) = ⟦ (b, 0) ⟧\), so we need to prove that

\[ ⟦ (a*b, 0) ⟧ = ⟦ (a, 0) ⟧ * ⟦ (b, 0) ⟧ \]

By definition of multiplication we have

\[ ⟦ (a, 0) ⟧ * ⟦ (b, 0) ⟧ = ⟦ (a*c+0*0, a*0+0*b) ⟧ \]

and the lemma follows.

Lemma 29
#

We have that \(i\) is injective.

Proof

Let \(a\) and \(b\) such that \(i(a)=i(b)\). This means \(⟦ (a,0) ⟧ = ⟦ (b,0) ⟧\) so \(a + 0 = 0 + b\) and hence \(a = b\).

1.2.4 The order

Definition 30
#

Let \(x\) and \(y\) in \(\mathrm{MyInt}\). We write \(x \leq y\) if there exist a natural number \(n\) such that

\[ y = x + i(n) \]
Lemma 31
#

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

Proof

We can just take \(n = 0\).

Lemma 32
#

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

Proof

Let \(x\), \(y\) and \(z\) such that \(x \leq y\) and \(y \leq z\). It follows that there exist \(p\) and \(q\) such that \(y = x + i(p)\) and \(z = y + i(q)\). One can now take \(p+q\) to show that \(x \leq z\).

Lemma 33
#

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

Proof

Let \(x\) and \(y\) such that \(x \leq y\) and \(y \leq x\). It follows that there exist \(p\) and \(q\) such that \(y = x + i(p)\) and \(x = y + i(q)\). In particular

\[ x = x + i(p) + i(q) \]

Since \(\mathrm{MyInt}\) is a ring, we obtain \(i(p)+i(q) = 0\). Moreover \(i(p+q)=i(p)+i(q)\) and \(i(0)=0\), so \(i(p+q)=i(0)\) and hence, since \(i\) is injective, \(p+q = 0\). Now, \(p\) and \(q\) are natural numbers, so \(p=q=0\) and so \(x=y\).

It follows that \(\leq \) is an order relation.

Lemma 34
#

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

Proof

Let \(x\) and \(y\) by in \(\mathrm{MyInt}\). We can write \(x = ⟦ (a,b) ⟧\) and \(y = ⟦ (c,d) ⟧\) and we need to prove that \(⟦ (a,b) ⟧ \leq ⟦ (c,d) ⟧\) or \(⟦ (c,d) ⟧ \leq ⟦ (a,b) ⟧\). Let’s consider two cases (we use that the order on \(\mathbb {N}\) is total):

  • if \(a + d \leq b + c\) let \(e\) be such that \(b + c = a + d + e\). We prove that \(⟦ (a,b) ⟧ \leq ⟦ (c,d) ⟧\) using \(e\). We have

    \[ ⟦ (a,b) ⟧+i(e) = ⟦ (a,b) ⟧ + ⟦ (e,0) ⟧ = ⟦ (a+e,b+0) ⟧ = ⟦ (a+e,b) ⟧ \]

    We have that \(⟦ (a+e,b) ⟧ = ⟦ (c,d) ⟧\) since

    \[ a+e+d=b+d \]

    by our assumption on \(e\) and so \(⟦ (a,b) ⟧ \leq ⟦ (c,d) ⟧\).

  • the case \(b + c \leq a + d\) is completely analogous.

Lemma 35
#

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

Proof

Clear.

Lemma 36
#

In \(\mathrm{MyInt}\) we have that \(0 \leq 1\).

Proof

We use \(1\) (as natural number). We need to prove that \(0 + i(1) = 1\). Unravelling the definitions this is obvious.

Lemma 37
#

Given two natural numbers \(a\) and \(b\), we have \(i(a) \leq b\) if and only if \(a \leq b\).

Proof
  • If \(i(a) \leq i(b)\), let \(n\) be such that \(i(b) = i(a)+i(n)=i(a+n)\). We obtain \(b = a + n\) by injectivity of \(i\) and so \(a \leq b\).

  • If \(a \leq b\), let \(k\) be such that \(b = a + k\). We can use \(k\) to show that \(i(a) \leq i(b)\).

1.2.5 Interaction between the order and the ring structure

Lemma 38
#

Let \(x\), \(y\) and \(z\) in \(\mathrm{MyInt}\) be such that \(x \leq y\). Then \(z + x ≤ z + y\).

Proof

Let \(n\) be such that \(y = x + i(n)\). It’s immediate that \(n\) also work to show that \(z + x ≤ z + y\).

Lemma 39
#

Let \(x\) and \(y\) in \(\mathrm{MyInt}\) be such that \(0 {\lt} x\) and \(0 {\lt} y\). Then \(0 {\lt} x * y\).

Proof

By Lemma 22 we already know that \(x*y \neq 0\), so it is enough to prove that \(0 \leq x*y\). Since \(0 {\lt} x\), we have in particular that \(0 \leq x\), and let \(n\) be such that \(x = 0 + i(n)\). Similarly, let \(m\) be such that \(y = 0 + i(m)\). We have \(0 + i(n) = i(n)\) and \(0 + i(m) = i(m)\), so we need to prove that \(0 \leq i(n)*i(m)\). We do so using \(n*m\): we have

\[ 0+i(n*m)=i(n*m)=i(n)*i(m) \]

as required.