Order Statistics in the Farey Sequences in Sublinear Time

Total Page:16

File Type:pdf, Size:1020Kb

Order Statistics in the Farey Sequences in Sublinear Time Order Statistics in the Farey Sequences in Sublinear Time Jakub Pawlewicz Institute of Informatics, Warsaw University Banacha 2, 02-097 Warsaw, Poland [email protected] Abstract. The paper presents the first sublinear algorithm for comput- ing order statistics in the Farey sequences. The algorithm runs in time p O(n3=4 log n) and in space O( n ) for Farey sequence of order n. This is a significant improvement to the algorithm from [1] that runs in time O(n log n). 1 Introduction The Farey sequence of order n (denoted Fn) is the increasing sequence of all irreducible fractions from interval [0; 1] with denominators less than or equal to n. The Farey sequences have numerous interesting properties and they are well known in the number theory and in the combinatorics. They are deeply investigated in [2]. In this paper we study the following algorithmic problem. For given positive integers n and k compute the k-th element of the Farey sequence of order n. This problem is known as order statistics problem. The solution to the order statistics problem is based on a solution to a related rank problem, i.e. the problem of finding the rank of a given fraction in the Farey sequence. Both, the order statistics problem and the rank problem, can be easily solved in quadratic time by listing all elements of the sequence (see [2, Problem 4-61] and Section 2.1). Faster solutions for order statistics are possible by reducing the main problem to the rank problem. The roughly linear time algorithm is presented in [1]. The authors present a solution of the rank problem working in time O(n) and in sublinear space. They also show how to reduce the order statistics problem to the rank problem by calling O(log n) instances of the rank problem. This gives an algorithm running in O(n log n) time. They remark that their solution to the rank problem could run in time O(n5=6+o(1)) if it was possible to compute Pn the sum i=1bxic, for a rational x, in this time or faster. This sum is related to counting lattice points in right triangles. A simple algorithm for that task running in logarithmic time can be found in [3]. Nevertheless, for completeness we present a simple logarithmic algorithm computing that sum in Section 3. The O(n5=6+o(1)) solution is complicated. For instance it involves summation of Möbius function and subexpotential integer factorization. In Section 2.3 we 2 Jakub Pawlewicz 3=4 present a simple algorithmp for the rank problem with time complexity O(n ) and space complexity O( n ). We assume RAM as a model of computation.1 What remains is to show a faster reduction in order to find order statistics in sublinear time. In [1] the reduction was made in two stages. The first stage j j+1 consists of finding out the interval n ; n containing the k-th term in the sequence. The interval is computed by a binary search with calling the rank problem O(log n) times. The second stage tracks the searched term by checking all fractions in the interval. Since there are at most n such fractions, in the worst case this stage runs in O(n) time, which dominates time complexity of j j+1 the reduction. In [1] the authors proposed to take smaller interval n2 ; n2 , since this interval contains exactly one fraction. However, there is a problem of tracking that fraction, which is not solved by them. In Section 2.2 we show solution to that problem. We also show another, more direct reduction running in logarithmic time and using O(log n) calls to the rank problem. This reduction is obtained by exploring Stern–Brocot tree in a smart way. 2 Computing order statistics in the Farey sequences 2.1 An O(n2) time algorithm We show two O(n2) time methods. The working time follows the number of 3 2 elements in the sequence Fn, which is asymptotically equal to π2 n . We use the following property of the Farey sequences. For two consecutive a c fractions b < d in a Farey sequence, the first fraction that appears between them a+c is b+d – the mediant of these two fractions. The mediant is already reduced and it firstly appears in Fb+d. Using this property one can successively compute all fractions. That way the Stern–Brocot tree2 is obtained. Farey fractions form a subtree. In–order traversal gives an O(n2) time and O(n) space algorithm. Space complexity depends on the depth of the Farey tree. The second O(n2) method is a straightforward application of a surprising a c e formula. For three consecutive fractions b < d < f the following holds: e tc − a b + n = , where t = : f td − b d That method works in optimal O(1) space. 2.2 Reduction to the rank problem In order to achieve a solution faster than quadratic one we reduce the problem of finding given term of the Farey sequence to a problem of counting the number of 1 In RAM (Random Access Machine) single cell can store arbitrarily large integers. Cell access or arithmetic operations on cells are performed in constant time. Also memory complexity is measured in cells. 2 For a description of Stern–Brocot tree together with its properties we refer to [2]. Order Statistics in the Farey Sequences in Sublinear Time 3 fractions bounded by a real number (the rank problem). To be more precise, for given positive integer n and real number x 2 [0; 1] we want to find the number a of fractions b belonging to sequence Fn not larger than x. We show how to solve the original problem given an algorithm for the rank problem. Reduction in linear time. We recall the reduction from [1]. Firstly, the inter- j j+1 val n ; n containing the k-th term is searched by a binary search starting from 0 n l r l m the interval n ; n , splitting interval n ; m into two smaller intervals n ; n m r l+r j j+1 and n ; n , where m = 2 . Next, we track the fraction in n ; n . Because 1 the size of the interval is n , it contains at most one fraction with denomina- tor b ≤ n. That fraction can be found in constant time since numerator must (j+1)b−1 be n . We check all such fractions for all possible denominators. Total tracking time is O(n) and whole reduction also works in time O(n). It is sufficient to use the above reduction to construct roughly linear time so- lution, but it is not enough if we want to create a sublinear algorithm. Therefore, we need faster reduction. We show two reductions with logarithmic time. Smaller interval. First, we can tune up the construction using intervals. As j j+1 it was suggested in [1] we can find smaller interval n2 ; n2 also by a binary search. Now in such interval there is at most one fraction in Fn which belongs 1 to that interval. This is because the size of the interval is n2 and because the a c following inequality holds for every two consecutive fractions b < d in sequence Fn: c a 1 1 − = ≤ : d b bd n2 The k-th term of the Farey sequence Fn is the only fraction from Fn in j j+1 the interval n2 ; n2 . What is left is to track this fraction. We use the Stern– Brocot tree to this task. The Stern–Brocot tree allows us to explore all irreducible 0 1 fraction in an organized way. We start from two fractions 1 and 0 . These fractions represent the interval where the k-th term resides. We repeatedly narrow that j j+1 interval to enclose the interval n2 ; n2 until we find the fraction. Assume we a c have already narrowed the interval to fractions b and d , such that a j j + 1 c < < ≤ : b n2 n2 d a+c Then, in a single iteration we split the interval by the mediant b+d . If the mediant j j+1 falls into the interval n2 ; n2 , then the k-th term is found and this is the a+c a c a+c mediant b+d . Otherwise, we replace one of the fractions b and d by b+d . If a+c j a a+c j+1 c b+d < n2 , we replace fraction b , otherwise b+d ≥ n2 and we replace d . The above procedure guarantees successful tracking. However, the time com- plexity is O(n) since in the worst case n iterations are needed. For instance 1 1 1 for k = 1 we replace the right fraction n times consecutively to 1 ; 2 ;:::; n . This problem can be solved by grouping successive substitutions of left or right fractions. 4 Jakub Pawlewicz Suppose we replace several times the left fraction. After first substitution we a+c c a+2c have fractions b+d and d . After second substitution the fractions become b+2d c and d and so on. Generally, after t substitutions of left fractions the final fraction a+tc is equal to b+td . In the above procedure we replace the left fractions as long as a + tc j < : (1) b + td n2 If t is the largest integer satisfying the above inequality then for the next mediant j a+(t+1)c a+(t+1)c j+1 we have n2 ≤ b+(t+1)d .
Recommended publications
  • A Note on the Computation of the Fraction of Smallest Denominator in Between Two Irreducible Fractions Isabelle Sivignon
    A note on the computation of the fraction of smallest denominator in between two irreducible fractions Isabelle Sivignon To cite this version: Isabelle Sivignon. A note on the computation of the fraction of smallest denominator in between two irreducible fractions. Discrete Applied Mathematics, Elsevier, 2016, 10.1016/j.dam.2015.08.029. hal-01228572 HAL Id: hal-01228572 https://hal.archives-ouvertes.fr/hal-01228572 Submitted on 13 Nov 2015 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Distributed under a Creative Commons Attribution| 4.0 International License A note on the computation of the fraction of smallest denominator in between two irreducible fractions Isabelle Sivignon Univ. Grenoble Alpes, GIPSA-Lab, F-38000 Grenoble, France CNRS, GIPSA-Lab, F-38000 Grenoble, France Abstract Given two irreducible fractions f and g, with f < g, we characterize the fraction h such that f < h < g and the denominator of h is as small as possible. An output-sensitive algorithm of time complexity O(d), where d is the depth of h is derived from this characterization. Keywords: simplest fraction, continued fractions, algorithm 1. Introduction Given two irreducible fractions defining an interval, we investigate the problem of finding the fraction of smallest denominator in this interval.
    [Show full text]
  • Regularity of Minkowski's Question Mark Measure, Its Inverse and A
    Regularity of Minkowski's question mark measure, its inverse and a class of IFS invariant measures Giorgio Mantica ∗y Vilmos Totik zx Abstract We prove the recent conjecture that Minkowski's question mark mea- sure is regular in the sense of logarithmic potential theory. The proof employs: an Iterated Function System composed of M¨obiusmaps, which yields the classical Stern{Brocot sequences, an estimate of the cardinality of large spacings between numbers in these sequences and a criterion due to Stahl and Totik. We also generalize this result to a class of balanced measures of Iterated Function Systems in one dimension. 1 Introduction and statement of the main re- sults 1.1 Minkowski's question mark function and measure A remarkable function was introduced by Hermann Minkowski in 1904, to map algebraic numbers of second degree to the rationals, and these latter to binary fractions, in a continuous, order preserving way [35]. This function is called the question mark function and is indicated by ?(x), perhaps because of its enigmatic yet captivating, multi{faceted personality. In fact, it is linked to continued fractions, to the Farey tree and to the theory of numbers [11, 42]. It also appears in the theory of dynamical systems, in relation with the Farey shift map [8, 10, 25] and in the coding of motions on manifolds of negative curvature [6, 17, 18, 23, 43]. Let us define Minkowski's question mark function following [42]. Consider the interval I = [0; 1] and let x 2 I. Write this latter in its continued fraction ∗Center for Non-linear and Complex Systems, Dipartimento di Scienza ed Alta Tecnologia, Universit`adell' Insubria, 22100 Como, Italy.
    [Show full text]
  • The Farey Sequence
    The Farey Sequence Jonathan Ainsworth, Michael Dawson, John Pianta, James Warwick Year 4 Project School of Mathematics University of Edinburgh March 15, 2012 Abstract The Farey sequence (of counting fractions) has been of interest to modern math- ematicians since the 18th century. This project is an exploration of the Farey sequence and its applications. We will state and prove the properties of the Farey sequence and look at their application to clock-making and to numerical approx- imations. We will further see how the sequence is related to number theory (in particular, to the Riemann hypothesis) and examine a related topic, namely the Ford circles. This project report is submitted in partial fulfilment of the requirements for the degree of BSc Mathematics except Pianta who is MA Mathematics 2 Contents Abstract 2 1 Introduction to Farey sequences 5 1.1 The Ladies' Diary . .5 1.2 Flitcon's solution . .6 1.3 Farey sequences . .8 1.4 Properties of the Farey Sequence . .8 1.5 Farey History . .9 1.6 Length of the Farey Sequence . 11 2 Clocks and Farey 12 2.1 Creation of the Stern-Brocot tree . 12 2.2 Navigating the Tree . 15 2.3 Gear Ratios . 18 3 Approximation and Fibonacci 23 3.1 Approximating irrationals using Farey Sequences . 23 3.2 Farey Sequences of Fibonacci Numbers . 25 4 Ford Circles 27 4.1 Introduction . 27 4.2 Motivation and definition . 27 4.3 Properties of Ford circles . 29 4.4 From algebra to geometry and back to algebra . 32 3 5 The Farey Sequence and The Riemann Hypothesis 36 5.1 Equivalent statement to the Riemann Hypothesis using the Farey Sequence .
    [Show full text]
  • The Farey Sequence and Its Niche(S)
    The Farey Sequence and Its Niche(s) Dylan Zukin May 12, 2016 1 Contents 1 Introduction to the Farey Sequence 3 2 A History of the Farey Sequence 3 3 Properties of the Farey Sequence 4 4 The Farey Dissection 7 5 Lattices and Farey Terms 8 5.1 What is a Lattice? . .8 5.2 The Fundamental Lattice . .9 5.3 Properties of the Fundamental Lattice . .9 6 What are Ford Circles? 11 6.1 Using the Farey Sequence to Prove Tangency . 12 6.2 Calculating Ford Circles . 13 7 Rational Approximation of Irrational Numbers 13 7.1 Theorems . 13 7.2 Using the Farey Dissection . 15 8 Hurwitz's Theorem 17 8.1 Proving Hurwitz's Theorem with the Farey Sequence . 17 8.2 Continued Fractions . 18 9 Conclusion 20 2 Abstract: Discovered by Haros in 1802, but named after a geologist 14 years later the properties of the Farey sequence remain a useful tool in mathematical proof. This paper will introduce the Farey sequence and its basic properties. Then continue onto many of its applications in the mathematical world. While the Farey sequence is mostly used in proof. Its properties give way to some surprising coincidences which generates further curiosity for this unique series of rational numbers. 1 Introduction to the Farey Sequence The Farey Sequence, sometimes called the Farey series, is a series of sequences in which each sequence consists of rational numbers ranging in value from 0 to 0 1 1. The first sequence, denoted F1 is simply f 1 ; 1 g. Then to create the nth row a b we look at the (n − 1)st row and between consecutive fractions a0 and b0 insert a + b [4]: a0 + b0 However the denominator of each term in Fn can be no larger than n.
    [Show full text]
  • On the Stern–Brocot Expansion of Real Numbers Tome 31, No 3 (2019), P
    Christophe REUTENAUER On the Stern–Brocot expansion of real numbers Tome 31, no 3 (2019), p. 697-722. <http://jtnb.centre-mersenne.org/item?id=JTNB_2019__31_3_697_0> © Société Arithmétique de Bordeaux, 2019, tous droits réservés. L’accès aux articles de la revue « Journal de Théorie des Nom- bres de Bordeaux » (http://jtnb.centre-mersenne.org/), implique l’accord avec les conditions générales d’utilisation (http://jtnb. centre-mersenne.org/legal/). Toute reproduction en tout ou partie de cet article sous quelque forme que ce soit pour tout usage autre que l’utilisation à fin strictement personnelle du copiste est con- stitutive d’une infraction pénale. Toute copie ou impression de ce fichier doit contenir la présente mention de copyright. cedram Article mis en ligne dans le cadre du Centre de diffusion des revues académiques de mathématiques http://www.centre-mersenne.org/ Journal de Théorie des Nombres de Bordeaux 31 (2019), 697–722 On the Stern–Brocot expansion of real numbers par Christophe REUTENAUER In memoriam Michel Mendès-France Résumé. Le développement de Stern–Brocot d’un nombre réel est une suite finie ou infinie de symboles l, r, signifiant « gauche » et « droite », qui re- présente le chemin dans l’arbre de Stern–Brocot déterminé par ce nombre. On montre que ce développement est périodique si et seulement si le nombre est quadratique, positif, avec conjugué négatif; dans ce cas la représentation de l’opposé du conjugué est obtenue par image miroir. Les pentes des suites sturmiennes morphiques sont exactement ces nombres. Deux nombres ont le même développement à partir d’un certain rang si et seulement s’ils sont équi- valents sous l’action de SL2(Z).
    [Show full text]