Laboratoire de l Informatique du Parallélisme

Similar documents
Laboratoire de l Informatique du Parallélisme. École Normale Supérieure de Lyon Unité Mixte de Recherche CNRS-INRIA-ENS LYON n o 8512

RN-coding of numbers: definition and some properties

Bound on Run of Zeros and Ones for Images of Floating-Point Numbers by Algebraic Functions

Basic building blocks for a triple-double intermediate format

New Results on the Distance Between a Segment and Z 2. Application to the Exact Rounding

Laboratoire de l Informatique du Parallélisme

Toward Correctly Rounded Transcendentals

LIP. Laboratoire de l Informatique du Parallélisme. Ecole Normale Supérieure de Lyon

The Euclidean Division Implemented with a Floating-Point Multiplication and a Floor

Multiplication by an Integer Constant: Lower Bounds on the Code Length

arxiv: v2 [math.nt] 21 Jun 2017

Laboratoire de l Informatique du Parallélisme

SYMMETRY AND SPECIALIZABILITY IN THE CONTINUED FRACTION EXPANSIONS OF SOME INFINITE PRODUCTS

Balance properties of multi-dimensional words

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction

Introduction and mathematical preliminaries

A RELATION BETWEEN SCHUR P AND S. S. Leidwanger. Universite de Caen, CAEN. cedex FRANCE. March 24, 1997

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015

Spurious Chaotic Solutions of Dierential. Equations. Sigitas Keras. September Department of Applied Mathematics and Theoretical Physics

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

= 10 such triples. If it is 5, there is = 1 such triple. Therefore, there are a total of = 46 such triples.

Ph219/CS219 Problem Set 3

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers.

X. Numerical Methods

1 Basic Combinatorics

SPI. Laboratoire de l Informatique du Parallélisme

Laboratoire de l Informatique du Parallélisme

Upper and Lower Bounds on the Number of Faults. a System Can Withstand Without Repairs. Cambridge, MA 02139

PRODUCTS THAT ARE POWERS. A mathematical vignette Ed Barbeau, University of Toronto

CHAPTER 8: EXPLORING R

SHOW ALL YOUR WORK IN A NEAT AND ORGANIZED FASHION

