Finding the truncated polynomial that is closest to a function arxiv:cs/ v1 [cs.ms] 4 Jul 2003

Similar documents
Computing Machine-Efficient Polynomial Approximations

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

Computing Machine-Efficient Polynomial Approximations

Hardware Operator for Simultaneous Sine and Cosine Evaluation

Accelerated Shift-and-Add algorithms

Fast and Accurate Bessel Function Computation

RN-coding of numbers: definition and some properties

Newton-Raphson Algorithms for Floating-Point Division Using an FMA

ON THE CHEBYSHEV POLYNOMIALS. Contents. 2. A Result on Linear Functionals on P n 4 Acknowledgments 7 References 7

Bounds for Variable Degree Rational L Approximations to the Matrix Cosine

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

Rigorous Polynomial Approximations and Applications

Elements of Floating-point Arithmetic

Toward Correctly Rounded Transcendentals

Table-Based Polynomials for Fast Hardware Function Evaluation

Table-based polynomials for fast hardware function evaluation

Efficient polynomial L -approximations

Modular Multiplication in GF (p k ) using Lagrange Representation

arxiv: v1 [math.nt] 3 Jun 2016

Remez Algorithm Applied to the Best Uniform Polynomial Approximations

8. Limit Laws. lim(f g)(x) = lim f(x) lim g(x), (x) = lim x a f(x) g lim x a g(x)

Computation of the error functions erf and erfc in arbitrary precision with correct rounding

Elements of Floating-point Arithmetic

PUTNAM TRAINING POLYNOMIALS. Exercises 1. Find a polynomial with integral coefficients whose zeros include

k-protected VERTICES IN BINARY SEARCH TREES

Analytic Number Theory Solutions

Laboratoire de l Informatique du Parallélisme

Efficient Function Approximation Using Truncated Multipliers and Squarers

Fast Polynomial Multiplication

Complex Numbers: Definition: A complex number is a number of the form: z = a + bi where a, b are real numbers and i is a symbol with the property: i

Mathematical preliminaries and error analysis

NEWMAN S INEQUALITY FOR INCREASING EXPONENTIAL SUMS

On-Line Hardware Implementation for Complex Exponential and Logarithm

POLARS AND DUAL CONES

Homework 8 Solutions to Selected Problems

ON EXPLICIT FORMULAE AND LINEAR RECURRENT SEQUENCES. 1. Introduction

Optimizing Scientific Libraries for the Itanium

Laboratoire de l Informatique du Parallélisme

Power series solutions for 2nd order linear ODE s (not necessarily with constant coefficients) a n z n. n=0

Fast and accurate Bessel function computation

Approximation theory

Simplifying Rational Expressions and Functions

Proofs. Chapter 2 P P Q Q

A Readable Introduction to Real Mathematics

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 =

Homework #2 Solutions Due: September 5, for all n N n 3 = n2 (n + 1) 2 4

Gal s Accurate Tables Method Revisited

Math 320: Real Analysis MWF 1pm, Campion Hall 302 Homework 8 Solutions Please write neatly, and in complete sentences when possible.

A note on parallel and alternating time

A Hardware-Oriented Method for Evaluating Complex Polynomials

Solutions to Exercises, Section 2.5

Chapter Two The transcendence of e and π.

Chapter 8. P-adic numbers. 8.1 Absolute values

Limits at Infinity. Horizontal Asymptotes. Definition (Limits at Infinity) Horizontal Asymptotes

Chapter 1 Error Analysis

Algebra Homework, Edition 2 9 September 2010

Polynomial Solutions of the Laguerre Equation and Other Differential Equations Near a Singular

A Simple Left-to-Right Algorithm for Minimal Weight Signed Radix-r Representations

New Minimal Weight Representations for Left-to-Right Window Methods

Proofs. Chapter 2 P P Q Q

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

Math 4310 Solutions to homework 7 Due 10/27/16

