A journey to the world of Numbers

4 The reals

We finally construct the real numbers starting from our rationals \(\mathrm{MyRat}\). As usual lean already has a type called \(\mathbb {R}\), so we define a new type called \(\mathrm{MyReal}\) that will be another definition of the real numbers.

The idea is the classical one: a real number is a Cauchy sequence of rationals, where two Cauchy sequences are identified when their difference tends to \(0\). We will use the absolute value \(|x|\) of an element \(x\) of \(\mathrm{MyRat}\), which lean already knows about: since \(\mathrm{MyRat}\) is ordered, \(|x|\) is defined as \(\max (x, -x)\).

4.1 Cauchy sequences

A sequence of rationals is just a function \(x \colon \mathrm{MyNat}\to \mathrm{MyRat}\), and we write \(x_n\) for its value at \(n\).

Definition 125
#

A sequence \(x \colon \mathrm{MyNat}\to \mathrm{MyRat}\) is a Cauchy sequence if

\[ \forall \varepsilon {\gt} 0, \ \exists N, \ \forall p, q \geq N, \ |x_p - x_q| \leq \varepsilon . \]
Lemma 126
#

Every Cauchy sequence \(x\) is bounded: there exists \(B {\gt} 0\) such that \(|x_n| \leq B\) for all \(n\).

Proof

Apply the definition with \(\varepsilon = 1\) to get an \(N\), and take \(B\) to be the maximum of \(1 + |x_N|\) and the finitely many values \(|x_0|, \dots , |x_{N-1}|\).

\(\mathrm{MyReal}\) will be a quotient of a type called \(\mathrm{MyPrereal}\).

Definition 127
#

Let \(\mathrm{MyPrereal}\) be the type of Cauchy sequences, that is the subtype of \(x \colon \mathrm{MyNat}\to \mathrm{MyRat}\) such that \(x\) is a Cauchy sequence.

Definition 128
#

We define a relation \(R\) on \(\mathrm{MyPrereal}\) as follows: \(x\) and \(y\) are related if and only if

\[ \forall \varepsilon {\gt} 0, \ \exists N, \ \forall n \geq N, \ |x_n - y_n| \leq \varepsilon , \]

in other words if their difference tends to \(0\).

Lemma 129
#

\(R\) is a reflexive relation.

Proof

Exercise.

Lemma 130
#

\(R\) is a symmetric relation.

Proof

Exercise.

Lemma 131
#

\(R\) is a transitive relation.

Proof

Exercise, using the triangle inequality and splitting \(\varepsilon \) into \(\varepsilon /2 + \varepsilon /2\).

Lemma 132
#

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 129, Lemma 130 and Lemma 131.

Lemma 133
#

For any rational \(x\), the constant sequence \(n \mapsto x\) is a Cauchy sequence.

Proof

Obvious, since \(|x - x| = 0 \leq \varepsilon \).

We now endow \(\mathrm{MyPrereal}\) with the algebraic operations, all defined termwise.

Definition 134
#

We define the zero of \(\mathrm{MyPrereal}\) as the constant sequence \(0\).

Definition 135
#

We define the one of \(\mathrm{MyPrereal}\) as the constant sequence \(1\).

Lemma 136
#

If \(x\) is a Cauchy sequence, then \(-x\) (the termwise negation) is a Cauchy sequence. In particular negation is well defined on \(\mathrm{MyPrereal}\).

Proof

Exercise.

Lemma 137
#

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

Proof

Exercise.

Lemma 138
#

If \(x\) and \(y\) are Cauchy sequences, then \(x + y\) (the termwise sum) is a Cauchy sequence. In particular addition is well defined on \(\mathrm{MyPrereal}\).

Proof

Exercise, splitting \(\varepsilon \) into \(\varepsilon /2 + \varepsilon /2\).

Lemma 139
#

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

Proof

Exercise.

Lemma 140
#

If \(x\) and \(y\) are Cauchy sequences, then \(x * y\) (the termwise product) is a Cauchy sequence. In particular multiplication is well defined on \(\mathrm{MyPrereal}\).

Proof

Write \(x_p y_p - x_q y_q = x_p(y_p - y_q) + (x_p - x_q)y_q\) and use that Cauchy sequences are bounded (Lemma 126).

Lemma 141
#

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

Proof

Exercise, again using boundedness.

Inversion is more delicate: to invert a Cauchy sequence we first need to know that, if it does not tend to \(0\), then it is eventually bounded away from \(0\).

Lemma 142

