Quantcast
Channel: User Gro-Tsen - MathOverflow
Viewing all articles
Browse latest Browse all 221

Answer by Gro-Tsen for Is there a natural bijection from $\mathbb{N}$ to $\mathbb{Q}$?

$
0
0

Since the Calkin–Wilf tree has been mentioned in other replies to this question, I think the Stern-Brocot tree needs to be mentioned as well, because (although it is very much related, basically up to a bit-reversal of the index), I think it more naturally defines a sequence that precisely enumerates all of $\mathbb{Q}$ (and not just the positive rationals):

Recursively define sequences $p_\leftarrow(n), q_\leftarrow(n), p_\rightarrow(n), q_\rightarrow(n), p(n), q(n)$ for $n\geq 1$ by:$$\begin{array}{cc}p_\leftarrow(1) = -1 & q_\leftarrow(1) = 0\\p_\rightarrow(1) = 1 & q_\rightarrow(1) = 0\\p(1) = 0 & q(1) = 1\\\end{array}$$and for $k\geq 1$$$\begin{array}{cc}p_\leftarrow(2k) = p_\leftarrow(k) & q_\leftarrow(2k) = q_\leftarrow(k)\\p_\rightarrow(2k) = p(k) & q_\rightarrow(2k) = q(k)\\p(2k) = p_\leftarrow(k)+p(k) & q(2k) = q_\leftarrow(k)+q(k)\\\end{array}$$and$$\begin{array}{cc}p_\leftarrow(2k+1) = p(k) & q_\leftarrow(2k+1) = q(k)\\p_\rightarrow(2k+1) = p_\rightarrow(k) & q_\rightarrow(2k+1) = q_\rightarrow(k)\\p(2k+1) = p(k)+p_\rightarrow(k) & q(2k+1) = q(k)+q_\rightarrow(k)\\\end{array}$$

Then the sequence $\big(\frac{p(n)}{q(n)}\big)_{n\geq 1}$, which starts as follows$$0,\; -1,\; 1,\; -2,\; -\frac{1}{2},\; \frac{1}{2},\; 2,\; -3,\; -\frac{3}{2},\; -\frac{2}{3},\; -\frac{1}{3},\;\frac{1}{3},\ldots$$defines a bijection between $\mathbb{N}_{\gt0}$ and $\mathbb{Q}$ (and $\frac{p(n)}{q(n)}$ is always irreducible). This bijection corresponds to breadth-first enumerating the Stern–Brocot tree having root $0$ (or more precisely, root $0/1$, left edge $-1/0$ and right edge $1/0$). In the above recursive definition, $p(n)/q(n)$ is the $n$-th node of the tree, $p_\leftarrow(n)/q_\leftarrow(n)$ is the closest smaller ancestor, and $p_\rightarrow(n)/q_\rightarrow(n)$ is the closest greater ancestor.

Alternatively, the sequence $u(n) := \frac{p(n)}{q(n)}$ can be defined as follows:

For all $r\geq 0$, we have $u(2^r) = -r$ and $u(2^{r+1}-1) = r$, and the rationals $u(2^r+1),\ldots,u(2^{r+1}-2)$ are, in order, those of smallest possible denominator so as to place exactly one of them (strictly) between any two consecutive rationals in the set $\lbrace u(1),\ldots,u(2^{r}-1)\rbrace$.

Alternatively,

The rational $[a_0;a_1,a_2,\ldots,a_s] := a_0 + \frac{1}{a_1+}\frac{1}{a_2+}\cdots\frac{1}{a_s}$ (with $a_0\geq 0$ and $a_1,\ldots,a_s\geq 1$) equals $u(n)$ where $n$ is written $1^{a_0+2} 0^{a_1} 1^{a_2}\cdots 0^{a_{(s-1)}} 1^{a_s-1}$ (for $s$ even) or $1^{a_0+2} 0^{a_1} 1^{a_2}\cdots 1^{a_{(s-1)}} 0^{a_s-1}$ (for $s$ odd) in binary (or just $1^{a_0+1}$ for $s=0$).

The rational $-[a_0;a_1,a_2,\ldots,a_s]$ equals $u(n)$ where $n$ is written $1\, 0^{a_0+1} 1^{a_1} \cdots 1^{a_{(s-1)}} 0^{a_s-1}$ (for $s$ even) or $1\, 0^{a_0+1} 0^{a_1} \cdots 0^{a_{(s-1)}} 1^{a_s-1}$ (for $s$ odd) in binary (or just $1\, 0^{a_0}$ for $s=0$).

The main difference between this sequence based on the Stern–Brocot and those based on the Calkin–Wilf tree is that in the present sequence, we get$$u(2^r) < u(2^r+1) < \cdots < u(2^{r+1}-1)$$for each $r\geq 0$ (and, as explained above, they are the simplest possible rationals we can interleave with the previously defined ones and satisfying this).

Here is a plot of $u(n)$ for $1\leq n\leq 1023$:graph of the Stern–Brocot based sequence


Viewing all articles
Browse latest Browse all 221

Trending Articles