2 Section 2 However, in order to apply the above idea, we will need to allow non standard intervals ('; ) in the proof. More precisely, ' and may gene

Lifting to non-integral idempotents

Hierarchy among Automata on Linear Orderings

Table-based polynomials for fast hardware function evaluation

DR.RUPNATHJI( DR.RUPAK NATH )

4 Linear Recurrence Relations & the Fibonacci Sequence

Topic 17. Analysis of Algorithms

Theorem 1 can be improved whenever b is not a prime power and a is a prime divisor of the base b. Theorem 2. Let b be a positive integer which is not

A general scheme for deciding the branchwidth

Basic Proof Techniques

Ecole Normale Supérieure de Lyon Institut IMAG Unité de recherche associée au CNRS n On the relations between dynamical

Discrete dynamics on the real line

RMT 2013 Power Round Solutions February 2, 2013

2005 Euclid Contest. Solutions

PUTNAM TRAINING NUMBER THEORY. Exercises 1. Show that the sum of two consecutive primes is never twice a prime.

1 + lim. n n+1. f(x) = x + 1, x 1. and we check that f is increasing, instead. Using the quotient rule, we easily find that. 1 (x + 1) 1 x (x + 1) 2 =

SMT 2013 Power Round Solutions February 2, 2013

Trajectories of rotations

Some Combinatorial Aspects of Time-Stamp Systems. Unite associee C.N.R.S , cours de la Liberation F TALENCE.

Individual Round CHMMC November 20, 2016

Note An example of a computable absolutely normal number

Math 1270 Honors ODE I Fall, 2008 Class notes # 14. x 0 = F (x; y) y 0 = G (x; y) u 0 = au + bv = cu + dv

Continued fractions and number systems: applications to correctly-rounded implementations of elementary functions and modular arithmetic.

CHAPTER 1 REAL NUMBERS KEY POINTS

ON THE BILINEAR COMPLEXITY OF THE MULTIPLICATION IN FINITE FIELDS. Stéphane Ballet & Robert Rolland

Some remarks on the Shannon capacity of odd cycles Bruno Codenotti Ivan Gerace y Giovanni Resta z Abstract We tackle the problem of estimating the Sha

1 Introduction A one-dimensional burst error of length t is a set of errors that are conned to t consecutive locations [14]. In this paper, we general

+ 1 3 x2 2x x3 + 3x 2 + 0x x x2 2x + 3 4

Error Correcting Codes Prof. Dr. P. Vijay Kumar Department of Electrical Communication Engineering Indian Institute of Science, Bangalore

The Topological Entropy of Iterated Piecewise Affine Maps is Uncomputable

A fast algorithm to generate necklaces with xed content

Coach Stones Expanded Standard Pre-Calculus Algorithm Packet Page 1 Section: P.1 Algebraic Expressions, Mathematical Models and Real Numbers

Constructions with ruler and compass.

Introduction to Real Analysis

SPI. Laboratoire de l Informatique du Parallélisme

Notes on Continued Fractions for Math 4400

Isolating critical cases for reciprocals using integer factorization. John Harrison Intel Corporation ARITH-16 Santiago de Compostela 17th June 2003

PRACTICE PROBLEMS: SET 1

Non-elementary Lower Bound for Propositional Duration. Calculus. A. Rabinovich. Department of Computer Science. Tel Aviv University

A note on parallel and alternating time

Essentials of Intermediate Algebra

COMPUTER ARITHMETIC. 13/05/2010 cryptography - math background pp. 1 / 162

On the coverage probability of the Clopper-Pearson confidence interval

The impact of heterogeneity on master-slave on-line scheduling

Part II. Number Theory. Year

Math Circle Beginners Group February 28, 2016 Euclid and Prime Numbers Solutions

ON THE CONTINUED FRACTION EXPANSION OF THE UNIQUE ROOT IN F(p) OF THE EQUATION x 4 + x 2 T x 1/12 = 0 AND OTHER RELATED HYPERQUADRATIC EXPANSIONS

THE UNIT GROUP OF A REAL QUADRATIC FIELD

MATH FINAL EXAM REVIEW HINTS

PERIODICITY OF SOME RECURRENCE SEQUENCES MODULO M

MAT115A-21 COMPLETE LECTURE NOTES

RANK AND PERIOD OF PRIMES IN THE FIBONACCI SEQUENCE. A TRICHOTOMY

Hierarchical Approximations of a Function by Polynomials in LEMA

Solutions to Practice Final

Algorithms CMSC Basic algorithms in Number Theory: Euclid s algorithm and multiplicative inverse

3 The language of proof

CPSC 467: Cryptography and Computer Security

Chapter 5 Linear Programming (LP)

Study of some equivalence classes of primes

CHAPTER 3: THE INTEGERS Z

PUTNAM TRAINING PROBLEMS

17 Galois Fields Introduction Primitive Elements Roots of Polynomials... 8

Laver Tables A Direct Approach

11.6: Ratio and Root Tests Page 1. absolutely convergent, conditionally convergent, or divergent?

Course 311: Michaelmas Term 2005 Part III: Topics in Commutative Algebra

MTH103 Section 065 Exam 2. x 2 + 6x + 7 = 2. x 2 + 6x + 5 = 0 (x + 1)(x + 5) = 0

LIP. Laboratoire de l Informatique du Parallélisme. Ecole Normale Supérieure de Lyon Institut IMAG Unité de recherche associée au CNRS n 1398

The Not-Formula Book for C2 Everything you need to know for Core 2 that won t be in the formula book Examination Board: AQA

Analysis on Graphs. Alexander Grigoryan Lecture Notes. University of Bielefeld, WS 2011/12

Transcription:

Laboratoire de l Informatique du Parallélisme Ecole Normale Supérieure de Lyon Unité de recherche associée au CNRS n 1398 An Algorithm that Computes a Lower Bound on the Distance Between a Segment and Z 2 Vincent Lefevre June 1997 Research Report N o 97-18 Ecole Normale Supérieure de Lyon 46 Allée d Italie, 69364 Lyon Cedex 07, France Téléphone : (+33) (0)4.72.72.80.00 Télécopieur : (+33) (0)4.72.72.80.80 Adresse électronique : lip@lip.ens lyon.fr

An Algorithm that Computes a Lower Bound on the Distance Between a Segment and Z 2 Vincent Lefevre June 1997 Abstract We give a fast algorithm for computing a lower bound on the distance between a straight line and the points of a regular grid. This algorithm is used to nd worst cases when trying to round the elementary functions correctly in oating-point arithmetic, which consists in returning the machine number that is the closest (there are other rounding modes) to the exact result. Keywords: elementary functions, oating-point arithmetic, rounding Resume Nous donnons un algorithme rapide permettant de calculer une minoration de la distance entre un segment de droite et les points d'une grille reguliere. Cet algorithme est utilise pour trouver les pires cas lorsque l'on arrondit exactement les fonctions elementaires en arithmetique a virgule ottante, ce qui consiste a renvoyer le nombre machine le plus proche (il existe d'autres modes d'arrondi) du resultat exact. Mots-cles: fonctions elementaires, arithmetique virgule-ottante, arrondi

An Algorithm that Computes a Lower Bound on the Distance Between a Segment and Z 2 Vincent Lefevre June 1997 1 Introduction Our goal is to provide exactly rounded elementary functions in oating-point arithmetic. That is, when computing f(x), where f is exp, log, sin, cos, etc... and x is a \machine number", we want to always get the machine number that is the closest 1 to f(x) [1]. To do this, we rst compute (with a precision that is somewhat higher than the \target" precision) an approximation to f(x). Then we round the approximation. The problem is to know if we get the same result as if we had rounded the exact value f(x). Indeed, if the approximation to f(x) is not accurate enough, we cannot ensure that f(x) is correctly rounded; this problem is known as the Table Maker's Dilemma. To solve this problem, we must know with which precision we must carry out the intermediate calculations; that is, we must know the smallest possible non-zero value of jf(x)? yj where x is a machine number and y is either a machine number or the average of two consecutive machine numbers, depending on the rounding mode. For a given x, the above distance jf(x)? yj is denoted d. We split the considered domain into very small intervals, and in each interval I, we look for the set S I of machine numbers x for which d is less than a given real " I ; we can choose " I small enough such that S I is generally empty, but large enough so that we can approximate the function by degree-1 polynomials, i.e., segments. Approximating the function can be performed quickly enough; the part that takes most of the time is the tests themselves. As the total number of points x is very large, e.g., of the order of 10 20 for the double-precision numbers, we need a very fast algorithm. In the chosen domains, the machine numbers are regularly spaced, so that we can multiply the numbers by powers of two to consider that they are, in fact, integers. Thus the problem is now: what are the points on the given segment such that the x-coordinate is an integer and the distance between the 1 We also consider other \rounding modes", e.g., we may want to get the largest machine number that is less than or equal to f(x). 1