Let \(x\) be in \(\mathrm{MyPrereal}\) with \(x \not\approx 0\). Then there exist \(\delta {\gt} 0\) and \(N\) such that \(\delta {\lt} |x_n|\) for all \(n \geq N\).

Proof

Since \(x \not\approx 0\) there is some \(\varepsilon {\gt} 0\) for which the defining condition fails; combine this with the Cauchy property to make \(|x_n|\) eventually larger than \(\delta = \varepsilon /2\).

Lemma 143
#

Let \(x\) be in \(\mathrm{MyPrereal}\) with \(x \not\approx 0\). Then the termwise inverse \(x^{-1}\) is a Cauchy sequence.

Proof

Using Lemma 142 the terms are eventually bounded away from \(0\), and then \(|x_p^{-1} - x_q^{-1}| = |x_p - x_q| / |x_p x_q|\) is controlled.

Definition 144
#

We define the inverse of \(x\) in \(\mathrm{MyPrereal}\) as the termwise inverse \(x^{-1}\) if \(x \not\approx 0\), and as \(0\) otherwise. Note that it is always defined.

Lemma 145
#

If \(x \approx x'\), then \(x^{-1} \approx x'^{-1}\).

Proof

Exercise.

4.2 The reals

4.2.1 Definitions

Definition 146
#

We define our reals \(\mathrm{MyReal}\) as

\[ \mathrm{MyReal}= \mathrm{MyPrereal}\, / \approx \]

We will write \(⟦ x ⟧\) for the class of the Cauchy sequence \(x\).

Definition 147
#

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

Definition 148
#

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

4.2.2 Field structure

Definition 149
#

We define the negation of \(⟦ x ⟧\) in \(\mathrm{MyReal}\) as \(⟦ -x ⟧\). Thanks to Lemma 137 this is well defined.

Definition 150
#

We define the addition of \(⟦ x ⟧\) and \(⟦ y ⟧\) in \(\mathrm{MyReal}\) as \(⟦ x + y ⟧\). Thanks to Lemma 139 this is well defined.

Definition 151
#

We define the multiplication of \(⟦ x ⟧\) and \(⟦ y ⟧\) in \(\mathrm{MyReal}\) as \(⟦ x * y ⟧\). Thanks to Lemma 141 this is well defined.

Definition 152
#

We define the inverse of \(⟦ x ⟧\) in \(\mathrm{MyReal}\) as \(⟦ x^{-1} ⟧\). Thanks to Lemma 145 this is well defined.

Proposition 153
#

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

Proof

All the ring axioms are checked by reducing to representatives and using that the operations are termwise, so everything follows from the corresponding properties in \(\mathrm{MyRat}\).

Lemma 154
#

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

Proof

If \(0 = 1\) then the constant sequences \(0\) and \(1\) would be related, which is false since \(|0 - 1| = 1\) does not become small.

Lemma 155
#

Let \(x \neq 0\) be in \(\mathrm{MyReal}\). Then \(x * x^{-1} = 1\).

Proof

Let \(x = ⟦ a ⟧\) with \(a \not\approx 0\). By Lemma 142 the terms \(a_n\) are eventually nonzero, so \(a_n a_n^{-1} = 1\) eventually, and hence \(a * a^{-1} \approx 1\).

Proposition 156
#

\(\mathrm{MyReal}\) with addition and multiplication is a field.

Proof

Clear because of Lemma 154 and Lemma 155.

4.2.3 The inclusion \(k \colon \mathrm{MyRat}\to \mathrm{MyReal}\)

Definition 157
#

We define a map

\begin{gather*} k \colon \mathrm{MyRat}\to \mathrm{MyReal}\\ x \mapsto ⟦ (n \mapsto x) ⟧ \end{gather*}

sending a rational to the class of the corresponding constant sequence.

Lemma 158
#

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

Proof

Clear from the definition.

Lemma 159
#

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

Proof

Clear from the definition.

Lemma 160
#

For all \(x\) in \(\mathrm{MyRat}\) we have that \(k(-x) = -k(x)\).

Proof

Clear from the definition.

Lemma 161
#

For all \(x\) and \(y\) in \(\mathrm{MyRat}\) we have that \(k(x + y) = k(x) + k(y)\).

Proof

Clear from the definition.

Lemma 162
#

For all \(x\) and \(y\) in \(\mathrm{MyRat}\) we have that \(k(x - y) = k(x) - k(y)\).

Proof

Clear from the definition.

Lemma 163
#

For all \(x\) and \(y\) in \(\mathrm{MyRat}\) we have that \(k(x * y) = k(x) * k(y)\).

Proof

Clear from the definition.

Lemma 164
#