ERROR BOUNDS ON COMPLEX FLOATING-POINT MULTIPLICATION

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

Formal verification of IA-64 division algorithms

Rolle s theorem: from a simple theorem to an extremely powerful tool

NUMBERS WITH INTEGER COMPLEXITY CLOSE TO THE LOWER BOUND

FUNCTION APPROXIMATION AND THE REMEZ ALGORITHM

MATH 1A, Complete Lecture Notes. Fedor Duzhin

#A5 INTEGERS 18A (2018) EXPLICIT EXAMPLES OF p-adic NUMBERS WITH PRESCRIBED IRRATIONALITY EXPONENT

6.1 Polynomial Functions

Auxiliary signal design for failure detection in uncertain systems

Factorization in Polynomial Rings

CORRECT ROUNDING OF ALGEBRAIC FUNCTIONS

Horizontal and Vertical Asymptotes from section 2.6

International Competition in Mathematics for Universtiy Students in Plovdiv, Bulgaria 1994

Advanced Mathematics Unit 2 Limits and Continuity

Advanced Mathematics Unit 2 Limits and Continuity

Introduction to Real Analysis Alternative Chapter 1

Computing the RSA Secret Key is Deterministic Polynomial Time Equivalent to Factoring

Course Notes for EE227C (Spring 2018): Convex Optimization and Approximation

Monomial transformations of the projective space

The Classical Relative Error Bounds for Computing a2 + b 2 and c/ a 2 + b 2 in Binary Floating-Point Arithmetic are Asymptotically Optimal

arxiv: v1 [math.mg] 15 Jul 2013

EXAMPLES OF PROOFS BY INDUCTION

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

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction

Generating Orthogonal Polynomials and their Derivatives using Vertex Matching-Partitions of Graphs

MATH 117 LECTURE NOTES

PACKING POLYNOMIALS ON SECTORS OF R 2. Caitlin Stanton Department of Mathematics, Stanford University, California

Vectors in Function Spaces

NOTES ON DIOPHANTINE APPROXIMATION

Jim Lambers MAT 610 Summer Session Lecture 2 Notes

MA1131 Lecture 15 (2 & 3/12/2010) 77. dx dx v + udv dx. (uv) = v du dx dx + dx dx dx

HMMT February 2018 February 10, 2018

Utah Integrated High School Mathematics Level III, 2014

Arithmetic Operators for Pairing-Based Cryptography

BRONX COMMUNITY COLLEGE LIBRARY SUGGESTED FOR MTH 30 PRE-CALCULUS MATHEMATICS

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

Problemen. x = 2X 3 y = 2Y 4

Transcription:

Finding the truncated polynomial that is closest to a function arxiv:cs/0307009v1 [cs.ms] 4 Jul 2003 Nicolas Brisebarre and Jean-Michel Muller September 1, 2018 Abstract When implementing regular enough functions (e.g., elementary or special functions) on a computing system, we frequently use polynomial approximations. In most cases, the polynomial that best approximates (for a given distance and in a given interval) a function has coefficients that are not exactly representable with a finite number of bits. And yet, the polynomial approximations that are actually implemented do have coefficients that are represented with a finite - and sometimes small - number of bits: this is due to the finiteness of the floating-point representations (for software implementations), and to the need to have small, hence fast and/or inexpensive, multipliers (for hardware implementations). We then have to consider polynomial approximations for which the degree-i coefficient has at most m i fractional bits (in other words, it is a rational number with denominator2 m i ). We provide a general method for finding the best polynomial approximation under this constraint. Then, we suggest refinements than can be used to accelerate our method. Introduction All the functions considered in this article are real valued functions of the real variable and all the polynomials have real coefficients. After an initial range reduction step [9, 8, 3], the problem of evaluating a functionϕin a large domain on a computer system is reduced to the problem of evaluating a possibly different function f in a small domain, that is generally of the form [0,a], where a is a small nonnegative real. Polynomial approximations are among the most frequently chosen ways of performing this last approximation. Two kinds of polynomial approximations are used: the approximations that minimize the average error, called least squares approximations, and the LArAl, Université Jean Monnet, 23, rue du Dr P. Michelon, F-42023 Saint-Étienne Cedex, France and LIP/Arénaire (CNRS-ENS Lyon-INRIA-UCBL), 46 Allée d Italie, F-69364 Lyon Cedex 07 FRANCE, Nicolas.Brisebarre@ens-lyon.fr LIP/Arénaire (CNRS-ENS Lyon-INRIA-UCBL), 46 Allée d Italie, F-69364 Lyon Cedex 07 FRANCE, Jean-Michel.Muller@ens-lyon.fr 1

