Do the numbers exist?
Since school you have calculated with , with and with , using rules such as and "every bounded increasing sequence has a limit". In the lessons on integers and real numbers we derived consequences of such rules. But a list of rules can be contradictory, and nothing so far guarantees that some system actually obeys all of them at once. The axioms of a "complete ordered field", for instance, ask a great deal: a field, with an order compatible with and , in which every non-empty bounded set has a least upper bound. Is there such a thing?
This lesson answers yes, by building one. Starting only from the natural numbers and the language of sets, we construct , then , then — and at the end we prove that the result is essentially unique: any two complete ordered fields are the same field with the elements renamed. Leopold Kronecker is reported to have said that "God made the integers; all else is the work of man". The constructions show how much of that work can be done with the natural numbers alone.
One idea, used three times
Each construction repairs a defect by adding formal expressions for the missing numbers, and then declaring when two expressions should name the same number.
- has no solution of . So we introduce formal differences "" for pairs of naturals — and since and should be equal, we identify with when .
- has no solution of . So we introduce formal quotients "" with , identifying with when .
- has no number whose square is : the rationals below have no least upper bound in . So we introduce, for each "gap", the set of rationals below it (a Dedekind cut) — or a sequence of rationals crowding towards it (a Cauchy sequence), identifying sequences that crowd towards the same place.
"Identifying" means passing to equivalence classes (see equivalence relations). The price is that every operation must be checked to be well defined: the answer must not depend on which member of a class we compute with. The Remainder families Wonder Trail, linked below, shows the same phenomenon for remainders.
The two sequences below are made of fractions only. The first iterates from above, the second from below. Both crowd towards the same point — a point that is not a fraction.
Babylonian iteration: fractions from above
Every term is a fraction; the fixed point x = √2 is not.
f(x) = (x + 2/x)/2
Iterates xₖ against k
- y = f(x)
- y = x
- cobweb path
Last iterates: x4 = 1.41421, x5 = 1.41421, x6 = 1.41421
The orbit appears to settle at a fixed point x* ≈ 1.41421.
Fixed points in view (numerical): x* = 1.4142 (attracting: |f′(x*)| < 1)
Based on 3,000 iterations in floating-point arithmetic: numerical evidence, not proof.
Climbing towards √2 from below
Each step stays in the cut {q : q² < 2} and gets closer to its upper edge.
f(x) = (2·x + 2)/(x + 2)
Iterates xₖ against k
- y = f(x)
- y = x
- cobweb path
Last iterates: x10 = 1.41421, x11 = 1.41421, x12 = 1.41421
The orbit appears to settle at a fixed point x* ≈ 1.41421.
Fixed points in view (numerical): x* = 1.4142 (attracting: |f′(x*)| < 1)
Based on 3,000 iterations in floating-point arithmetic: numerical evidence, not proof.
Definitions
Definition— well-defined operation on classes
Let be an equivalence relation on a set with classes . A function induces an operation on classes, , if it is compatible with : whenever and , also . We then say the operation is well defined.
Definition— ordered field
An ordered field is a field with a total order such that implies , and , imply . An upper bound of is a with for all ; a least upper bound or supremum is an upper bound below every other upper bound (see order theory). is complete if every non-empty subset that is bounded above has a supremum in , and Archimedean if for every there is a natural number with .
Definition— Dedekind cut
A Dedekind cut is a subset such that
- and ;
- is closed downwards: if and , then ;
- has no greatest element: for every there is with .
Picture a cut as "all the rationals strictly to the left of a point on the line". For a rational the cut describes itself; condition 3 makes this the only cut describing (we do not allow ).
Definition— Cauchy sequence of rationals
A sequence of rationals is Cauchy if for every rational there is with for all . Two Cauchy sequences are equivalent if their difference tends to : for every rational , for all large .
The integers from pairs of naturals
On define if . Think of as ""; the condition is rearranged so that it makes sense in , where subtraction is not always possible.
Theorem— Proposition 1
is an equivalence relation on .
Proof
Reflexivity () and symmetry are clear. For transitivity, suppose and . Adding,
and cancelling — legitimate in , where implies — gives , i.e. .
∎
Define to be the set of equivalence classes. Guided by and , set
Theorem— Proposition 2 (well-definedness)
These formulas define operations on equivalence classes: equivalent inputs give equivalent outputs.
Proof
Addition. If and , then adding the two equations gives , which says .
Multiplication. It suffices to change one factor at a time, because is transitive. Suppose ; we show , that is,
Group the left side as and the right side as . Since , these are equal. Changing the second factor is the same computation with the roles exchanged.
∎
The ring axioms for now follow from those of by computing with representatives; for example associativity of addition reduces to associativity in each coordinate. The class is the additive identity, the multiplicative identity, and , because . The map embeds in preserving and , and every class is or for a unique (subtract the smaller coordinate from both), so consists of the natural numbers and their negatives — exactly the integers we know. The order is if .
Example— A rule that is not well defined
Why not multiply pairs componentwise, ? Because (both stand for ) while and , and . The "product" of the number and the number would depend on how was written. Well-definedness is never automatic.
The rationals as a field of fractions
The same recipe works over any integral domain — a commutative ring with and no zero divisors ( implies or ). On pairs define if .
Theorem— Proposition 3
is an equivalence relation, and the operations
are well defined. The classes form a field , the field of fractions of , and is an injective ring homomorphism .
Proof
Transitivity. Suppose and , with . Then
and since and has no zero divisors, forces .
The operations make sense: because — no zero divisors again.
Addition is well defined. Let . Then , so ; similarly in the second argument. Multiplication: .
Field axioms. They follow from those of by computing with representatives; and are the zero and identity, and if then and is its inverse, since . Finally means , so is injective.
∎
Taking gives . Writing for , the definitions become the familiar rules for fractions. Every fraction has a representative with , and (with ) is defined by ; this makes an ordered field.
Example— Where zero divisors break the construction
Over , which has zero divisors (), the same definition is not even transitive: (as ) and , but (as ). One would be forced to declare . Rings with zero divisors can still be "localised", but only by inverting carefully chosen elements, and information is lost.
Universal property. is the smallest field containing , in a precise sense: every injective ring homomorphism into a field extends to exactly one ring homomorphism , namely . For there is even less freedom: there is at most one ring homomorphism from to any ring.
The real numbers from Dedekind cuts
Let be the set of Dedekind cuts, ordered by inclusion: means . Each rational gives the cut , and if and only if , so sits inside with its order. But there are new cuts too:
Theorem— Proposition 4 (a cut for √2)
is a Dedekind cut, and it is not of the form for any rational .
Proof
and . If and : either , or , in which case , so and . For no greatest element, let . If , then is larger. If , then ; put . Then
so and . Finally, if , then but every rational below is in ; as , , and . If , the same map gives with and , so — impossible. Hence , contradicting the irrationality of (proved in the lesson on real numbers).
∎
Theorem— Proposition 5 (cuts are totally ordered)
For any cuts , either or .
Proof
Suppose , and pick . Let . If , then (as or and is closed downwards) — a contradiction. So , and because is closed downwards. Thus .
∎
Theorem— Theorem 6 (least-upper-bound property)
Let be a non-empty set of cuts that is bounded above by some cut . Then the union is a cut, and it is the least upper bound of .
Proof
is a cut. It is non-empty, because contains some cut, which is non-empty. It is not all of : every is contained in , so . It is closed downwards: if , then for some , and every lies in . It has no greatest element: if , then contains some , and .
is an upper bound, since for every . It is the least one: if is a cut with for every , then .
∎
The lattice-theoretic content is striking: in the ordered set of cuts, suprema are simply unions. Everything else is work. Addition is defined by (with as identity), and multiplication first for positive cuts by , then extended by the sign rules. Checking that this gives an ordered field takes several pages of routine verification; see Rudin's Principles of Mathematical Analysis, appendix to chapter 1. The result:
Theorem— Theorem 7 (Dedekind)
The Dedekind cuts, with these operations and the inclusion order, form a complete ordered field, and embeds in it as an ordered subfield.
Proof: completeness is Theorem 6; the field and order axioms are a long verification, which we do not reproduce (see the reading list).
The real numbers from Cauchy sequences
Cantor and Méray proposed a different construction, closer to how we compute with real numbers. Let be the set of Cauchy sequences of rationals, and identify equivalent ones. The sequences
(the decimal truncations of and the Babylonian iteration) are equivalent, and their class is the real number . Similarly is equivalent to the constant sequence , which is the precise meaning of .
Sums and products are computed termwise: and . One checks that sums and products of Cauchy sequences are Cauchy (for products one uses that Cauchy sequences are bounded) and that the operations are well defined. A sequence not equivalent to is eventually bounded away from , so it can be inverted termwise from some point on; a class is positive if its terms are eventually at least some fixed rational . The result is again a complete ordered field: completeness is proved by approximating each term of a Cauchy sequence of real numbers by a rational with , and showing that is Cauchy and its class is the limit. This is how Mathlib builds (as Real.ofCauchy), and the same construction, with a different notion of distance, produces the -adic numbers.
Why are there two constructions? Cuts make the order and completeness easy and the algebra laborious; Cauchy sequences make the algebra easy and the order laborious. The next theorem says it does not matter which one we choose.
There is only one complete ordered field
Theorem— Theorem 8 (complete ordered fields are Archimedean)
In a complete ordered field , the natural numbers are not bounded above. Consequently, between any two elements of there is a rational number.
Proof
Suppose were bounded above, with supremum . Then is not an upper bound, so for some natural number . But then , and is a natural number — contradicting that is an upper bound.
For density: choose a natural number , so that . The multiples , , are spaced apart, and there is a least integer with (by the Archimedean property, the set of such is non-empty and bounded below). Then , so .
∎
Theorem— Theorem 9 (uniqueness of the reals)
If and are complete ordered fields, there is exactly one order-preserving field isomorphism .
Proof sketch. Every ordered field contains a copy of (the multiples of and their quotients), and any field homomorphism must be the identity on it. Define by
The set is non-empty and bounded above in by the Archimedean property, so the supremum exists by completeness of . Density of (Theorem 8) shows that is strictly increasing and is the identity on , that it has the inverse , and, with more work, that it preserves sums and products. Any order-preserving isomorphism must send to this supremum, which gives uniqueness. Mathlib contains a complete formal proof (cited in the formal section).
So the Dedekind reals and the Cauchy reals are isomorphic, and so is any other model of the axioms. "The real numbers" is a meaningful phrase: up to unique isomorphism there is only one complete ordered field.
The constructions in Lean
Lean's quotient types make the constructions literal: Quotient s is the type of equivalence classes of a Setoid (a type with an equivalence relation), and a function on representatives descends to classes — via Quotient.lift or Quotient.map₂ — only when given a proof that it respects the relation. In Lean, well-definedness cannot be forgotten: the definition does not compile without the proof.
The integers. Transitivity (Proposition 1), with the cancellation step made explicit; the setoid and the type of classes; the well-definedness lemmas of Proposition 2, each a calc following the human grouping; and the operations themselves, whose definitions consume those proofs.
/-- **Transitivity of `(a, b) ~ (c, d) ⟺ a + d = c + b`.** Adding the two hypotheses gives
`(a + f) + (c + d) = (e + b) + (c + d)`, and in `ℕ` we may cancel `c + d`. Cancellation is the one
property of `ℕ` that the construction really needs. -/
theorem intRel_trans {a b c d e f : ℕ} (h₁ : a + d = c + b) (h₂ : c + f = e + d) :
a + f = e + b := by
have h : (a + f) + (c + d) = (e + b) + (c + d) :=
calc (a + f) + (c + d) = (a + d) + (c + f) := by ring
_ = (c + b) + (e + d) := by rw [h₁, h₂]
_ = (e + b) + (c + d) := by ring
exact Nat.add_right_cancel h/-- The equivalence relation on `ℕ × ℕ` whose classes are the integers: `(a, b) ~ (c, d)` means
`a + d = c + b`, i.e. "`a - b = c - d`" written without subtraction. Reflexivity and symmetry are
immediate; transitivity is `intRel_trans`. -/
def intSetoid : Setoid (ℕ × ℕ) where
r p q := p.1 + q.2 = q.1 + p.2
iseqv := ⟨fun _ => rfl, fun h => h.symm, fun h₁ h₂ => intRel_trans h₁ h₂⟩/-- The constructed integers: equivalence classes of pairs of natural numbers. -/
def PairInt : Type := Quotient intSetoid/-- **Addition of classes is well defined.** If `(a, b) ~ (a', b')` and `(c, d) ~ (c', d')`, then
`(a + c, b + d) ~ (a' + c', b' + d')`: add the two equations. -/
theorem add_respects {a b c d a' b' c' d' : ℕ} (h₁ : a + b' = a' + b) (h₂ : c + d' = c' + d) :
(a + c) + (b' + d') = (a' + c') + (b + d) := by
calc (a + c) + (b' + d') = (a + b') + (c + d') := by ring
_ = (a' + b) + (c' + d) := by rw [h₁, h₂]
_ = (a' + c') + (b + d) := by ring/-- **Multiplication of classes is well defined (first argument).** With
`(a, b) · (c, d) = (ac + bd, ad + bc)` — the rule `(a - b)(c - d) = (ac + bd) - (ad + bc)` —
replacing `(a, b)` by an equivalent `(a', b')` gives an equivalent product. The key step groups
the terms as `(a + b')c + (a' + b)d` and uses `a + b' = a' + b`. -/
theorem mul_respects_left {a b a' b' c d : ℕ} (h : a + b' = a' + b) :
(a * c + b * d) + (a' * d + b' * c) = (a' * c + b' * d) + (a * d + b * c) := by
calc (a * c + b * d) + (a' * d + b' * c) = (a + b') * c + (a' + b) * d := by ring
_ = (a' + b) * c + (a + b') * d := by rw [h]
_ = (a' * c + b' * d) + (a * d + b * c) := by ring/-- **Multiplication of classes is well defined (second argument):** the same computation with
the roles of the factors exchanged, grouping as `a(c + d') + b(c' + d)`. -/
theorem mul_respects_right {a b c d c' d' : ℕ} (h : c + d' = c' + d) :
(a * c + b * d) + (a * d' + b * c') = (a * c' + b * d') + (a * d + b * c) := by
calc (a * c + b * d) + (a * d' + b * c') = a * (c + d') + b * (c' + d) := by ring
_ = a * (c' + d) + b * (c + d') := by rw [h]
_ = (a * c' + b * d') + (a * d + b * c) := by ring/-- Addition on the constructed integers: `[(a, b)] + [(c, d)] = [(a + c, b + d)]`. It is
well defined by `add_respects`. -/
def add : PairInt → PairInt → PairInt :=
Quotient.map₂ (fun p q => (p.1 + q.1, p.2 + q.2))
(fun _ _ h₁ _ _ h₂ => add_respects h₁ h₂)/-- Multiplication: `[(a, b)] · [(c, d)] = [(ac + bd, ad + bc)]`. Well defined because changing
one argument at a time gives equivalent results (`mul_respects_left`, `mul_respects_right`),
and the relation is transitive. -/
def mul : PairInt → PairInt → PairInt :=
Quotient.map₂ (fun p q => (p.1 * q.1 + p.2 * q.2, p.1 * q.2 + p.2 * q.1))
(fun _p p' hp q _q' hq =>
intRel_trans (mul_respects_left (c := q.1) (d := q.2) hp)
(mul_respects_right (a := p'.1) (b := p'.2) hq))To check that the construction really produces the integers, we compare it with Mathlib's ℤ (which is built differently, as an inductive type). The map is well defined, turns the constructed operations into the usual ones, and is a bijection — so it is a ring isomorphism.
/-- The comparison map to Mathlib's integers: `[(a, b)] ↦ a - b`. It is well defined because
`a + d = c + b` implies `a - b = c - d` in `ℤ`. -/
def toInt : PairInt → ℤ :=
Quotient.lift (fun p : ℕ × ℕ => (p.1 : ℤ) - p.2)
(fun p q (h : p.1 + q.2 = q.1 + p.2) => by
have h' : (p.1 : ℤ) + q.2 = q.1 + p.2 := by exact_mod_cast h
linear_combination h')/-- The comparison map turns the constructed addition into the addition of `ℤ`:
`(a + c) - (b + d) = (a - b) + (c - d)`. -/
theorem toInt_add (x y : PairInt) : toInt (add x y) = toInt x + toInt y := by
induction x using Quotient.inductionOn with | h p =>
induction y using Quotient.inductionOn with | h q =>
show ((p.1 + q.1 : ℕ) : ℤ) - ((p.2 + q.2 : ℕ) : ℤ) = ((p.1 : ℤ) - p.2) + ((q.1 : ℤ) - q.2)
push_cast
ring/-- …and the constructed multiplication into the multiplication of `ℤ`:
`(ac + bd) - (ad + bc) = (a - b)(c - d)`. -/
theorem toInt_mul (x y : PairInt) : toInt (mul x y) = toInt x * toInt y := by
induction x using Quotient.inductionOn with | h p =>
induction y using Quotient.inductionOn with | h q =>
show ((p.1 * q.1 + p.2 * q.2 : ℕ) : ℤ) - ((p.1 * q.2 + p.2 * q.1 : ℕ) : ℤ)
= ((p.1 : ℤ) - p.2) * ((q.1 : ℤ) - q.2)
push_cast
ring/-- **The construction really produces the integers.** The comparison map is a bijection:
injective because `a - b = c - d` in `ℤ` gives `a + d = c + b` in `ℕ`, and surjective because
`n = n⁺ - n⁻` with `n⁺ = max(n, 0)` and `n⁻ = max(-n, 0)`. Together with `toInt_add` and
`toInt_mul`, it is an isomorphism of rings. -/
theorem toInt_bijective : Function.Bijective toInt := by
constructor
· intro x y hxy
induction x using Quotient.inductionOn with | h p =>
induction y using Quotient.inductionOn with | h q =>
change (p.1 : ℤ) - p.2 = (q.1 : ℤ) - q.2 at hxy
apply Quotient.sound
show p.1 + q.2 = q.1 + p.2
omega
· intro n
refine ⟨Quotient.mk intSetoid (n.toNat, (-n).toNat), ?_⟩
show ((n.toNat : ℕ) : ℤ) - (((-n).toNat : ℕ) : ℤ) = n
omegaFractions. Transitivity of in any commutative ring without zero divisors, with the cancellation of as the crucial last line; the counterexample, checked by decide; and Mathlib's statements that is the field of fractions of and that ring homomorphisms out of are unique.
/-- **Transitivity of equality of fractions**, `(a, b) ~ (c, d) ⟺ ad = cb`, in any commutative
ring without zero divisors (such as `ℤ`). From `ad = cb` and `cf = ed` we get
`(af)d = (eb)d`, and we cancel `d ≠ 0`. That cancellation is exactly where "no zero divisors"
is used. -/
theorem frac_trans {R : Type*} [CommRing R] [NoZeroDivisors R] {a b c d e f : R} (hd : d ≠ 0)
(h₁ : a * d = c * b) (h₂ : c * f = e * d) : a * f = e * b := by
have h : (a * f) * d = (e * b) * d :=
calc (a * f) * d = (a * d) * f := by ring
_ = (c * b) * f := by rw [h₁]
_ = b * (c * f) := by ring
_ = b * (e * d) := by rw [h₂]
_ = (e * b) * d := by ring
exact mul_right_cancel₀ hd h/-- **With zero divisors, "fractions" break.** In `ℤ/6ℤ`, using the same rule
`(a, b) ~ (c, d) ⟺ ad = cb` with non-zero denominators, `3/1 ~ 0/2` and `0/2 ~ 0/1`, but
`3/1 ≁ 0/1`: the relation is not transitive, because `2 · 3 = 0` lets us "cancel" wrongly. -/
theorem frac_trans_fails_zmod6 :
let r : ZMod 6 × ZMod 6 → ZMod 6 × ZMod 6 → Prop := fun p q => p.1 * q.2 = q.1 * p.2
r (3, 1) (0, 2) ∧ r (0, 2) (0, 1) ∧ ¬ r (3, 1) (0, 1) := by
decide/-- **`ℚ` is the field of fractions of `ℤ`.** Mathlib's instance `Rat.isFractionRing`: every
rational is `a / b` with `a, b ∈ ℤ`, `b ≠ 0`, and `a / b = c / d` exactly when `ad = cb`. -/
theorem rat_isFractionRing : IsFractionRing ℤ ℚ := Rat.isFractionRing/-- **A universal property in miniature:** there is at most one ring homomorphism from `ℚ` to
any ring, because it is forced on `ℤ` and then on fractions. Mathlib's `RingHom.ext_rat`. -/
theorem ringHom_rat_unique {R : Type*} [Semiring R] (f g : ℚ →+* R) : f = g :=
RingHom.ext_rat f gDedekind cuts. A cut is a structure carrying a set of rationals together with proofs of the three conditions. The rational cuts and the cut for (Proposition 4, including the step ) are constructed; cuts are totally ordered (Proposition 5); and the union of a bounded non-empty family is a cut and its least upper bound (Theorem 6).
/-- A **Dedekind cut**: a set of rationals that is non-empty, not everything, closed downwards,
and has no greatest element. Think of it as "the rationals below a real number". -/
structure Cut where
/-- The rationals below the real number. -/
carrier : Set ℚ
nonempty : carrier.Nonempty
ne_univ : carrier ≠ Set.univ
lower : ∀ ⦃p q : ℚ⦄, p ∈ carrier → q < p → q ∈ carrier
no_max : ∀ p ∈ carrier, ∃ q ∈ carrier, p < q/-- Cuts are ordered by inclusion. -/
instance instLE : LE Cut := ⟨fun A B => A.carrier ⊆ B.carrier⟩/-- The cut of a rational number `r`: all rationals below `r`. -/
def ofRat (r : ℚ) : Cut where
carrier := {q | q < r}
nonempty := ⟨r - 1, by simp⟩
ne_univ := fun h => lt_irrefl r (h ▸ Set.mem_univ r : r ∈ {q : ℚ | q < r})
lower := fun _ _ hp hq => lt_trans hq hp
no_max := fun p hp => by
have hp' : p < r := hp
exact ⟨(p + r) / 2, show (p + r) / 2 < r by linarith, by linarith⟩/-- **The cut of `√2`:** the rationals `q` with `q < 0` or `q² < 2`. It has no greatest element:
if `0 ≤ p` and `p² < 2`, the rational `(2p + 2)/(p + 2)` is larger than `p` and its square is
still below `2`. -/
def sqrtTwo : Cut where
carrier := {q | q < 0 ∨ q * q < 2}
nonempty := ⟨0, Or.inr (by norm_num)⟩
ne_univ := by
intro h
have h2 : (2 : ℚ) ∈ {q : ℚ | q < 0 ∨ q * q < 2} := h ▸ Set.mem_univ 2
rcases h2 with h2 | h2 <;> norm_num at h2
lower := by
intro p q hp hqp
rcases lt_or_ge q 0 with hq | hq
· exact Or.inl hq
· right
rcases hp with hp | hp
· linarith
· nlinarith
no_max := by
intro p hp
rcases lt_or_ge p 0 with hp0 | hp0
· exact ⟨0, Or.inr (by norm_num), hp0⟩
· have hp2 : p * p < 2 := by
rcases hp with hp | hp
· linarith
· exact hp
have hpos : 0 < p + 2 := by linarith
refine ⟨(2 * p + 2) / (p + 2), Or.inr ?_, ?_⟩
· rw [div_mul_div_comm, div_lt_iff₀ (by positivity)]
nlinarith
· rw [lt_div_iff₀ hpos]
nlinarith/-- **Cuts are totally ordered.** If `A ⊄ B`, pick `p ∈ A` with `p ∉ B`. Every `q ∈ B` is below
`p` (otherwise `p ≤ q` would put `p` in `B`, which is closed downwards), so `q ∈ A`. -/
theorem le_total (A B : Cut) : A ≤ B ∨ B ≤ A := by
by_cases h : A ≤ B
· exact Or.inl h
· right
obtain ⟨p, hpA, hpB⟩ := Set.not_subset.mp h
intro q hqB
rcases lt_or_ge q p with hqp | hpq
· exact A.lower hpA hqp
· exfalso
rcases hpq.lt_or_eq with hlt | heq
· exact hpB (B.lower hqB hlt)
· exact hpB (heq ▸ hqB)/-- The **supremum** of a non-empty family `S` of cuts that is bounded above by a cut `B`: the
union of the family. The proofs check that the union is again a cut: it is non-empty because `S`
and its members are; it is not everything because it lies inside `B`; and it is closed
downwards and has no greatest element because each member is and has none. -/
def sup (S : Set Cut) (hS : S.Nonempty) (hB : ∃ B : Cut, ∀ A ∈ S, A ≤ B) : Cut where
carrier := ⋃ A ∈ S, A.carrier
nonempty := by
obtain ⟨A, hA⟩ := hS
obtain ⟨p, hp⟩ := A.nonempty
exact ⟨p, Set.mem_biUnion hA hp⟩
ne_univ := by
obtain ⟨B, hB⟩ := hB
obtain ⟨q, hq⟩ : ∃ q, q ∉ B.carrier := by
by_contra h
exact B.ne_univ (Set.eq_univ_of_forall fun q => by_contra fun hq => h ⟨q, hq⟩)
intro h
have hq' : q ∈ ⋃ A ∈ S, A.carrier := h ▸ Set.mem_univ q
obtain ⟨A, hA, hqA⟩ := Set.mem_iUnion₂.mp hq'
exact hq (hB A hA hqA)
lower := by
intro p q hp hqp
obtain ⟨A, hA, hpA⟩ := Set.mem_iUnion₂.mp hp
exact Set.mem_biUnion hA (A.lower hpA hqp)
no_max := by
intro p hp
obtain ⟨A, hA, hpA⟩ := Set.mem_iUnion₂.mp hp
obtain ⟨q, hqA, hpq⟩ := A.no_max p hpA
exact ⟨q, Set.mem_biUnion hA hqA, hpq⟩/-- **The least-upper-bound property of the cuts.** The union `sup S` is an upper bound of `S`
(each member is contained in the union) and it is the least one (if every member of `S` lies in
`C`, so does their union). -/
theorem sup_isLUB (S : Set Cut) (hS : S.Nonempty) (hB : ∃ B : Cut, ∀ A ∈ S, A ≤ B) :
(∀ A ∈ S, A ≤ sup S hS hB) ∧ (∀ C : Cut, (∀ A ∈ S, A ≤ C) → sup S hS hB ≤ C) := by
constructor
· intro A hA p hp
exact Set.mem_biUnion hA hp
· intro C hC p hp
obtain ⟨A, hA, hpA⟩ := Set.mem_iUnion₂.mp hp
exact hC A hA hpAWhat Mathlib provides. Completeness of Mathlib's (built from Cauchy sequences), and the isomorphism between any two conditionally complete linearly ordered fields — Theorem 9, formalised in full in Mathlib with exactly the map .
/-- **Completeness of Mathlib's `ℝ`** (built from Cauchy sequences of rationals): every non-empty
set of reals that is bounded above has a least upper bound. This is `Real.exists_isLUB`. -/
theorem real_complete {S : Set ℝ} (hne : S.Nonempty) (hbdd : BddAbove S) : ∃ x, IsLUB S x :=
Real.exists_isLUB hne hbdd/-- **Uniqueness of the complete ordered field.** Any two conditionally complete linearly
ordered fields are isomorphic as ordered rings: Mathlib's
`ConditionallyCompleteLinearOrderedField.inducedOrderRingIso`, which sends `x` to the supremum
of the rationals below `x`. (Mathlib also proves the isomorphism is unique.) -/
noncomputable def complete_ordered_field_unique (F G : Type*)
[Field F] [ConditionallyCompleteLinearOrder F] [IsStrictOrderedRing F]
[Field G] [ConditionallyCompleteLinearOrder G] [IsStrictOrderedRing G] : F ≃+*o G :=
ConditionallyCompleteLinearOrderedField.inducedOrderRingIso F GNot formalised here: the ring axioms for the constructed integers (they follow by transport along the bijection toInt, but we do not build the CommRing instance), the field structure on cuts (addition and multiplication of cuts), the fact that the √2 cut is not rational, and the Cauchy construction itself (Mathlib's Real is that construction).
Testing well-definedness, and approaching a gap
An operation on classes is well defined if every choice of representatives gives equivalent answers. A computer can try all small choices. The correct rules pass; the tempting wrong ones — multiplying integer pairs componentwise, or adding fractions by adding numerators and denominators (the mediant) — fail, and the search returns explicit counterexamples. A counterexample is a proof of failure; a pass is only evidence.
"""Is an operation on equivalence classes well defined? Test every representative.
Integers are built as classes of pairs (a, b) of naturals with
(a, b) ~ (c, d) iff a + d = c + b, and fractions as classes of pairs (a, b)
with b != 0 and (a, b) ~ (c, d) iff ad = cb. An operation on pairs defines an
operation on classes only if equivalent inputs always give equivalent outputs.
The experiment checks this exhaustively for small pairs: the lesson's addition
and multiplication pass, while two tempting rules - "multiply componentwise"
for integer pairs and the "mediant" (a + c)/(b + d) for fractions - fail, and
it prints a counterexample for each. It also shows "fractions" over Z/6Z
breaking transitivity. Exhaustive for small cases; the general claims are
the lesson's proofs.
"""
import itertools
N = range(7)
def int_rel(p, q):
"""(a, b) ~ (c, d) iff a + d = c + b: both stand for a - b = c - d."""
return p[0] + q[1] == q[0] + p[1]
def int_add(p, q):
"""(a, b) + (c, d) = (a + c, b + d)."""
return (p[0] + q[0], p[1] + q[1])
def int_mul(p, q):
"""(a, b)(c, d) = (ac + bd, ad + bc), from (a - b)(c - d)."""
return (p[0] * q[0] + p[1] * q[1], p[0] * q[1] + p[1] * q[0])
def int_bad(p, q):
"""A tempting but wrong rule: multiply componentwise."""
return (p[0] * q[0], p[1] * q[1])
def frac_rel(p, q):
"""(a, b) ~ (c, d) iff ad = cb."""
return p[0] * q[1] == q[0] * p[1]
def frac_add(p, q):
"""a/b + c/d = (ad + cb)/(bd)."""
return (p[0] * q[1] + q[0] * p[1], p[1] * q[1])
def mediant(p, q):
"""The 'freshman sum' (a + c)/(b + d)."""
return (p[0] + q[0], p[1] + q[1])
def counterexample(pairs, rel, op):
"""First (p, p', q, q') with p ~ p', q ~ q' but op(p, q) !~ op(p', q')."""
equiv = [(p, p2) for p in pairs for p2 in pairs if rel(p, p2)]
for (p, p2), (q, q2) in itertools.product(equiv, repeat=2):
if not rel(op(p, q), op(p2, q2)):
return p, p2, q, q2
return None
def transitivity_failure(n):
"""Pairs in Z/nZ with non-zero second entry breaking transitivity."""
pairs = [(a, b) for a in range(n) for b in range(1, n)]
def rel(p, q):
return (p[0] * q[1] - q[0] * p[1]) % n == 0
for x, y, z in itertools.product(pairs, repeat=3):
if rel(x, y) and rel(y, z) and not rel(x, z):
return x, y, z
return None
def main():
ints = [(a, b) for a in N for b in N]
fracs = [(a, b) for a in range(0, 5) for b in range(1, 6)]
print(f"Integer pairs (a, b) with 0 <= a, b <= 6: {len(ints)}")
for name, op in [("(a+c, b+d)", int_add), ("(ac+bd, ad+bc)", int_mul),
("(ac, bd)", int_bad)]:
bad = counterexample(ints, int_rel, op)
verdict = "well defined" if bad is None else f"FAILS: {bad}"
print(f" {name:<16}{verdict}")
p, p2, q, q2 = counterexample(ints, int_rel, int_bad)
print(f" {p} ~ {p2} and {q} ~ {q2}, but the products")
print(f" {int_bad(p, q)} and {int_bad(p2, q2)} are not equivalent")
print()
print(f"Fraction pairs a/b with 0 <= a <= 4, 1 <= b <= 5: {len(fracs)}")
for name, op in [("(ad+cb)/(bd)", frac_add), ("(a+c)/(b+d)", mediant)]:
bad = counterexample(fracs, frac_rel, op)
verdict = "well defined" if bad is None else f"FAILS: {bad}"
print(f" {name:<16}{verdict}")
p, p2, q, q2 = counterexample(fracs, frac_rel, mediant)
m1, m2 = mediant(p, q), mediant(p2, q2)
print(f" {p[0]}/{p[1]} = {p2[0]}/{p2[1]} and {q[0]}/{q[1]} = {q2[0]}/{q2[1]},"
f" but {m1[0]}/{m1[1]} != {m2[0]}/{m2[1]}")
print()
for n in (5, 6):
print(f"'Fractions' over Z/{n}Z, transitivity counterexample:",
transitivity_failure(n))
print()
print("Epistemic status: exhaustive checks over small representatives, plus")
print("explicit counterexamples. A failure found here is a proof that the")
print("rule is not well defined; a pass is only evidence. The lesson proves")
print("well-definedness of the correct operations for all representatives.")
if __name__ == "__main__":
main()The second experiment works entirely inside , with exact fractions. The climbing sequence stays inside the cut and the Babylonian sequence outside it, and the gap between them shrinks rapidly — two equivalent Cauchy sequences of rationals, crowding towards a point that does not contain.
"""Closing in on the square root of 2 with rationals only: cuts and Cauchy sequences.
Two sequences of exact fractions approach the "missing" number sqrt(2): the
Babylonian (Newton) iteration x -> (x + 2/x)/2 from above, and the map
q -> (2q + 2)/(q + 2) from below, which the lesson uses to show that the
Dedekind cut {q : q < 0 or q^2 < 2} has no largest element. The experiment
checks with exact rational arithmetic that the lower terms stay inside the
cut, the upper terms stay outside, the gap between them shrinks, and the two
sequences are equivalent Cauchy sequences (their difference tends to 0). It
also checks that no fraction with denominator up to 1000 squares to 2. All
arithmetic is exact; the statements about limits are not proved by it.
"""
from fractions import Fraction
TWO = Fraction(2)
def in_cut(q):
"""Membership in the Dedekind cut of sqrt(2): q < 0 or q^2 < 2."""
return q < 0 or q * q < TWO
def babylonian(x):
"""One Newton step for x^2 = 2: the average of x and 2/x."""
return (x + TWO / x) / 2
def climb(q):
"""The lesson's step inside the cut: (2q + 2)/(q + 2) > q when q^2 < 2."""
return (2 * q + 2) / (q + 2)
def iterate(step, start, n):
"""The list [start, step(start), ..., step^n(start)]."""
terms = [Fraction(start)]
for _ in range(n):
terms.append(step(terms[-1]))
return terms
def no_rational_root(max_den):
"""True if no p/q with 1 <= q <= max_den has (p/q)^2 = 2."""
for q in range(1, max_den + 1):
p = int((2 * q * q) ** 0.5)
if any(r * r == 2 * q * q for r in (p - 1, p, p + 1)):
return False
return True
def main():
upper = iterate(babylonian, 2, 5)
lower = iterate(climb, 1, 5)
print(" n lower (in cut) upper (not in cut) gap upper - lower")
for n, (lo, up) in enumerate(zip(lower, upper)):
lo_s, up_s = f"{lo}", f"{up}"
if len(up_s) > 18:
up_s = f"({len(str(up.numerator))} digits)/..."
gap = float(up - lo)
print(f"{n:>2} {lo_s:<15} {up_s:<18} {gap:.3e}")
print("all lower terms in the cut:", all(in_cut(q) for q in lower))
print("no upper term in the cut: ", not any(in_cut(x) for x in upper))
print("lower terms increase: ",
all(a < b for a, b in zip(lower, lower[1:])))
err = [float(x * x - TWO) for x in upper]
print("upper x^2 - 2:", ", ".join(f"{e:.1e}" for e in err[1:]))
print("(Newton roughly squares the error at each step.)")
print("no fraction p/q with q <= 1000 squares to 2:", no_rational_root(1000))
print()
print("Epistemic status: exact rational arithmetic for finitely many terms.")
print("It shows the gap shrinking but cannot show that it tends to 0, nor")
print("that sqrt(2) is irrational (only that no small fraction works). Those")
print("are proved in the lesson and in the lesson on real numbers.")
if __name__ == "__main__":
main()Exercises
1. Constructing ℤ, ℚ and ℝ
Warm-upHumanWith iff , which pairs of natural numbers lie in the class that represents the integer ? (Choose all that apply.)
2. Constructing ℤ, ℚ and ℝ
Warm-upHumanUsing , compute . Which integer does the resulting class represent?
3. Constructing ℤ, ℚ and ℝ
CoreHumanIn the proof that equality of fractions () is transitive, from and we derive . Which step needs the hypothesis that the ring has no zero divisors?
4. Constructing ℤ, ℚ and ℝ
CoreHumanEach rule below is defined on a representative (or two, and ) of a rational number, with . Which rules are not well defined as functions of the rational numbers? (Choose all that apply.)
5. Constructing ℤ, ℚ and ℝ
CoreHumanWhich of these subsets of are Dedekind cuts (non-empty, not all of , closed downwards, no greatest element)? (Choose all that apply.)
6. Constructing ℤ, ℚ and ℝ
CoreHumanWhich example shows that is not complete (that not every non-empty, bounded-above subset has a least upper bound in )?
7. Constructing ℤ, ℚ and ℝ
CoreFormalIn the lesson's Lean file, PairInt.add is defined with Quotient.map₂ (fun p q => (p.1 + q.1, p.2 + q.2)) (proof). What is the second argument, and what happens if you leave it out?
8. Constructing ℤ, ℚ and ℝ
StretchComputationalImplement the integers as pairs of natural numbers. Write canonical(p), returning the representative of the class of p that has a in at least one coordinate, and mul(p, q) using . Then check, for all pairs with entries up to , that mul is well defined: equivalent inputs give outputs with the same canonical form.
Common misconceptions
Misconception
"Operations on equivalence classes are automatically well defined." They are not. Componentwise multiplication of integer pairs, and the mediant of fractions, are perfectly good operations on pairs that do not respect the equivalence: but the mediants of these with are . Every operation on classes needs a proof that it does not depend on the representatives.
Misconception
"The constructions tell us what numbers really are." They show that structures with the required properties exist (given and set theory), not that "is" a set of pairs or "is" a set of rationals. The Dedekind and Cauchy constructions produce different sets, yet Theorem 9 says they are isomorphic; what matters is the structure, which is unique up to unique isomorphism.
Misconception
" is complete because between any two rationals there is another." Density is not completeness. The rationals are dense, yet is bounded above with no least upper bound in , and the Babylonian sequence is Cauchy with no rational limit.
Misconception
" is slightly less than ." In the Cauchy construction is the class of , which differs from the constant sequence by : the two sequences are equivalent, so they are the same real number. With cuts: the rationals below are exactly the rationals below .
Misconception
"A cut is the same as its supremum, so is also a cut." Condition 3 (no greatest element) rules out ; without it, every rational would be described by two different cuts. Conventions differ between books (some use upper sets, or allow a greatest element and exclude the other one), but each makes the correspondence one-to-one.
Many ways of seeing
Analysis— Completion of a metric space, and other completions of Q
The Cauchy construction works in any metric space : the completion is the set of Cauchy sequences up to equivalence, and sits densely inside the complete space ; every uniformly continuous map from to a complete space extends uniquely to . Completing for the usual distance gives . But has other distances: for a prime , when with . Completing for gives the field of -adic numbers, in which converges (to ). Ostrowski's theorem (1916) says that up to equivalence these are all the non-trivial absolute values on : so and the are all the completions of (see real analysis and congruences).
Topology— Completeness is connectedness
Give an ordered set its order topology. A densely ordered set without endpoints is connected if and only if it is Dedekind complete (every non-empty bounded-above subset has a supremum). So the completeness of is the same thing as its connectedness — the intermediate value theorem in disguise — while is totally disconnected: for any irrational , the sets and split into two disjoint open pieces. The Dedekind construction is an instance of a general order-theoretic completion, the Dedekind–MacNeille completion, which embeds any partially ordered set into a complete lattice (see point-set topology).
Algebra— Group completion and localisation
The construction of works for any commutative monoid : pairs modulo iff for some give an abelian group , the Grothendieck group, with a universal property — every monoid homomorphism from to an abelian group factors uniquely through . (The extra is needed when lacks cancellation; for it can be dropped.) Applied to isomorphism classes of vector bundles, this is the starting point of topological K-theory. The construction of is localisation: for a multiplicative subset of a commutative ring , the ring of fractions — used constantly in commutative algebra and algebraic geometry.
Logic— Categorical in second-order logic, not in first-order logic
The axioms of a complete ordered field are categorical: by Theorem 9 they have exactly one model up to isomorphism. But the completeness axiom quantifies over all subsets — it is a second-order statement. If we keep only first-order consequences (statements about elements), uniqueness fails: by the compactness theorem there are non-Archimedean ordered fields — such as the hyperreals of non-standard analysis — that satisfy exactly the same first-order sentences as , and by the Löwenheim–Skolem theorem there are countable ones, such as the field of real algebraic numbers. Tarski proved (1948) that this first-order theory, the theory of real closed fields, is decidable (see model theory).
Geometry— Eudoxus, Euclid and the continuous line
Book V of Euclid's Elements (about 300 BCE), usually credited to Eudoxus, defines when two ratios of magnitudes are equal: if, for all whole numbers , exactly when , and likewise with and . In modern terms, a ratio is determined by the set of fractions below it — a Dedekind cut, more than two thousand years early. Dedekind discussed the relationship with Euclid's definition in letters to Rudolf Lipschitz (1876). Geometry also motivated completeness: Euclid's very first construction assumes that two circles cross where they ought to, a continuity assumption that rational coordinates do not satisfy. Hilbert's axioms for geometry (1899) acquired, in later editions, an axiom of completeness for exactly this reason, so that the points of a line correspond to the real numbers (see Euclidean geometry).
Wonder Trails
History and global context
- Ancient ratios. Greek mathematicians discovered incommensurable magnitudes (the side and diagonal of a square), and Eudoxus's theory of proportion, preserved in Book V of Euclid's Elements, handled them rigorously without numbers. Negative quantities and zero were treated as numbers in Chinese and Indian mathematics many centuries before Europe (see the integers lesson).
- Decimals. Decimal fractions were used by al-Uqlīdisī (952–953 CE, Damascus) and al-Kāshī (1427, Samarkand), and popularised in Europe by Simon Stevin's De Thiende (1585). An infinite decimal is, implicitly, a Cauchy sequence.
- Arithmetisation. In the nineteenth century, analysts wanted the foundations of calculus to rest on arithmetic rather than geometric intuition. William Rowan Hamilton (1837) defined complex numbers as pairs of reals. Karl Weierstrass lectured on a construction of the reals in Berlin in the 1860s. In 1872 three constructions appeared: Charles Méray's and Georg Cantor's by sequences (Méray's dated from 1869), and Richard Dedekind's by cuts, in Stetigkeit und irrationale Zahlen, an idea he said he had conceived in 1858 while teaching calculus in Zürich.
- Foundations of the naturals. Dedekind's Was sind und was sollen die Zahlen? (1888) and Giuseppe Peano's axioms (1889) characterised the natural numbers themselves. David Hilbert (1900) described the reals axiomatically as a complete ordered field, and Edmund Landau's Grundlagen der Analysis (1930) carried out the whole chain of constructions in full detail.
Further reading
- Edmund Landau, Foundations of Analysis (1930; English translation 1951) — every step from the Peano axioms to the complex numbers, in full.
- Walter Rudin, Principles of Mathematical Analysis (1953; 3rd ed. 1976) — the appendix to chapter 1 constructs from Dedekind cuts.
- Terence Tao, Analysis I (2006) — constructs , and (by Cauchy sequences) with careful attention to well-definedness.
- Richard Dedekind, Essays on the Theory of Numbers (English translation by W. W. Beman, 1901) — Dedekind's own accounts of cuts and of the natural numbers.
- Heinz-Dieter Ebbinghaus and others, Numbers (German 1983; English 1990) — the number systems, their constructions and their history, from to the octonions and beyond.