Two trees enumerating the positive rationals

Two trees enumerating the positive rationals

Lionel Ponton
lionel.ponton@gmail.com
Abstract

We give two trees allowing to represent all positive rational numbers. These trees can be seen as ternary and quinary analogues of the Calkin-Wilf 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 Calkin-Wilf tree. Finally, we show that the two sequences we have obtained, together with Calkin-Wilf sequence, are the only ones which satisfy a relation analogue to Newman’s relation and enumerate the positive rationals.

1 Introduction

It is well-known, 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 Cantor-Bernstein’s theorem.

In 2000, N. Calkin and H. S. Wilf [CW00] have described an elegant explicit enumeration of . Its first few terms are

 11,\leavevmode\nobreak 12,\leavevmode\nobreak 21,\leavevmode\nobreak 13,\leavevmode\nobreak 32,\leavevmode\nobreak 23,\leavevmode\nobreak 31,\leavevmode\nobreak 14,\leavevmode\nobreak 43,\leavevmode\nobreak 35,\leavevmode\nobreak 52,\leavevmode\nobreak 25,\leavevmode\nobreak 53,\leavevmode\nobreak 34,\leavevmode\nobreak 41,\leavevmode\nobreak 15,\leavevmode\nobreak 54,\leavevmode\nobreak 47,...

This sequence, known as Calkin-Wilf sequence, is defined by a binary tree the following way :

1. the top of the tree is ;

2. the vertex labeled has two children : the left child labeled and the right child labeled .

This leads to the Calkin-Wilf tree, whose first few rows are :

The Calkin-Wilf 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 Calkin-Wilf 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 Stern-Brocot tree [GKP94, pp. 116-123 et pp. 305-306] and closely connected to the Calkin-Wilf 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. 110-114] and [Nor10]).