approximations that minimize the worst-case error, called least maximum approximations, or minimax approximations. In both cases, we want to minimize a distance p f, where p is a polynomial of a given degree. For least squares approximations, that distance is: ( a 1/2 p f 2,[0,a] = w(x)(f(x) p(x)) dx) 2, 0 where w is a continuous weight function, that can be used to select parts of [0, a] where we want the approximation to be more accurate. For minimax approximations, the distance is: p f,[0,a] = max 0 x a p(x) f(x). The least squares approximations are computed by a projection method using orthogonal polynomials. Minimax approximations are computed using an algorithm due to Remez [13, 5]. See [7, 6] for recent presentations of elementary function algorithms. In this paper, we are concerned with minimax approximations. Our approximations will be used in finite-precision arithmetic. Hence, the computed polynomial coefficients are usually rounded: the coefficient p i of the minimax approximation p(x) = p 0 +p 1 x+ +p n x n is rounded to, say, the nearest multiple of 2 mi. By doing that, we obtain a slightly different polynomial approximation ˆp. But we have no guarantee that ˆp is the best minimax approximation to f among the polynomials whose degree i coefficient is a multiple of 2 mi. The aim of this paper is to give a way of finding this best truncated approximation. We have two goals in mind: rather low precision (say, around 15 bits), hardware-oriented, for specificpurpose implementations. In such cases, to minimize multiplier sizes (which increases speed and saves silicon area), the values ofm i, fori 1, should be very small. The degrees of the polynomial approximations are low. Typical recent examples are given in [19, 10]. Roughly speaking, what matters here is to reduce the cost (in terms of delay and area) without making the accuracy unacceptable; single-precision or double-precision, software-oriented, general-purpose implementations for implementation on current microprocessors. Using Table-driven methods, such as the ones suggested by Tang [15, 16, 17, 18], the degree of the polynomial approximations can be made rather low. Roughly speaking, what matters in that case is to get very high accuracy, without making the cost (in terms of delay and memory) unacceptable. The outline of the paper is the following. We give an account of Chebyshev polynomials and some of their properties in Section 1. Then, in Section 2, we 2

provide a general method that finds the best truncated approximation of a functionf over a compact interval[0,a]. We finish with two examples. Our method is implemented in Maple programs that can be downloaded from http://www.ens-lyon.fr/ nbriseba/trunc.html. We plan to prepare a C version of these programs which should be much faster. 1 Some reminders on Chebyshev polynomials Definition 1 (Chebyshev polynomials) The Chebyshev polynomials can be defined either by the recurrence relation or by T 0 (x) = 1 T 1 (x) = x T n (x) = 2xT n 1 (x) T n 2 (x); (1) T n (x) = { cos ( ncos 1 x ) ( x 1) cosh ( ncosh 1 x ) (x > 1). (2) The first Chebyshev polynomials are listed below. T 0 (x) = 1, T 1 (x) = x, T 2 (x) = 2x 2 1, T 3 (x) = 4x 3 3x, T 4 (x) = 8x 4 8x 2 +1, T 5 (x) = 16x 5 20x 3 +5x. An example of Chebyshev polynomial (T 7 ) is plotted in Fig. 1. These polynomials play a central role in approximation theory. Among their many properties, the following ones will be useful in the sequel of this paper. A presentation of the Chebyshev polynomials can be found in [1] and especially in [14]. Property 1 Forn 0, we have T n (x) = n 2 n/2 ( 1) k(n k 1)! k!(n 2k)! (2x)n 2k. k=0 Hence, T n has degree n and its leading coefficient is 2 n 1. It has n real roots, all strictly between 1 and 1. Property 2 There are exactlyn+1 valuesx 0,x 1,x 2,...,x n such that 1 = x 0 < x 1 < x 2 < < x n = 1, 3

