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}\).
Let \(\mathrm{MyPreint}\) be \(\mathbb {N}\times \mathbb {N}\).
We define a relation \(R\) on \(\mathrm{MyPreint}\) as follows: \((a,b)\) and \((c, d)\) are related if and only if
\(R\) is a reflexive relation.
This follows by commutativity of addition in \(\mathbb {N}\).
\(R\) is a symmetric relation.
This follows by commutativity of addition in \(\mathbb {N}\).
\(R\) is a transitive relation.
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
Since addition on \(\mathbb {N}\) is cancellative we get
as wanted.
We have that \(R\) is an equivalence relation. From now on, we will write \(x \approx y\) for \(x R y\).
We define an operation, called negation on \(\mathrm{MyPreint}\) as follows: the negation of \(x = (a,b)\) is \((b,a)\):
If \(x \approx x'\), then \(-x \approx -x'\).
Let \(x = (a,b)\) and \(x' = (a',b')\), so by assumption \(a + b' = b + a'\). By definition we have
We need to show \(b+a'=b'+a\), which follows immediately from \(a + b' = b + a'\).
We define an operation, called addition on \(\mathrm{MyPreint}\) as follows: the addition of \(x = (a,b)\) and \(y = (b, c)\) is
If \(x \approx x'\) and \(y \approx y'\), then \(x + y \approx x' + y'\).
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
Adding these two equalities we get
and hence
that is \(x + y = (a+c,b+d) \approx (a'+c',b'+d') = x'+y'\).
We define an operation, called multiplication on \(\mathrm{MyPreint}\) as follows: the multiplication of \(x = (a,b)\) and \(y = (b, c)\) is
If \(x \approx x'\) and \(y \approx y'\), then \(x * y \approx x' * y'\).
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
Multiplying the first equality by \(c'\) and by \(d'\) we get
and
Multiplying the second equality by \(a\) and by \(b\) we get
and
Adding the last two equations and cancelling the terms appearing on both sides we finally have
that is \(x * y \approx x'*y'\).
1.2 The integers
1.2.1 Definitions
We define our integers \(\mathrm{MyInt}\) as
We will write \(⟦ (a, b) ⟧\) for the class of \((a,b)\).
We define the zero of \(\mathrm{MyInt}\), denoted \(0\) as the class of \((0,0)\).
We define the one of \(\mathrm{MyInt}\), denoted \(1\) as the class of \((1,0)\).
1.2.2 Commutative ring structure
We define the negation of \(x = ⟦ (a, b) ⟧\) in \(\mathrm{MyInt}\) as
Thanks to Lemma 8 this is well defined.
We define the addition of \(x = ⟦ (a, b) ⟧\) and \(y = ⟦ (c, d) ⟧\) in \(\mathrm{MyInt}\) as
Thanks to Lemma 10 this is well defined.
We define the multiplication of \(x = ⟦ (a, b) ⟧\) and \(y = ⟦ (c, d) ⟧\) in \(\mathrm{MyInt}\) as
Thanks to Lemma 12 this is well defined.
Addition on \(\mathrm{MyInt}\) is associative.
To prove the lemma it is enough to prove that, for all \(a\), \(b\), \(c\), \(d\), \(e\) and \(f\) in \(\mathbb {N}\), we have
Unravelling the definitions this is
that is true by associativity and commutativity in \(\mathbb {N}\).
\(\mathrm{MyInt}\) with addition and multiplication is a commutative ring.
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.
In \(\mathrm{MyInt}\) we have \(0 \neq 1\).
If \(0 = 1\) by definition we would have \(⟦ (0,0) ⟧ = ⟦ (1,0) ⟧\) so \(0+1=0+0\) in \(\mathbb {N}\), that is absurd.
Let \(x\) and \(y\) in \(\mathrm{MyInt}\) such that \(x \neq 0\) and \(y \neq 0\). Then \(x*y \neq 0\).
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.
Let \(x\), \(y\) and \(z\) in \(\mathrm{MyInt}\) such that \(x \neq 0\) and \(y * x = z * x\). Then \(y = z\).
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}\)
We define a map
We have that \(i(0) = 0\).
Clear from the definition.
We have that \(i(1) = 1\).
Clear from the definition.
For all \(a\) and \(b\) in \(\mathbb {N}\) we have that
We have \(i(a+b) = ⟦ (a+b, 0) ⟧\), \(i(a) = ⟦ (a, 0) ⟧\) and \(i(b) = ⟦ (b, 0) ⟧\), so we need to prove that
that is obvious from the definition.
For all \(a\) and \(b\) in \(\mathbb {N}\) we have that
We have \(i(a*b) = ⟦ (a*b, 0) ⟧\), \(i(a) = ⟦ (a, 0) ⟧\) and \(i(b) = ⟦ (b, 0) ⟧\), so we need to prove that
By definition of multiplication we have
and the lemma follows.
We have that \(i\) is injective.
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
Let \(x\) and \(y\) in \(\mathrm{MyInt}\). We write \(x \leq y\) if there exist a natural number \(n\) such that
The relation \(\leq \) on \(\mathrm{MyInt}\) is reflexive.
We can just take \(n = 0\).
The relation \(\leq \) on \(\mathrm{MyInt}\) is transitive.
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\).
The relation \(\leq \) on \(\mathrm{MyInt}\) is antisymmetric.
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
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.
The order \(\leq \) on \(\mathrm{MyInt}\) is a total order.
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.
We have that \(\mathrm{MyInt}\) with \(\leq \) is a linear order
Clear.
In \(\mathrm{MyInt}\) we have that \(0 \leq 1\).
We use \(1\) (as natural number). We need to prove that \(0 + i(1) = 1\). Unravelling the definitions this is obvious.
Given two natural numbers \(a\) and \(b\), we have \(i(a) \leq b\) if and only if \(a \leq b\).
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
Let \(x\), \(y\) and \(z\) in \(\mathrm{MyInt}\) be such that \(x \leq y\). Then \(z + x ≤ z + y\).
Let \(n\) be such that \(y = x + i(n)\). It’s immediate that \(n\) also work to show that \(z + x ≤ z + y\).
Let \(x\) and \(y\) in \(\mathrm{MyInt}\) be such that \(0 {\lt} x\) and \(0 {\lt} y\). Then \(0 {\lt} x * y\).
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
as required.