y-coordinate and the integers is less than a given "? We recall that in most cases, there are no such points (from the choice of "). The naive approach consists in testing each point whose x-coordinate is an integer: each iteration requires an addition and a comparison by calculating modulo 1 (this is possible if one uses the integer arithmetic of the processor), and shifting the segment by " upwards: with only one unsigned comparison, we can test if a given point is in the interval [0; 2"]. The time required by the other operations can be neglected. If the number of points to test, denoted N, is large enough (e.g., 1000 or larger), there exists a faster method, using the fact that the set S I is generally empty: we can look for a lower bound on the distance d, and if d is larger than ", then S I is empty; otherwise, we can split the interval into subintervals and use this method with dierent parameters or use the naive approach. The segment has an equation of the form y = ax? b, where x is restricted to a given interval, e.g., 0 x < N. In Section 2, we give some mathematical preliminaries and notations. In Section 3, we study the distribution of the points k:a modulo 1, where k is an integer satisfying an inequality 0 k < n; in particular, we mention a theorem known as the three-distance theorem [2, 3, 4]. In Section 4, we give the algorithm, based on the properties described in Section 3. 2 Mathematical Preliminaries { Notations R, Q, Z, N respectively denote the sets of real numbers, rational numbers, integers and non-negative integers. R =Z is the additive group of the real numbers modulo 1. This set can be viewed as a circle, or the segment [0; 1] where both points 0 and 1 are identied (i.e., reals 0 and 1 represent the same point). With this second representation, the point represented by 0 (or 1) can be regarded as an origin. If a 2 R =Z and k 2 N, k is said to be the (group) index of k:a (in the group generated by a). If a 2 R, its image in R =Z will also be denoted a, as there is no possible confusion. [x; y] represents an interval of real numbers (open, if one has round brackets). [[x; y]] represents an interval of integers. The symbol # denotes the cardinality of a nite set. 3 Properties of k:a mod 1 In this section, we study the properties of the points y = k:a modulo 1, where a is a given real number and k is an integer restricted to a given interval, e.g., 2

