In this paper we present the Stern-Brocot tree as a basis for performing exact arithmetic on rational numbers. There exists an elegant binary representation for positive rational numbers based on this tree [Graham et al., Concrete Mathematics, 1994]. We will study this representation by investigating various algorithms to perform exact rational arithmetic using an adaptation of the homographic and the quadratic algorithms that were first proposed by Gosper for computing with continued fractions. We will show generalisations of homographic and quadratic algorithms to multilinear forms in n variables. Finally, we show an application of the algorithms for evaluating polynomials.
Historical backgroundRecently exact arithmetic has been considered as a suitable approach to the problem of dealing with round-off errors and building more reliable and versatile programming tools for computation with rational and real numbers. According to this approach, real numbers are represented as an infinite stream over a finite or infinite alphabet and the computation over them is done in a lazy manner (also called: on-line, call-by-need, corecursive, etc.): in order to compute a function on a real number, we start absorbing the first element of the stream representing the real number. At each step we output an element of the output stream or we may need more information about the input, in which case we absorb the next element of the input stream.There have been many theoretical and practical instances of applying this idea. A rather general theoretical approach is taken by Konečný [12], where the limitation theorems for IFS-representations of real numbers is given. IFS-representations are representations of real numbers using an infinite composition of contracting functions on a compact interval. These include the representations by means of Möbius maps that is developed by Edalat and Potts [6,23]. Edalat and Potts's work generalises earlier works by Gosper [7,8], Vuillemin [27] and Menissier-Morain [19]. Gosper, in his famous unpublished work [7], showed how to add, multiply, subtract and divide two continued fractions. He introduced the idea of using homographic and quadratic algorithms. His algorithms are presented for regular N-fractions of rational numbers and were the first instance of lazy exact arithmetic on rational numbers. *