Two trees enumerating the positive rationals
Abstract
We give two trees allowing to represent all positive rational numbers. These trees can be seen as ternary and quinary analogues of the CalkinWilf tree. For each of these two trees, we give recurrence formulas allowing to compute the rational number corresponding to the node . These are analogues of the formulas given by Donald Knuth and Moshe Newman for the CalkinWilf tree. Finally, we show that the two sequences we have obtained, together with CalkinWilf sequence, are the only ones which satisfy a relation analogue to Newman’s relation and enumerate the positive rationals.
1 Introduction
It is wellknown, since Cantor’s first works on the theory of cardinality, that the rationals are countable. However, it is not so simple to give an explicit enumeration of all of them. Most of the time (see [Bra05]), one proves that is countable by constructing a bijection (or an injection) from to , which yields an injection from to , and the conclusion follows from CantorBernstein’s theorem.
In 2000, N. Calkin and H. S. Wilf [CW00] have described an elegant explicit enumeration of . Its first few terms are
This sequence, known as CalkinWilf sequence, is defined by a binary tree the following way :

the top of the tree is ;

the vertex labeled has two children : the left child labeled and the right child labeled .
This leads to the CalkinWilf tree, whose first few rows are :
The CalkinWilf sequence is then obtained by reading the fraction on level 1, then the two fractions on level 2 from left to right, then the four fractions on level 3 from left to right, and so on. Besides the fact that every positive rational number appears once and only once in reduced form in the tree, this sequence has another remarkable property : the numerator of the term of rank is equal to the denominator of the term of rank . In other words, there exists a sequence of positive integers such that the term of rank of the CalkinWilf sequence is equal to . In fact, the sequence has been discovered as soon as the mid 19th century, independently by the German mathematician M. Stern [Ste58] and the French clockmaker A. Brocot [Bro61] by considering the median fraction of two fractions and . This procedure leads to another binary tree which enumerates the rationals, named the SternBrocot tree [GKP94, pp. 116123 et pp. 305306] and closely connected to the CalkinWilf tree (see [Man09] and [BBT10]). B. Reznick [Rez08] notes that Stern has proved in his 1858 paper that, for every pair of positive coprime integers , there exists one and only one integer such that and . In other words, Stern proved that is countable more than 15 years before Cantor’s first papers on the subject. The sequence , which is known nowadays as Stern diatomic sequence, has been widely studied since that time and is known to be connected with many other subjects such as hyperbinary representations, Farey sequences, continued fractions, the Fibonacci sequence or the Minkowski ?function (see [AZ06, pp. 110114] and [Nor10]).
CalkinWilf sequence gives also the answer to a problem set by D. Knuth [Knu01] : if denotes the padic valuation of the positive integer , prove that the sequence defined by
(1) 
enumerates the positive rationals. Various solutions to this problem have been given in [KRSS03], among which C. P. Ruppert’s one, which associates to the sequence a tree almost identical to CalkinWilf tree, the only difference being that the vertices are labeled, not by the rationals , but by the pairs of coprime positive integers , which is clearly the same. Hence Knuth sequence is exactly the same as CalkinWilf sequence.
The editors of [KRSS03] also quote an answer of Moshe Newman, who has shown that the sequence satisfies the recurrence relation :
(2) 
where denotes the integral part of the real number This implies, in particular, the striking result :
(3) 
Another way to formulate Newman’s result consists in saying that the function defined on by
(4) 
generates all positive rationals by iteration starting from .
The purpose of this paper is to construct two sequences et satisfying relations similar to (1) and (2). For doing this, we define two trees : a ternary tree associated to the sequence and a quinary tree associated to the sequence . These two trees are not labeled by rationals or pairs of coprime integers, but by triples of integers. They can be considered as generalizations of the CalkinWilf tree, in the sense that they lead to sequences which enumerate the postive rationals and satisfy relations similar to (1), (2) and (3). However, these generalizations are quite different from those proposed by T. Mansour and M. Shattuck ([MS11] and [MS15]), by B. Bates and T. Mansour [BM11] and by S. H. Chan [Cha11]. Finally, we show that the sequences and are, together with the CalkinWilf sequence, the only sequences which enumerate the positive rationals and are defined by and a recurrence relation of the form :
(5) 
where is defined by (4) and .
2 A ternary tree
2.1 Definition
We consider the ternary tree whose vertices are labeled by triples of integers and such that :

the top of the tree is ;

the children of are defined by :

if is odd :

if is even :

