# Cantor-diagonal numbers

Define $c : [0,1]^{\mathbb{N}} \to [0,1]$ to be the Cantor diagonalization function for binary expansion. By convention, let us say that the binary expansion of a number with two admissible expansions (e.g. $1/2$) is the one that does not end in an infinite tail of $1$s.

I am interested in what numbers can be added to countably infinite sets of real numbers using $c$, especially dense sets. For example, we can construct an irrational number by enumerating the rationals in $[0,1]$ and applying $c$ to the sequence. We can construct a transcendental number by enumerating the algebraic numbers in $[0,1]$ and applying $c$ to the sequence. And so on.

However, which number we actually get depends on the order as well as the set, and there are continuum-many orderings of a countably infinite set. So at least from the perspective of cardinality, reordering a fixed countable set could generate everything in $[0,1]$ except for that set.

My questions:

• Can we get all of the irrationals in $[0,1]$ by reordering the rationals?
• Can we get all of the transcendentals in $[0,1]$ by reordering the algebraic numbers?
• If those examples work, does this work for other sets like $\{ 1/n : n \in \mathbb{N} \}$, or is it specific to dense sets? (It cannot work with a completely arbitrary set: for instance if all the numbers in your set have the same first digit then $c$ will only be able to give you numbers with the other binary digit.)
• Is this specific to binary or would it work in any base?
• For the first one, do you need all rationals to be used? I can think of an argument using a strict subset of the rationals. – typesanitizer Apr 23 '17 at 15:05
• @theindigamer As formulated, yes, it needs to be all rationals (and no duplicates in any given sequence). But similar configurations are of interest too. – Ian Apr 23 '17 at 15:10
• do you mean all rationals, or all dyadic rationals (I may have an answer for the latter)? well, it may not matter, I will try to post – Mirko Apr 23 '17 at 17:01
• @Mirko All rationals in $[0,1]$, but again dyadic rationals would be of interest too. I would also be interested if adding elements to a set could make its "diagonalization closure" (the union of the set and the elements that can be obtained through the above procedure) smaller. – Ian Apr 23 '17 at 17:25
• Yes, but $0.01111\dots=0.1$ is the first term of the sequence. The usual Cantor diagonal function is defined so as to produce a number which is distinct from all terms of the sequence, and does not work so well in base $2.$ – bof Apr 23 '17 at 21:41