For all \(x\) in \(\mathrm{MyRat}\) we have that \(k(x^{-1}) = k(x)^{-1}\).

Proof

Exercise.

Lemma 165
#

We have that \(k\) is injective.

Proof

If \(k(x) = k(y)\) then the constant sequences \(x\) and \(y\) are related, so \(|x - y|\) is arbitrarily small and hence \(x = y\).

4.3 Positivity

To define the order on \(\mathrm{MyReal}\) we follow the same strategy as for \(\mathrm{MyRat}\): we first introduce a notion of positivity and nonnegativity at the level of \(\mathrm{MyPrereal}\).

4.3.1 Positive prereals

Definition 166
#

Given \(x\) in \(\mathrm{MyPrereal}\), we say that \(x\) is positive if there exist \(\delta {\gt} 0\) and \(N\) such that \(\delta \leq x_n\) for all \(n \geq N\), in other words if \(x\) is eventually bounded below by a positive rational.

Lemma 167
#

If \(x\) is positive, then there exists \(N\) such that \(0 {\lt} x_n\) for all \(n \geq N\).

Proof

Immediate from the definition.

Lemma 168
#

The one of \(\mathrm{MyPrereal}\) is positive.

Proof

Take \(\delta = 1\).

Lemma 169
#

If \(x \approx 0\), then \(x\) is not positive.

Proof

If \(x\) were positive its terms would eventually be at least \(\delta {\gt} 0\), contradicting \(x \approx 0\).

Lemma 170
#

If \(x\) is positive, then \(x \not\approx 0\).

Proof

Contrapositive of Lemma 169.

Lemma 171
#

If \(x \approx x'\) and \(x\) is positive, then \(x'\) is positive.

Proof

Exercise.

Lemma 172
#

Let \(x\) and \(y\) in \(\mathrm{MyPrereal}\) both positive. Then \(x + y\) is positive.

Proof

Exercise.

Lemma 173
#

Let \(x\) and \(y\) in \(\mathrm{MyPrereal}\) both positive. Then \(x * y\) is positive.

Proof

Exercise.

4.3.2 Nonnegative prereals

Definition 174
#

Given \(x\) in \(\mathrm{MyPrereal}\), we say that \(x\) is nonnegative if either \(x\) is positive or \(x \approx 0\).

Lemma 175
#

If \(x \approx 0\), then \(x\) is nonnegative.

Proof

Clear from the definition.

Lemma 176
#

If there exists \(N\) such that \(0 \leq x_n\) for all \(n \geq N\), then \(x\) is nonnegative.

Proof

If \(x \not\approx 0\) then, by an argument similar to Lemma 142, \(x\) is eventually bounded below by a positive rational, hence positive.

Lemma 177
#

The zero of \(\mathrm{MyPrereal}\) is nonnegative.

Proof

Clear, since \(0 \approx 0\).

Lemma 178
#

The one of \(\mathrm{MyPrereal}\) is nonnegative.

Proof

Clear because of Lemma 168.

Lemma 179
#

If \(x \approx x'\) and \(x\) is nonnegative, then \(x'\) is nonnegative.

Proof

Follows from Lemma 171.

Let \(x\) be in \(\mathrm{MyPrereal}\) such that both \(x\) and \(-x\) are nonnegative. Then \(x \approx 0\).

Proof

Suppose \(x \not\approx 0\). Since \(x\) is nonnegative, \(x\) is positive. Since \(-x\) is nonnegative, either \(-x \approx 0\) or \(-x\) is positive. The first case implies \(x \approx 0\), a contradiction. In the second case, \(x_n\) and \(-x_n\) are both eventually bounded below by positive rationals, which is impossible on a common tail. Hence \(x \approx 0\).

Lemma 181

Let \(x\) be in \(\mathrm{MyPrereal}\) such that \(x\) is not nonnegative. Then \(-x\) is nonnegative.

Proof

If \(x\) is not nonnegative then it is in particular not eventually nonnegative, so \(-x\) is eventually bounded below by a positive rational.

4.3.3 Nonnegative reals

The notion of nonnegativity descends to \(\mathrm{MyReal}\).

Definition 182
#

We say that \(⟦ x ⟧\) in \(\mathrm{MyReal}\) is nonnegative if \(x\) is nonnegative. Thanks to Lemma 179 this does not depend on the representative.

Lemma 183

The zero of \(\mathrm{MyReal}\) is nonnegative.

Proof

Clear because of Lemma 177.

Lemma 184

Let \(x\) be in \(\mathrm{MyReal}\) such that both \(x\) and \(-x\) are nonnegative. Then \(x = 0\).

