1-- Uncountability of the Dedekind reals - Digits2-- Part of Cumulus, the Grace17 mathematics library.3-- Copyright (c) 2026 Grant Passmore.4-- Released under the Apache License 2.0. See LICENSE in the repository root.5-- Authors: Grant Passmore67module Grace.Cumulus.Real.Uncountable.Digits8import Nat.Pow9import Set1011-- The membership bit of n in X, represented as a von Neumann natural. The12-- bounded separation is either {1} or empty, so its union is respectively13-- 1 or 0, so the construction stays inside set theory.14def binaryDigitSet (X n : Set) : Set:=15 { d ∈ {1} | n ∈ X }16def binaryDigitRaw (X n : Set) : Set:=⋃(binaryDigitSet(X, n))1718theorem binaryDigitRaw.one (X n : Set)19requires member : n ∈ X20shows binaryDigitRaw(X, n) =121proof22unfold binaryDigitRaw23ext x24simp [set.union, binaryDigitSet, singleton.membership, member]2526theorem binaryDigitRaw.zero (X n : Set)27requires missing : ¬(n ∈ X)28shows binaryDigitRaw(X, n) =029proof30unfold binaryDigitRaw31ext x32simp [set.union, binaryDigitSet, singleton.membership, missing, nat.zero, set.empty]3334theorem binaryDigitRaw.cases (X n : Set)35shows binaryDigitRaw(X, n) =0∨ binaryDigitRaw(X, n) =136proof37have membershipCases : n ∈ X ∨¬(n ∈ X) bytauto38cases membershipCases with member | missing39 . right40exact binaryDigitRaw.one with member41 . left42exact binaryDigitRaw.zero with missing4344instance binaryDigitRaw.natural (X n : Set)45showsNat(binaryDigitRaw(X, n))46proof47havecases:= binaryDigitRaw.cases at X, n48casescaseswith zero | one49 . rw zero50exact Naturals.constructor.zero51 . rw one52typecheck5354def binaryDigit (X n : Set) : Nat:= binaryDigitRaw(X, n)5556theorem binaryDigit.zero (X n : Set)57requires missing : ¬(n ∈ X)58shows binaryDigit(X, n) =059proof60unfold binaryDigit61exact binaryDigitRaw.zero with missing6263theorem binaryDigit.one (X n : Set)64requires member : n ∈ X65shows binaryDigit(X, n) =166proof67unfold binaryDigit68exact binaryDigitRaw.one with member6970theorem binaryDigit.cases (X n : Set)71shows binaryDigit(X, n) =0∨ binaryDigit(X, n) =172proof73havecases:= binaryDigitRaw.cases at X, n74casescaseswith zero | one75 . left76simp [binaryDigit]77 . right78simp [binaryDigit]7980theorem binaryDigit.natural (X n : Set)81showsNat(binaryDigit(X, n))82proof83unfold binaryDigit84exact binaryDigitRaw.natural8586-- Base-four prefixes with digits 0 and 2. The gap between those digits is87-- what makes the eventual real recover every membership bit uniquely.88def cantorPrefix (X : Set, n : Nat) →Nat89| X, zero =>090| X, succ(n) =>4* cantorPrefix(X, n) +2* binaryDigit(X, n)9192theorem cantorPrefix.zero (X : Set)93shows cantorPrefix(X, 0) =094proof95simp [cantorPrefix]9697theorem cantorPrefix.succ (X : Set, n : Nat)98shows cantorPrefix(X, succ(n)) =994* cantorPrefix(X, n) +2* binaryDigit(X, n)100proof101simp [cantorPrefix]102103theorem cantorPrefix.natural (X : Set, n : Nat)104showsNat(cantorPrefix(X, n))105proof106induction n107| zero =>108have shape := cantorPrefix.zero at X109rw shape110typecheck111| succ(k) using ih =>112have shape := cantorPrefix.succ at X, k113rw shape114have digitNatural := binaryDigit.natural at X, k115have rightNatural := mul.closed at binaryDigit(X, k), 2with digitNatural116exact add.closed with rightNatural117118theorem pow.four_nonzero (n : Nat)119shows4 ^ n ≠0120proof121induction n122| zero =>123have shape := pow.zero at4124rw shape125intro equal126have impossible := Naturals.disjoint.zero.succ at0127apply impossible128rw equal129rfl130| succ(k) using ih =>131have shape := pow.succ at4, k132rw shape133have fourNonzero : 4≠0134intro fourZero135have zeroFour : 0=4136rw fourZero137rfl138have impossible := Naturals.disjoint.zero.succ at3139exact impossible with zeroFour140exact mul.nonzero with fourNonzero, ih141142theorem natural.four_nonzero143shows4≠0144proof145intro fourZero146have zeroFour : 0=4147rw fourZero148rfl149have impossible := Naturals.disjoint.zero.succ at3150exact impossible with zeroFour151