Calkin–Wilf tree

From testwiki
Revision as of 09:18, 6 January 2025 by imported>Citation bot (Added doi-broken-date. | Use this bot. Report bugs. | Suggested by Dominic3203 | Category:Integer sequences | #UCB_Category 162/220)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:Short description Template:Multiple image In number theory, the Calkin–Wilf tree is a tree in which the vertices correspond one-to-one to the positive rational numbers. The tree is rooted at the number 1, and any rational number Template:Mvar expressed in simplest terms as the fraction Template:Math has as its two children the numbers Template:Math and Template:Math. Every positive rational number appears exactly once in the tree. It is named after Neil Calkin and Herbert Wilf, but appears in other works including Kepler's Harmonices Mundi.

The sequence of rational numbers in a breadth-first traversal of the Calkin–Wilf tree is known as the Calkin–Wilf sequence. Its sequence of numerators (or, offset by one, denominators) is Stern's diatomic series, and can be computed by the fusc function.

History

The tree from Kepler's Harmonices Mundi (1619)

The Calkin–Wilf tree is named after Neil Calkin and Herbert Wilf, who considered it in a 2000 paper. In a 1997 paper, Jean Berstel and Aldo de Luca[1] called the same tree the Raney tree, since they drew some ideas from a 1973 paper by George N. Raney.[2] Stern's diatomic series was formulated much earlier by Moritz Abraham Stern, a 19th-century German mathematician who also invented the closely related Stern–Brocot tree. Even earlier, a similar tree (including only the fractions between 0 and 1) appears in Kepler's Harmonices Mundi (1619).[3]

Definition and structure

The Calkin–Wilf tree, drawn using an H tree layout.

The Calkin–Wilf tree may be defined as a directed graph in which each positive rational number Template:Math occurs as a vertex and has one outgoing edge to another vertex, its parent, except for the root of the tree, the number 1, which has no parent.

The parent of any rational number Template:Math can be determined after placing the number into simplest terms, as a fraction Template:Math with Template:Math relatively prime. If Template:Math, its parent is Template:Math; if Template:Math, its parent is Template:Math. Thus, in either case, the parent is a fraction with a smaller sum of numerator and denominator, so repeated reduction of this type must eventually reach the number 1. As a graph with one outgoing edge per vertex and one root reachable by all other vertices, the Calkin–Wilf tree must indeed be a tree.

The children of any vertex in the Calkin–Wilf tree may be computed by inverting the formula for the parents of a vertex. Each vertex Template:Math has one child whose value is less than 1, Template:Math (because Template:Math). Similarly, each vertex Template:Math has one child whose value is greater than 1, Template:Math.[4]

As each vertex has two children, the Calkin–Wilf tree is a binary tree. However, it is not a binary search tree: its inorder does not coincide with the sorted order of its vertices. However, it is closely related to a different binary search tree on the same set of vertices, the Stern–Brocot tree: the vertices at each level of the two trees coincide, and are related to each other by a bit-reversal permutation.Template:Sfnp

Breadth first traversal

The Calkin–Wilf sequence, depicted as the red spiral tracing through the Calkin–Wilf tree

The Calkin–Wilf sequence is the sequence of rational numbers generated by a breadth-first traversal of the Calkin–Wilf tree,

Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, Template:Sfrac, ….

Because the Calkin–Wilf tree contains every positive rational number exactly once, so does this sequence.[5] The denominator of each fraction equals the numerator of the next fraction in the sequence. The Calkin–Wilf sequence can also be generated directly by the formula

qi+1=12qiqi+1

where Template:Mvar denotes the Template:Mvarth number in the sequence, starting from Template:Math, and Template:Math represents the integral part.[6]

It's also possible to calculate Template:Mvar directly from the run-length encoding of the binary representation of Template:Mvar: the number of consecutive 1s starting from the least significant bit, then the number of consecutive 0s starting from the first block of 1s, and so on. The sequence of numbers generated in this way gives the continued fraction representation of Template:Mvar. Example:

i = 1081 = 100001110012: The continued fraction is [1;2,3,4,1] hence Template:Math.
i = 1990 = 111110001102: The continued fraction is [0;1,2,3,5] hence Template:Math.

In the other direction, using the continued fraction of any Template:Mvar as the run-length encoding of a binary number gives back Template:Mvar itself. Example:

Template:Math: The continued fraction is [0;1,3] hence Template:Mvar = 11102 = 14.
Template:Math: The continued fraction is [1;3]. But to use this method, the length of the continued fraction must be an odd number. So [1;3] should be replaced by the equivalent continued fraction [1;2,1]. Hence Template:Mvar = 10012 = 9.

A similar conversion between run-length-encoded binary numbers and continued fractions can also be used to evaluate Minkowski's question mark function; however, in the Calkin–Wilf tree the binary numbers are integers (positions in the breadth-first traversal) while in the question mark function they are real numbers between 0 and 1.

Stern's diatomic sequence

Scatterplot of Template:Math

Stern's diatomic sequence is the integer sequence

0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, 1, … Template:OEIS.

Using zero-based numbering, the Template:Mvarth value in the sequence is the value Template:Math of the fusc function, named[7] according to the obfuscating appearance of the sequence of values and defined by the recurrence relations

fusc(2n)=fusc(n)fusc(2n+1)=fusc(n)+fusc(n+1),

with the base cases Template:Math and Template:Math.

The Template:Mvarth rational number in a breadth-first traversal of the Calkin–Wilf tree is the number Template:Math.[8] Thus, the diatomic sequence forms both the sequence of numerators and the sequence of denominators of the numbers in the Calkin–Wilf sequence.

The function Template:Math is the number of odd binomial coefficients of the form Template:Math, Template:Math,[9] and also counts the number of ways of writing Template:Mvar as a sum of powers of two in which each power occurs at most twice. This can be seen from the recurrence defining fusc: the expressions as a sum of powers of two for an even number Template:Math either have no 1s in them (in which case they are formed by doubling each term in an expression for Template:Mvar) or two 1s (in which case the rest of the expression is formed by doubling each term in an expression for Template:Math), so the number of representations is the sum of the number of representations for Template:Mvar and for Template:Math, matching the recurrence. Similarly, each representation for an odd number Template:Math is formed by doubling a representation for Template:Mvar and adding 1, again matching the recurrence.[10] For instance,

6 = 4 + 2 = 4 + 1 + 1 = 2 + 2 + 1 + 1

has three representations as a sum of powers of two with at most two copies of each power, so Template:Math.

Relation to Stern–Brocot tree

The Calkin–Wilf tree resembles the Stern–Brocot tree in that both are binary trees with each positive rational number appearing exactly once. Additionally, the top levels of the two trees appear very similar, and in both trees, the same numbers appear at the same levels. One tree can be obtained from the other by performing a bit-reversal permutation on the numbers at each level of the trees.Template:Sfnp Alternatively, the number at a given node of the Calkin–Wilf tree can be converted into the number at the same position in the Stern–Brocot tree, and vice versa, by a process involving the reversal of the continued fraction representations of these numbers.Template:Sfnp However, in other ways, they have different properties: for instance, the Stern–Brocot tree is a binary search tree: the left-to-right traversal order of the tree is the same as the numerical order of the numbers in it. This property is not true of the Calkin–Wilf tree.

Notes

Template:Reflist

References

  1. Template:Harvtxt, Section 6.
  2. Template:Harvtxt.
  3. Template:Citation.
  4. The description here is dual to the original definition by Calkin and Wilf, which begins by defining the child relationship and derives the parent relationship as part of a proof that every rational appears once in the tree. As defined here, every rational appears once by definition, and instead the fact that the resulting structure is a tree requires a proof.
  5. Template:Harvtxt: "a list of all positive rational numbers, each appearing once and only once, can be made by writing down Template:Sfrac, then the fractions on the level just below the top of the tree, reading from left to right, then the fractions on the next level down, reading from left to right, etc." Template:Harvtxt discuss efficient functional programming techniques for performing this breadth first traversal.
  6. Template:Harvtxt credit this formula to Moshe Newman.
  7. The fusc name was given in 1976 by Edsger W. Dijkstra; see EWD570 and EWD578.
  8. Template:Harvtxt, Theorem 1.
  9. Template:Harvtxt.
  10. The OEIS entry credits this fact to Template:Harvtxt and to uncited work of Lind. However, Carlitz's paper describes a more restricted class of sums of powers of two, counted by Template:Math instead of by Template:Math.