The only thing given is \(a=a\). Pairs, composition, \(0\), \(1\), sum, product, recursion, induction, \(\mathbb N\), \(\mathbb Z\), the dyadic points, the unit length and \(\mathbb R\) are computed from it in this order. The one step used on the infinite side is the whole of a level (C26).
The statement \(a=a\) has two places. Reading the two places separately gives the pair \((a,a)\); this is the diagonal
At most one. \(X\) has at most one point when every pair of \(X\) is a diagonal pair, that is, when \(\Delta :X\to X\times X\) reaches every pair.
Exactly one. \(X\) has exactly one point when it has at most one and it has a point.
Every later use of “exactly one” is therefore a statement about the diagonal.
Let \(P=\{(x,y):x=y\}\). Then \(\Delta :A\to P\) and \(\pi _1:P\to A\).
(J). \(\Delta \) and \(\pi _1\) are inverse to each other: the only equal pairs are the diagonal pairs.
Fixing the left place at \(a\) gives \(\Sigma _x(a=x)\), and its only point is \(\Delta (a)=(a,\mathrm {refl})\).
Carrying. If \(p:a=x\), then \((x,p)=(a,\mathrm {refl})\) by (J), so anything stated at \(a\) is carried to \(x\): \(P(a)\to P(x)\). Carrying along \(\mathrm {refl}\) changes nothing.
Composition of equalities. For \(p:a=b\) and \(q:b=c\), the composite \(p\cdot q:a=c\) is \(p\) carried along \(q\). By (J) each law needs to be computed only at \(\mathrm {refl}\):
where \(p^{-1}\) is \(\mathrm {refl}\) carried along \(p\).
Composition of relations.
The first line is (J): the middle place contracts to one point.
Arrows. An arrow is a relation \(R\) for which \(\Sigma _b R(a,b)\) has exactly one point for each \(a\); that point is written \(f(a)\). Arrows are closed under composition,
Kernel.
\(1\). A kind with a point in which every pair is diagonal; \(\Sigma _x(a=x)\) is one. Exactly one arrow goes into it from any \(X\).
\(\times \). The right adjoint of \(\Delta \): an arrow \(C\to A\times B\) is two arrows, one for each place.
\(+\). The left adjoint of \(\Delta \): an arrow \(A+B\to C\) is two arrows, one from each part. Computing equality inside \(A+B\),
\(0\). The place where the pair \((\mathrm {inl},\mathrm {inr})\) falls on the diagonal. Equivalently \(\neg (a=a)=((a=a)\to 0)\simeq (1\to 0)\simeq 0\). Exactly one arrow goes out of it to any \(X\).
Let \(F\) be built from \(0,1,+,\times \) and gluing. An \(F\)-structure on \(A\) is an arrow \(\alpha :FA\to A\); a co-structure is an arrow \(\gamma :A\to FA\).
Least. The structure with exactly one arrow out to every structure. It is the colimit of \(0\to F0\to F^{2}0\to \cdots \).
Greatest. The co-structure with exactly one arrow in from every co-structure. It is the limit of \(1\leftarrow F1\leftarrow F^{2}1\leftarrow \cdots \).
Both are fixed. Let \(\alpha :FA\to A\) be least. Then \(F\alpha :FFA\to FA\) is a structure, so there is one \(h:A\to FA\) with \(h\circ \alpha =F\alpha \circ Fh\). The composite \(\alpha \circ h:A\to A\) keeps the structure, and so does \(\mathrm {id}\); hence
That the two chains have a colimit and a limit is the whole of a level (C26); it is the only step here that is used and not computed.
Add to \(a\) one arrow \(s:a\to a\) and compose (Section 69.3).
(U). For any \(X\) and any \(e:X\to X\) there is exactly one functor from the loop sending \(s\) to \(e\).
Put
\(1+X\) is forced. A point and an arrow on \(X\) are one arrow from \(1+X\):
Recursion is the “there is” of (U): for \((X,z,e)\),
Induction is the “exactly one” of (U): if \(P\subseteq \mathbb N\) contains \(0\) and is closed under \(S\), then \(\mathbb N\to P\hookrightarrow \mathbb N\) and \(\mathrm {id}\) both keep the structure, so the pair is diagonal and \(P=\mathbb N\).
\(Sn\neq 0\). Into \((1+1,\ \mathrm {inl},\ \text {constant }\mathrm {inr})\) the arrow is \(h(0)=\mathrm {inl}\), \(h(Sn)=\mathrm {inr}\), and \(\mathrm {inl}\neq \mathrm {inr}\).
\(K(S)=\Delta \). Into \((1+\mathbb N,\ \mathrm {inl},\ \mathrm {inr}\circ [0,S])\):
The same, read as equalities.
Finite kinds and counting. \(\mathrm {Fin}(n)\) is the set of places of \(s\) in \(s^{n}\); there are \(n\), and \(\mathrm {Fin}(n+1)=1+\mathrm {Fin}(n)\). If \(1+A\cong 1+B\) by \(f\) then \(A\cong B\): when \(f(*)=*\) restrict \(f\); when \(f(*)=b_0\) and \(f(a_0)=*\), send \(a_0\) to \(b_0\) and keep \(f\) elsewhere. Hence \(\mathrm {Fin}(m)\cong \mathrm {Fin}(n)\) gives \(m=n\). The order is \(m\le n\) when \(s^{k}\circ s^{m}=s^{n}\) for some \(k\). \(S\) is injective on \(\mathbb N\) and misses \(0\), which no injective arrow on a \(\mathrm {Fin}(n)\) does; so \(\mathbb N\) is not finite, and \(|\mathbb N|=\aleph _0\).
Taking \(e=s^{m}\) in (U) gives one functor \(\mu _m:s\mapsto s^{m}\). Put
Add \(t\) with \(t\circ s=\mathrm {id}=s\circ t\); now \(\mathbb Z=\mathrm {Hom}(a,a)\). The kernel of \((a,b)\mapsto s^{a}t^{b}\) is
Reading one \(s\) as \(s\circ s\) is \(\mu _2\); it is the gluing \(X\vee X\) of two copies end to start. Level \(n\) is the \(2^{n}+1\) boundary points of \(s^{2^{n}}\), and level \(n\) goes into level \(n+1\) by \(k\mapsto 2k\); a point is written \(k/2^{n}=2k/2^{n+1}\). The colimit is \(D\cap [0,1]\), the least kind for gluing. The whole of \(D\) is the colimit of \(\mathbb Z\xrightarrow {\mu _2}\mathbb Z\xrightarrow {\mu _2}\cdots \), in which halving is the inverse of \(\mu _2\). Sum is taken on a common level and product multiplies numerators and adds levels:
A point is a choice of one cell on every level, each inside the last. Level \(n\) has \(2^{n}\) cells and goes down by \(k\mapsto \lfloor k/2\rfloor \), so the limit is the words without end \(2^{\mathbb N}\). A boundary point lies in two cells and has two words,
Equality is read in \(D\). With \(w|_n=\sum _{k\le n}d_k2^{-k}\in D\),
Greatest. \(I\to I\vee I\) sends \([0w]\) to \([w]\) in the left copy and \([1w]\) to \([w]\) in the right copy; the twins of \(\tfrac 12\) go to the glued point. For any co-structure \(c:X\to X\vee X\), write \(0\) when \(c(x)\) is in the left copy and \(1\) when it is in the right copy, and go on. At the glued point both choices are allowed; the left one continues at the end point and gives \(111\cdots \), the right one continues at the start point and gives \(000\cdots \), so the two words are twins. This is the one arrow into \(I\): any other agrees with it on every finite reading, and then equals it by the reading of equality above.
Size. \(0\mapsto 01\), \(1\mapsto 10\) gives words with no constant tail, hence no twins, so \(2^{\mathbb N}\to I\) is injective on them and \(|I|=2^{\aleph _0}\). A list \(e:\mathbb N\to 2^{\mathbb N}\) misses \(n\mapsto \neg \,e(n)(n)\), since \(\neg \) has no fixed point; so \(2^{\aleph _0}>\aleph _0\).
Arithmetic. Cut at \(n\) digits, every operation is a computation in \(D\) (Section 69.10); equality is the reading of Section 69.11. With the digits \(\{-1,0,1\}\) the mean gives one digit for every two digits read and the product one for every three.
The field laws hold because each side, cut at \(n\) digits, is computed by Sections 69.7–69.8, the two cuts differ by at most \(c\,2^{-n}\), and then the sides are equal.
Order and least upper bound. Words are ordered by the first place where they differ, and twins are neighbours. For a family with a member, the least upper bound is read digit by digit: the digit is \(1\) when some member in the chosen cell has \(1\) there. This is the one arrow into the greatest kind.
A point that is not a fraction. The digits of \(\sqrt {1/2}\) are read by \((2a+1)^{2}<2^{2k+1}\), which is never an equality (odd against even):
\(\mathbb Q\) and cuts. \(\mathbb Q\) is \(\mathbb Z\) with every \(\mu _b\) inverted, with kernel \((a,b)\sim (c,d)\) when \(a\,d=c\,b\); inside \(\mathbb R\) it is the words that are eventually periodic. With \(U(A)\) the upper bounds and \(L(B)\) the lower bounds, \(A\subseteq L(B)\) exactly when \(B\subseteq U(A)\), and a cut is a fixed part of \(LU\). Reading whether the middle lies in the cut is a co-structure for gluing, so the cuts of the unit length have exactly one arrow into \(I\), and it is an isomorphism.
| what comes out | from where |
| pairs, “exactly one” | the two places of \(a=a\), \(\Delta \) |
| composition, identity, laws | matching the middle by \(\Delta \), contracting by (J) |
| injective, \(0\), quotients | a kernel compared with \(\Delta \) |
| least, greatest, fixed | exactly one arrow out, exactly one arrow in |
| recursion, induction | “there is” and “exactly one” in (U) |
| sum, product, power | composing arrows, composing functors, iterating |
| \(\mathbb Z\), \(D\), \(\mathbb Q\) | inverting \(s\), \(\mu _2\), every \(\mu _b\) |
| \(I\), \(\mathbb R\) | the greatest side of gluing, and a kernel |
The file checks Sections 69.1–69.9; for \(D\), the kernel and that sum and product do not depend on the representative; for \(I\), that the reading of equality is an equivalence, that twins satisfy it on every level, and that the two choices at a glued point are twins; for \(\mathbb R\), the gluing, \(\tfrac 13+\tfrac 23=1\) and \(\tfrac 13+\tfrac 13=\tfrac 23\) on every level, and the first eight digits of \(\sqrt {1/2}\). The least upper bound and the converse reading of twins use excluded middle and are not in the file; the field laws of \(\mathbb R\) are checked on each level in \(D\).
OneChain2.lean
/-
OneChain.lean
From a = a to the numbers: core Lean 4 only (no Mathlib, no imports).
No `axiom`, no `sorry`, no `propext`, no `Classical`, no `Quot.sound`,
no `funext`. The `#print axioms` lines at the end report this.
Sections 1-9: a = a, composition, N, Z, words. Sections 10-12: D, I, R.
-/
universe u
/-! ## 1. Pairs and the diagonal -/
section Diagonal
variable {α : Type u}
def diag (a : α) : α × α := (a, a)
theorem fst_diag (a : α) : (diag a).1 = a := rfl
theorem snd_diag (a : α) : (diag a).2 = a := rfl
end Diagonal
/-! ## 2. (J): the only equal pairs are the diagonal pairs -/
inductive Path {α : Type u} (a : α) : α → Type u where
| refl : Path a a
namespace Path
variable {α : Type u}
/-- (J): everything equal to `a` is the one point `(a, refl)`. -/
theorem contract (a x : α) (p : Path a x) :
(Sigma.mk x p : Sigma (fun y => Path a y)) = Sigma.mk a Path.refl := by
cases p; rfl
/-! ## 3. Composition of equalities, with its laws -/
def carry {P : α → Type u} {a x : α} : Path a x → P a → P x
| .refl, h => h
def trans {a b c : α} : Path a b → Path b c → Path a c
| p, .refl => p
def symm {a b : α} : Path a b → Path b a
| .refl => .refl
theorem trans_refl {a b : α} (p : Path a b) : trans p .refl = p := rfl
theorem refl_trans {a b : α} (q : Path a b) : trans .refl q = q := by
cases q; rfl
theorem trans_assoc {a b c d : α} (p : Path a b) (q : Path b c) (r : Path c d) :
trans (trans p q) r = trans p (trans q r) := by
cases r; rfl
theorem trans_symm {a b : α} (p : Path a b) : trans p (symm p) = .refl := by
cases p; rfl
end Path
/-! ## 3'. Composition of relations: match the middle, then forget it -/
section Relations
variable {α β γ δ : Type u}
/-- Unit law: putting the diagonal in the middle changes nothing. -/
theorem comp_unit (R : α → β → Prop) (a : α) (c : β) :
(∃ b, a = b ∧ R b c) ↔ R a c :=
⟨fun ⟨_, h, r⟩ => by cases h; exact r, fun r => ⟨a, rfl, r⟩⟩
theorem comp_assoc (R : α → β → Prop) (S : β → γ → Prop) (T : γ → δ → Prop)
(a : α) (d : δ) :
(∃ c, (∃ b, R a b ∧ S b c) ∧ T c d) ↔ (∃ b, R a b ∧ ∃ c, S b c ∧ T c d) :=
⟨fun ⟨c, ⟨b, r, s⟩, t⟩ => ⟨b, r, c, s, t⟩,
fun ⟨b, r, c, s, t⟩ => ⟨c, ⟨b, r, s⟩, t⟩⟩
/-- Composition of arrows is computed, not assumed: `(g ∘ f) a = g (f a)`. -/
theorem comp_arrows (f : α → β) (g : β → γ) (a : α) (c : γ) :
(∃ b, f a = b ∧ g b = c) ↔ g (f a) = c :=
⟨fun ⟨_, h, k⟩ => by cases h; exact k, fun k => ⟨f a, rfl, k⟩⟩
/-- The diagonal lies in every kernel. -/
theorem diag_le_ker (f : α → β) (x : α) : f x = f x := rfl
end Relations
/-! ## 4. Sum: the two parts do not meet; `0` is the negation of `a = a` -/
section SumZero
variable {α β : Type u}
theorem inl_ne_inr (a : α) (b : β) : (Sum.inl a : Sum α β) ≠ Sum.inr b :=
fun h => nomatch h
theorem inr_inj {b b' : β} (h : (Sum.inr b : Sum α β) = Sum.inr b') : b = b' :=
Sum.inr.inj h
theorem not_not_refl (a : α) : ¬ ¬ (a = a) := fun h => h rfl
end SumZero
/-! ## 5. One loop: ℕ, recursion, induction -/
inductive N where
| z : N
| s : N → N
namespace N
/-- Recursion: the "there is" of (U). -/
def iter {X : Type u} (x0 : X) (e : X → X) : N → X
| .z => x0
| .s n => e (iter x0 e n)
/-- The "exactly one" of (U). -/
theorem iter_unique {X : Type u} (x0 : X) (e : X → X) (h : N → X)
(h0 : h N.z = x0) (hs : ∀ n, h (N.s n) = e (h n)) :
∀ n, h n = iter x0 e n := by
intro n
induction n with
| z => exact h0
| s n ih => exact (hs n).trans (congrArg e ih)
/-- Induction. -/
theorem ind (P : N → Prop) (h0 : P N.z) (hs : ∀ n, P n → P (N.s n)) :
∀ n, P n := by
intro n
induction n with
| z => exact h0
| s n ih => exact hs n ih
/-- `[0, S] : 1 + ℕ → ℕ` and its inverse (the least kind is fixed). -/
def unpred : Sum Unit N → N
| .inl _ => N.z
| .inr n => N.s n
def pred : N → Sum Unit N
| .z => .inl ()
| .s n => .inr n
theorem pred_unpred (x : Sum Unit N) : pred (unpred x) = x := by
cases x <;> rfl
theorem unpred_pred (n : N) : unpred (pred n) = n := by
cases n <;> rfl
/-- `S n ≠ 0`, read off a map into `1 + 1`. -/
def isS : N → Sum Unit Unit :=
iter (X := Sum Unit Unit) (Sum.inl ()) (fun _ => Sum.inr ())
theorem s_ne_z (n : N) : N.s n ≠ N.z :=
fun h =>
have h' : (Sum.inr () : Sum Unit Unit) = Sum.inl () := congrArg isS h
nomatch h'
/-- The kernel of `S` is the diagonal, read off `pred`. -/
theorem s_inj {m n : N} (h : N.s m = N.s n) : m = n :=
have h' : (Sum.inr m : Sum Unit N) = Sum.inr n := congrArg pred h
Sum.inr.inj h'
/-! ## 6. Sum is composition: `add m n = S^m n` -/
def add (m n : N) : N := iter n N.s m
theorem z_add (n : N) : add N.z n = n := rfl
theorem s_add (m n : N) : add (N.s m) n = N.s (add m n) := rfl
theorem add_z (m : N) : add m N.z = m := by
induction m with
| z => rfl
| s m ih => exact congrArg N.s ih
theorem add_s (m n : N) : add m (N.s n) = N.s (add m n) := by
induction m with
| z => rfl
| s m ih => exact congrArg N.s ih
theorem add_comm (m n : N) : add m n = add n m := by
induction m with
| z => exact (add_z n).symm
| s m ih => exact (congrArg N.s ih).trans (add_s n m).symm
theorem add_assoc (a b c : N) : add (add a b) c = add a (add b c) := by
induction a with
| z => rfl
| s a ih => exact congrArg N.s ih
theorem add_left_comm (a b c : N) : add a (add b c) = add b (add a c) :=
(add_assoc a b c).symm.trans
((congrArg (fun t => add t c) (add_comm a b)).trans (add_assoc b a c))
theorem add_right_cancel {a b : N} (c : N) (h : add a c = add b c) : a = b := by
induction c with
| z => exact (add_z a).symm.trans (h.trans (add_z b))
| s c ih =>
exact ih (s_inj ((add_s a c).symm.trans (h.trans (add_s b c))))
/-! ## 7. Product is iterated sum: `mul m n = (n + ·)^m 0` -/
def mul (m n : N) : N := iter N.z (add n) m
theorem z_mul (n : N) : mul N.z n = N.z := rfl
theorem s_mul (m n : N) : mul (N.s m) n = add n (mul m n) := rfl
theorem mul_z (m : N) : mul m N.z = N.z := by
induction m with
| z => rfl
| s m ih => exact ih
theorem mul_s (m n : N) : mul m (N.s n) = add m (mul m n) := by
induction m with
| z => rfl
| s m ih =>
exact (congrArg (fun t => N.s (add n t)) ih).trans
(congrArg N.s (add_left_comm n m (mul m n)))
theorem mul_comm (m n : N) : mul m n = mul n m := by
induction m with
| z => exact (mul_z n).symm
| s m ih => exact (congrArg (add n) ih).trans (mul_s n m).symm
/-- Distributivity. -/
theorem add_mul (a b c : N) : mul (add a b) c = add (mul a c) (mul b c) := by
induction a with
| z => rfl
| s a ih =>
exact (congrArg (add c) ih).trans (add_assoc c (mul a c) (mul b c)).symm
theorem mul_assoc (a b c : N) : mul (mul a b) c = mul a (mul b c) := by
induction a with
| z => rfl
| s a ih =>
exact (add_mul b (mul a b) c).trans (congrArg (add (mul b c)) ih)
/-- Powers: iterate the product. -/
def num : Nat → N
| 0 => N.z
| k + 1 => N.s (num k)
def pow (m n : N) : N := iter (num 1) (mul m) n
example : add (num 2) (num 3) = num 5 := rfl
example : mul (num 3) (num 2) = num 6 := rfl
example : mul (num 2) (num 3) = num 6 := rfl
example : mul (num 2) (add (num 1) (num 2)) = num 6 := rfl
example : pow (num 2) (num 3) = num 8 := rfl
end N
/-! ## 8. ℤ: pairs up to the kernel of the difference -/
namespace Z
open N
abbrev rel (p q : N × N) : Prop := add p.1 q.2 = add q.1 p.2
theorem rel_refl (p : N × N) : rel p p := rfl
theorem rel_symm {p q : N × N} (h : rel p q) : rel q p := h.symm
theorem add_swap (a b c d : N) :
add (add a b) (add c d) = add (add a d) (add c b) :=
have e1 : add b (add c d) = add d (add c b) :=
(congrArg (add b) (N.add_comm c d)).trans
((N.add_left_comm b d c).trans (congrArg (add d) (N.add_comm b c)))
(N.add_assoc a b (add c d)).trans
((congrArg (add a) e1).trans (N.add_assoc a d (add c b)).symm)
/-- Transitivity: add the two equations and cancel. -/
theorem rel_trans {p q r : N × N} (h1 : rel p q) (h2 : rel q r) : rel p r :=
have k : add (add p.1 r.2) (add q.1 q.2) = add (add r.1 p.2) (add q.1 q.2) :=
(add_swap p.1 r.2 q.1 q.2).trans
((congrArg (fun t => add t (add q.1 r.2)) h1).trans
((congrArg (add (add q.1 p.2)) h2).trans
((N.add_comm (add q.1 p.2) (add r.1 q.2)).trans
(add_swap r.1 q.2 q.1 p.2))))
N.add_right_cancel (add q.1 q.2) k
def zadd (p q : N × N) : N × N := (add p.1 q.1, add p.2 q.2)
def zmul (p q : N × N) : N × N :=
(add (mul p.1 q.1) (mul p.2 q.2), add (mul p.1 q.2) (mul p.2 q.1))
/-- `2 + (-3) = -1`. -/
example : rel (zadd (num 2, num 0) (num 0, num 3)) (num 0, num 1) := rfl
/-- `(-1)(-1) = 1`. -/
example : zmul (num 0, num 1) (num 0, num 1) = (num 1, num 0) := rfl
/-- `(-2) · 3 = -6`. -/
example : zmul (num 0, num 2) (num 3, num 0) = (num 0, num 6) := rfl
end Z
/-! ## 9. The greatest kind for `2 × X`: words without end -/
namespace Word
open N
abbrev W := N → Bool
def head (w : W) : Bool := w N.z
def tail (w : W) : W := fun n => w (N.s n)
theorem iter_shift {X : Type u} (x0 : X) (e : X → X) (n : N) :
iter (e x0) e n = e (iter x0 e n) := by
induction n with
| z => rfl
| s n ih => exact congrArg e ih
/-- The one map into the greatest kind. -/
def unfold {X : Type u} (c : X → Bool × X) (x : X) : W :=
fun n => (c (iter x (fun y => (c y).2) n)).1
theorem unfold_head {X : Type u} (c : X → Bool × X) (x : X) :
head (unfold c x) = (c x).1 := rfl
theorem unfold_tail {X : Type u} (c : X → Bool × X) (x : X) (n : N) :
tail (unfold c x) n = unfold c (c x).2 n :=
congrArg (fun y => (c y).1) (iter_shift x (fun y => (c y).2) n).symm
/-- It is the only one: any map that reads the same digit and goes on
agrees with it at every place. -/
theorem unfold_unique {X : Type u} (c : X → Bool × X) (k : X → W)
(hh : ∀ x, head (k x) = (c x).1)
(ht : ∀ x n, tail (k x) n = k (c x).2 n) :
∀ n x, k x n = unfold c x n := by
intro n
induction n with
| z => intro x; exact hh x
| s n ih =>
intro x
exact (ht x n).trans ((ih (c x).2).trans (unfold_tail c x n).symm)
/-- `not` has no fixed point. -/
theorem not_ne (b : Bool) : (!b) ≠ b := by
cases b
· intro h; exact Bool.noConfusion (h : true = false)
· intro h; exact Bool.noConfusion (h : false = true)
/-- The diagonal: no list of words contains every word. -/
theorem diagonal (e : N → W) : ∀ n, (fun m => !(e m m)) ≠ e n :=
fun n h => not_ne (e n n) (congrFun h n)
end Word
/-! ## 10. D: doubling inverted (the least side of gluing) -/
namespace N
theorem iter_shift {X : Type u} (x0 : X) (e : X → X) (n : N) :
iter (e x0) e n = e (iter x0 e n) := by
induction n with
| z => rfl
| s n ih => exact congrArg e ih
theorem add4 (a b c d : N) :
add (add a b) (add c d) = add (add a c) (add b d) :=
(add_assoc a b (add c d)).trans
((congrArg (add a) (add_left_comm b c d)).trans
(add_assoc a c (add b d)).symm)
/-- Doubling: reading one `s` as `s ∘ s`. -/
def dbl (n : N) : N := add n n
theorem dbl_s (a : N) : dbl (N.s a) = N.s (N.s (dbl a)) :=
congrArg N.s (add_s a a)
theorem dbl_add (a b : N) : dbl (add a b) = add (dbl a) (dbl b) :=
add4 a b a b
theorem dbl_inj {a b : N} (h : dbl a = dbl b) : a = b := by
induction a generalizing b with
| z =>
cases b with
| z => rfl
| s b =>
have e : N.s (N.s (dbl b)) = N.z := (dbl_s b).symm.trans h.symm
exact absurd e (s_ne_z _)
| s a ih =>
cases b with
| z =>
have e : N.s (N.s (dbl a)) = N.z := (dbl_s a).symm.trans h
exact absurd e (s_ne_z _)
| s b =>
have e : N.s (N.s (dbl a)) = N.s (N.s (dbl b)) :=
(dbl_s a).symm.trans (h.trans (dbl_s b))
exact congrArg N.s (ih (s_inj (s_inj e)))
/-- `sh m k` is `k` doubled `m` times: the point `k` seen `m` levels up. -/
def sh (m k : N) : N := iter k dbl m
theorem sh_dbl (m k : N) : sh m (dbl k) = dbl (sh m k) := iter_shift k dbl m
theorem sh_add (m a b : N) : sh m (add a b) = add (sh m a) (sh m b) := by
induction m with
| z => rfl
| s m ih => exact (congrArg dbl ih).trans (dbl_add (sh m a) (sh m b))
theorem sh_sh (m n k : N) : sh m (sh n k) = sh (add m n) k := by
induction m with
| z => rfl
| s m ih => exact congrArg dbl ih
theorem sh_comm (m n k : N) : sh m (sh n k) = sh n (sh m k) :=
(sh_sh m n k).trans
((congrArg (fun t => sh t k) (add_comm m n)).trans (sh_sh n m k).symm)
theorem sh_inj (m : N) {a b : N} (h : sh m a = sh m b) : a = b := by
induction m with
| z => exact h
| s m ih => exact ih (dbl_inj h)
theorem dbl_mul (a b : N) : mul (dbl a) b = dbl (mul a b) := add_mul a a b
theorem mul_dbl (a b : N) : mul a (dbl b) = dbl (mul a b) :=
(mul_comm a (dbl b)).trans
((dbl_mul b a).trans (congrArg dbl (mul_comm b a)))
theorem sh_mul (m a b : N) : mul (sh m a) b = sh m (mul a b) := by
induction m with
| z => rfl
| s m ih => exact (dbl_mul (sh m a) b).trans (congrArg dbl ih)
theorem mul_sh (m a b : N) : mul a (sh m b) = sh m (mul a b) := by
induction m with
| z => rfl
| s m ih => exact (mul_dbl a (sh m b)).trans (congrArg dbl ih)
end N
namespace D
open N
/-- A dyadic point `k / 2^n` is the pair `(k, n)`; the kernel says
`k / 2^n = j / 2^m` when `k · 2^m = j · 2^n`. -/
abbrev rel (x y : N × N) : Prop := sh y.2 x.1 = sh x.2 y.1
theorem rel_refl (x : N × N) : rel x x := rfl
theorem rel_symm {x y : N × N} (h : rel x y) : rel y x := h.symm
theorem rel_trans {x y w : N × N} (h1 : rel x y) (h2 : rel y w) : rel x w :=
sh_inj y.2
((sh_comm y.2 w.2 x.1).trans
((congrArg (sh w.2) h1).trans
((sh_comm w.2 x.2 y.1).trans
((congrArg (sh x.2) h2).trans (sh_comm x.2 y.2 w.1)))))
/-- `k / 2^n = 2k / 2^(n+1)`: the same point one level up. -/
theorem rel_up (k n : N) : rel (k, n) (dbl k, N.s n) := (sh_dbl n k).symm
def double (x : N × N) : N × N := (dbl x.1, x.2)
def half (x : N × N) : N × N := (x.1, N.s x.2)
/-- Halving is the inverse of doubling. -/
theorem double_half (x : N × N) : rel (double (half x)) x := sh_dbl x.2 x.1
theorem half_double (x : N × N) : rel (half (double x)) x := sh_dbl x.2 x.1
def dadd (x y : N × N) : N × N :=
(add (sh y.2 x.1) (sh x.2 y.1), add x.2 y.2)
def dmul (x y : N × N) : N × N := (mul x.1 y.1, add x.2 y.2)
theorem dadd_comm (x y : N × N) : dadd x y = dadd y x :=
(congrArg (fun t => (t, add x.2 y.2)) (N.add_comm (sh y.2 x.1) (sh x.2 y.1))).trans
(congrArg (fun t => (add (sh x.2 y.1) (sh y.2 x.1), t)) (N.add_comm x.2 y.2))
theorem dmul_comm (x y : N × N) : dmul x y = dmul y x :=
(congrArg (fun t => (t, add x.2 y.2)) (N.mul_comm x.1 y.1)).trans
(congrArg (fun t => (mul y.1 x.1, t)) (N.add_comm x.2 y.2))
theorem dmul_assoc (x y w : N × N) : dmul (dmul x y) w = dmul x (dmul y w) :=
(congrArg (fun t => (t, add (add x.2 y.2) w.2)) (N.mul_assoc x.1 y.1 w.1)).trans
(congrArg (fun t => (mul x.1 (mul y.1 w.1), t)) (N.add_assoc x.2 y.2 w.2))
/-- One summand moved across the kernel. -/
theorem lift_one {k n k' n' : N} (m m' : N) (h : sh n' k = sh n k') :
sh (add n' m') (sh m k) = sh (add n m) (sh m' k') :=
(sh_sh n' m' (sh m k)).symm.trans
((sh_comm n' m' (sh m k)).trans
((congrArg (sh m') (sh_comm n' m k)).trans
((congrArg (fun t => sh m' (sh m t)) h).trans
((congrArg (sh m') (sh_comm m n k')).trans
((sh_comm m' n (sh m k')).trans
((congrArg (sh n) (sh_comm m' m k')).trans
(sh_sh n m (sh m' k'))))))))
/-- Sum does not depend on the representative. -/
theorem dadd_rel {x x' y y' : N × N} (hx : rel x x') (hy : rel y y') :
rel (dadd x y) (dadd x' y') :=
have e1 : sh (add x'.2 y'.2) (sh y.2 x.1) = sh (add x.2 y.2) (sh y'.2 x'.1) :=
lift_one y.2 y'.2 hx
have e2 : sh (add x'.2 y'.2) (sh x.2 y.1) = sh (add x.2 y.2) (sh x'.2 y'.1) :=
(congrArg (fun t => sh t (sh x.2 y.1)) (N.add_comm x'.2 y'.2)).trans
((lift_one x.2 x'.2 hy).trans
(congrArg (fun t => sh t (sh x'.2 y'.1)) (N.add_comm y.2 x.2)))
(sh_add (add x'.2 y'.2) (sh y.2 x.1) (sh x.2 y.1)).trans
((congrArg (fun t => add t (sh (add x'.2 y'.2) (sh x.2 y.1))) e1).trans
((congrArg (add (sh (add x.2 y.2) (sh y'.2 x'.1))) e2).trans
(sh_add (add x.2 y.2) (sh y'.2 x'.1) (sh x'.2 y'.1)).symm))
theorem mul_sh_sh (a b k j : N) : mul (sh a k) (sh b j) = sh (add a b) (mul k j) :=
(sh_mul a k (sh b j)).trans
((congrArg (sh a) (mul_sh b k j)).trans (sh_sh a b (mul k j)))
/-- Product does not depend on the representative. -/
theorem dmul_rel {x x' y y' : N × N} (hx : rel x x') (hy : rel y y') :
rel (dmul x y) (dmul x' y') :=
(mul_sh_sh x'.2 y'.2 x.1 y.1).symm.trans
((congrArg (fun t => mul t (sh y'.2 y.1)) hx).trans
((congrArg (mul (sh x.2 x'.1)) hy).trans
(mul_sh_sh x.2 y.2 x'.1 y'.1)))
/-- `1/2 + 1/4 = 3/4`. -/
example : rel (dadd (num 1, num 1) (num 1, num 2)) (num 3, num 2) := rfl
/-- `3/4 · 1/2 = 3/8`. -/
example : dmul (num 3, num 2) (num 1, num 1) = (num 3, num 3) := rfl
end D
/-! ## 11. I: the greatest side of the same gluing -/
namespace I
open N Word
def bit : Bool → N
| true => N.s N.z
| false => N.z
/-- The word cut at `n` digits, as a numerator on level `n`. -/
def tr (w : W) : N → N
| .z => N.z
| .s n => add (bit (w n)) (dbl (tr w n))
/-- Two numerators on one level differ by at most one. -/
abbrev near (a b : N) : Prop := ∃ p r : Bool, add (bit p) a = add (bit r) b
/-- Equality of points of `I`, read in `D`: no finite cut tells them apart. -/
abbrev eqv (u v : W) : Prop := ∀ n, near (tr u n) (tr v n)
theorem near_refl (a : N) : near a a := ⟨false, false, rfl⟩
theorem near_symm {a b : N} : near a b → near b a :=
fun ⟨p, r, h⟩ => ⟨r, p, h.symm⟩
theorem eqv_refl (u : W) : eqv u u := fun n => near_refl (tr u n)
theorem eqv_symm {u v : W} (h : eqv u v) : eqv v u := fun n => near_symm (h n)
theorem tr_congr {u v : W} (h : ∀ n, u n = v n) : ∀ n, tr u n = tr v n := by
intro n
induction n with
| z => rfl
| s n ih =>
exact (congrArg (fun b => add (bit b) (dbl (tr u n))) (h n)).trans
(congrArg (fun t => add (bit (v n)) (dbl t)) ih)
/-- Two steps of `near`: equal, one apart, or two apart. -/
theorem tri (p q r t : Bool) (a c : N)
(h : add (bit q) (add (bit p) a) = add (bit r) (add (bit t) c)) :
near a c ∨ N.s (N.s a) = c ∨ a = N.s (N.s c) := by
cases p <;> cases q <;> cases r <;> cases t <;>
first
| exact Or.inl ⟨false, false, h⟩
| exact Or.inl ⟨true, false, h⟩
| exact Or.inl ⟨false, true, h⟩
| exact Or.inl ⟨false, false, s_inj h⟩
| exact Or.inl ⟨true, false, s_inj h⟩
| exact Or.inl ⟨false, true, s_inj h⟩
| exact Or.inl ⟨false, false, s_inj (s_inj h)⟩
| exact Or.inr (Or.inl h)
| exact Or.inr (Or.inr h)
theorem two_steps {a b c : N} {p r q t : Bool}
(h1 : add (bit p) a = add (bit r) b) (h2 : add (bit q) b = add (bit t) c) :
add (bit q) (add (bit p) a) = add (bit r) (add (bit t) c) :=
(congrArg (add (bit q)) h1).trans
((add_left_comm (bit q) (bit r) b).trans (congrArg (add (bit r)) h2))
theorem no_gap (q p x r t y : Bool) :
add (bit q) (add (bit p) (bit x)) ≠
add (bit r) (add (bit t) (add (bit y) (num 4))) := by
cases q <;> cases p <;> cases x <;> cases r <;> cases t <;> cases y <;>
exact fun h => nomatch h
/-- Two apart on one level cannot be within two on the next. -/
theorem gap_false (X : N) (q p x r t y : Bool)
(h : add (bit q) (add (bit p) (add (bit x) X)) =
add (bit r) (add (bit t) (add (bit y) (add (num 4) X)))) : False :=
have l : add (bit q) (add (bit p) (add (bit x) X)) =
add (add (bit q) (add (bit p) (bit x))) X :=
(congrArg (add (bit q)) (add_assoc (bit p) (bit x) X).symm).trans
(add_assoc (bit q) (add (bit p) (bit x)) X).symm
have m : add (bit r) (add (bit t) (add (bit y) (add (num 4) X))) =
add (add (bit r) (add (bit t) (add (bit y) (num 4)))) X :=
(congrArg (fun k => add (bit r) (add (bit t) k))
(add_assoc (bit y) (num 4) X).symm).trans
((congrArg (add (bit r))
(add_assoc (bit t) (add (bit y) (num 4)) X).symm).trans
(add_assoc (bit r) (add (bit t) (add (bit y) (num 4))) X).symm)
no_gap q p x r t y (add_right_cancel X (l.symm.trans (h.trans m)))
theorem dbl_ss (a : N) : dbl (N.s (N.s a)) = add (num 4) (dbl a) :=
(dbl_s (N.s a)).trans (congrArg (fun k => N.s (N.s k)) (dbl_s a))
/-- The reading of equality is transitive, so it is an equivalence. -/
theorem eqv_trans {u v w : W} (h1 : eqv u v) (h2 : eqv v w) : eqv u w := by
intro n
have ⟨p, r, e1⟩ := h1 n
have ⟨q, t, e2⟩ := h2 n
have ⟨p', r', e1'⟩ := h1 (N.s n)
have ⟨q', t', e2'⟩ := h2 (N.s n)
have K' : add (bit q') (add (bit p') (add (bit (u n)) (dbl (tr u n)))) =
add (bit r') (add (bit t') (add (bit (w n)) (dbl (tr w n)))) :=
two_steps e1' e2'
cases tri p q r t (tr u n) (tr w n) (two_steps e1 e2) with
| inl h => exact h
| inr h =>
cases h with
| inl hc =>
have e : dbl (tr w n) = add (num 4) (dbl (tr u n)) :=
(congrArg dbl hc.symm).trans (dbl_ss (tr u n))
exact (gap_false (dbl (tr u n)) q' p' (u n) r' t' (w n)
(K'.trans (congrArg
(fun k => add (bit r') (add (bit t') (add (bit (w n)) k))) e))).elim
| inr ha =>
have e : dbl (tr u n) = add (num 4) (dbl (tr w n)) :=
(congrArg dbl ha).trans (dbl_ss (tr w n))
exact (gap_false (dbl (tr w n)) r' t' (w n) q' p' (u n)
(K'.symm.trans (congrArg
(fun k => add (bit q') (add (bit p') (add (bit (u n)) k))) e))).elim
/-- Reading the first digit apart. -/
theorem tr_tail (w : W) (n : N) :
tr w (N.s n) = add (sh n (bit (w N.z))) (tr (tail w) n) := by
induction n with
| z => rfl
| s n ih =>
exact (congrArg (fun k => add (bit (w (N.s n))) (dbl k)) ih).trans
((congrArg (add (bit (w (N.s n))))
(dbl_add (sh n (bit (w N.z))) (tr (tail w) n))).trans
(add_left_comm (bit (w (N.s n))) (dbl (sh n (bit (w N.z))))
(dbl (tr (tail w) n))))
/-- Twins: `u 0111…` and `u 1000…`. -/
inductive Twin : W → W → Prop where
| base (u v : W) : u N.z = false → v N.z = true →
(∀ k, u (N.s k) = true) → (∀ k, v (N.s k) = false) → Twin u v
| step (u v : W) : u N.z = v N.z → Twin (tail u) (tail v) → Twin u v
theorem base_step (u v : W) (hu0 : u N.z = false) (hv0 : v N.z = true)
(hu : ∀ k, u (N.s k) = true) (hv : ∀ k, v (N.s k) = false) :
∀ n, N.s (tr u (N.s n)) = tr v (N.s n) := by
intro n
induction n with
| z =>
have eu : tr u (N.s N.z) = N.z :=
congrArg (fun b => add (bit b) N.z) hu0
have ev : tr v (N.s N.z) = N.s N.z :=
congrArg (fun b => add (bit b) N.z) hv0
exact (congrArg N.s eu).trans ev.symm
| s n ih =>
have eu : tr u (N.s (N.s n)) = N.s (dbl (tr u (N.s n))) :=
congrArg (fun b => add (bit b) (dbl (tr u (N.s n)))) (hu n)
have ev : tr v (N.s (N.s n)) = dbl (tr v (N.s n)) :=
congrArg (fun b => add (bit b) (dbl (tr v (N.s n)))) (hv n)
exact (congrArg N.s eu).trans
(((dbl_s (tr u (N.s n))).symm.trans (congrArg dbl ih)).trans ev.symm)
/-- Twins have cuts that are equal or one apart on every level. -/
theorem twin_near {u v : W} (h : Twin u v) :
∀ n, tr u n = tr v n ∨ N.s (tr u n) = tr v n := by
induction h with
| base u v hu0 hv0 hu hv =>
intro n
cases n with
| z => exact Or.inl rfl
| s n => exact Or.inr (base_step u v hu0 hv0 hu hv n)
| step u v h0 _ ih =>
intro n
cases n with
| z => exact Or.inl rfl
| s n =>
have hd : add (sh n (bit (u N.z))) (tr (tail v) n) = tr v (N.s n) :=
(congrArg (fun b => add (sh n (bit b)) (tr (tail v) n)) h0).trans
(tr_tail v n).symm
cases ih n with
| inl e =>
exact Or.inl ((tr_tail u n).trans
((congrArg (add (sh n (bit (u N.z)))) e).trans hd))
| inr e =>
exact Or.inr ((congrArg N.s (tr_tail u n)).trans
((add_s (sh n (bit (u N.z))) (tr (tail u) n)).symm.trans
((congrArg (add (sh n (bit (u N.z)))) e).trans hd)))
/-- The twin kernel lies inside the reading of equality. -/
theorem twin_eqv {u v : W} (h : Twin u v) : eqv u v := fun n =>
match twin_near h n with
| Or.inl e => ⟨false, false, e⟩
| Or.inr e => ⟨true, false, e⟩
def ones : W := fun _ => true
def zeros : W := fun _ => false
/-- `0111… ∼ 1000…`. -/
theorem half_twins :
eqv (fun n => match n with | .z => false | .s _ => true)
(fun n => match n with | .z => true | .s _ => false) :=
twin_eqv (Twin.base _ _ rfl rfl (fun _ => rfl) (fun _ => rfl))
/-! ### Gluing: the two choices at the glued point are twins -/
theorem unfold_fixed {X : Type u} (c : X → Bool × X) (x : X) (b : Bool)
(hx : c x = (b, x)) : ∀ n, unfold c x n = b := by
intro n
have fix : ∀ n, iter x (fun y => (c y).2) n = x := by
intro n
induction n with
| z => rfl
| s n ih =>
exact (congrArg (fun y => (c y).2) ih).trans (congrArg Prod.snd hx)
exact (congrArg (fun y => (c y).1) (fix n)).trans (congrArg Prod.fst hx)
/-- At a glued point one co-structure goes left and continues at the end
point, the other goes right and continues at the start point: the two
words are twins. -/
theorem glued_twin {X : Type u} (c c' : X → Bool × X) (top bot x : X)
(htop : c top = (true, top)) (hbot : c' bot = (false, bot))
(hl : c x = (false, top)) (hr : c' x = (true, bot)) :
Twin (unfold c x) (unfold c' x) :=
Twin.base _ _
(congrArg Prod.fst hl)
(congrArg Prod.fst hr)
(fun k => (unfold_tail c x k).trans
((congrArg (fun y => unfold c y k) (congrArg Prod.snd hl)).trans
(unfold_fixed c top true htop k)))
(fun k => (unfold_tail c' x k).trans
((congrArg (fun y => unfold c' y k) (congrArg Prod.snd hr)).trans
(unfold_fixed c' bot false hbot k)))
/-! ### Size: a copy of all words with no twins -/
def enc : W → N → Bool
| w, .z => w N.z
| w, .s .z => !(w N.z)
| w, .s (.s n) => enc (tail w) n
theorem enc_even (n : N) : ∀ w : W, enc w (dbl n) = w n := by
induction n with
| z => intro w; rfl
| s n ih =>
intro w
exact (congrArg (enc w) (dbl_s n)).trans (ih (tail w))
theorem enc_odd (n : N) : ∀ w : W, enc w (N.s (dbl n)) = !(w n) := by
induction n with
| z => intro w; rfl
| s n ih =>
intro w
exact (congrArg (fun k => enc w (N.s k)) (dbl_s n)).trans (ih (tail w))
/-- The copy is injective. -/
theorem enc_inj {u v : W} (h : ∀ k, enc u k = enc v k) : ∀ n, u n = v n :=
fun n => (enc_even n u).symm.trans ((h (dbl n)).trans (enc_even n v))
/-- It has no constant tail, hence no twins. -/
theorem enc_no_tail (w : W) (n : N) : enc w (N.s (dbl n)) ≠ enc w (dbl n) :=
fun h => not_ne (w n) ((enc_odd n w).symm.trans (h.trans (enc_even n w)))
end I
/-! ## 12. ℝ: an integer and a point of the unit length -/
namespace R
open N Word I
abbrev Pt := (N × N) × W
/-- The point cut at `n` digits, as an integer on level `n`. -/
def val (x : Pt) (n : N) : N × N :=
(add (sh n x.1.1) (tr x.2 n), sh n x.1.2)
abbrev znear (P Q : N × N) : Prop :=
∃ p r : Bool, Z.rel (add (bit p) P.1, P.2) (add (bit r) Q.1, Q.2)
/-- Equality of reals: every cut agrees up to its own precision. -/
abbrev req (x y : Pt) : Prop := ∀ n, znear (val x n) (val y n)
theorem req_refl (x : Pt) : req x x := fun _ => ⟨false, false, rfl⟩
theorem req_symm {x y : Pt} (h : req x y) : req y x := fun n =>
match h n with
| ⟨p, r, e⟩ => ⟨r, p, Z.rel_symm e⟩
theorem sh_z (n : N) : sh n N.z = N.z := by
induction n with
| z => rfl
| s n ih => exact congrArg dbl ih
theorem tr_zeros (n : N) : tr zeros n = N.z := by
induction n with
| z => rfl
| s n ih => exact congrArg dbl ih
/-- `0.111… + 2^{-n} = 1` on every level. -/
theorem tr_ones (n : N) : N.s (tr ones n) = sh n (num 1) := by
induction n with
| z => rfl
| s n ih => exact (dbl_s (tr ones n)).symm.trans (congrArg dbl ih)
/-- The gluing: `n` with `x = 1` is `n + 1` with `x = 0`. -/
theorem glue (a b : N) : req ((a, b), ones) ((N.s a, b), zeros) := fun n =>
have e : N.s (add (sh n a) (tr ones n)) = add (sh n (N.s a)) (tr zeros n) :=
(add_s (sh n a) (tr ones n)).symm.trans
((congrArg (add (sh n a)) (tr_ones n)).trans
((sh_add n a (num 1)).symm.trans
((congrArg (sh n) ((add_s a N.z).trans (congrArg N.s (add_z a)))).trans
((add_z (sh n (N.s a))).symm.trans
(congrArg (add (sh n (N.s a))) (tr_zeros n).symm)))))
⟨true, false, congrArg (fun k => add k (sh n b)) e⟩
/-! ### 1/3 and 2/3 -/
def alt : Bool → W
| b, .z => b
| b, .s n => alt (!b) n
def third : W := alt false -- 0.0101…
def twoThirds : W := alt true -- 0.1010…
theorem alt_not (n : N) : ∀ b : Bool, alt (!b) n = !(alt b n) := by
induction n with
| z => intro b; rfl
| s n ih => intro b; exact ih (!b)
theorem bit_compl (c : Bool) : add (bit c) (bit (!c)) = num 1 := by
cases c <;> rfl
theorem alt_compl (b : Bool) (n : N) :
add (tr (alt b) n) (tr (alt (!b)) n) = tr ones n := by
induction n with
| z => rfl
| s n ih =>
exact (add4 (bit (alt b n)) (dbl (tr (alt b) n))
(bit (alt (!b) n)) (dbl (tr (alt (!b)) n))).trans
((congrArg
(fun c => add (add (bit (alt b n)) (bit c))
(add (dbl (tr (alt b) n)) (dbl (tr (alt (!b)) n))))
(alt_not n b)).trans
((congrArg
(fun k => add k (add (dbl (tr (alt b) n)) (dbl (tr (alt (!b)) n))))
(bit_compl (alt b n))).trans
(congrArg (fun k => N.s k)
((dbl_add (tr (alt b) n) (tr (alt (!b)) n)).symm.trans
(congrArg dbl ih)))))
/-- `1/3 + 2/3` is one step below `1` on every level: `1/3 + 2/3 = 1`. -/
theorem third_twoThirds (n : N) :
N.s (add (tr third n) (tr twoThirds n)) = sh n (num 1) :=
(congrArg N.s (alt_compl false n)).trans (tr_ones n)
/-- `2/3` on level `n` is `1/3` on level `n + 1`: `1/3 + 1/3 = 2/3`. -/
theorem twice_third (n : N) : tr third (N.s n) = tr twoThirds n :=
(tr_tail third n).trans
((congrArg (fun k => add k (tr (tail third) n)) (sh_z n)).trans
(tr_congr (u := tail third) (v := twoThirds) (fun _ => rfl) n))
/-! ### The digits of √(1/2), read by `(2a+1)² < 2^(2k+1)` -/
def rt : Nat → Nat
| 0 => 0
| k + 1 => if (2 * rt k + 1) ^ 2 < 2 ^ (2 * k + 1) then 2 * rt k + 1 else 2 * rt k
/-- The first eight digits are `10110101`. -/
theorem rt_eight : rt 8 = 181 := by decide
theorem rt_bounds : 181 ^ 2 < 2 ^ 15 ∧ 2 ^ 15 < 182 ^ 2 := by decide
end R
/-! ## Axiom report -/
#print axioms Path.contract
#print axioms Path.trans_assoc
#print axioms comp_unit
#print axioms comp_arrows
#print axioms N.iter_unique
#print axioms N.s_ne_z
#print axioms N.s_inj
#print axioms N.add_comm
#print axioms N.mul_comm
#print axioms N.add_mul
#print axioms N.mul_assoc
#print axioms Z.rel_trans
#print axioms Word.unfold_unique
#print axioms Word.diagonal
#print axioms D.rel_trans
#print axioms D.dadd_rel
#print axioms D.dmul_rel
#print axioms D.double_half
#print axioms I.eqv_trans
#print axioms I.twin_eqv
#print axioms I.half_twins
#print axioms I.glued_twin
#print axioms I.enc_inj
#print axioms I.enc_no_tail
#print axioms R.glue
#print axioms R.third_twoThirds
#print axioms R.twice_third
#print axioms R.rt_eight
#print axioms R.rt_bounds
Halving is the inverse of \(\mu _2\) (Section 69.10). Applied \(n\) times to \(1\) it gives the point \((1,n)\) of \(D\), written \(2^{-n}\). Then
By induction \(n<2^{n}\), since \(n+1\le 2^{n}+1\le 2^{n}+2^{n}\). And if \(|x|\le 2^{-n}\) for every \(n\) then \(x=0\): this is the reading of equality of Section 69.11. So \(2^{-n}\) is one thing read four ways: the unit seen from level \(n\), the whole tail after \(n\) digits, the length of one cell, and the error of a cut.
Use the digits \(\{-1,0,1\}\). A word \(d\) has the value \(\sum _kd_k2^{-k}\) in \([-1,1]\); the cells overlap by half, and the kernel is “same value”, for example \(1,-1\sim 0,1\). Two words are equal when their cuts differ by at most two steps on every level; this is transitive, since a difference of three on one level is at least six two levels up. A real is a pair \((m,d)\) read as \(2^{m}\cdot d\).
(L) There is one. Let \(q_n\in D\) with \(|q_n-v|\le 2^{-n}\) and \(|v|\le 1\). Read \(q_{3}\): the first digit is \(1\) if \(q\ge \tfrac 14\), \(-1\) if \(q\le -\tfrac 14\), and \(0\) otherwise. In each case \(2v-e\) lies in \([-1,1]\) again, since \(q\ge \tfrac 14\) gives \(v\ge \tfrac 18\) and \(|q|<\tfrac 14\) gives \(|v|<\tfrac 38\). Go on with \(2v-e\) and \(q_{j+3}\). So every such sequence has a word.
(P) Exactly one. Call a map readable when each digit of the output needs finitely many digits of the input. If \(f\) and \(g\) are readable and agree on \(D\), they agree everywhere: for \(x\) cut at \(m\) digits to \(d\in D\),
Sum and product are not chosen. Each is the readable map that agrees with the sum and product of \(D\): there is one by (L), and exactly one by (P).
The laws. Each law has two readable sides that agree on \(D\) (Sections 69.7–69.10); by (P) they agree on \(\mathbb R\). Nothing further is to be proved.
The mean, digit by digit. Let \(t_k=x_k+y_k\) and keep a state \(a\). Read \(m=2a+t\); give \(e=\mathrm {sgn}(m)\) if \(|m|\ge 2\) and \(e=0\) otherwise; the new state is \(m-4e\), again between \(-2\) and \(2\).
The second line is the case that the digits \(\{0,1\}\) cannot decide.
A product. Reading \(\tfrac 13\cdot \tfrac 13\) by (L), \(v\) goes through \(.111,\ .222,\ .444,\ -.111,\ -.222,\ -.444\) and returns; the digits are \(0,0,1,0,0,-1\) repeated, with value \((\tfrac 18-\tfrac 1{64})\cdot \tfrac {64}{63}=\tfrac 19\).
Order. \(x<y\) when the cuts are apart on some level. Then \(x+z<y+z\), and \(xz<yz\) for \(z>0\), since both hold in \(D\) and are read on a level.
Inverse. Where \(|x|\ge 2^{-m}\), \(|1/x-1/x'|\le 4^{m}|x-x'|\), so \(1/x\) is given by (L), and \(x\cdot (1/x)=1\) by (P). Here \(x\neq 0\) is read as: apart from \(0\) on some level.
Completeness, three times (L). A sequence whose terms come within \(2^{-n}\) of each other has a limit; cells inside one another fix one point; an increasing sequence with a bound converges.
The product \((1-r)(1+r+\cdots +r^{n})=1-r^{n+1}\) telescopes. By induction \((1+a)^{n}\ge 1+na\), so for \(r=1/(1+a)\) we get \(r^{n}\le 1/(1+na)\), which goes below every \(2^{-m}\). Hence
\(D\) inverted \(\mu _2\). In the other direction, divide by the image of \(\mu _p^{\,n}\): the remainders form \(1\leftarrow \mathbb Z/p\leftarrow \mathbb Z/p^{2}\leftarrow \cdots \), and the limit \(\mathbb Z_p\) is the greatest kind for \(p\times X\), the words \(p^{\mathbb N}\). These are the words of \(I\); only the reading differs.
| \(I\) | \(\mathbb Z_2\) | |
| reading | \(\sum d_k2^{-k}\) | \(\sum d_k2^{k}\) |
| cut at \(n\) digits | a point of \(D\) on level \(n\) | the remainder by \(2^{n}\) |
| kernel | twins | \(\Delta \) |
| carry | may wait for ever | only goes forward |
There are no twins, since the remainder by \(2^{n}\) and the first \(n\) digits determine each other. Each \(\mathbb Z/p^{n}\) is a ring and the remainder maps keep sum and product, so the laws pass to the limit by “exactly one arrow in”; no signed digits are needed.
A word is invertible when its first digit is not \(0\): on each level the inverse exists and is the only one. \(p\) has no inverse; inverting \(\mu _p\) gives \(\mathbb Q_p\). Roots are read digit by digit as well: in \(\mathbb Z_7\), \(3^{2}\equiv 2\), and \((3+7t)^{2}\equiv 2\ (\mathrm {mod}\ 49)\) gives \(t=1\), so \(\sqrt 2=3+1\cdot 7+\cdots \), with \(10^{2}=2+2\cdot 49\).
Open. A part is open when membership is settled by a finite cut; in \(I\) it must contain both twins or neither. A map is continuous when it is readable. A sequence \(x_k\) has limit \(x\) when for each \(n\) it is eventually within \(2^{-n}\) of \(x\); equivalently the map \(\omega \to \mathbb R\) extends continuously to \(\omega +1\) (Section 71.11), and the limit is the value at \(\omega \).
Compact. Let cells cover the words. Call a finite word bad when the words beginning with it are not covered by finitely many of the cells. A bad word has a bad child, so if the empty word is bad there is a word without end all of whose cuts are bad; but it lies in one cell of the cover, and that cut is not bad. So finitely many cells suffice. (Excluded middle is used for “bad”.) Hence a continuous map on \(I\) needs a number of input digits that does not depend on the input, it is bounded, and it takes a greatest value.
Connected. Let \(f:I\to 2\) be continuous. It is constant on each cell of some level \(n\). Two neighbouring cells share a boundary point, the twins, so \(f\) has the same value on both; going through the \(2^{n}\) cells, \(f\) is constant. The gluing is the connectedness. In \(\mathbb Z_p\) there is no gluing, and “the first digit” is continuous and not constant.
A value in between. If \(f\) is continuous with \(f(a)<0<f(b)\), choose at each step the half on which the sign changes; the cells fix a point where \(f=0\). The digits of \(\sqrt {1/2}\) were read this way.
A cell of \(n\) digits has measure \(2^{-n}\): flipping the next digit is an isomorphism exchanging its two halves, so they are equal, and the whole is \(1\). If a cell is a disjoint union of cells, the union is finite by compactness, so adding finitely many is enough. The points of \(D\) have measure \(0\): cover the \(k\)-th by a cell of length \(2^{-(n+k)}\), in total at most \(2^{-n}\); so \(I\), of measure \(1\), is not countable. The copy of all words by \(0\mapsto 01\), \(1\mapsto 10\) is covered by \(2^{n}\) cells of \(2n\) digits, of total \(2^{-n}\): measure \(0\) and size \(2^{\aleph _0}\). A section of \(\mathbb R\to \mathbb R/\mathbb Q\) is a choice (Section 71.12); countably many translates of its image cover \([0,1]\) inside \([-1,2]\), so one number added to itself without end would lie between \(1\) and \(3\): the image has no measure.
Integral. For continuous \(f\) on \(I\) the level sums \(S_n=\sum _{k<2^{n}}f(k/2^{n})\,2^{-n}\) come within \(2^{-m}\) of each other, and \(\int _0^1f\) is given by (L). With \(N=2^{n}\):
Derivative. \(f'(x)\) is the limit of the quotient \((f(b)-f(a))/(b-a)\) over cells \([a,b]\) around \(x\).
The two are inverse. On every level, exactly,
\(\exp \) from halving and squaring.
\(\log \) and powers. \(\log \) is the inverse of \(\exp \), with \(\log '(x)=1/x\) and \(\log x=\int _1^{x}dt/t\). Then
\(i\). \(-1\) was \(\mu _{-1}\) (Section 69.9). A map that gives \(\mu _{-1}\) when done twice is the quarter turn \(i:(a,b)\mapsto (-b,a)\). With it
The circle. \(\exp (it)=\lim _n(1+it/2^{n})^{2^{n}}\) has size \(\lim (1+t^{2}/N^{2})^{N/2}=1\); its two places are \(\cos t\) and \(\sin t\). Reading \(\exp (i(s+t))=\exp (is)\exp (it)\) by the product above,
\(\pi \). \(\mathbb R\) is the circle unwound (Section 69.12); \(\pi \) is the least \(t>0\) with \(\exp (it)=-1\). Doubling the angle is \(\mu _2\) on the circle, and inverting it is the half angle:
| what comes out | from where |
| sum, product, inverse on \(\mathbb R\) | (L) |
| the field laws, the uniqueness of \(\exp \) | (P) |
| limits, integrals, derivatives | (L) on a sequence in \(D\) |
| \(\int f'=f(1)-f(0)\) | a telescoping sum on each level |
| connected | neighbouring cells share twins |
| \(\mathbb Z_p\) | the same words, read from the other end |
| \(\pi \) | \(\mu _2\) inverted on the circle |
Excluded middle is used for compactness, for the value in between, and for the least upper bound; choice is used only for the part with no measure.