1 0.5 1 0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8 1 x 0.5 1 Figure 1: Graph of the polynomial T 7 (x). which satisfy T n (x i ) = ( 1) n i max x [ 1,1] T n(x) i, i = 0,..., n. That is, the maximum absolute value of T n is attained at the x i s, and the sign of T n alternates at these points. We recall that a monic polynomial is a polynomial whose leading coefficient is 1. Property 3 (Monic polynomials of smallest norm) Let a, b R, a b. The monic degree-n polynomial having the smallest.,[a,b] norm in [a,b] is (b a) n 2 2n 1 T n ( 2x b a b a The central result in polynomial approximation theory is the following theorem, due to Chebyshev. Theorem 1 (Chebyshev) Let a, b R, a b. The polynomial p is the minimax approximation of degree n to a continuous function f on [a,b] if and only if there exist at least n+2 values ). a x 0 < x 1 < x 2 <... < x n+1 b 4

such that: p(x i ) f(x i ) = ( 1) i [p(x 0 ) f(x 0 )] = ± f p,[a,b]. Throughout the paper, we will make frequent use of the polynomials T n (x) = T n(2x 1). The first polynomials Tn are given below. We have (see [4, Chap. 3] for example)tn(x) = T 2n (x 1/2 ), hence all the coefficients oftn are nonzero integers. T0 (x) = 1, T1 (x) = 2x 1, T2(x) = 8x 2 8x+1, T3 (x) = 32x3 48x 2 +18x 1, T4 (x) = 128x4 256x 3 +160x 2 32x+1, T5(x) = 512x 5 1280x 4 +1120x 3 400x 2 +50x 1. Theorem 2 (Polynomial of smallest norm with degree-k coefficient equal to1.) Let a (0,+ ), define ( x β 0 +β 1 x+β 2 x 2 + +β n x n = Tn a). Let k be an integer, 0 k n, the polynomial 1 ( x ) Tn. β k a has the smallest.,[0,a] norm in [0,a] among the polynomials of degree at most n with a degree-k coefficient equal to 1. That norm is 1/β k. Moreover, when k = n = 0 or 1 k n, this polynomial is the only one having this property. Proving this theorem first requires the following results. Proposition 1 Let(δ i ) i=0,...,n be an increasing sequence of nonnegative integers and P(x) = a 0 x δ0 + +a n x δn R[x], then eitherp = 0 orp has at mostnzeros in (0,+ ). Proof. By induction on n. For n = 0, it is straightforward. Now we assume that the property is true until the rank n. Let P(x) = a 0 x δ0 + + a n x δn + a n+1 x δn+1 R[x] with 0 δ 0 < < δ n+1 and a 0 a 1...a n+1 0. Assume that P has at least n+2 zeros in (0,+ ). Then P 1 = P/x δ0 has at least n+2 zeros in(0,+ ). Thus, the nonzero polynomial P 1 (x) = (δ 1 δ 0 )a 1 x δ1 δ0 + + (δ n+1 δ 0 )a n+1 x δn+1 δ0 has, from Rolle s Theorem, at least n + 1 zeros in (0,+ ), which contradicts the induction hypothesis. 5