satisfying 0 k < N (where N is a given positive integer). Since R nq is dense into R and thanks to topological properties, we can suppose that a =2 Q for the mathematical study; thus we avoid casual equalities (see below). The numbers a and y may be regarded as elements of R =Z. Let us take for n 2 N : E n = fk:a 2 R =Z : k 2 N ; k < ng: Since a =2 Q, the set E n has exactly n elements, i.e., there is no multiple-order point. On examples, we can see that the distribution of the points of E n has very interesting properties. In particular, we will look for a construction of E n based on distances between consecutive points on R =Z. An example is given on the following gure. We chose a rational number (17=45) for a to make the notations simpler and multiplied the rational numbers by 45 to get integers, and instead of dealing with R =Z, we deal with Z=45Z. Of course, in our example, we have chosen n small enough to avoid the problems mentioned above (casual equalities... ). For 0 i < n, the e n;i 's denote the images of the points of E n in [0; 1), in increasing order. We dene e n;n = 1, which represents the same point as e n;0 = 0. The distances between two consecutive points on the segment [0; 1] (or the circle R =Z) are the values e n;i+1? e n;i for 0 i < n. We now give a new construction of E n (the equivalence will be proved later), based on distances. For all n 2, we dene a sign s n 2 f?1; +1g and a sequence S n of n 4-tuples S n = (d n;i ; r n;i ; j n;i ; k n;i ) 0i<n where d n;i is a positive real number representing a distance, r n;i is a positive integer representing a rank associated with the distance, and both j n;i and k n;i are elements of N representing group indices. Let us take D n = fd n;i : 0 i < ng, which is the set of the distances in S n, h n = max D n and `n = min D n ; we will show that D n has two or three elements only (this is the three-distance theorem). The sequence S n and the sign s n are dened by: d 2;0 = a; d 2;1 = 1? a; r 2;0 = r 2;1 = 1; s 2 = sign(1? 2a); j 2;0 = 0; k 2;0 = 1; j 2;1 = 1; k 2;1 = 0; and the following transformation. Let i be the unique index such that d n;i = h n and the rank r n;i is minimal. The 4-tuple (d n;i ; r n;i ; j n;i ; k n;i ) is replaced by two consecutive 4-tuples dened below; the other terms of the sequence remain unmodied and in the same order. The distances of the two 4-tuples are `n and h n? `n but the order is determined by s n : `n then h n? `n, if s n = +1; h n? `n then `n, if s n =?1. The new ranks are the smallest positive integers such that all the ranks associated with the distance are dierent, i.e., all the couples (d; r) in the sequence are dierent; note that h n? `n 6= `n since a is irrational. The group indices (j n;i ; k n;i ) are replaced by (j n;i ; n) and (n ; k n;i ). Finally, we take s n+1 = s n sign(h n? 2`n), i.e., the sign of s n changes if and 3