Calkin-Wilf sequence gives also the answer to a problem set by D. Knuth [Knu01] : if denotes the p-adic valuation of the positive integer , prove that the sequence defined by

 x0=0 and, for every n∈N∗, xn=11+2v2(n)−xn−1 (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 Calkin-Wilf 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 Calkin-Wilf sequence.

The editors of [KRSS03] also quote an answer of Moshe Newman, who has shown that the sequence satisfies the recurrence relation :

 For every n∈N∗, xn=11+2⌊xn−1⌋−xn−1 (2)

where denotes the integral part of the real number This implies, in particular, the striking result :

 For every n∈N∗, ⌊xn−1⌋=v2(n). (3)

Another way to formulate Newman’s result consists in saying that the function defined on by

 f:x↦11+2⌊x⌋−x (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 Calkin-Wilf 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 Calkin-Wilf sequence, the only sequences which enumerate the positive rationals and are defined by and a recurrence relation of the form :

 For every n∈N∗, un=f(un−1)k, (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 :

1. the top of the tree is ;

2. the children of are defined by :

1. if is odd :

2. 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

 N3n−1 =(4(cn+1)an−bn;2an;0) N3n =(an;2an+bn;cn+1) N3n+1 =(2an+bn;2an+2bn;0)

As and are positive integers, it is clear that , , and are positive integers. Moreover, since ,

 a3n−1=4(cn+1)an−bn=4an−(bn−4ancn)⩾2an (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),

 b3n−1−4a3n−1c3n−1=2an⩽a3n−1⩽2a3n−1.

For , by using(6),

 b3n−4a3nc3n=bn−4ancn−2an⩽2an−2an=0⩽2a3n,

And for ,

 b3n+1−4a3n+1c3n+1=2an+2bn⩽4an+2bn=2a3n+1.

In the case where is even, the proof is similar. One only has to replace (6) by

 a3n−1=2(cn+1)an−bn2=2an−bn−4ancn2⩾an. (7)

Hence Lemma 2 is proved by induction.

Now we put, for every ,

 tn=anbn.

By Lemma 2, is a sequence of positive reduced rationals. The first few terms of this sequence are :

We remark that, for every ,

 t3k−1=4(ck+1)ak−bk2ak=2(v3(k)+1)−12tk=2v3(3k)−12tk, (8) t3k=ak2ak+bk=tk2tk+1, (9) t3k+1=2ak+bk2ak+2bk=2tk+12tk+2. (10)

We extend this sequence to by putting

 t0=0.

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

 12(1+2v3(1)−t0)=12=t1and12(1+2v3(2)−t1)=1=t2.

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)

 tn=2(v3(k)+1)−12tk=2(v3(k)+1)−[1+2v3(k)−tk−1]=1+tk−1. (11)

Moreover, since is the right child of , by (10). But , whence

 12(1+2v3(n)−tn−1)=12(1−2tk−1+12tk−1+2)=1+tk−1=tn.

2nd case. — If is the middle child of , then and is the left child of . By using (8), we have

 tn−1=t3k−1=2v3(3k)−12tk=2v3(n)−12tk.

Therefore by using (9) we obtain

 12(1+2v3(n)−tn−1)=12+1tk=tk2tk+1=tn.

3rd case. — If is the right child of then and is the middle child of . Hence, by (9) and (10),

 tn−1=tk2tk+1andtn=2tk+12tk+2.

Since , we have

 12(1+2v3(n)−tn−1)=12(1−tk2tk+1)=2tk+12tk+2=tn.

Proposition is proved by induction.

Corollary 1.

— For every , .

Proof. — This is exactly the equality (11).

Corollary 2.

— For every , , and .

Proof. — Let . Since ,

 t3k=tk2tk+1∈]0;12[andt3k+1=2tk+12tk+2∈]12;1[.

Moreover, from corollary 1, .

Remark 1.

— As , and , we can also see that for every , , et .

Now we prove that the sequence satisfies relations similar to (2) and (3).

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.

From 1 and 2 we get directly

Corollary 3.

— Let be defined in (4). Then the sequence satisfies and, for every ,

 tn=12(1+2⌊tn−1⌋−tn−1)=f(tn−1)2.

2.3 The sequence (tn) enumerates Q+

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.

Hence the ternary tree enabled us to construct a sequence which enumerates the non negative rationals and satisfies recurrence relations similar to (1) and (2). Now we give a similar construction by using a quinary tree.

3 A quinary tree

3.1 Definition

We consider the quinary tree whose vertices are labeled by triples of integers such that :

1. the top of the tree is ;

2. 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 i-th 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,

 s5k−3=3(4ck+3)ak−2bk3(6ck+5)ak−3bk=3(4ck+3)−2sk3(6ck+5)−3sk, (12) s5k−2=(6ck+5)ak−bk6(ck+1)ak−bk=6ck+5−1sk6(ck+1)−1sk, (13) s5k−1=6(ck+1)ak−bk3ak=2(ck+1)−13sk, (14) s5k=ak3ak+bk=13+1sk, (15) s5k+1=3ak+bk6ak+3bk=3sk+16sk+3=3+1sk6+3sk. (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

 13(1+2v5(1)−s0)=13=s1et13(1+v5(2)−s1)=12=s2.

Assume that, for a given , the property is true for every positive integer . Denote () the parent of .

1st case. — If is the first child of then and is the fifth child of . By the induction hypothesis,

 sk=13(1+2v5(k)−sk−1)=13(1+2ck−sk−1).

Hence, by using (12),

 sn=3(4ck+3)−2sk3(6ck+5)−3sk=3(4ck+3)−6(2ck+1−sk−1)3(6ck+5)−9(2ck+1−sk−1)=1+2sk−12+3sk−1. (17)

As , (16) yields

 13(2v5(n)+1−sn−1)=13(1−s5(k−1)+1)=13(1−3sk−1+16sk−1+3)=2sk−1+33sk−1+2=sn.

2nd case. — If is the second child of then and is the first child of . As , (12) and (13) yield

 13(2v5(n)+1−sn−1)=13(1−s5k−3)=13(1−3(4ck+3)ak−2bk3(6k+5)ak−3bk)=(6ck+5)ak−bk6(ck+1)ak−bk=s5k−2=sn.

3rd case. — If is the third child of then and is the second child of . As , (13) and (14) yield

 13(2v5(n)+1−sn−1