Corollary 1 Let k be an integer, 1 k n, and P(x) = n e j x j R[x]. j=0 j k IfP has at least n zeros in [0,+ ) and at most a simple zero in 0, then P = 0. j=1 j k Proof. If P(0) 0, then P has at least n zeros in (0,+ ), hence P = 0 from Proposition 1. Suppose now that P(0) = 0. We can rewrite P as P(x) = n e j x j. As P has at least n 1 zeros in (0,+ ), it must yet vanish identically from Proposition 1. Proof of Theorem 2. We give the proof in the case a = 1 (the general case is a straightforward generalization). The casek = n = 0 is straightforward. n Denote Tn (x) = a k x k. From Property 2, there exist 0 = η 0 < η 1 < < η n = 1 such that k=0 a 1 k T n(η i ) = a 1 k ( 1)n i T n,[0,1] = a 1 k ( 1)n i. Now, we assume 1 k n. This part of the proof follows step by step n the proof of Theorem 2.1 in [14]. Let q(x) = c j x j R[x] satisfy x k q(x),[0,1] a 1 k. We suppose that xk q a 1 k T n. Then the polynomial n P(x) = a 1 k T n(x) (x k q(x)) has the form d j x j and is not identically zero. Hence there exist i andj, 0 i < j n, such that P(η 0 ) = = P(η i 1 ) = 0,P(η i ) 0 andp(η j ) 0,P(η j+1 ) = = P(η n ) = 0 (otherwise, the nonzero polynomial P would have at least n distinct roots in[0, 1] which would contradict Corollary 1). Let l such that P(η l ) 0 then sgn P(η l ) = sgn a 1 k T n(η l ) = ( 1) n l sgn a 1 k. Let m such that P(η l) 0, P(η l+1 ) = = P(η l+m 1 ) = 0, P(η l+m ) 0 : P has at leastm 1 zeros in[η l,η l+m ]. We distinguish two cases: Ifmis even, we have sgnp(η l ) = sgnp(η l+m ) and thus,p must have an even number of zeros (counted with multiplicity) in[η l,η l+m ]. If m is odd, we have sgn P(η l ) = sgn P(η l+m ) and thus, P must have an odd number of zeros (counted with multiplicity) in[η l,η l+m ]. In both cases, we conclude that P has at leastmzeros in[η l,η l+m ]. ThenP has at leastj i zeros in[η i,η j ]. Finally,P has not less thani+(j i)+n j = n zeros in [0,1] (P has at least i zeros in [η 0,η i ) and at least n j j=0, j k j=0, j k 6

zeros in(η j,η n ]). Note that we also obtained thatp has no less thann 1 zeros in(0,1]. AsP is nonzero, this contradicts Corollary 1. n To end, we assume k = 0 and n 1. Let q(x) = c j x j R[x] satisfy 1 q(x),[0,1] < a0 1. Then the polynomial P(x) = a 1 0 T n (x) (1 q(x)) n has the form d j x j and is not identically zero. This polynomial changes sign j=1 between any two consecutive extrema of T n, hence it has at least n zeros in (0,1). As it cancels also at 0, we deduce that P vanishes identically, which is the contradiction desired. Remark 1 When k = 0 and n 1, it is not possible to prove unicity: for example, let a = 1, k = 0, n = 1, the polynomials 1 λx with λ [0,2] have all a.,[0,1] norm equal to1. 2 Getting the truncated polynomial that is closest to a function in[0,a] Let a (0,+ ), let f be a function defined on [0,a] and m 0, m 1,..., m n be n + 1 integers. Define P n [m0,m1,...,mn] as the set of the polynomials of degree less than or equal to n whose degree-i coefficient is a multiple of 2 mi for all i between0andn(we will call these polynomials truncated polynomials ). Let p be the minimax approximation to f on [0,a]. Define ˆp as the polynomial whose degree-i coefficient is obtained by rounding the degree-i coefficient ofpto the nearest multiple of2 mi (with an arbitrary choice in case of a tie) for i = 0,..., n: ˆp is an element of P n [m0,m1,...,mn]. Also define ǫ and ˆǫ as j=1 ǫ = f p,[0,a] and ˆǫ = f ˆp,[0,a]. We assume that ˆǫ 0. Let λ [ ǫ ˆǫ,1], we are looking for a truncated polynomial p P n [m0,m1,...,mn] such that and f p,[0,a] = min q P [m 0,m 1,...,mn] n f q,[0,a] f p,[0,a] λ f ˆp,[0,a]. (3) When λ = 1, this problem has a solution since ˆp satisfies (3). It should be noticed that, in that case,p is not necessarily equal to ˆp. In the following, we compute bounds on the coefficients of a polynomial q P n [m0,m1,...,mn] such that ifq is not within these bounds, then p q,[0,a] > ǫ+λˆǫ. 7