n = 2 0 17 1 28 1 1 17 28 n = 3 n = 4 n = 5 n = 6 n = 7 0 17 1 17 2 11 1 2 1 h 3 0 6 3 11 1 17 2 11 1 2 2 1 h 3 - l 3 l 3 h 4 0 6 3 11 1 6 4 11 2 11 1 2 2 3 1 l 4 h 4 - l 4 0 d 3 1 4 2 5 6,0 d 6,1 d 6,2 d 6,3 d 6,4 d 6,5 e6,0 e6,1 e6,2 e6,3 e6,4 e6,5 e6,6 0 6 3 6 6 5 1 6 4 11 2 6 5 5 1 4 2 2 3 3 1 17 11 6 11 n = 8 0 6 3 6 6 5 1 6 4 6 7 5 2 6 5 5 1 4 2 2 5 3 3 1 6 5 n = 9 0 8 5 3 6 6 5 1 6 4 6 7 5 2 6 5 5 1 4 4 2 2 5 3 3 1 n = 10 0 8 5 3 6 6 5 1 9 5 4 6 7 5 2 6 5 5 1 4 4 2 2 5 5 3 3 1 only if `n+1 < `n; this choice ensures that intervals having the same length are split in the same way (see gure). We can associate a function f n : [[0; n? 1]]! R =Z with each sequence S n, such that each function f n is a restriction of a function f : N! R =Z with f(0) = 0 and f(k)? f(j) = d (mod 1) for each (d; r; j; k) of a sequence S n. Let us take the last example. For n = 2, we have two points on the circle Z=45Z, with respective coordinates f(0) = 0 and f(1) = 17 (modulo 45). These two points form two intervals. The rst interval has length 17, the left end is point 0, the right end is point 1, and the rank is 1 (initial interval); thus (d; r; j; k) = (17; 1; 0; 1). The second interval has length 45? 17 = 28, the left end is point 1, the right end is point 0, and the rank is also 1; thus (d; r; j; k) = (28; 1; 1; 0). Now, let us consider the n = 3 to 4 iteration. For 4

n = 3, we have f(0) = 0, f(1) = 17, and f(2) = 34. The interval of length h 3 = 17 and the minimal rank is I = (17; 1; 0; 1). This 4-tuple is replaced by I 0 = (6; 1; 0; 3) and I 00 = (11; 2; 3; 1) respectively. Since d 0 + d 00 = d, j 0 = j, k 00 = k, and k 0 = j 00 = n, this transformation denes a new point f(3) = 6. We now give the theorem showing that both constructions (E n and S n ) are equivalent. It will be proved later. Theorem 1 For all n 2 and 0 i < n, we have: d n;i = e n;i+1? e n;i, e n;i = j n;i :a and e n;i+1 = k n;i :a, i.e., 8 k 0; f(k) = k:a. Let us take C n = #fi : d n;i = h n g and dene a sequence ( i ; i ): ( 0 ; 0 ) = (a; 1? a); ( i+1 ; i+1 ) = (minf i ; i g; j i? i j); i.e., at each iteration, one keeps the smaller element and replaces the larger one by the dierence. The following theorem says that some sequences S n contain only two dierent distances, and the next pair of distances is obtained by replacing the larger distance with the dierence. Between such two sequences, there is a transient period, where the three distances (both distances of the initial sequence, and the dierence) are present. Theorem 2 There exists a strictly increasing function ' : N! N such that '(0) = 2, and for all i 0: D '(i) = f i ; i g; and for '(i) < n < '(i + 1); D n = f i ; i ; i+1 g: For all i and n such that '(i) 6 n < '(i + 1), one has '(i + 1) = n + C n. In particular, '(i + 1)? '(i) = C '(i). Proof. Theorem 2 is a direct consequence of the construction of the sequences S n : we only use the fact that, at each iteration, an interval of length h n is replaced by two intervals of lengths `n and h n? `n. Theorem 1 will be deduced from the following lemma. Lemma 1 For all n such that #D n = 2, i.e., n 2 '(N ): 1. r n;0 = r n;n?1 = 1; 2. if s n = +1, then d n;0 = `n and d n;n?1 = h n ; if s n =?1, then d n;0 = h n and d n;n?1 = `n; 3. j n;0 = k n;n?1 = 0, k n;0 = #fi : d n;i = d n;n?1 g, j n;n?1 = #fi : d n;i = d n;0 g; 5

