I remember my professor in college challenging me with this question, which I failed to answer satisfactorily: I know there exists a bijection between the rational numbers and the natural numbers, but can anyone produce an explicit formula for such a bijection?
 2,909
 1
 9
 26
 3,861
 4
 24
 29

13Do you need a formula or does the picture and explanation in http://en.wikipedia.org/wiki/Countable_set#Formal_Definition_and_Properties suffice? See also http://en.wikipedia.org/wiki/Cantor_pairing_function#Cantor_pairing_function – lhf Oct 24 '10 at 03:10

I wasn't familiar with pairing functions, so let me look at that more closely. My professor insisted, though, that I come up with a formula, and of course that would also require that equivalent pairs (in the rational number sense) shouldn't get counted more than once. – Alex Basson Oct 24 '10 at 04:55

1@lhf. Maybe you should post your comment as an answer; otherwise, it's not unlikey that this question remains unanswered. – Agustí Roig Oct 24 '10 at 05:21

Could you provide a list of features that you consider legitimate to include in your formula? Often when these questions are posed, responses are met with "that doesn't count as a formula." – Douglas S. Stones Oct 24 '10 at 05:43

4Don't know if it would count as "explicit" but every rational number occurs exactly one in the CalkinWilf sequence http://en.wikipedia.org/wiki/Calkin%E2%80%93Wilf_tree – Jyotirmoy Bhattacharya Oct 24 '10 at 06:42

There's even a shirt! http://thenerdiestshirts.com/blog/mathshirtcw – George Lowther Oct 24 '10 at 23:19

Ok, that shirt is awesome. – Alex Basson Oct 28 '10 at 10:56