Knowing these bounds will allow an exhaustive searching ofp. To do that, consider a polynomial q whose degree-i coefficient is p i +δ i, with δ i 0. Let us see how close canq be top. We have (q p)(x) = δ i x i + 0 j n, j i Hence, q p,[0,a] is minimum implies that x i + 1 δ i 0 j n, j i 0 j n, j i (q j p j )x j. (q j p j )x j,[0,a] is minimum. Hence, we have to find the polynomial of degree n, with fixed degree-i coefficient, whose norm is smallest. This is given by Theorem 2. Therefore, we have x i + 1 (q j p j )x j,[0,a] 1 δ i β i, where β i is the nonzero degree-i coefficient of Tn (x/a). Therefore, we must have q p,[0,a] δ i β i. Now, if a polynomial is at a distance greater than ǫ + λˆǫ from p, it cannot be p since q f,[0,a] q p,[0,a] p f,[0,a] > λˆǫ. Therefore, if there exists i,0 i n, such that δ i > (ǫ+λˆǫ) β i then q p > ǫ+λˆǫ and thereforeq p. Hence, the degree-i coefficient ofp necessarily lies in the interval[p i (ǫ+λˆǫ) β i,p i +(ǫ+λˆǫ) β i ]. Thus we have 2 mi (p i (ǫ+λˆǫ) β i ) 2 mi p i }{{} (p 2mi i +(ǫ+λˆǫ) β i ), (4) }{{} m i M i since 2 mi p i is a rational integer: we have M i m i + 1 possible values for the integer 2 mi p i. This means that we have n i=0 (M i m i +1) polynomials candidates. If this amount is small enough, we search for p by computing the norms f q,[0,a], q running among the possible polynomials. Otherwise, we need an additional step to decrease the number of candidates. Hence, we give now a method for this purpose. Condition (3) means f(x) λˆǫ n p i xi f(x)+λˆǫ (5) i=0 8

for all x [0, a]. In particular, we have i.e., since 2 m0 p 0 is an integer, f(0) λˆǫ p 0 f(0)+λˆǫ 2 m0 (f(0) λˆǫ) 2 m0 p 0 2m0 (f(0)+λˆǫ). The n+1inequations given by (4) define a polytope to which the numerators (i.e. the2 mi p i ) belong. The idea is to try to make this polytope smaller in order to reduce our final exhaustive search. We do that thanks to inequations (5) considered for a certain number (chosen by the user) of values of x [0,a]. Once we got a small enough polytope, we start our exhaustive search using libraries (such as Polylib [11] and CLooG [2]) specially designed for scanning efficiently the integer points of polytopes and producing only the corresponding loops in our program of exhaustive search. CLooG implements the Quilleré et al. algorithm [12]. 3 Examples We implemented in Maple a weakened version of the process described in the previous section. By this, we mean that in the step of refinement of the polytope, we only determine its vertices using the simplex method instead of scanning its integer points. The program first computes the bounds obtained from Chebyshev polynomials and then, if these bounds are too large, computes the vertices of the polytope obtained from inequations (4) and inequations (5) considered for x i = i da where d is an integer parameter chosen by the user, i an integer, 0 i d and A is a rational number close and less than or equal to a. 3.1 Cosine function in [0,π/4] with a degree-3 polynomial In [0, π/4], the distance between the cosine function and its best degree-3 minimax approximation is 0.00011. This means that such an approximation is not good enough for single-precision implementation of the cosine function. It can be of interest for some special-purpose implementations. In this example, the bounds given by the first step (associated to Chebyshev polynomials) are good enough to avoid the use of the polytope refinement. >m := [12,10,6,4]:polstar(cos,Pi/4,3,m); "minimax = ",.9998864206 + (.00469021603 + (-.5303088665 +.06304636099 x) x) x "Distance between f and p =",.0001135879209 9

3 17 2 5 "hatp = ", - x - -- x + ---- x + 1 32 1024 "Distance between f and hatp =",.0006939707 >Do you want to continue (y;/n;)? y; >Enter the value of parameter lambda: 1/2; degree 0: 4 possible values between 2047/2048 and 4097/4096 degree 1: 22 possible values between -3/512 and 15/1024 degree 2: 5 possible values between -9/16 and -1/2 degree 3: 1 possible values between 1/16 and 1/16 440 polynomials need be checked >Do you want to try to refine the bounds (y;/n;)?n; 1 3 17 2 3 4095 "pstar = ", -- x - -- x + --- x + ---- 16 32 512 4096 "Distance between f and pstar =",.0002441406250 "Time elapsed (in seconds) =", 1.840 In this example, the distance betweenf and p is approximately0.35 times the distance between f and ˆp. Using our method saves around log 2 (0.35) 1.5 bits of accuracy. 3.2 Exponential function in [0, log(1 + 1/2048)] with a degree-3 polynomial In [0, log(1 + 1/2048)], the distance between the exponential function and its best degree-3 minimax approximation is around 1.8 10 17, which should be sufficient for a faithfully rounded double precision implementation provided there is much care in the polynomial evaluation. The bounds given to get p 10

using the first step are too large (there are 18523896 polynomials to test). Hence, we must use the polytope refinement. >Digits:=30: >m := [56,45,33,23]: polstar(exp,log(1.+1./2048),3,m); "minimax = ",.999999999999999981509827946165 + (1.00000000000121203815619648271 + (.499999987586063030320493910112 +.166707352549861488779274879363 x) x) x -16 "Distance between f and p =",.1849017208895 10 1398443 3 4294967189 2 35184372088875 "hatp = ", ------- x + ---------- x + -------------- x 8388608 8589934592 35184372088832 72057594037927935 + ----------------- 72057594037927936 "Distance between f and hatp =", -16.23624220969326235229443 10 >Do you want to continue (y;/n;)? y; >Enter the value of parameter lambda: 1; degree 0: 6 possible values between 18014398509481983/18014398509481984 and 72057594037927937/72057594037927936 degree 1: 109 possible values between 35184372088821/35184372088832 and 35184372088929/35184372088832 degree 2: 146 possible values between 4294967117/8589934592 and 2147483631/4294967296 degree 3: 194 possible values between 699173/4194304 and 1398539/8388608 18523896 polynomials need be checked >Do you want to try to refine the bounds (y;/n;)?y; >Enter the value of parameter d: 25; 11

degree 0: 2 possible values between 72057594037927935/72057594037927936 and 1 degree 1: 27 possible values between 35184372088857/35184372088832 and 35184372088883/35184372088832 degree 2: 32 possible values between 536870897/1073741824 and 4294967207/8589934592 degree 3: 44 possible values between 1398421/8388608 and 21851/131072 76032 polynomials need be checked >Do you want to try to refine the bounds (y;/n;)?n; >Do you want to change the value of Digits (y;/n;)?y; >Enter the value of Digits: 21; 1398443 3 2147483595 2 35184372088873 "pstar = ", ------- x + ---------- x + -------------- x 8388608 4294967296 35184372088832 72057594037927935 + ----------------- 72057594037927936 "Distance between f and pstar =", -16.20246280367096470182285 10 "Time elapsed (in seconds) =", 54721.961 In this last example, the distance between f and p is approximately 0.85 times the distance betweenf and ˆp. Using our method saves around log 2 (0.85) 0.22 bits of accuracy. References [1] P. Borwein and T. Erdélyi, Polynomials and Polynomials Inequalities, Graduate Texts in Mathematics, 161, Springer-Verlag, 1995. [2] C. Bastoul. CLooG, a loop generator for scanning Z-polyhedra, User s Guide, available from http://www.prism.uvsq.fr/ cedb/bastools/cloog.html. [3] M. Daumas, C. Mazenc, X. Merrheim, and J.- M. Muller. Modular range reduction: A new algorithm for fast and accurate computation of the elemen- 12

tary functions. Journal of Universal Computer Science, 1(3):162 175, March 1995. [4] L. Fox and I. B. Parker, Chebyshev Polynomials in Numerical Analysis, Oxford Mathematical Handbooks, Oxford University Press, 1972. [5] J. F. Hart, E. W. Cheney, C. L. Lawson, H. J. Maehly, C. K. Mesztenyi, J. R. Rice, H. G. Thacher, and C. Witzgall. Computer Approximations. Wiley, New York, 1968. [6] P. Markstein. IA-64 and Elementary Functions: Speed and Precision. Hewlett- Packard Professional Books. Prentice Hall, 2000. ISBN: 0130183482. [7] J.-M. Muller. Elementary Functions, Algorithms and Implementation. Birkhäuser, Boston, 1997. [8] K. C. Ng. Argument reduction for huge arguments: Good to the last bit (can be obtained by sending an e-mail to the author: kwok.ng@eng.sun.com). Technical report, SunPro, 1992. [9] M. Payne and R. Hanek. Radian reduction for trigonometric functions. SIGNUM Newsletter, 18:19 24, 1983. [10] J.A. Pineiro, J.D. Bruguera, and J.-M. Muller. Faithful powering computation using table look-up and a fused accumulation tree. In Burgess and Ciminiera, editors, Proc. of the 15th IEEE Symposium on Computer Arithmetic (Arith-15). IEEE Computer Society Press, 2001. [11] Polylib, a library of polyhedral functions, User s Manual, available from http://www.irisa.fr/polylib/. [12] F. Quilleré, S. Rajopadhye and D. Wilde. Generation of efficient nested loops from polyhedra. International Journal of Parallel Programming, 28(5):469 498, October 2000. [13] E. Remes. Sur un procédé convergent d approximations successives pour déterminer les polynômes d approximation. C.R. Acad. Sci. Paris, 198, 1934, pp 2063 2065. [14] T. J. Rivlin. Chebyshev polynomials. From approximation theory to algebra and number theory. Second edition. Pure and Applied Mathematics. John Wiley & Sons, Inc., New York, 1990. [15] P. T. P. Tang. Table-driven implementation of the exponential function in IEEE floating-point arithmetic. ACM Transactions on Mathematical Software, 15(2):144 157, June 1989. [16] P. T. P. Tang. Table-driven implementation of the logarithm function in IEEE floating-point arithmetic. ACM Transactions on Mathematical Software, 16(4):378 400, December 1990. 13

[17] P. T. P. Tang. Table lookup algorithms for elementary functions and their error analysis. In P. Kornerup and D. W. Matula, editors, Proceedings of the 10th IEEE Symposium on Computer Arithmetic, pages 232 236, Grenoble, France, June 1991. IEEE Computer Society Press, Los Alamitos, CA. [18] P. T. P. Tang. Table-driven implementation of the expm1 function in IEEE floating-point arithmetic. ACM Transactions on Mathematical Software, 18(2):211 222, June 1992. [19] B. Wei, J. Cao and J. Cheng. High-performance architectures for elementary function generation. In Burgess and Ciminiera, editors, Proc. of the 15th IEEE Symposium on Computer Arithmetic (Arith-15). IEEE Computer Society Press, 2001. 14