Professional Documents
Culture Documents
net/publication/4261523
CITATIONS READS
3 66
1 author:
Laurent Fousse
University Joseph Fourier - Grenoble 1
28 PUBLICATIONS 764 CITATIONS
SEE PROFILE
All content following this page was uploaded by Laurent Fousse on 06 November 2015.
Laurent Fousse
Université Henri-Poincaré Nancy 1
laurent@komite.net
1
In this paper, f : [a, b] → R is the C ∞ function we want From (1) we deduce that Pn has only monomials of degree
to integrate on a finite domain [a, b] and n is the number of the parity of n and has rational coefficients. We recall Ro-
points of the Gauss-Legendre method. Let drigues’ representation:
1 dn
Z b
I= f (x)dx Pn = ((x2 − 1)n )
a 2n n! dxn
be the exact value of the integral. We define the inner prod- which shows that we can use 2n as common denominator
uct of f and g on [a, b] for the admissible weight function for the polynomial’s coefficients. Thus Pn can be written
w as −n
2 Qn (X 2 ) if n is even
Z b
Pn (X) =
< f, g >= w(x)f (x)g(x)dx. 2−n XQn (X 2 ) otherwise.
a
This leads to the definition of a sequence of orthogonal The problem of computing Pn is reduced to the one of com-
polynomials (pi )i≥0 such that: puting Qn , which has integer coefficients. The procedure is
detailed in Algorithm 1.
∀i ∈ N, deg(pi ) = i
∀(i, j) ∈ N2 , < pi , pj >= δi,j Algorithm 1 Computation of the Legendre Polynomials
I NPUT: n ≥ 2.
where δi,j is Kronecker’s delta. For fixed n > 0, pn
O UTPUT: Qn .
has n distinct roots in (a, b) which we name x0 < x1 <
1: Q0 ← 1
. . . < xn−1 . The Gauss quadrature method associated to
2: Q1 ← 2
the weight function w on [a, b] is the interpolatory method
3: p ← 0 . holds the parity of the polynomial currently
at evaluation points (xi )0≤i<n such that
computed
Z b n−1
X 4: for i ← 2 to n do
w(x)p(x)dx = wi p(xi ) 5: Qp ← −4(i − 1)Qp + 2(2i − 1)X 1−p Q1−p
a i=0 6: Qp ← 1i Qp . exact integer divisions
holds for every polynomial p of degree up to n − 1 (this is 7: p←1−p
enough to define the weights wi although the method will 8: end for
be shown to integrate accurately polynomials of degree up 9: return Q1−p
to 2n − 1).
The Gauss-Legendre quadrature method is the Gauss 2.3. Mathematical error
method for the weight function w = 1. Additionally
the Legendre polynomials (Pn )n≥0 are usually defined on In this section we give the bound on the mathematical
[−1, 1] and normalized such that Pn (1) = 1 and we will error made with the Gauss-Legendre quadrature method. A
follow this custom here. generic proof for any weight function w can be found in [2].
2
2.4. Floating-point Arithmetics and together with ulp(◦(a + b)) ≥ ulp(a + b) ≥ ulp(a)
(Lemma 2) this concludes the proof.
For the error analysis of Algorithm 2, we need a few
useful lemmas concerning the “ulp calculus”, as well as Lemma 5. For x and y real numbers and using rounding
some definitions. The floating-point numbers are repre- to nearest in precision p we have
sented with radix 2 (this could be generalized for any radix 5
but radix 2 is simpler and is natural on computers). For | ◦ (◦(x) · ◦(y)) − xy| ≤ ulp(◦(◦(x) · ◦(y))).
2
this section, p is the working precision, and we assume all
floating-point numbers are normalized, which means in our
3. Pre-computations
notations that the exponent range is unbounded. We denote
by ◦(x) the floating-point number rounded to nearest in pre-
cision p of a given real value x. In the integration algorithm the evaluation points and the
weights of the method do not depend on the function to inte-
Definition 1 (Exponent, Unit in the last place). For a non- grate and their computation can thus be shared among sev-
zero real number x we define E(x) := 1 + blog2 |x|c, such eral executions of the algorithm. We will now explain how
that 2E(x)−1 ≤ |x| < 2E(x) , and ulp(x) := 2E(x)−p . these quantities are computed.
For a real x 6= 0 and a working precision p we always have
2p−1 ulp(x) ≤ |x| < 2p ulp(x). If x is a floating-point 3.1. Evaluation points
number, then ulp(x) is the weight of the least significant bit
— zero or not — in the p-bit mantissa of x. For all real x, Computing the roots (x0i )0≤i<n of Pn reduces to the
ulp(x) is always greater than zero by definition. computation of the roots of Qn . Let m = b n2 c and u0 <
u1 < . . . < um−1 be the roots of Qn , we have:
Lemma 1. If c 6= 0 and x 6= 0 then c · ulp(x) < 2 · ulp(cx).
0 0 √
Lemma 2. Assuming no underflow occurs then in all xi , xn−1−i = {± ui } , 0 ≤ i < m
rounding modes for a non zero real x we have: ulp(x) ≤
and x0m = 0 if n is odd.
ulp(◦(x)), where ◦(x) is the rounding of x in the chosen
The process of computing the roots of Qn involves two
mode with an unbounded exponent range.
steps:
Lemma 3. Let x a non-zero real and ◦(x) its rounding to
nearest on p bits. Then |x| ≤ (1 + 2−p )| ◦ (x)|. 1. root isolation, that is finding m intervals that contain
exactly one positive root of Qn each,
Lemma 4. Let a and b be two non-zero floating-point num-
bers of the same sign and precision p then in all rounding 2. root refinement.
modes
3 The root isolation is made using Uspensky’s algorithm as
ulp(a) + ulp(b) ≤ ulp(◦(a + b)). described in [11]. The input of the algorithm is Qn (x), and
2
the output is a sequence of m intervals of the form 2clii where
P ROOF: It suffices to consider the case where a and b are
positive. The definition of ulp gives: ci and li are integers and such that [ 2clii , c2i +1
li ] contains ex-
3
We will assume that b − a as well as a were computed as Algorithm 2 Gauss-Legendre integration
rounded to nearest of the correct value. The error analysis I NPUT: ba, b[− a, (cwi ), f, (vbi ), n . where wi are the
for the translated points on [a, b] gives: weights and vi is defined in §2.4.
b a p-bit approximation of b f (x)dx with
R
5 O UTPUT: I, a
| ◦ (vbi · b[
− a) − vi · (b − a)| ≤ ulp(◦(vbi · b[
− a)) error bounded by Theorem 3.
2
1: for i ← 0 to n − 1 do
using Lemma 5, then 2: t ← ◦((b[ − a) · vbi )
3: xbi ← ◦(t + b a)
1 5 1 4: fbi ← ◦(f (xbi ))
|xbi − xi | ≤ ulp(xbi ) + ulp(◦(vbi · b[
− a)) + ulp(b
a)
2 2 2 5: ybi ← ◦(fbi · w
ci )
17 6: end for
≤ ulp(xbi ). [Lemma 4] b ← sum(ybi , i = 0 . . . n − 1)
4 7: S . with Demmel and
Hida algorithm [3]
3.2. Weights 8: Db ← ◦(b[ − a)/2
9: return ◦(D b S)
b = Ib
The weights (wi )0≤i<n satisfy the equation
Z 1 n−1
X 4. Integration Algorithm
p(x)dx = wi p(xi ) In order to provide an error bound on the numerical result
−1 i=0 given by the Gauss-Legendre method, we will have a step-
by-step look into Algorithm 2.
for every polynomial of degree ≤ 2n −Q1 (see Section 2.3). In addition to the parameters of Algorithm 2 we need
For i ∈ [0, n − 1] we write Li (x) = j6=i (x − xj ). No- an upper bound M2n of |f (2n) | on [a, b]; p is the working
Pn (x) 0
tice that Li (x) = (x−xi )Pn0 (xi ) . Li has degree n − 2 so by a
precision expressed in the number of bits of the mantissa, b
1 and b[− a are given as the rounded to nearest floating-point
L0i , Pn >= −1 Pn (x)L0i (x)dx =
R
definition < 0:
number in the desired precision; M1 an upper bound of |f 0 |
Z 1 on [a, b]. We will now prove our main theorem:
1
0 = [Pn (x)Li (x)]−1 − Pn0 (x)Li (x)dx.
−1 Theorem 3. Let δybi = 11 4 ulp(ybi ) + 6M1 w
ci ulp(b
xi ), where
ybi , w
ci and xbi are defined in Algorithm 2. When computing
Pn0 Li has degree 2n − 1 so it is integrated exactly by the the numerical quadrature of f using Algorithm 2 with p ≥ 2
method: the total error on the result is bounded by:
4
possible by the strong semantics of floating-point op- ulp(b
xi ) vanishes. For the error bound we keep track of
erations in MPFR but it is not necessarily easy. With only max(δybi ).
the already estimated error on x
bi we have:
3. Summation of the yi ’s: this is done with Demmel and
xi ) − f (xi )| = |f 0 (θi )(b
|f (b xi − xi )|, Hida summation algorithm [3], which guarantees an
error of at most 1.5 ulp on the final result. This algo-
for some θi ∈ [min(xi , x bi ), max(xi , x
bi )] and with an rithm uses a larger working precision p0 ≈ p+log2 (n).
upper bound on f 0 we can bound this error absolutely. Pn−1
Let S = i=0 yi .
Let fbi = ◦(f (b
xi )) be the floating-point number com-
puted. At this step we now have: 3
|Sb − S| ≤ b + n · max(δyb ).
ulp(S) i
2
δfbi = |fbi − f (xi )| ≤ |f 0 (θi )(b
xi − xi )| + ulp(fbi )
17 b−a
I= b−a
We note D = b−a
≤ M1 · ulp(b
xi ) + ulp(fbi ). 4. Multiplication by 2 : 2 S. 2
4 and assume as before that the input b[ − a was com-
puted as the rounded to nearest of its exact value. Since
the division by 2 is exact in binary we have:
2. Computation of the yi = f (xi ) · wi . The accumulated
error so far: 1
|D
b − D| ≤
ulp(D)
b
1 2
|b
yi − yi | ≤ ulp(ybi ) + |fbi w
ci − f (xi )wi | 1
2 |Ib − I| ≤ b + |SbD
ulp(I) b − SD|
1 2
≤ ulp(ybi ) + 1
2 ≤ b + 1 |S|ulp(
ulp(I) b b + D|Sb − S|
D)
fbi |c
wi − wi | + wi |fbi − f (xi )| 2 2
3 b + D 3 Dulp(S)
1 1 ≤ ulp(I) b +
≤ ulp(ybi ) + fbi ulp(c wi ) + wi δfbi 2 2
2 2
3 nD · max(δybi )
≤ ulp(ybi ) + [Lemmas 1 and 2]
2
17
3 b 3 ulp(S)
b + (1 + 2−p )D
wi M1 · ulp(b xi ) + ulp(fi ) ≤ ulp(I) b +
2 2
b
4
[Lemmas 1 and 2] (1 + 2−p )Dn
b · max(δyb )
i
3 [Lemma 3]
≤ ulp(ybi ) +
2 9
≤ ( + 3 · 2−p )ulp(I)
b +
17 2
(1 + 2−p )c wi M1 · ulp(b xi ) +
4 n(1 + 2−p )D
b · max(δyb ).
i
(1 + 2−p )c wi ulp(fbi ) [Lemmas 1 and 2]
[Lemma 3]
7
≤ ( + 21−p )ulp(ybi ) +
2 Corollary 1. If we assume furthermore that the sign of f
17
(1 + 2−p )M1 w ci ulp(b
xi ) does not change on [a, b], then we have the following bound:
4
[Lemmas 1 and 2] 161
0
Btotal = b + 425 nM1 D
ulp(I) b max(c
wi ulp(xbi ))
7 4 64
≤ ( + 21−p )ulp(ybi ) +
2 (b − a)2n+1 (n!)4
+ M2n .
17 (2n + 1)[(2n)!]3
+ 17 · 2−p−2 M1 w
ci ulp(b
xi )
4
= δybi . P ROOF: Let us assume for example that f ≥ 0, knowing
that the Gauss-Legendre weights are positive we have
Remark: when bounding the error on x bi , fbi as well as
ybi , the term with ulp(b xi ) vanishes if the error on x bi is ∀i ∈ [0, n − 1], ybi = ◦(c
wi · fbi ) ≥ 0
zero. One can easily show with our assumption that
no underflow occurs, and that if x bi = 0 then the error so
on x bi is zero (i.e., xi = 0) and the ill-defined quantity ulp(ybi ) ≤ 21−p ybi .
5
Pn−1
Let S̃ = i=0 ybi , we know that The derivatives of g need more work, but we can write
3 g (i) (x) = Gi (x)e−x
2
|S̃ − S|
b ≤ ulp(S)
b
2
S̃ ≤ (1 + 3 · 2−p )Sb where Gi (x) is a polynomial and
n−1
X 7 G0 = 1
L = ( + 21−p )ulp(ybi )
i=0
2 Gi+1 = −2xGi (x) + G0i (x) for i ≥ 0. (3)
n−1
7 X
From Equation (3) we see that Gi is an integer polynomial
≤ ( + 21−p )21−p ybi
2 i=0 of degree i and has only monomials of the same parity as i.
7 Furthermore the leading coefficient of Gi is (−2)i .
≤ 21−p ( + 21−p )(1 + 3 · 2−p )Sb We will now prove by recurrence that for i ≥ 0 the coef-
2
ficients of Gi are bounded in absolute value by (i + 1)!.
≤ (7 + 22−p )(1 + 3 · 2−p )ulp(S).
b
The property is true for G0 (x) = 1. Assume the property
From this we get the following bound on the error on S:
b true for some i ≥ 0 and write
i
3
+ (7 + 21−p )(1 + 3 · 2−p ) ulp(S)
X
|Sb − S| ≤ b Gi (x) = aj xj
2
j=0
17 −p−2 i+1
+nM1 + 17 · 2 max(c
wi ulp(xbi )) X
4 Gi+1 (x) = bj xj .
j=0
and substituting this expression in the bound of |Ib−I| above
yields the announced result. For j ≤ i − 1 we have
bj = −2aj−1 + (j + 1)aj+1
5. Experiments: a complete example
|bj | ≤ 2(i + 1)! + (j + 1)(i + 1)!
Algorithm 2 was implemented using the MPFR library ≤ (j + 3)(i + 1)!
[13]. In addition to the result of the integration, the program ≤ (i + 2)!.
gives the error bounds Bmath and Brounding on the mathemat-
ical and rounding errors, respectively. Since bi = 0 and |bi+1 | = 2i+1 < (i + 2)! the property
We give now as an example how to use our algorithm holds for i + 1.
to compute an accurate value for the integral given in the For n ≥ 0 and x ∈ [17, 42] we know that
introduction, namely:
Z 42 |Gn (x)| ≤ n · (n + 1)!xn .
2
I= e−x log xdx. We may now bound |f (n) | as follows:
17
2
|f (n) (x)| ≤ |Gn (x)|e−x log x
2
Let f (x) = e−x log x. We need to provide a bound on the
derivatives of f on [a, b] = [17, 42]. This bound should be n−1
X n 2
sharp enough as it will dictate the order n of the method + |Gi (x)|e−x (n − i − 1)!xi−n
i
used for a given target precision (see [12, p. 181]). i=0
2
We note ≤ n · (n + 1)!xn e−x log x +
2 n−1
g(x) = e−x X i(i + 1) 2i−n −x2
n! x e
h(x) = log x. i=0
n−i
2
≤ n · n!e−x (n + 1)xn log x + (n − 1)xn−2 .
Leibniz’s formula gives
n i
X n d dn−i In particular the following bound is valid for x ∈ [17, 42]:
f (n) (x) = g(x) h(x).
i dxi dxn−i 2
i=0
|f (n) | ≤ n·n!e−17 (n + 1)42n log 42 + (n − 1)42n−2 .
6
p m nopt ppre pmeas t τ The results are given in Figure 2 for a comparison of the
53 16 20 27 37 8 50 predicted error bound and the measured error, and Figure 3
113 16 35 87 103 16 80 for a comparison of the rounding error bound and the math-
200 16 54 174 193 96 55 ematical error bound.
500 32 80 474 498 404 34
Looking at Figure 1 we see that when we use the optimal
1000 32 142 974 998 620 37
number of points n, the accuracy actually achieved is very
2000 32 254 1974 1994 2952 44
close to the working precision: in other words, almost all
5000 32 556 4974 4995 32818 51
bits are correct (except for p = 53 bits). The gap between
the number of bits predicted to be correct and the number
Figure 1. Optimized order nopt , predicted precision ppred of bits measured to be correct (what we may call our “pes-
and measured precision pmeas for different working preci- simism factor”) is stable at about 25 bits. We may consider
sions p in bits and orders m of composition. The timings t for example that for a working precision of 2000 bits a loss
are given in ms (with τ the percentage of total time taken of 20 in the number of predicted good bits (i.e., 1% of the
by the weights computation) and were done on a 2.4GHz working precision) is satisfactory.
AMD Opteron™ 250 processor. -200
measured
total
-400
53 bits and 113 bits to reproduce the double and quad preci- -600
sion, and precisions 200, 500, 1000, 2000 and 5000 bits to
observe the behaviour of our algorithm in higher precision. log(error)
-800
7
-200
math order on specific sub-intervals, as needed. We are also in-
rounding
-400 terested to see how this kind of error bounds could be given
-600 for the double exponential integration [8].
-800 3500
Computation time
-1000
3000
log(error)
-1200
-1400 2500
-1600
Time (ms)
2000
-1800
-2000 1500
-2200
1000
-2400
0 50 100 150 200 250 300 350 400
n
500
0
Figure 3. The bounds Brounding on the rounding error and 0 50 100 150 200 250 300 350 400
n
Bmath on the mathematical error when computing I with
m = 8 and 1000 bits of precision, for several numbers of
points n of the method. Figure 4. Total computing time in milliseconds when
computing I with m = 8 and 1000 bits of precision, on
a 2.4GHz AMD Opteron™ 250 processor.
possible to use precomputed values for these coefficients.
As for the actual value of I computed, we get References
I ≈ 0.256572850056 · 10−126 [1] D. H. Bailey, X. S. Li, and K. Jeyabalan. A comparison
of three high-precision quadrature schemes. Experimental
which means that the first value v1 given by Maple 10 had Mathematics, 14(3):317–329, 2005.
one correct digit out of ten displayed. [2] P. J. Davis and P. Rabinowitz. Methods of numerical integra-
tion. Academic Press, New York, 2nd edition, 1984.
Our source code will be released under the GNU LGPL [3] J. Demmel and Y. Hida. Accurate and efficient floating point
within a few months. summation. SIAM J. Sci. Comput., 25(4):1214–1248, 2003.
[4] W. Gautschi. Algorithm 726; ORTHPOL–a package of rou-
tines for generating orthogonal polynomials and Gauss-type
6. Conclusion quadrature rules. ACM Trans. Math. Softw., 20(1):21–62,
1994.
[5] N. J. Higham. Accuracy and Stability of Numerical Algo-
The Gauss-Legendre quadrature scheme provides a ro- rithms. SIAM, 2nd edition, 2002.
bust numerical integration algorithm, in the sense that an [6] IEEE standard for binary floating-point arithmetic. Techni-
increase in the order of the method results usually in an in- cal Report ANSI-IEEE Standard 754-1985, New York, 1985.
approved March 21, 1985: IEEE Standards Board, approved
crease in the accuracy of the results. This is not true of
July 26, 1985: American National Standards Institute, 18
the Newton-Cotes quadrature scheme for example, where pages.
the stability suffers from coefficients of different signs for [7] F. Jézéquel, F. Rico, J.-M. Chesneaux, and M. Charikhi. Re-
n ≥ 8, if the working precision is not increased accordingly. liable computation of a multiple integral involved in the neu-
Providing the function f is sufficiently smooth on a finite tron star theory. Math. Comput. Simul., 71(1):44–61, 2006.
[8] M. Mori. Discovery of the Double Exponential Transforma-
integration domain [a, b] and bounds on its derivatives are
tion and Its Developments. Publ. RIMS, 41:897–935, 2005.
known, we were able in this paper to propose a quadrature [9] W. Oevel. Numerical computations in MuPAD 1.4. math-
algorithm with a complete error analysis. Our bound on the PAD, 8(1), 1998.
final error is valid for any precision or order of the method, [10] N. Revol. Interval newton iteration in multiple precision for
and since it is an actual bound and not a mere estimate we the univariate case. Numerical Algorithms, 34(2-4):417–426,
dec 2003.
do in fact compute an interval containing the true value of [11] F. Rouillier and P. Zimmermann. Efficient isolation of a poly-
the integral. nomial real roots. Journal of Computational and Applied
As future work we consider an adaptation of our error Mathematics, 162(1):33–50, 2003.
bound when using an adaptive quadrature scheme. If the [12] J. Stoer and R. Bulirsch. Introduction to Numerical Analysis.
bounds on the derivatives of f are known not only globally Springer Verlag, 3rd edition, 2002.
[13] The Spaces project. The MPFR library, version 2.2.0.
for the whole interval but more precisely for sub-intervals,
http://www.mpfr.org/, 2005.
we may be able to use automatically a higher composition