Proof

Follows from Lemma 180.

Lemma 185
#

Let \(x\) and \(y\) in \(\mathrm{MyReal}\) both nonnegative. Then \(x + y\) is nonnegative.

Proof

Reduce to representatives and use Lemma 172 (treating the cases where one of them is \(\approx 0\) separately).

Lemma 186
#

Let \(x\) and \(y\) in \(\mathrm{MyReal}\) both nonnegative. Then \(x * y\) is nonnegative.

Proof

Reduce to representatives and use Lemma 173.

4.4 The order

Definition 187
#

Let \(x\) and \(y\) in \(\mathrm{MyReal}\). We write \(x \leq y\) if \(y - x\) is nonnegative.

Lemma 188

We have that \(0 \leq x\) if and only if \(x\) is nonnegative.

Proof

Clear.

Lemma 189
#

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

Proof

Clear because of Lemma 178.

Lemma 190
#

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

Proof

Clear because of Lemma 183.

Lemma 191
#

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

Proof

It follows from Lemma 185, since \((z - y) + (y - x) = z - x\).

Lemma 192
#

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

Proof

It follows from Lemma 184.

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

4.4.1 Interaction between the order and the ring structure

Lemma 193
#

Let \(x\), \(y\) and \(t\) in \(\mathrm{MyReal}\) be such that \(x \leq y\). Then \(x + t \leq y + t\).

Proof

Clear from the definitions, since \((y + t) - (x + t) = y - x\).

Lemma 194
#

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

Proof

It follows from Lemma 186.

We have proved that \(\mathrm{MyReal}\) is an ordered ring.

4.4.2 Interaction between the order and the inclusion

Lemma 195
#

Let \(x\) and \(y\) in \(\mathrm{MyRat}\). We have that \(k(x) \leq k(y)\) if and only if \(x \leq y\).

Proof

Exercise.

Lemma 196
#

Let \(x\) and \(y\) in \(\mathrm{MyRat}\). We have that \(k(x) {\lt} k(y)\) if and only if \(x {\lt} y\).

Proof

Immediate from Lemma 195 and Lemma 165.

4.4.3 The linear order structure

Lemma 197
#

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

Proof

This follows by Lemma 181.

Lemma 198
#

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

Proof

Clear from the lemmas above.

Lemma 199
#

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

Proof

Exercise, using that a positive real is the class of a positive prereal and Lemma 173.

We now have that \(\mathrm{MyReal}\) is a strict ordered ring.

4.5 Density and completeness

The whole point of this construction is that \(\mathrm{MyReal}\) is complete: every Cauchy sequence of reals converges. We first record that \(\mathrm{MyRat}\) is dense in \(\mathrm{MyReal}\) (through \(k\)).

4.5.1 Density

Lemma 200
#

Let \(x\) in \(\mathrm{MyReal}\) and let \(\varepsilon \) in \(\mathrm{MyRat}\) with \(0 {\lt} \varepsilon \). Then there exists \(r\) in \(\mathrm{MyRat}\) with \(|x - k(r)| {\lt} k(\varepsilon )\).

Proof

Pick a representative \(a\) of \(x\); by the Cauchy property the rational \(r = a_N\) for \(N\) large enough works.

Lemma 201
#

Let \(x\) in \(\mathrm{MyReal}\) with \(0 {\lt} x\). Then there exists \(r\) in \(\mathrm{MyRat}\) with \(0 {\lt} r\) and \(k(r) {\lt} x\).

Proof

A positive real is the class of a positive prereal, which is eventually bounded below by a positive rational \(r\).

Lemma 202
#

Let \(x\) in \(\mathrm{MyReal}\) and let \(\varepsilon \) in \(\mathrm{MyReal}\) with \(0 {\lt} \varepsilon \). Then there exists \(r\) in \(\mathrm{MyRat}\) with \(|x - k(r)| {\lt} \varepsilon \).

Proof

Combine Lemma 201 (to find a rational below \(\varepsilon \)) with Lemma 200.

4.5.2 Limits and Cauchy sequences in \(\mathrm{MyReal}\)

Definition 203
#

A sequence \(f \colon \mathrm{MyNat}\to \mathrm{MyReal}\) tends to \(x\) in \(\mathrm{MyReal}\) if

\[ \forall \varepsilon {\gt} 0, \ \exists N, \ \forall n \geq N, \ |f_n - x| \leq \varepsilon . \]
Definition 204
#

A sequence \(f \colon \mathrm{MyNat}\to \mathrm{MyReal}\) is convergent if it tends to some \(x\) in \(\mathrm{MyReal}\).