I think for the irrationals the answer is yes. Note that some rationals are dyadic irrationals, for example $\frac13$ (as discussed at https://en.wikipedia.org/wiki/Dyadic_rational )

I will write an answer about rationals and irrationals (and a modification of this argument would work for a similar question involving dyadic rationals and dyadic irrationals, if that was meant).

On re-reading I realized that a similar argument works, with trivial modification, for the second version of the question, involving algebraic and transcendental numbers.

Let $p_n$, $n=1,2,3,...$ lists all rationals. Let $x$ be any irrational. (From now on, this $x$ and the order of the $p_n$ will be fixed.). For convenience, let $d_n(x)$ denote the $n$-th digit of the binary expansion of $x$. (So the binary expansion of $x$ is the sequence $\langle d_1(x), d_2(x), ... \rangle$, where I take $\Bbb N=\{1,2,...\}$ rather that $\{0,1,2,...\}$).

It is easily seen that for each $m$ the set $P(m)$ of all rationals $p$ such that $d_m(p)\not=d_m(x)$ is infinite. (That is, the set $\{n:d_m(p_n)\not=d_m(x)\}$ is infinite.)

Also, for each $n$ there are infinitely many $k$ such that $d_k(p_n)\not=d_k(x)$. Indeed, if there were only finitely many such $k$, then the difference $p_n-x$ would have been a rational, contradicting that $p_n$ is rational but $x$ is irrational. (For the other version, if $p_n$ were algebraic, and $x$ were transcendental, then $p_n-x$ would be transcendental (and hence not rational), and again there would be infinitely many $k$ such that $d_k(p_n)\not=d_k(x)$.)

We could recursively construct a sequence $k(n)$, $n=1,2...$, such that:
1. $d_{k(n)}(p_n)\not=d_{k(n)}(x)$ , and
2. $k(n+1)>k(n)$ for all $n$.
(This $k(n)$ could be used below ... but apparently I ended up ignoring it, but the idea is relevant, and used in step A described further down.)

Using the above, now we need to define a different enumeration (a permutation) of the rationals, that would generate $x$ when diagonalization is applied to it.

There will be some hand-waving, in an attempt to avoid introducing more notation. The idea is that the recursive construction of a suitable sequence alternates two types of steps, A and B, as described further below. (Also, note that in the construction below, I may define the value for a certain index, even if the values for some smaller indices were not yet defined, but those will be taken care of at later steps.)

Step A. Take the first rational that has not yet been used. That is, take the smallest $n$ such that $p_n$ was not already used. Take a large enough $k$ that is:
1. available: that is, the value of the new ordering of the rationals is not yet defined at $k$, and
2. $d_k(p_n)\not=d_k(x)$.
Then let the $k$-th term of the new ordering of the rationals be $p_n$.

Step B. Take the first $m$ such that the value of the new ordering of the rationals is not yet defined for $m$. (Think of this as the first $m$ for which $d_m(x)$ has not been taken care of yet.) Take the smallest $n$ such that:
1. $n$ is available: that is, $p_n$ has not been used yet, and
2. $d_m(p_n)\not=d_m(x)$.
Then let the $m$-th term of the new ordering of the rationals be $p_n$.

I read the above and I think it works, though I will post and read again. I believe that steps A and B convey the idea (how to take not only enough many suitable rationals to generate $x$, but to also find a way to insert each rational at a suitable spot). One could perhaps introduce more notation to describe the details, to verify, if desired. (Of course, it is also used above, that when we apply the Cantor diagonalization $c$ to the resulting sequence, we have only two choices $0$ and $1$ at each coordinate $n$, so we have to end up choosing back $d_n(x)$. )

Can we get all of the irrationals in [0,1] by reordering the rationals?

I think the answer for this first subquestion is yes.

Edit: I just realized that a large part of the proof below the horizontal line is actually useless, so here is a much simpler proof. Consider a fixed enumeration of $\mathbb{Q}$ given as $a_1, a_2,\ldots$ and an irrational $r$. To get a sequence $b_1, b_2, \ldots$ which maps to $r$ by $c$, use the algorithm:

• For $n=1$, pick the lowest $m$ such that $a_m$'s first digit is the opposite of the first digit of $r$ and set $b_1=a_m$. Such an $m$ clearly exists as all rational numbers are included in $a_1,a_2,\ldots$. Mark the number $m$.
• For $n=k$, pick the lowest unmarked $m$ such that $a_m$'s $k$-th digit is the opposite of the $k$-th digit of $r$ and set $b_k=a_m$.

In the end (after $\mathbb{N}$ steps), all $m$'s will be marked (otherwise there is a least $m$ which is unmarked, which means that infinitely many consecutive digits of $r$ coincide with those of $a_m$, contradiction).

Can we get all of the transcendentals in [0,1] by reordering the algebraic numbers?

Use the same method and the fact that if $a$ is algebraic and if $a$ and $b$ have the "tail" of the binary expansion equal (i.e. $\exists\, k\in \mathbb{N}$ s.t. $\mathrm{frac}(2^ka) = \mathrm{frac}(2^k b)$) then $b$ is algebraic (because $a-b$ is rational and thus $b= a + (b-a)$ is algebraic).

If those examples work, does this work for other sets like $\{1/n:n\in \mathbb{N}\}$, or is it specific to dense sets? (It cannot work with a completely arbitrary set: for instance if all the numbers in your set have the same first digit then c will only be able to give you numbers with the other binary digit.)

Since it worked with $\mathbb{Q}\cap [0,1]$, it is easy to see that it will also work with $\mathbb{Q}\cap [0,1/2]$. Of course, this idea can be extended to arbitrarily small intervals by adding finitely many elements to take care of all possible combinations of the first $\ell$ digits.

Let the binary expansion for a general rational number be $0.p_1 p_2\ldots p_n q_1 \ldots q_k q_1\ldots q_k \ldots$. The rational numbers can be partitioned into finite sets $R_{n,m}$ ($m=q_1\ldots q_k$) for given values of $n$ and $m$; to make sure that the sets do not overlap, we demand that whenever $n\geq k$, we have $p_{n-(k-1)}\ldots p_n \neq q_1\ldots q_k$ and we restrict the choice of $m$ to the set $S$ that is specified by the following algorithm:

• At step 0 (0), $S_0 = \mathbb{N}$ (starting at 0).
• At step 1 (1), $S_1 = S_0\backslash \{1,11,111,\ldots\}$ (this step is special as we want to avoid the recurring 1s at the end).
• At step 2 (10), $S_{10} = S_1\backslash \{1010, 101010, \ldots\}$.
• At step 3 (11), $S_{11} = S_{10}$ as $11$ was already removed.

and so on. In general, if the element is present, then remove all the terms obtained by concatenating it two or more times. If not, then just use the same set as earlier. The set $S$ is defined as the intersection $S_0\cap S_1\cap S_{10} \cap \ldots$, so $S$ is naturally ordered.

Let us now return to the partitioning of the rational numbers. For every number $m$ in $S$, we can count the finitely many elements of $R_{n,m}$. The number of elements in $R_{n,m}$ is $2^n$ if $n<k$ and $2^{n-k}(2^k-1)$ if $n\geq k$ (recall that $k$ is the length of $m = q_1\ldots q_k$). These counts are illustrated in the table below. The entries marked with ~~ are not present in $S$ but shown for simplicity.

   S  | n=0 | n=1 | n=2 | n=3 | ...
0  |  1  |  1  |  2  |  4  | ...
~1~ | - - - - - - - - - - - - ...
10  |  1  |  2  |  3  |  6  | ...
~11~ | - - - - - - - - - - - - ...
100  |  1  |  2  |  4  |  7  | ...
...  | ...


For every element in $R_{n,m}$ there is the standard ordering of reals. We order $\mathbb{Q}$ by looking at the table in a zig-zag manner ($R_{0,0} < R_{1,0} < R_{0,10} < R_{2,0} < R_{1,10} < \ldots$) and using the ordering of $R_{n,m}$ at each entry in the table. (Of course, the table is unnecessary but I think it helps with intuition.)

Let an irrational $r$ be given. The first digit is zero or one, so pick $0.100\ldots$ (the second element of $\mathbb{Q}$) or $0.000\ldots$ (the first element of $\mathbb{Q}$) respectively and "mark" the number that was used. For the $\ell$-th digit of $r$, we pick the lowest unmarked element of this ordering of the rationals so the the diagonalization function $c$ maps the digit correctly. Clearly each rational will be used in finite time, otherwise the number $r$ will itself be rational (it will end up having a recurring tail $q_1\ldots q_k$ if it keeps "avoiding" the lowest unmarked number).

P.S. Feel free to edit this answer to improve clarity.