4. for all (d; r; j; k), the values j? r and k? r only depend on the value of d. Proof. This lemma can be proved by induction on n. The main points are given in this proof. Details are left to the reader. For the proof, (i; m) denotes the point i of the lemma for n = m (1 i 4, m 2). We can easily verify that, from the denition of S 2, the lemma is true for n = 2. Assume that the lemma is true for a given n 2 '(N ). Let us prove that it is still true for the next value n 0 2 '(N ). We recall that, from the initial value n to the next value n 0, each interval of length h n is split into two intervals. First, let us see what happens for n + 1. The interval of length h n and rank 1 is split into two intervals of lengths `n and h n? `n. From point (1; n), this interval is adjacent to an end point of [0; 1]. From the construction of S n+1, the two new intervals are placed in such a way that the interval of length h n?`n is adjacent to the end point. This proves point (1; n + 1), therefore point (1; n 0 ). Using point (2; n) and the fact that s has changed if and only if ` has changed, this also proves point (2; n 0 ). Now, let us consider point 3. From the construction of the sequences, both indices j m;0 and k m;m?1 will still be zero for m = n 0, and one of the indices k m;0 and j m;m?1, depending on the value of s n, will not change from m = n to m = n 0. Let us denote this index by (m) and the other index by 0 (m). From points (2; n) and (3; n), this index (m) is equal to #fi : d n;i = h n g, which is equal to #fi : d n0 ;i = h n? `ng; this proves the part of point (3; n 0 ) concerning (n 0 ). The other index 0 (n 0 ) will be added when m = n + 1, therefore it will be equal to n. And we have #fi : d n0 ;i = `ng = #fi : d n;i = `ng + #fi : d n;i = h n g = #S n = n; which proves the last part of point (3; n 0 ). Concerning point 4, let us start with d = `n. By symmetry, we can take s n = +1 (the opposite case is similar). For all (`n; r; j; k), where 1 r j n;n?1, we have j = r? 1 and k = k n;0 + r? 1. The new 4-tuple (`n; j n;n?1 + 1; j; k) in S n+1 will satisfy j = j n;n?1 and k = n. Thus we still have j = r? 1 and k = #S n = k n;0 + j n;n?1 = k n;0 + r? 1. Distance d = h n? `n (the other distance in S n 0) is new in S n+1, so that there is nothing else to verify for the moment. We have just proved point (4; n + 1). Points (4; n + 2) to (4; n 0 ) can be deduced from point (4; n + 1) and the construction of the sequences. Now, we can prove Theorem 1. Proof of Theorem 1. We prove Theorem 1 by induction, in a way similar to the proof of the lemma. For n = 2, Theorem 1 is true. 6