Definition 205
#

A sequence \(f \colon \mathrm{MyNat}\to \mathrm{MyReal}\) is a Cauchy sequence if

\[ \forall \varepsilon {\gt} 0, \ \exists N, \ \forall p, q \geq N, \ |f_p - f_q| \leq \varepsilon . \]
Lemma 206

Let \(f \colon \mathrm{MyNat}\to \mathrm{MyReal}\) and \(x\) in \(\mathrm{MyReal}\). If for every rational \(\varepsilon {\gt} 0\) there exists \(N\) such that \(|f_n - x| \leq k(\varepsilon )\) for all \(n \geq N\), then \(f\) tends to \(x\).

Proof

It is enough to check the condition for \(\varepsilon \) of the form \(k(\delta )\), which is possible by density (Lemma 201).

Lemma 207

Let \(x\) in \(\mathrm{MyPrereal}\). Then the sequence \(n \mapsto k(x_n)\) tends to \(⟦ x ⟧\).

Proof

Immediate from the definition of \(\approx \) and Lemma 206: the Cauchy property of \(x\) is exactly what is needed.

4.5.3 Completeness

Lemma 208

Let \(x\) in \(\mathrm{MyReal}\). Then there exists a natural number \(n\) such that \(x \leq k(i(n+1))\), where \(i \colon \mathrm{MyNat}\to \mathrm{MyRat}\) is the inclusion.

Proof

Apply density with \(\varepsilon = 1\) to find \(r\) with \(|x-k(r)|{\lt}1\), so \(x{\lt}k(r+1)\). Then use Lemma 124 to bound \(r+1\) by some \(i(m)\), enlarge this to a bound of the form \(i(n+1)\), and transfer the inequality through \(k\).

Lemma 209
#

Let \(x\) in \(\mathrm{MyReal}\) with \(0 {\lt} x\). Then there exists a natural number \(n\) such that \(k(i(n+1)^{-1}) \leq x\).

Proof

Apply Lemma 208 to \(x^{-1}\) and take inverses.

Lemma 210

Let \(x\) in \(\mathrm{MyReal}\) and \(n\) a natural number. Then there exists a rational \(r\) such that \(|x - k(r)| {\lt} k(i(n+1)^{-1})\).

Proof

Apply density (Lemma 200) with \(\varepsilon = i(n+1)^{-1}\).

Lemma 211
#

Let \(f \colon \mathrm{MyNat}\to \mathrm{MyReal}\). Then there exists \(g \colon \mathrm{MyNat}\to \mathrm{MyRat}\) such that \(|f_n - k(g_n)| {\lt} k(i(n+1)^{-1})\) for all \(n\).

Proof

Apply Lemma 210 for each \(n\) and collect the choices.

Definition 212
#

Given \(f \colon \mathrm{MyNat}\to \mathrm{MyReal}\), we define \(\mathrm{approx}(f) \colon \mathrm{MyNat}\to \mathrm{MyRat}\) to be a choice of rational approximating sequence as in Lemma 211.

Lemma 213
#

For all \(n\) we have \(|f_n - k(\mathrm{approx}(f)_n)| {\lt} k(i(n+1)^{-1})\).

Proof

This is the defining property of \(\mathrm{approx}(f)\).

Lemma 214

If \(f \colon \mathrm{MyNat}\to \mathrm{MyReal}\) is a Cauchy sequence, then \(\mathrm{approx}(f)\) is a Cauchy sequence of rationals.

Proof

Estimate \(|\mathrm{approx}(f)_p - \mathrm{approx}(f)_q|\) by inserting \(f_p\) and \(f_q\) and using Lemma 213, together with the archimedean property (Lemma 209) to make the error terms small.

Definition 215
#

If \(f \colon \mathrm{MyNat}\to \mathrm{MyReal}\) is a Cauchy sequence, then \(\mathrm{approx}(f)\), being a Cauchy sequence of rationals, defines an element of \(\mathrm{MyPrereal}\).

Theorem 216
#

\(\mathrm{MyReal}\) is complete: every Cauchy sequence \(f \colon \mathrm{MyNat}\to \mathrm{MyReal}\) is convergent.

Proof

Let \(a = \mathrm{approx}(f)\), seen as an element of \(\mathrm{MyPrereal}\) (Definition 215), and let \(x = ⟦ a ⟧\). By Lemma 207 the sequence \(n \mapsto k(a_n)\) tends to \(x\), and by Lemma 213 the sequence \(f\) stays close to \(n \mapsto k(a_n)\), so \(f\) tends to \(x\). Hence \(f\) is convergent.