Accurate Evaluation of Polynomials in Legendre Basis

This paper presents a compensated algorithm for accurate evaluation of a polynomial in Legendre basis. Since the coefficients of the evaluated polynomial are fractions, we propose to store these coefficients in two floating point numbers, such as doubledouble format, to reduce the effect of the coefficients’ perturbation. The proposed algorithm is obtained by applying error-free transformation to improve the Clenshaw algorithm. It can yield a full working precision accuracy for the ill-conditioned polynomial evaluation. Forward error analysis and numerical experiments illustrate the accuracy and efficiency of the algorithm.

The Clenshaw algorithm [4,5] is usually used to evaluate a linear combination of Chebyshev polynomials, but it can apply to any class of functions that can be defined by a three-term recurrence relation.Therefore the Clenshaw algorithm can evaluate a polynomial in Legendre basis.The error analysis of the Clenshaw algorithm was considered in the literatures [6][7][8][9][10].The relative accuracy bound of the computed values p() by the Clenshaw algorithm verifies      () − p ()      () ≤ cond (, ) ×  () .
Motivated by them, we apply error-free transformations to analyze the effect of round-off errors and then compensate them to the original result of the Clenshaw algorithm.Since the coefficients of the Legendre polynomial are fractions, the coefficient perturbations in the evaluation may exist when the coefficients are truncated to floating point numbers.We store the coefficients which are not floating point numbers in double-double format, with the double working precision, to get the perturbation.We also compensate the approximate perturbed errors to the original result of the Clenshaw algorithm.Based on the above, we construct a compensated Clenshaw algorithm for the evaluation of a linear combination of Legendre polynomials, which can yield 2 Journal of Applied Mathematics a full working precision accuracy and its relative accuracy bound satisfies      () − p ()      () ≤  () + cond (, ) ×  ( 2 ) . ( The paper is organized as follows.Section 2 shows some basic notations in error analysis, floating point arithmetic, error-free transformations, compensated algorithm, Clenshaw algorithm, and condition number.Section 3 presents the compensated algorithm and its error bound.Section 4 gives several numerical experiments to illustrate the efficiency and accuracy of the compensated algorithm for polynomial in Legendre basis.

Mathematical and Arithmetical Preliminaries
where ∘ ∈ {+, −, ×, ÷} and | 1 |, | 2 | ≤  ( is the round-off unit).We also assume that the computed result of  ∈ R in floating point arithmetic is denoted by â and the set of all floating point numbers is denoted by F. The following definition will be used in error analysis (see more details in [17]).
There are three classic properties which will also be used in error analysis:

Accurate Sum and Product.
Let ,  ∈ F, and no overflow nor underflow occurs.The transformation (, ) → (,) is regarded as an error-free transformation (EFT) that causes  ∈ F to exist such that  ∘  =  + ,  =   .
Let us show the error-free transformations of the sum and product of two floating point numbers in Algorithms 1-3 which are the  algorithm by Knuth [18] and the  algorithm by Dekker [19], respectively.
We present the compensated algorithm for the product of three floating point numbers in Algorithm 4, which refers to [20].
According to Theorem  [5].We recall it in Algorithm 5.
Barrio et al. [21] proposed a general polynomial condition number for any polynomial basis defined by a linear recurrence and used this new condition number to give the error bounds for the Clenshaw algorithm.Based on this general condition number, we propose the absolute Legendre polynomial, which is similar to the absolute polynomial mentioned in [7,21].Definition 4. Let   () be Legendre polynomial.We define the absolute Legendre polynomial p () which is associated with   () and satisfies where |  ()| ≤ p (), ∀ ≥ 0.
The absolute Legendre polynomial satisfies the following property.
Following Definition 4, we introduce the condition number for the evaluation of polynomials in Legendre basis [21].
, where   () is Legendre polynomial.Let p () be the absolute Legendre polynomial.Then the absolute condition number is and the relative condition number is

Compensated Algorithm for Evaluating Polynomials
In this section, we exhibit the exact round-off errors generated by the Clenshaw algorithm with EFT.We also analyze the perturbations generated by truncating the fractions in Algorithm 5. We propose a compensated Clenshaw algorithm to evaluate finite Legendre series and present its error bound in the following.
Remark 11.When  = , the th step of Algorithm 5 is b =  (ℎ)   , so that we only need to consider the perturbation of coefficient   .
Next we deduce the round-off error bound.Let  (44)  5−1 is (), so this round-off error may influence the accuracy, we also need to consider it in our compensated algorithm.
From Theorem 3 we have known that round-off error ), so this round-off error does not influence the accuracy.
Observing the error bounds we described above, the perturbation generated by the third part of coefficients in (18) does not influence the accuracy.Thanks to the V   algorithm in Appendix B (see Algorithm 13), we only need to split the coefficients into two floating point numbers.
Applying EFT, the ℎ algorithm and the V   algorithm, considering all errors which may influence the numerical result in working precision in Algorithm 5, we obtain the compensated Clenshaw algorithm in Algorithm 6.
Here we give the error bound of Algorithm 6.   ,  ()  ) [ℎ3, 3] =   ( (ℎ)  +2 ,  () +2 ,  (ℎ) +1 ,  () +1 ) [ℎ4, 4] =   (ℎ2, 2, ℎ3, 3) [ (ℎ)   ,  ()  ] =   (ℎ4, 4,  (ℎ)  ,  ()  ) end  = [ (ℎ)  0 ,   Toolbox in Figure 1.The polynomials in Legendre basis evaluated by the compensated algorithm are much more smooth drawing and just a little oscillation in the intervals [0.7485, 0.7515] in Figure 2. In fact, if we use the Symbolic Toolbox to get the polynomial coefficients, the oscillation will be smaller than it is in Figure 2.However, this method is expensive.We just need to use the V algorithm to get the coefficients; the result obtained by the ℎ algorithm is almost the same as that by using the Symbolic Toolbox in working precision.counting on average.We also implement ℎ and ℎ by using Microsoft Visual C++ 2008 on Windows 7. Similar to the statement in [23], we assume that the computing time of these algorithms does not depend on the coefficients of polynomial in Legendre basis nor the argument .So we generate the tested polynomials with random coefficients and arguments in the interval (−1, 1), whose degrees vary from 20 to 10000 by the step 50.The average measured computing time ratio of ℎ to ℎ in C code is 58.29%.The reason why the measured computing time ratio is better than the theoretical flop count one can be referred to the analysis in terms of instruction level parallelism (ILP) described in [24,25].

Conclusions
This paper introduces a compensated Clenshaw algorithm for accurate evaluation of the finite Legendre series.The ℎ algorithm is not precise enough for an ill-conditioned problem, especially evaluating a polynomial in the neighborhood of a multiple root.However, this new algorithm can yield a full precision accuracy in working precision, as the same as the original Clenshaw algorithm using double-double arithmetic and rounding into the working precision.Meanwhile this compensated Clenshaw algorithm is more efficient which means that it is much more useful to accurately evaluate the polynomials in Legendre basis for illconditioned situations.