Assume that the theorem is true for a given n 2 '(N ). Let us prove that it is true for n + 1, then for the other values up to the next value in '(N ). By symmetry, we assume that s n = +1. According to the lemma, we have j n;n?1 + k n;0 = n. Therefore f(n) = j n;n?1 :a + `n = j n;n?1 :a + d n;0 = j n;n?1 :a + k n;0 :a = n:a; and the theorem is true for n + 1. Considering the interval (h n ; r + 1; j; k), we have j = j n;n?1 + r since j? r is a constant (according to the lemma). Thus f(n + r) = j:a + `n = (j n;n?1 + r):a + k n;0 :a = (n + r):a and the theorem is true for n + r + 1. 4 Algorithm We will consider the successive D '(i), and memorize the position of point b in the interval that contains this point (the distance from b to the lower bound of the interval) and the way in which the intervals are split, i.e., the values h n, `n and s n, where n = '(i). We recall that, at each iteration, the intervals of length h n are split into two intervals of lengths `n and h n? `n (in the order given by s n ), and the intervals of length `n remain unchanged. We stop when n N, where N is the initial number of values to be tested. Then we can calculate the distance from b to the two ends of the interval. In fact, we want to know whether the distance between the segment and Z 2 is larger than " or not. To avoid calculating the distance from b to the upper end of the interval, we apply the algorithm to b+" instead of b, i.e., the segment is shifted by " downwards, and we only need to know the distance from b to the lower end of the interval, which is directly given by the algorithm. Note that with this algorithm, we consider more points than wanted. But the number of considered points is bounded from above by twice the initial number of points, i.e., 2N, which is not too large for our problem, since the value of N can be chosen such that the probability that the test fails is still small. In order to avoid copying or swapping values and testing \status variables" (such as s), we will replace the variables ` and h by the variables x = d n;0 and y = d n;n?1 (thus we avoid swapping ` and h each time h becomes less than `) and we will remove status variables, like s, by duplicating the code: one part for s = +1 and one part for s =?1. Thus we will know the position of h and ` without any test: (x; y) = (`; h) in the part where s = +1, and (x; y) = (h; `) in the part where s =?1. Instead of comparing ` and h, and updating s, we will compare x and y and perform a conditional branch. We dene two new variables: u and v, which denote the number of intervals of respective lengths x and y; they are only used for calculating n. The variable 7

b will be modied in such a way that it always contains the distance from the considered point to the lower end of the interval. Of course, we will apply the algorithm to rational values, whereas the mathematical study considered irrational values for practical reasons. The algorithm remains the same, but we must be careful concerning the particular cases (h = `, then ` = 0) and ensure there is no innite loop. We have four possible states: h+: the interval containing the point has length h and s = +1. h?: the interval containing the point has length h and s =?1. `?: the interval containing the point has length ` and s =?1. `+: the interval containing the point has length ` and s = +1. In fact, we will group h? and `+ (point b in the interval of length x), as well as h+ and `? (point b in the interval of length y). The algorithm given below can be implemented in dierent ways; an optimization may require that some instructions are moved, removed or added. Initialization: x = a; y = 1? a; u = v = 1; Innite loop: if (b < x) while (x < y) if (u + v > N) exit y?= x; u += v; if (u + v > N) exit x?= y; v += u; else b?= x; while (y < x) if (u + v > N) exit x?= y; v += u; if (u + v > N) exit y?= x; u += v; If b is larger than 2", then the distance between the segment and Z 2 is larger than ". Otherwise the test fails, and we need a more accurate test (e.g., by splitting the segment or using a slower algorithm). We notice that this algorithm \contains" Euclid's algorithm, which is used to compute the development of a into a continued fraction. When one of the rst partial quotients of the continued fraction of a is very large, the above algorithm is rather slow; for instance, x is much smaller than y (a partial quotient is large) and u is small (the partial quotient is one of the rst ones), thus the number u of points added at each iteration is small, and many iterations are needed. It is possible to speed up the algorithm in these cases; however it will slow it down in the general case, which occurs much more 8

often. Dierent solutions are possible, but they depend on the context in which the algorithm is applied. 5 Conclusion The algorithms have been implemented on Sun SparcStations to nd the value of x, among the double-precision oating-point numbers in [ 1 ; 1], for which the 2 distance between exp x and a machine number or a number equidistant to two consecutive machine numbers is minimal. The naive algorithm required 3 cycles per argument in average. The method described in this paper allowed to deal with 30 arguments per cycle in average (with non-optimal parameters). With the above algorithm, we obtained a speed-up of 90 over the naive algorithm. This can still be improved by choosing better parameters, and by improving the implementation (e.g., using the fact that the slope of the segment increases very slowly for this particular problem). Thanks to this algorithm, we will be able to solve the Table Maker's Dilemma in a reasonable time. References [1] V. Lefevre, J.-M. Muller, and A. Tisserand. Towards correctly rounded transcendentals. In Proceedings of the 13th IEEE Symposium on Computer Arithmetic, Asilomar, USA, 1997. IEEE Computer Society Press, Los Alamitos, CA. [2] V. T. Sos. On the distribution mod 1 of the sequence n. Ann. Univ. Sci. Budapest, Eotvos Sect. Math., 1:127{134, 1958. [3] J. Suranyi. Uber die Anordnung der Vielfachen einer reellen Zahl mod 1. Ann. Univ. Sci. Budapest, Eotvos Sect. Math., 1:107{111, 1958. [4] S. Swierczkowski. On successive settings of an arc on the circumference of a circle. Fundamenta Math., 46:187{189, 1958. 9