Hence the first few levels of are :
The three children of the vertex are called respectively the left, the middle and the right child of and we say that is the parent of these three children.
For every , we denote by the vertex of index of the tree read from the top and, at each level, from left to right. Hence, , , , and so on… Observe that, by definition, for every , the left, middle and right children of are respectively , and .
Lemma 1.
— For every , .
Proof. — For it is true since . Assume that for a given . Then the left child of is whence by definition . Similarly, is the right child of and . Finally, as is the middle child of , , and lemma 1 is proved by induction.
Lemma 2.
— For every , and are positive coprime integers and .
Proof. — For it is true since , and . Assume that, for a given , and are positive coprime integers satisfying .
Assume that is odd. Then the three children of are
As and are positive integers, it is clear that , , and are positive integers. Moreover, since ,
(6) 
and is also a positive integer.
Let . Then divides and . Hence is odd since is odd and therefore divides . As and are coprime, we have , which means that are coprime. Similarly we obtain
Finally, for we have, by using (6),
For , by using(6),
And for ,
In the case where is even, the proof is similar. One only has to replace (6) by
(7) 
Hence Lemma 2 is proved by induction.
Now we put, for every ,
By Lemma 2, is a sequence of positive reduced rationals. The first few terms of this sequence are :
We remark that, for every ,
(8)  
(9)  
(10) 
We extend this sequence to by putting
We will show that enumerates the non negative rationals, i.e. that is a bijection from to . Before this, we will give two recurrence relations satisfied by the sequence .
2.2 Two recurrence relations
First we prove that the sequence satisfies a recurrence relation similar to (1).
Proposition 1.
— For every , .
Proof. — This is true for and , since
Now assume that, for a given integer , the property is true for every positive integer . Denote ) the parent of .
1st case. — If is the left child of then and is the right child of . As the property is true when we have by using (8)
(11) 
Moreover, since is the right child of , by (10). But , whence
2nd case. — If is the middle child of , then and is the left child of . By using (8), we have
Therefore by using (9) we obtain
Since , we have
Proposition is proved by induction.
Corollary 1.
— For every , .
Proof. — This is exactly the equality (11).
Corollary 2.
— For every , , and .
Proof. — Let . Since ,
Moreover, from corollary 1, .
Remark 1.
— As , and , we can also see that for every , , et .
Proposition 2.
— For every , .
Proof. — For , clearly .
Let Assume that, for every positive integer , and denote by the parent of ().
If is the left child of then , whence and by Remark 1 .
If is the right child of then , and .
If is the middle child of then and is the left child of . Hence, by Corollary 1, and . By the induction hypothesis, it follows that .
Proposition 2 is proved by induction.
Corollary 3.
— Let be defined in (4). Then the sequence satisfies and, for every ,
2.3 The sequence enumerates
Theorem 1.
— The mapping is a bijection from to .
Proof. — As and is reduced for every , we have to prove that, for every pair of non zero coprime natural integers , there exists one and only one such that and .
The proof is by induction on .
If then and Corollary 2 implies that is the only one integer such that .
Assume that, for a given integer , the property is true for every . Let be a pair of non zero coprime natural integers such that .
1st case : . Then, by Corollary 2, if exists, there exists such that . Hence is the middle child of . Therefore . Now, and and are coprime. By the induction hypothesis, there exists one and only one integer such that and which proves that is the one and only one integer such that and .
2nd case : Then, since and are coprime. By Corollary 2, is the sole integer such that and .
3rd case : Then, by Corollary 2, if exists, there exists such that . Hence is the right child of . If is even . Since and and are coprime, we see, as in the first case, that is the one and only one integer such that and . If is odd then As and and are coprime (since is even), we draw the same conclusion.
4th case : Then since and are coprime. But this is impossible because .
5th case : Then, by Corollary 2, if exists, there exists an integer such that . Hence is the left child of . In this case, we cannot argue as before because, for odd , is not necessarily greater than as can be seen, for example, when and . However, by Corollary 1, , whence . As and and are coprime, by the induction hypothesis there exists one and only one integer such that and This shows that is the one and only one integer such that and .
Theorem 1 is therefore proved by induction.
3 A quinary tree
3.1 Definition
We consider the quinary tree whose vertices are labeled by triples of integers such that :

the top of the tree is ;

the children of are defined by :

if doesn’t divide :

if 3 divides :

The five children of the vertex are called from left to right respectively first, second, third, fourth and fifth child of
For every , we denote the vertex of index of the tree read from the top and, at each level, from left to right. Thus, , , , , , and so on…
By definition, for every , the ith child of is .
It is easy to check, as in Lemmas 1 and 2, that for every , , , (with, this time, and . Hence, by putting for every , , we define a sequence of positive reduced rationals, whose first few terms are :
It can be remarked that, for every , whether 3 divides or not,
(12)  
(13)  
(14)  
(15)  
(16) 
We extend this sequence to by putting . We will now show, as we did for that , enumerates the elements of .
3.2 Recurrence relations
Proposition 3.
— For every ,
Proof. — For and this is true since
Assume that, for a given , the property is true for every positive integer . Denote () the parent of .