1) That would be equivalent to a bijection from the natural numbers to all relatively prime pairs of natural numbers. 2) We know there is no upper bound to the number of prime numbers but we have not yet produced an explicit bijection between them and N. 3) Would a solution for 1 imply a solution for 2? (I don't know.) – Jan 17 '14 at 13:23

See the first part of http://people.mpimbonn.mpg.de/zagier/files/doi/10.4169/amer.math.monthly.120.03.243/NewLooksAtOldNumberTheory.pdf – Dec 14 '14 at 18:43

Wikipedia contains several explicit examples: [Cantor pairing function](http://en.wikipedia.org/wiki/Cantor_pairing_function#Cantor_pairing_function), [Stern–Brocot tree](http://en.wikipedia.org/wiki/SternBrocot_tree), [Calkin–Wilf tree](http://en.wikipedia.org/wiki/CalkinWilf_tree). – lhf Oct 24 '10 at 11:05
7 Answers
We will first find a bijection $h_{+}:\mathbb Z^+\to \mathbb Q^+$. From there, we easily get a bijection $h:\mathbb Z\to \mathbb Q$ by defining: $$h(n)=\begin{cases}h_{+}(n)&n>0\\ 0&n=0\\ h_{+}(n)&n<0 \end{cases}$$
From there, we can use any of the bijections $\mathbb N\to\mathbb Z$ to get our bijection between $\mathbb N$ and $\mathbb Q$. (We'll need a specific such bijection below, $s$.)
Now, every positive integer can be written uniquely as $p_1^{a_1}p_2^{a_2}\cdots$, where the $p_1=2,p_2=3,p_3=5,\dots$ is the sequence of all primes, and the $a_i$ are nonnegative integers, and are nonzero for only finitely many $i$s.
Similarly, every positive rational number can be written uniquely as $p_1^{b_1}p_2^{b_2}\cdots$ where the $b_i$ are integers and only finitely many of the $b_i$ are nonzero.
So define $s:\mathbb N\to\mathbb Z$ (where we take $\mathbb N$ to include $0$):
$$s(n)= (1)^n\left\lfloor\frac{n+1}{2}\right\rfloor $$
The sequence $s(0),s(1),s(2),s(3),\dots$ would be $0,1,1,2,2\dots$, and this is a bijection from $\mathbb N$ to $\mathbb Z$. The only properties we really need for $s$ is that $s$ is a bijection and $s(0)=0$.
Then for any $n=p_1^{a_1}p_2^{a_2}\cdots\in\mathbb Z^+$, define $$h_{+}(n)=p_1^{s(a_1)}p_2^{s(a_2)}\cdots $$
This then defines our bijection $h_{+}:\mathbb Z^+\to \mathbb Q^{+}$.
A potientially interesting feature of $h_+$ is that it is multiplicative  that is, if $\gcd(m,n)=1$ then $h_{+}(mn)=h_+(m)h_{+}(n).$
Another answer.
We again assume $0\in\mathbb N.$
We will need an explicit bijection $\phi:\mathbb N\to\mathcal P_{\text{Fin}}(\mathbb N),$ where $\mathcal P_{\text{Fin}}(\mathbb N)$ is the set of all finite subsets of $\mathbb N.$
We will also use that if $q\neq 1$ is a positive rational number, then $q$ can be written uniquely as a continued fraction:
$$\left[a_0,a_1,\dots,a_k\right]=a_0+\cfrac1{a_1+\cfrac{1}{\ddots +\cfrac{1}{a_k}}}$$ where $a_0$ is a nonnegative integer, the other $a_i$ are positive integers, and $a_k>1.$
We define $g_+:\mathcal P_{\text{Fin}}(\mathbb N)\to\mathbb Q^{+}$ as:
$$\begin{align} &g_+(\emptyset)=1\\ &g_+(\{n\})=n+2\\ &g_+\left(\left\{b_0<b_1<\cdots<b_k\right\}\right)=\left[b_0,b_1b_0,\dots,b_{k1}b_{k2},b_{k}b_{k1}+1\right],\quad k>0 \end{align}$$
The uniqueness of the continued fractions ensures this is a bijection. We had to do some a slight hack to deal with the problem of the empty set.
Then we define $b:\mathbb Z\to \mathbb Q$ similar to before:
$$b(m)=\begin{cases} 0&m=0\\ g_+(\phi(m))&m>0\\ g_+(\phi(m))&m<0 \end{cases}$$ And then compose with any bijection $\mathbb N\to\mathbb Z.$ You can use the function $s$ from the previous section. Then $b\circ s$ is a bijection.
This leaves $\phi,$ but every natural number $n$ can be written uniquely in binary, as $n=\sum_{a\in A_n} 2^{a}$ for some finite set $A_n\subseteq \mathbb N.$ Then we can take $\phi(n)=A_n.$
This means that if $n\in\mathbb N$ then $b(2^n)=n+2$ and $b(0)=1.$ Also, $b(1+2^n)=g_+(\{0,n\})=\frac{1}{n+1}.$
$g_+$ is nice because it can be extended to $\mathcal P(\mathbb N)\to\mathbb R^+$ to show a bijection between these two sets, because every irrational number has a unique infinite continued fraction.
 164,948
 17
 196
 376

1

3Because in each case, only finitely many of the exponents can be nonzero. @RFZ – Thomas Andrews Nov 07 '17 at 22:52
We will first create a bijection from $\mathbb{N}$ to $\mathbb{Q}^{+}$ and then use this to create a bijection from $\mathbb{N}$ to $\mathbb{Q}$.
Step One: Let us first define Stern's diatomic series. This process formalizes the SternBrocot tree mentioned above.
$a_{1} = 1 \\ a_{2k}=a_{k} \\ a_{2k+1}=a_{k}+a_{k+1}$
To get a feel for this series, let us list out the first few terms.
$a_{1}=1 \\ a_{2}=a_{1}=1 \\ a_{3}=a_{1}+a_{2}=1+1=2 \\ a_{4}=a_{2}=1 \\ a_{5}=a_{2}+a_{3}=1+2=3 \\ a_{6}=a_{3}=2 \\ a_{7}=a_{3}+a_{4}=2+1=3 \\ a_{8}=a_{4}=1$
Now to obtain the $n^{th}$ rational number, we define $f: \mathbb{N} \rightarrow \mathbb{Q}^{+}$, by $f(n)= \dfrac{a_{n}}{a_{n+1}}$.
Let us list out the first few terms.
$f(1)= a_{1}/a_{1+1} = 1/1 \\ f(2)= a_{2}/a_{2+1} = 1/2 \\ f(3)= a_{3}/a_{3+1} = 2/1 \\ f(4)= a_{4}/a_{4+1} = 1/3 \\ f(5)= a_{5}/a_{5+1} = 3/2 \\ f(6)= a_{6}/a_{6+1} = 2/3 \\ f(7)= a_{7}/a_{7+1} = 3/1 $
This function enables us to say that the $6^{th}$ rational number is $2/3$. Moreover, this function is a bijection. For proof of this, see Theorem 5.1 here http://faculty.plattsburgh.edu/sam.northshield/080412.pdf.
Since $f$ is a bijection this implies that $f^{1}$ exists. That means given a rational number we can find the corresponding natural number. For example suppose you have a fraction, say it is $1/4$. Can we determine the $n$ such that $f(n)=1/4$? The answer is a resounding yes. Given a positive rational number, $q \in \mathbb{Q}$, the $n$ such that $f(n)=q$ is found by $n=f^{1}(q)$. This function, $f^{1}$, is given as follows:
$f^{1}(1)=1 \\ f^{1}(q)= 2f^{1} \bigg(\dfrac{q}{1q} \bigg) ~ \text{if} ~ q<1 \\ f^{1}(q) = 2f^{1}(q1)+1 ~\text{if}~ q>1$
As an example, we see from above that $f(5)={3/2}$. Let us plug $(3/2)$ into $f^{1}$ and see if we get 5.
$f^{1}(3/2)=2f^{1} \bigg(\dfrac{3/2}{1(3/2)} \bigg)+1=2f^{1} \bigg(\dfrac{1}{2} \bigg)+1.$ A quick calculation yields that $f^{1} \bigg(\dfrac{1}{2} \bigg)=2$ and so we get $f^{1}(3/2)=2f^{1} \bigg(\dfrac{1}{2} \bigg)+1=2(2)+1=5$.
Step Two: We showed there exists a bijection between $\mathbb{N}$ and $\mathbb{Q}^{+}$. We now attempt to show there exists an explicit bijection between $\mathbb{N}$ and $\mathbb{Q}$. Using the work done in Step One, it appears easier to first create a bijection between $\mathbb{Z}$ and $\mathbb{Q}$. The reason for doing so is because we have already created a bijection from the positive integers (natural numbers) to the positive rationals. So it only seems natural that by adding in the negative integers, we can map them to the negative rationals and thus obtain a bijection. We do this as follows:
$$ g(z) = \begin{cases} \dfrac{a_{z}}{a_{z+1}}, & \text{if } z>0 \\ \\  \dfrac{a_{z}}{a_{(z1)}}, & \text{if } z<0 \\ \\ 0, & \text{if } z=0 \end{cases} $$ where the $a_{i}$ term refers to the $i^{th}$ term in Stern's diatomic series.
We already referenced a proof by Northshield showing that $g(z)=\dfrac{a_{z}}{a_{z+1}}$ if $z>0$ is a bijection from $\mathbb{N} \rightarrow \mathbb{Q}^{+}$. Equivalently, we may write this as $g$ is a bijection from $\mathbb{Z}^{+}$ to $\mathbb{Q}^{+}$ for $z>0$. Now, it follows by the symmetry of the problem that $g(z)= \dfrac{a_{z}}{a_{(z1)}}$ is a bijection from $\mathbb{Z}^{}$ to $\mathbb{Q}^{}$ if $z<0$. That is, $g$ is a bijection between the negative integers and the negative rationals. So we have covered all the positive and negative rationals. The only element in the rationals that is not accounted for is the zero element. So we shall have the integer $0$ mapping to the rational number $0$. However, $g$ is a bijection from the integers to the rationals. We wish to find a bijection from the natural numbers to the rationals. So we shall now define the wellknown bijection from the natural numbers to the integers.
$$ h(n) = \begin{cases} \dfrac{n}{2}, & \text{if }n\text{ is even} \\ \dfrac{n1}{2}, & \text{if }n\text{ is odd} \end{cases} $$
You may check for yourself that $h$ is a bijection. It follows that $g~\circ~ h: \mathbb{N} \rightarrow \mathbb{Q}$ is a bijection since the composition of two bijections is a bijection. Thus, we have an explicit bijection from $\mathbb{N}$ to $\mathbb{Q}$.
However, given a rational number, can we find what this rational number maps to in the set of natural numbers? Although I do not prove it, the answer is yes and is given by the following piecewise defined function which is an extension of the function defined in Step One. We first define $g^{1}: \mathbb{Q} \rightarrow \mathbb{Z}$ as
$$ g^{1}(q) = \begin{cases} 2f^{1}(q1)+1, & \text{if } q>1 \\ 1, & \text{if } q=1 \\ 2f^{1} \bigg(\dfrac{q}{1q} \bigg), & \text{if } 0<q<1 \\ 0, & \text{if } q=0 \\ 2 \Bigg(f^{1} \bigg(\dfrac{q}{1+q}\bigg) \Bigg), & \text{if } 1<q<0 \\ 1, & \text{if } q=1 \\ 2(f^{1}(q1)+1), & \text{if } q<1 \end{cases} $$
We now define the function $h^{1}: \mathbb{Z} \rightarrow \mathbb{N}$ as follows:
$$ h^{1}(z)= \begin{cases} 2z, & \text{if } z>0 \\ 1, & \text{if } z=0 \\ 2z1, & \text{if } z<0 \\ \end{cases} $$
Then $h^{1} \circ g^{1}: \mathbb{Q} \rightarrow \mathbb{N}$ is the bijection we are looking for.
 89,705
 18
 102
 171
 363
 2
 7

Superb exposition! ... but I think you've made a little typo in the bit where you tell how to do the explicit inverse of _f_ for arbitrary input: in the actual example you've put $\operatorname{f^{1}}({3\over2})=2\operatorname{f^{1}}\left(\frac{{3\over2}}{1{3\over2}}\right)+1$; & I think it ought to be $2\operatorname{f^{1}}({3\over2}1)+1$. – AmbretteOrrisey Dec 12 '18 at 06:38

What this boils down to as an algorithm, is: commence the euclidian algorithm on the numerator & denominator, & represent the _quotients_ as _run lengths of bits_ from right to left, beginning with 0 if the fraction <1 & 1 if >1. Also proceed all the way to the remainder of 0, rather than only to a remainder of 1. The very last step is to _OR_ the leftmost bit with 1. This algorithm has indeed already been expounden by __Calkin & Wilf__ ... though I do not have a specific reference handy. – AmbretteOrrisey Dec 17 '18 at 08:04
Recently I was reading some papers by Don Zagier and found this one most interesting. Here, you can get not only a satisfactory proof of the bijection, but also you will have the notion of the rational number immediately after, or before, a given number, which we don't have in Cantor's proof.
Theorem:
The map $$S(x)=\frac{1}{2\lfloor x\rfloorx+1}$$ has the property that, among the sequence $S(0),S(S(0),S(S(S(0)),\cdots $ every positive rational numbers appears once and only once.
Therefore if we write $S^n(x)$ for $n^{th}$ iterate of $S$, then we obtain an explicit bijection $F:\mathbb{N}\to \mathbb{Q}^{+}$ by $F(n)=S^n(0) $. The proof is explained in the link I have mentioned above.
 2,909
 1
 9
 26

1Cf. [Calkin–Wilf sequence](https://en.m.wikipedia.org/wiki/Calkin–Wilf_tree) – J. W. Tanner May 22 '20 at 05:24
Preliminaries
I will be using the Continued Fraction conception. Firstly, let us consider only rationals that are less than 1. So $$q < 1, \quad q\in\mathbb{Q}$$ So every rational $q$ can be written as a continued fraction: $$q = \cfrac{1}{a_1 + \cfrac{1}{a_2 +\cfrac{1}{a_3 + ...}}} := [a_1, a_2, a_3, ...]$$ Note that none of the $a_i$ is zero and for every $q\in\mathbb{Q}$ its q.f. is of the finite length. Also note that we're using only that kind of q.f.'s in which all the numerators are 1's.
Formula
Let us construct a bijection $\Phi$ between rationals and naturals as follows: $$\Phi: q \mapsto \prod_{i=1}^{n_q}p_{i}^{a_i  1},$$ where $n_q$ is the length of q.f. for $q$ and $p_i$ is $i$th prime number. The inverse is straightforward.
Example
$$\Phi\Big(\frac{30}{43}\Big) = 2^03^15^27^3 = 25725$$ This is because $$\frac{30}{43} = \cfrac{1}{1+\cfrac{1}{2+\cfrac{1}{3+\cfrac{1}{4}}}} := [1,2,3,4]$$ And viceversa: $$\Phi^{1}(225) = \frac{10}{13} = \cfrac{1}{1+\cfrac{1}{3+\cfrac{1}{3}}}$$ This is because $$225 = 2^03^25^2$$
Of course this works iff there is bijection between those kind of continued fractions and rationals. But it is not too hard to prove.
P.S. I feel that I'm missing something here. Please, verify.
 1,240
 8
 18

It's very good! It provides a bijection between $\mathbb{Q} \cap (0,1)$ and the integers $>0$. Indeed, any such positive integer corresponds to an element of finite support in $\prod_{p } \mathbb{N}$. Any such element of finite support, increase by $1$ all the components up to the last $\ne 0$ element, Now compose the continued fraction from it (implicitly you use that the continued fraction does not end with $1$ as a last quotient). – orangeskid Oct 11 '17 at 16:59


@Wolfgang Very interesting, and thank you! This second example, however, confuses me. As you observe, $\frac{10}{13} := [1, 3, 3]$. So shouldn't $\Phi(\frac{10}{13}) = 2^{11}3^{31}5^{31} = 2^03^25^2 = 225$? – Alex Basson Oct 12 '17 at 00:50

The method used here cobbles together parts and pieces of the Euler's totient function to create our sequence that bijectively covers all the rational numbers.
The function is implemented using the python programming language, but the interested reader can figure out what is happening by inspecting the output.
Here is the program:
#********
# Desc: Define a bijection of natural numbers to the rational numbers
#********
import sys
import fractions
def moreTicks(curTick):
for k in range(1, curTick):
if fractions.gcd(curTick, k) == 1:
moreTicksList.append(fractions.Fraction(k, curTick))
return curTick + 1
#*******#
while True:# M A I N L I N E #
#*******#
# # initialize state of function machine
step = 0
negSide = 0
posSide = 0
curTick = 2
phiList = []
print(0, ', ', end='')
while True:
#print('expand by phi(n) count on working range')
moreTicksList = []
curTick = moreTicks(curTick)
for i in range(negSide, posSide + 1):
for f in moreTicksList:
print(f + fractions.Fraction(i, 1), ', ', end='')
for f in moreTicksList:
phiList.append(f)
#print("add phiList to '' side")
negSide = negSide  1
print(negSide, ', ', end='')
for f in phiList:
print(f + fractions.Fraction(negSide, 1), ', ', end='')
#print("add phiList to '+' side")
posSide = posSide + 1
print(posSide, ', ', end='')
for f in phiList:
print(f + fractions.Fraction(posSide, 1), ', ', end='')
step = step + 1
if step == 7:
print('...', end='')
sys.exit()
Here is the output sequence (you can use the slider to see further out):
0 , 1/2 , 1 , 1/2 , 1 , 3/2 , 2/3 , 1/3 , 1/3 , 2/3 , 4/3 , 5/3 , 2 , 3/2 , 5/3 , 4/3 , 2 , 5/2 , 7/3 , 8/3 , 7/4 , 5/4 , 3/4 , 1/4 , 1/4 , 3/4 , 5/4 , 7/4 , 9/4 , 11/4 , 3 , 5/2 , 8/3 , 7/3 , 11/4 , 9/4 , 3 , 7/2 , 10/3 , 11/3 , 13/4 , 15/4 , 14/5 , 13/5 , 12/5 , 11/5 , 9/5 , 8/5 , 7/5 , 6/5 , 4/5 , 3/5 , 2/5 , 1/5 , 1/5 , 2/5 , 3/5 , 4/5 , 6/5 , 7/5 , 8/5 , 9/5 , 11/5 , 12/5 , 13/5 , 14/5 , 16/5 , 17/5 , 18/5 , 19/5 , 4 , 7/2 , 11/3 , 10/3 , 15/4 , 13/4 , 19/5 , 18/5 , 17/5 , 16/5 , 4 , 9/2 , 13/3 , 14/3 , 17/4 , 19/4 , 21/5 , 22/5 , 23/5 , 24/5 , 23/6 , 19/6 , 17/6 , 13/6 , 11/6 , 7/6 , 5/6 , 1/6 , 1/6 , 5/6 , 7/6 , 11/6 , 13/6 , 17/6 , 19/6 , 23/6 , 25/6 , 29/6 , 5 , 9/2 , 14/3 , 13/3 , 19/4 , 17/4 , 24/5 , 23/5 , 22/5 , 21/5 , 29/6 , 25/6 , 5 , 11/2 , 16/3 , 17/3 , 21/4 , 23/4 , 26/5 , 27/5 , 28/5 , 29/5 , 31/6 , 35/6 , 34/7 , 33/7 , 32/7 , 31/7 , 30/7 , 29/7 , 27/7 , 26/7 , 25/7 , 24/7 , 23/7 , 22/7 , 20/7 , 19/7 , 18/7 , 17/7 , 16/7 , 15/7 , 13/7 , 12/7 , 11/7 , 10/7 , 9/7 , 8/7 , 6/7 , 5/7 , 4/7 , 3/7 , 2/7 , 1/7 , 1/7 , 2/7 , 3/7 , 4/7 , 5/7 , 6/7 , 8/7 , 9/7 , 10/7 , 11/7 , 12/7 , 13/7 , 15/7 , 16/7 , 17/7 , 18/7 , 19/7 , 20/7 , 22/7 , 23/7 , 24/7 , 25/7 , 26/7 , 27/7 , 29/7 , 30/7 , 31/7 , 32/7 , 33/7 , 34/7 , 36/7 , 37/7 , 38/7 , 39/7 , 40/7 , 41/7 , 6 , 11/2 , 17/3 , 16/3 , 23/4 , 21/4 , 29/5 , 28/5 , 27/5 , 26/5 , 35/6 , 31/6 , 41/7 , 40/7 , 39/7 , 38/7 , 37/7 , 36/7 , 6 , 13/2 , 19/3 , 20/3 , 25/4 , 27/4 , 31/5 , 32/5 , 33/5 , 34/5 , 37/6 , 41/6 , 43/7 , 44/7 , 45/7 , 46/7 , 47/7 , 48/7 , 47/8 , 45/8 , 43/8 , 41/8 , 39/8 , 37/8 , 35/8 , 33/8 , 31/8 , 29/8 , 27/8 , 25/8 , 23/8 , 21/8 , 19/8 , 17/8 , 15/8 , 13/8 , 11/8 , 9/8 , 7/8 , 5/8 , 3/8 , 1/8 , 1/8 , 3/8 , 5/8 , 7/8 , 9/8 , 11/8 , 13/8 , 15/8 , 17/8 , 19/8 , 21/8 , 23/8 , 25/8 , 27/8 , 29/8 , 31/8 , 33/8 , 35/8 , 37/8 , 39/8 , 41/8 , 43/8 , 45/8 , 47/8 , 49/8 , 51/8 , 53/8 , 55/8 , 7 , 13/2 , 20/3 , 19/3 , 27/4 , 25/4 , 34/5 , 33/5 , 32/5 , 31/5 , 41/6 , 37/6 , 48/7 , 47/7 , 46/7 , 45/7 , 44/7 , 43/7 , 55/8 , 53/8 , 51/8 , 49/8 , 7 , 15/2 , 22/3 , 23/3 , 29/4 , 31/4 , 36/5 , 37/5 , 38/5 , 39/5 , 43/6 , 47/6 , 50/7 , 51/7 , 52/7 , 53/7 , 54/7 , 55/7 , 57/8 , 59/8 , 61/8 , 63/8 , ...
The sequence 'calibrates' the rational number 'tick marks' on our ideal 'measuring rod'.
 10,521
 1
 17
 43
Set $\Bbb N = \{1,2,3,4,\dots\}$.
Here we will define a bijective mapping between $\Bbb N$ and the subset of rational numbers
$\quad \Bbb Q_{\gt 0}^{\lt 1} = \{q \in \Bbb Q \mid 0 \lt q \lt 1\}$
For integer $n \ge 1$ define the set
$\tag 1 F_n = \{s/t\in \Bbb Q \mid [s, t \in \Bbb N] \land [t \le n] \land [s \lt t\}]$
We have a chain of inclusions
$\tag 2 \emptyset = F_1 \subset F_2 \subset F_3 \subset \dots \subset F_k \subset \dots $
and denote the union of these sets by $F$; observe that $F = \Bbb Q_{\gt 0}^{\lt 1}$.
Let the number of elements in the set $F_k$ be denoted by $f_k$.
If $k \gt 1$ let $G_k = F_k \setminus F_{k1}$; observe that $G_k$ has an ordering relation $\le$ defined on it.
We define a function $\Gamma: \Bbb N \to F$ by the specification
$\quad$ Given $m \in \Bbb N$
$\quad$ Find $k \in \Bbb N$ such that $f_k \lt m \le f_{k+1}$
$\quad$ Set $\Gamma(m)$ to the
$\tag 3 [mf_k]^\text{th} \text{ element of } G_{k+1}$
Exercise: Show that $\Gamma$ is a well defined function that puts the sets into a $\text{1:1 correspondence}$.
See also the wikipedia article Farey sequence.
 10,521
 1
 17
 43
This is a bijection between the SternBrocot tree and the tree of Natural numbers. Every left node is given by $ L_n = [2 P_n ] $ and every right one by $ R_n= [2 P_n +1 ]$ where $P_n $ is the value of the parent node and $P_0=[1]$. We have the sequence of transformations $ P_n \rightarrow [ L_n , R_n ]$, $L_n \rightarrow P_{n+1}$, $R_n \rightarrow P^\prime_{n+1}$ .
In list notation for the tree (count the brackets) this is
$$ n = 1 \mapsto [1,[2],[3]] $$
$$n = 2 \mapsto [1,[2,[4], [5]], [3,[6], [7]]] $$ $$ n = 3 \mapsto [1,[2,[4,[8],[9]],[5,[10],[11]]],[3,[6,[12],[13]],[7,[14],[15]]]] $$ and so on.
 1,039
 7
 16