Stern–Brocot tree
In number theory, the Stern–Brocot tree is an infinite complete binary tree in which the vertices correspond one-for-one to the positive rational numbers, whose values are ordered from the left to the right as in a search tree.
The Stern–Brocot tree was introduced independently by Moritz Stern (1858) and Achille Brocot (1861). Stern was a German number theorist; Brocot was a French clockmaker who used the Stern–Brocot tree to design systems of gears with a gear ratio close to some desired value by finding a ratio of smooth numbers near that value.
The root of the Stern–Brocot tree corresponds to the number 1. The parent-child relation between numbers in the Stern–Brocot tree may be defined in terms of continued fractions or mediants, and a path in the tree from the root to any other number q provides a sequence of approximations to q with smaller denominators than q. Because the tree contains each positive rational number exactly once, a breadth first search of the tree provides a method of listing all positive rationals that is closely related to Farey sequences. The left subtree of the Stern–Brocot tree, containing the rational numbers in the range (0,1), is called the Farey tree.
Generating rule
Each vertex in the tree can be associated with a triple of fractions consisting of three fractions in the same row as the vertex, namely the fraction immediately to the left of the vertex, the fraction at the vertex itself, and the fraction immediately to the right of the vertex. (Refer to the figure above.) The left and right fractions do not correspond to vertices in the same row as the vertex, but rather to vertices in some preceding row. Each such fraction can be understood as labeling the region of the plane bounded by two infinite paths descending from the preceding vertex labeled by the same fraction. The second element of a triple will always be the mediant of the first and third elements. For example, the root is associated with [math]\displaystyle{ \left(\tfrac{0}{1},\tfrac{1}{1},\tfrac{1}{0}\right) }[/math] and its left and right descendents are associated with [math]\displaystyle{ \left(\tfrac{0}{1},\tfrac{1}{2},\tfrac{1}{1}\right) }[/math] and [math]\displaystyle{ \left(\tfrac{1}{1},\tfrac{2}{1},\tfrac{1}{0}\right) }[/math]. The tree is generated by the following rule: the left descendent of [math]\displaystyle{ \left(\tfrac{a}{b},\tfrac{c}{d},\tfrac{e}{f}\right) }[/math] is [math]\displaystyle{ \left(\tfrac{a}{b},\tfrac{a+c}{b+d},\tfrac{c}{d}\right) }[/math] and the right descendent is [math]\displaystyle{ \left(\tfrac{c}{d},\tfrac{c+e}{d+f},\tfrac{e}{f}\right) }[/math].
A tree of continued fractions
The relationship between parents and descendants can also be understood in terms of continued fractions. Every positive rational number [math]\displaystyle{ q }[/math] may be expressed as a continued fraction of the form [math]\displaystyle{ q = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3 + \cfrac{1}{\ddots+\cfrac1{a_k}}}}}= [a_0; a_1, a_2, \ldots, a_k] }[/math] where [math]\displaystyle{ k }[/math] and [math]\displaystyle{ a_0 }[/math] are non-negative integers, and each subsequent coefficient [math]\displaystyle{ a_i }[/math] is a positive integer. This representation is not unique because [math]\displaystyle{ [a_0; a_1, a_2, \ldots, a_{k-1}, 1] = [a_0; a_1, a_2, \ldots, a_{k-1}+1], }[/math] but using this equivalence to replace every continued fraction ending with a one by a shorter continued fraction shows that every rational number has a unique representation in which the last coefficient is greater than one. Then, unless [math]\displaystyle{ q=1 }[/math], the number [math]\displaystyle{ q }[/math] has a parent in the Stern–Brocot tree given by the continued fraction expression [math]\displaystyle{ [a_0; a_1, a_2, \ldots, a_k-1]. }[/math] Equivalently this parent is formed by decreasing the denominator in the innermost term of the continued fraction by 1, and contracting with the previous term if the fraction becomes [math]\displaystyle{ \tfrac11 }[/math]. For instance, the rational number 23⁄16 has the continued fraction representation [math]\displaystyle{ \frac{23}{16}=1+\cfrac1{2+\cfrac1{3+\frac12}} = [1;2,3,2], }[/math] so its parent in the Stern–Brocot tree is the number [math]\displaystyle{ [1;2,3,1]=[1;2,4]=1+\cfrac1{2+\frac14}=\frac{13}{9}. }[/math]
Conversely each number [math]\displaystyle{ q }[/math] in the Stern–Brocot tree has exactly two children: if [math]\displaystyle{ q = [a_0; a_1, a_2, \ldots, a_k] = [a_0; a_1, a_2, \ldots, a_k-1,1] }[/math] then one child is the number represented by the continued fraction [math]\displaystyle{ \displaystyle [a_0; a_1, a_2, \ldots, a_k+1] }[/math] while the other child is represented by the continued fraction [math]\displaystyle{ [a_0; a_1, a_2, \ldots, a_k-1,2]. }[/math] One of these children is less than [math]\displaystyle{ q }[/math] and this is the left child; the other is greater than [math]\displaystyle{ q }[/math] and it is the right child (in fact the former expression gives the left child if [math]\displaystyle{ k }[/math] is odd, and the right child if [math]\displaystyle{ k }[/math] is even). For instance, the continued fraction representation of 13⁄9 is [1;2,4] and its two children are [1;2,5] = 16⁄11 (the right child) and [1;2,3,2] = 23⁄16 (the left child).
It is clear that for each finite continued fraction expression one can repeatedly move to its parent, and reach the root [1;]=1⁄1 of the tree in finitely many steps (in a0 + ... + ak − 1 steps to be precise). Therefore, every positive rational number appears exactly once in this tree. Moreover all descendants of the left child of any number q are less than q, and all descendants of the right child of q are greater than q. The numbers at depth d in the tree are the numbers for which the sum of the continued fraction coefficients is d + 1.
Mediants and binary search
The Stern–Brocot tree forms an infinite binary search tree with respect to the usual ordering of the rational numbers.[1][2] The set of rational numbers descending from a node q is defined by the open interval (Lq,Hq) where Lq is the ancestor of q that is smaller than q and closest to it in the tree (or Lq = 0 if q has no smaller ancestor) while Hq is the ancestor of q that is larger than q and closest to it in the tree (or Hq = +∞ if q has no larger ancestor).
The path from the root 1 to a number q in the Stern–Brocot tree may be found by a binary search algorithm, which may be expressed in a simple way using mediants. Augment the non-negative rational numbers to including a value 1/0 (representing +∞) that is by definition greater than all other rationals. The binary search algorithm proceeds as follows:
- Initialize two values L and H to 0/1 and 1/0, respectively.
- Until q is found, repeat the following steps:
- Let L = a/b and H = c/d; compute the mediant M = (a + c)/(b + d).
- If M is less than q, then q is in the open interval (M,H); replace L by M and continue.
- If M is greater than q, then q is in the open interval (L,M); replace H by M and continue.
- In the remaining case, q = M; terminate the search algorithm.
The sequence of values M computed by this search is exactly the sequence of values on the path from the root to q in the Stern–Brocot tree. Each open interval (L,H) occurring at some step in the search is the interval (LM,HM) representing the descendants of the mediant M. The parent of q in the Stern–Brocot tree is the last mediant found that is not equal to q.
This binary search procedure can be used to convert floating-point numbers into rational numbers. By stopping once the desired precision is reached, floating-point numbers can be approximated to arbitrary precision.[3] If a real number x is approximated by any rational number a/b that is not in the sequence of mediants found by the algorithm above, then the sequence of mediants contains a closer approximation to x that has a denominator at most equal to b; in that sense, these mediants form the best rational approximations to x.
The Stern–Brocot tree may itself be defined directly in terms of mediants: the left child of any number q is the mediant of q with its closest smaller ancestor, and the right child of q is the mediant of q with its closest larger ancestor. In this formula, q and its ancestor must both be taken in lowest terms, and if there is no smaller or larger ancestor then 0/1 or 1/0 should be used respectively. Again, using 7/5 as an example, its closest smaller ancestor is 4/3, so its left child is (4 + 7)/(3 + 5) = 11/8, and its closest larger ancestor is 3/2, so its right child is (7 + 3)/(5 + 2) = 10/7.
Relation to Farey sequences
The Farey sequence of order n is the sorted sequence of fractions in the closed interval [0,1] that have denominator less than or equal to n. As in the binary search technique for generating the Stern–Brocot tree, the Farey sequences can be constructed using mediants: the Farey sequence of order n + 1 is formed from the Farey sequence of order n by computing the mediant of each two consecutive values in the Farey sequence of order n, keeping the subset of mediants that have denominator exactly equal to n + 1, and placing these mediants between the two values from which they were computed.
A similar process of mediant insertion, starting with a different pair of interval endpoints [0/1,1/0], may also be seen to describe the construction of the vertices at each level of the Stern–Brocot tree. The Stern–Brocot sequence of order 0 is the sequence [0/1,1/0], and the Stern–Brocot sequence of order i is the sequence formed by inserting a mediant between each consecutive pair of values in the Stern–Brocot sequence of order i − 1. The Stern–Brocot sequence of order i consists of all values at the first i levels of the Stern–Brocot tree, together with the boundary values 0/1 and 1/0, in numerical order.
Thus the Stern–Brocot sequences differ from the Farey sequences in two ways: they eventually include all positive rationals, not just the rationals within the interval [0,1], and at the nth step all mediants are included, not only the ones with denominator equal to n. The Farey sequence of order n may be found by an inorder traversal of the left subtree of the Stern–Brocot tree, backtracking whenever a number with denominator greater than n is reached.
Additional properties
If [math]\displaystyle{ { \frac{p_1}{q_1}, \frac{p_2}{q_2}, \dots, \frac{p_n}{q_n} } }[/math] are all the rationals at the same depth in the Stern–Brocot tree, then
- [math]\displaystyle{ \sum_{k=1}^n \frac{1}{p_kq_k} = 1 }[/math].
Moreover, if [math]\displaystyle{ {\frac{p}{q} \lt \frac{p'}{q'}} }[/math] are two consecutive fractions at or above a certain level in the tree (in the sense that any fraction between them, must be in a lower level of the tree), then
- [math]\displaystyle{ p'q - pq' = 1 }[/math].[4]
Along with the definitions in terms of continued fractions and mediants described above, the Stern–Brocot tree may also be defined as a Cartesian tree for the rational numbers, prioritized by their denominators. In other words, it is the unique binary search tree of the rational numbers in which the parent of any vertex q has a smaller denominator than q (or if q and its parent are both integers, in which the parent is smaller than q). It follows from the theory of Cartesian trees that the lowest common ancestor of any two numbers q and r in the Stern–Brocot tree is the rational number in the closed interval [q, r] that has the smallest denominator among all numbers in this interval.
Permuting the vertices on each level of the Stern–Brocot tree by a bit-reversal permutation produces a different tree, the Calkin–Wilf tree, in which the children of each number a/b are the two numbers a/(a + b) and (a + b)/b. Like the Stern–Brocot tree, the Calkin–Wilf tree contains each positive rational number exactly once, but it is not a binary search tree.
See also
- Minkowski's question-mark function, whose definition for rational arguments is closely related to the Stern–Brocot tree
- Calkin–Wilf tree
Notes
- ↑ Graham, Ronald L.; Knuth, Donald E.; Patashnik, Oren (1994), Concrete mathematics (Second ed.), Addison-Wesley, pp. 116–118, ISBN 0-201-55802-5
- ↑ Gibbons, Jeremy; Lester, David (2006), "Functional pearl: Enumerating the rationals", Journal of Functional Programming 16 (3): 281–291, doi:10.1017/S0956796806005880.
- ↑ Sedgewick and Wayne, Introduction to Programming in Java. A Java implementation of this algorithm can be found here.
- ↑ Bogomolny credits this property to Pierre Lamothe, a Canadian music theorist.
References
- Brocot, Achille (1861), "Calcul des rouages par approximation, nouvelle méthode", Revue Chronométrique 3: 186–194.
- Brocot, Achille (1862), "Calcul des rouages par approximation, nouvelle méthode", https://gallica.bnf.fr/ark:/12148/bpt6k1661912?rk=21459;2
- "Ueber eine zahlentheoretische Funktion", Journal für die reine und angewandte Mathematik 55: 193–220, 1858, http://www.digizeitschriften.de/resolveppn/GDZPPN002150301.
- Berstel, Jean; Lauve, Aaron; Reutenauer, Christophe; Saliola, Franco V. (2009), Combinatorics on words. Christoffel words and repetitions in words, CRM Monograph Series, 27, Providence, RI: American Mathematical Society, ISBN 978-0-8218-4480-9
External links
- Aiylam, Dhroova (2013), Modified Stern-Brocot Sequences, Bibcode: 2013arXiv1301.6807A
- Austin, David, Trees, Teeth, and Time: The mathematics of clock making, Feature Column from the AMS, http://www.ams.org/featurecolumn/archive/stern-brocot.html
- Bogomolny, Alexander, Stern Brocot-Tree, cut-the-knot, http://www.cut-the-knot.org/blue/Stern.shtml, retrieved 2008-09-03.
- Sloane, N. J. A., The Stern–Brocot or Farey Tree, On-line Encyclopedia of Integer Sequences, http://oeis.org/stern_brocot.html.
- Wildberger, Norman, MF96: Fractions and the Stern-Brocot tree, https://www.youtube.com/watch?v=CiO8iAYC6xI.
- Weisstein, Eric W.. "Stern–Brocot Tree". http://mathworld.wolfram.com/Stern-BrocotTree.html.
- Stern–Brocot tree at PlanetMath.org.
- Infinite fractions, Numberphile
- Amazing Graphs III, Numberphile
- OEIS sequence A002487 (Stern's diatomic series (or Stern-Brocot sequence))
Original source: https://en.wikipedia.org/wiki/Stern–Brocot tree.
Read more |