Preprint
Article

This version is not peer-reviewed.

Legendre Series Analysis and Computation via Composed Abel-Fourier Transform

A peer-reviewed article of this preprint also exists.

Submitted:

19 May 2023

Posted:

22 May 2023

You are already at the latest version

Abstract
We prove that the Legendre coefficients associated with a function f(x) can be represented as the Fourier coefficients of a suitable Abel-type transform of the function itself. Thus, the computation of N Legendre coefficients can be performed efficiently in O(NlogN) operations by means of a single Fast Fourier Transform of the Abel-type transform of f(x). We also show how the symmetries associated with the Abel-type transform can be exploited to further reduce the computational complexity. The dual problem of calculating the sum of Legendre expansions is also considered. We prove that a Legendre series can be written as the Abel transform of a suitable Fourier series. This fact allows us to state an efficient algorithm for the evaluation of Legendre expansions. Finally, numerical tests are presented to exemplify and confirm the theoretical results.
Keywords: 
;  ;  ;  

1. Introduction

The computation of the coefficients of Legendre expansions is a very important problem in numerical analysis and applied mathematics with a wide range of applications including, just to mention a few, approximation theory [1], special function theory [2], spectral methods for differential equations [3] and construction of quadrature formulae [3,4]. Its importance has emerged also in connection with the computation of spectra of highly oscillatory Fredholm integral operators, which play an important role in laser engineering [5]. For its relevance, this problem attracted a significant reserach attention since the Seventies [6,7].
The difficulty of the problem lies essentially in the fact that these coefficients are represented by integrals whose integrands oscillate rapidly for large values of the index of the polynomial. Standard quadrature procedures for the calculation of N Legendre coefficients lead only to slow O ( N 2 ) algorithms (see, e.g., Ref. [6,8]). The first contribution for a more efficient computation of Legendre coefficients traces back to the work of Orszag [9], where the algorithm uses a slowly converging first-order WKB expansion of the Legendre polynomials.
More efficiently, in Ref. [10] the Legendre coefficients are obtained by transforming the corresponding Chebyshev coefficients through a multipole-like expansion, which yields a fast  O ( N log N ) algorithm, though requiring a considerable and rather expensive initialization phase. In this context, various improvements have been proposed, e.g., in [11,12]. Remaining within this kind of approach, [13] describes an O ( N ( log N ) 2 / log log N ) Chebyshev-Legendre transform, which is based on the Stieltjes’ asymptotic formula for the Legendre polynomials of large degree. Mori et al. [14] employed the same asymptotic formula to produce a fast O ( N log N ) algorithm but affected by a problem of numerical instability for large N. The connection between Legendre and Chebyshev coefficients is analyzed also in [15] in the case of piecewise smooth functions. In Ref. [16] (see also [17]) an O ( N ( log N ) 2 ) algorithm is given, for N a power of two, which requires a suitably preprocessed data structure.
Another way to tackle this problem has been described in [18], where an algorithm for the rapid computation of the Legendre coefficients is presented when the analytic expression of the input function is known on a Bernstein ellipse in the complex plane. The algorithm has O ( N log N ) complexity but requires the knowledge of the region of analyticity of the function in C .
In this paper we present an alternative procedure. The basic idea of our method consists in exploiting the Dirichlet-Murphy integral representation of the Legendre polynomials. We prove that the coefficients of the Legendre expansion of a function f ( x ) are connected with a subset of the Fourier coefficients (the ones with nonnegative index) of an Abel-type transform of f ( x ) .
The numerical implementation of the algorithm follows straightforwardly and is very efficient. The aforementioned Fourier coefficients (which represent the sought for Legendre coefficients) can be computed in O ( N log N ) operations by a single Fast Fourier Transform (FFT) after the evaluation of the Abel-type integral by means of standard quadrature techniques.
The dual problem of calculating the values of (finite) Legendre expansions is analyzed in Section 3. In SubSection 3.1 we prove that the Legendre expansions can be computed by means of a (inverse) cosine transform of a sequence of coefficients, which is obtained by a suitable linear transformation of the given set of N Legendre coefficients. Further, a novel algorithm is presented in SubSection 3.2, where the Legendre expansions are proved to be the Abel-type transform of a Fourier series, the coefficients of the latter being the Legendre coefficients of the function f ( x ) . This leads to an efficient algorithm which requires the computation of one FFT and of one Abel-type integral.

2. Connection between Legendre expansions and Fourier series

The standard form of the Legendre expansion reads:
f ( x ) = n = 0 c n P n ( x ) ( x [ 1 , 1 ] ) ,
where P n ( x ) are the Legendre polynomials, which can be defined by the generating function [19]:
n = 0 P n ( x ) t n = 1 2 x t + t 2 1 2 ( | x | 1 , | t | < 1 ) ,
and the coefficients { c n } n = 0 are given by:
c n = n + 1 2 1 1 f ( x ) P n ( x ) d x ( n 0 ) .
The conditions to be satisfied by f ( x ) to guarantee the uniform convergence of the series in (1) will be discussed in the next section. However, for our current purpose of computing the Legendre coefficients c n , it is sufficient to assume that f ( x ) be absolutely integrable on the interval [ 1 , 1 ] . For later convenience, we define the normalized Legendre coefficients as
a n c n 2 n + 1 ( n 0 ) .
We can now state the following theorem.
Theorem 1. 
The normalized Legendre coefficients { a n } n = 0 coincide with the Fourier coefficients, with n 0 , of an Abel-type transform of f ( x ) , that is:
a n = π π f ^ ( y ) e i n y d y ( n 0 ) ,
where the 2 π -periodic function f ^ ( y ) is defined by
f ^ ( y ) = 1 2 π i ε ( y ) e i y 2 cos y 1 f ( x ) [ 2 ( x cos y ) ] 1 2 d x ( y R ) ,
ε ( y ) being the sign function.
Proof. 
We consider the Dirichlet-Murphy integral representation of the Legendre polynomials [20](Ch. III, §5.4):
P n ( cos u ) = i π u ( 2 π u ) e i ( n + 1 2 ) y 2 ( cos u cos y ) 1 2 d y .
Plugging (7) into equality (3) (after the change of variable x cos u ), we have:
2 π i a n = 0 π d u f ( cos u ) sin u u ( 2 π u ) e i ( n + 1 2 ) y 2 ( cos u cos y ) 1 2 d y .
Interchanging the order of integration in (8) we obtain:
2 π i a n = 0 π d y e i ( n + 1 2 ) y 0 y f ( cos u ) sin u 2 ( cos u cos y ) 1 2 d u + π 2 π d y e i ( n + 1 2 ) y 0 ( 2 π y ) f ( cos u ) sin u 2 ( cos u cos y ) 1 2 d u .
Next, if we make the change of variables: y y 2 π and u u , the second integral on the r.h.s. of (9) becomes:
e i π π 0 d y e i ( n + 1 2 ) y 0 y f ( cos u ) sin u 2 ( cos u cos y ) 1 2 d u .
Then, (9) becomes
2 π i a n = 0 π d y e i ( n + 1 2 ) y 0 y f ( cos u ) sin u 2 ( cos u cos y ) 1 2 d u + e i π π 0 d y e i ( n + 1 2 ) y 0 y f ( cos u ) sin u 2 ( cos u cos y ) 1 2 d u ,
which, after the change of variable cos u x into the integrals on the r.h.s., yields:
a n = π π f ^ ( y ) e i n y d y ( n 0 ) ,
with f ^ ( y ) given by (6). □
It is easy to check from (6) that f ^ ( y ) satisfies the following symmetry relation:
f ^ ( y ) = e i y f ^ ( y ) ,
which, in view of (5), induces the following symmetry on the coefficients a n :
a n = a n 1 ( n Z ) .

2.1. Numerical issues

Let us now consider the actual problem of computing the first N Legendre coefficients { c n } n = 0 N 1 (or, equivalently, Nnormalized coefficients { a n } n = 0 N 1 ) associated with the function f ( x ) (see (1) and (3)).
The numerical implementation of the algorithm suggested by Theorem 1 requires the computation of the Fourier coefficients (5) of the Abel-type integral function f ^ ( y ) defined in (6). For what concerns the computation of f ^ ( y ) , the integrand presents a weak algebraic singularity at the end point of the domain of integration, which can be effectively handled by means of a proper nonlinear change of variable. This technique, along with the use of a standard quadrature formula (e.g., the Gauss-Legendre one), allows obtaining high accuracy with a small number of nodes [21]. Quadrature formulae suited to end-point singular integrands can also be used [22,23].
It is ought to stress that the function f ^ ( y ) does not depend on the order n of the Legendre polynomial. Therefore, the computational cost for evaluating f ^ ( y ) is independent of the number N of Legendre coefficients to be computed. This means that the number of knots which are necessary to compute the integral in f ^ ( y ) (with a prescribed fixed accuracy ϵ ) does not depend on N, but depends only upon the oscillatory characteristics of the function f ( x ) (i.e., the number of samples needed to determine f ( x ) uniquely) and on the accuracy ϵ . The oscillatory contributions due to the Legendre polynomials or, in other words, the dependence on the order n of the Legendre polynomial, are accounted for only in the Fourier formula (5) and are neatly separated from the oscillatory contributions ascribable to the input function f ( x ) . The consequence of this decoupling is the low computational complexity of the whole algorithm. In fact, formula (5) makes it possible to take full advantage of the computational efficiency of the Fast Fourier Transform both in terms of speed of computation and of accuracy [24,25]. The first N Fourier coefficients a n of f ^ ( y ) (which coincide with the normalized Legendre coefficients of f ( x ) ) can thus be computed by a single FFT from the values (samples) of f ^ ( y ) at N distinct points in O ( N log N )  time. As we have seen above, the number of operations for the calculation of each sample of f ^ ( y ) is independent of N and, consequently, the (asymptotic) computational complexity of the entire algorithm for the computation of the Legendre coefficients coincides with that of the FFT, i.e., O ( N log N ) . Moreover, in view of the symmetry relation (13), the number of calls to the procedure for the computation of the Abel integral is halved. Of course, if O ( N ) samples are needed to determine uniquely the function f ( x ) and we want the error ϵ to be as small as possible, then all the O ( N ) samples of f ( x ) must be used for the numerical computation of the Abel integral and, consequently, the total number of operations in the algorithm will be O ( N 2 ) . Therefore, following logical lines similar to those adopted by Alpert and Rokhlin in Ref. [1] (and, more generally, in methods like, e.g., the Fast Multipole Methods [26]), the reduction of complexity from O ( N 2 ) to O ( N log N ) is obtained by accepting a lower precision in the computation (in our case, a lower precision in the computation of the Abel integral).
We want to remark two additional features of the algorithm just presented. First, the algorithm does not require the knowledge of the input function f ( x ) at a specific and prescribed set of knots (see, for instance, Ref. [10] where the input function is supposed to be known at Chebyshev knots). The function f ( x ) enters the algorithm only through its Abel-type integral. This allows a significant flexibility in choosing the quadrature scheme which is more suitable for the distribution of knots at which the input function is known (e.g., uniform grid, Chebyshev grid, set of measurements of f ( x ) non-uniformly distributed).
The final remark concerns the robustness of the algorithm against the noise. In the case the values of f ( x ) are only approximately known, e.g., when the input samples of f ( x ) represent measurements affected by error, the effects of the noise in the calculation of the coefficients c n are damped by the algorithm. In fact, the noisy input samples of f ( x ) are smoothed by the Abel integral operator [27] before being analyzed (encoded as samples of f ^ ( y ) ) by the oscillatory Fourier integral (5).
The procedure described above has been implemented in double precision arithmetics using the standard open source GNU Scientific Library (GSL) [28]. Feasibility and accuracy of the algorithm have been verified by direct comparison of the obtained numerical results with the true Legendre coefficients for a variety of functions. Hereafter we report some of them.
Table 1 displays the absolute error E n | c n True c n Computed | in the computation of Legendre coefficients for four functions with different degree of regularity: the discontinuous function f 1 ( x ) = γ ε ( x x 0 ) (with ε ( · ) being the sign function and γ a constant), whose Legendre coefficients are c 0 ( 1 ) = γ x 0 , c n ( 1 ) = γ P n 1 ( x 0 ) P n + 1 ( x 0 ) for n 1 ; the C 0 [ 1 , 1 ] function: f 2 ( x ) = | x | 3 / 2 , whose Legendre coefficients are [3](p. 78):
c n ( 2 ) = ( α + 1 ) 1 if n = 0 ( α = 3 2 ) , ( ( 2 n + 1 ) α ( α 2 ) ( α n + 2 ) ( ( α + 1 ) ( α + 3 ) ( α + n + 1 ) if n is even , 0 if n is odd ;
the function f 3 ( x ) = ( 1 2 x t + t 2 ) 1 / 2 with c n ( 3 ) = t n (with a singlarity for x outside the interval [ 1 : 1 ] , see (2)); the C -analytic function: f 4 ( x ) = e β x J 0 ( β 1 x 2 ) with c n ( 4 ) = β n / n ! ( J 0 denoting the Bessel function of the first kind and zeroth order).
The first observation from Table 1 is that the accuracy depends on the degree of smoothness of the function because of the computation of the Abel transform of f ( x ) that, in order to obtain a given target precision, requires more quadrature knots for low regular functions. For what concerns the smooth (within the interval [ 1 , 1 ] ) functions f 3 and f 4 , which give similar results, the accuracy increases significantly to reach values comparable with the ϵ -machine.
The algorithm sources of error are: the approximation of integral (5) by the Discrete Fourier Transform; the approximation of the Abel transform (6) by quadratures and, finally, the finite accuracy of the floating-point arithmetic. The first source of error is ruled by N. This is clearly visible from Figure 1(A), where the maximum error E m a x ( N ) max n [ 0 , N 1 ] E n is plotted versus N. For the C 0 -function f 2 ( x ) (asterisks), we see that for low values of N the maximum error is mainly ascribable to the error due to the approximation of the Fourier integral with the DFT and to the approximation of the Abel integral: it decreases like N 2 up to N 10 3 , and then starts increasing like O ( N ) , as in the case of smooth functions. From the comparison with the plot of maximum error for smooth functions (triangles), we can also say that the number of points N used in the DFT need not to be unnecessary large unless the function f ( x ) itself has low regularity.
The computation of N Legendre coefficients c n by ordinary quadrature produces an O ( N 2 ) algorithm. The increment of performances of the algorithm presented here has been verified by evaluating the speed of computation at (nearly) same precision. The results of these tests are illustrated in Figure 1(B), where the execution time T (in seconds) is plotted versus the number N of computed Legendre coefficients. The results show an O ( N ) execution time (at least in the N-interval we considered, up to N 5 · 10 5 ) independently of the regularity properties of the input function f ( x ) , confirming the expected great increase of computational speed (asymptotically, the awaited improvement ratio being proportional to N / log N ). Such an increase of performances will become even more crucial for the efficient evaluation of multivariate Legendre transform [5] and of spherical harmonic expansions [30], which will be the subject of a forthcoming paper.

3. Computation of Legendre expansions

Let us now move on to consider the problem of evaluating the function f ( x ) from the set of Legendre coefficients c n . In general, in the complex plane the domain of convergence of the Legendre expansion (1) is the maximal ellipse with foci at ± 1 within which the function f is analytic [31]. This rather restricted class of functions can be greatly enlarged when we limit ourselves to consider convergence issues on the segment x [ 1 , 1 ] . In Ref. [32] W. H. Young showed the tight connection between Legendre series and Fourier series when x ( 1 , 1 ) . In particular, he proved that in any internal closed interval of ( 1 , 1 ) the series of Legendre (1) behaves in respect to convergence, divergence, or oscillation, uniform or otherwise, precisely like the Fourier series of f ( cos u ) where x = cos u , provided the terms c n of series (1) are such that
n 1 2 c n 0 for n ,
the latter being the natural necessary condition for the convergence of the series (1). More explicitly, e.g., E. W. Hobson [33] provided a test of convergence stating that if the condition
1 1 ( 1 x 2 ) 1 4 | f ( x ) | d x <
is satisfied (the latter condition being equivalent to require that f ( cos u ) sin u be integrable on u [ 0 , π ] ), then the series (1) is convergent for any x ( 1 , 1 ) near which f is of bounded variation. Since the points x = ± 1 are singular points of Legendre’s equation, the convergence at the end points of the interval requires somehow more stringent (than in the Fourier case) conditions such as, e.g., f ( x ) being of bounded variation over the entire interval [ 1 , 1 ] .
This parallelism between Legendre and Fourier expansions have been already exploited in the previous section where we proved that the (normalized) Legendre coefficients of f ( x ) coincide with the Fourier coefficients of the function f ^ ( y ) . In the next two subsections we continue our analysis along this line, and present two algorithms for the computation of values of Legendre expansions.

3.1. An algorithm for the evaluation of Legendre series

In the theorem that follows we will prove that a Legendre expansion can be computed by calculating the (inverse) cosine transform of a sequence which is obtained by a suitable linear transformation of the set of Legendre coefficients c n .
Theorem 2. 
Let f ( x ) be the function given in (1). Assume that f ( x ) is such that the Legendre expansion (1) and the Fourier expansion of f ( cos u ) converge uniformly on x [ 1 , 1 ] and u [ 0 , π ] , respectively. Then f ( cos u ) , u [ 0 , π ] , can be written as follows:
f ( cos u ) = φ 0 2 + m = 1 + φ m cos m u ,
the coefficients φ m ( m = 0 , 1 , 2 , ) being given by:
φ m = n = 0 + k m , n c n ( m = 0 , 1 , 2 , ) ,
c n denoting the Legendre coefficients associated with f ( x ) (see (3)) and
k m , n = 2 π 0 π P n ( cos u ) cos ( m u ) d u ( m , n = 0 , 1 , 2 , ) .
Proof. 
Since f ( x ) is compactly supported on x [ 1 , 1 ] , the function f ( cos u ) ( u [ 0 , π ] ) is a 2 π -periodic function of u. Then, the latter can be represented as the Fourier series,
f ( cos u ) = 1 2 π n = + f n e i n u ( u [ 0 , π ] ) .
In view of the uniform convergence of the two series, from (1) and (21) we have:
1 2 π n = + f n e i n u = n = 0 + c n P n ( cos u ) ,
so that, multiplying both sides of (22) by e i m u and integrating on u [ π , π ] , we have:
n = + f n 1 2 π π π e i ( m n ) u d u = n = 0 + c n π π P n ( cos u ) e i m u d u .
The term in the parenthesis on the l.h.s. of (23) is the integral representation of the Kronecker delta δ m , n . Then, from (23) we have:
φ m f m π = n = 0 + 2 π 0 π P n ( cos u ) cos ( m u ) d u · c n = n = 0 + k m , n c n ,
with k m , n defined in (20). Finally, expansion (18) follows readily by observing that φ m = φ m . □
It is worth remarking that the transformation K { k m , n } m , n = 0 , which connects the Legendre coefficients of f ( x ) with the Fourier coefficients of f ( cos u ) , is independent of f ( x ) , can be computed with arbitrary precision, and can be regarded as known. In the next proposition we list some known facts on the structure of the matrix K, we give the analytic expression of its entries as smooth function of the indexes (see Ref. [10]), and provide an iterative procedure for computing its elements.
Proposition 1.(i) The coefficients k m , n (defined in (20)) can be written as follows:
k m , n = 2 π 1 1 P n ( x ) T n ( x ) d x 1 x 2 ,
T n ( · ) denoting the Chebyshev polynomials of the first kind.
(ii) The matrix K is upper triangular, and its entries k m , n can be computed as follows:
k m , n = 1 π Λ n 2 2 for m = 0 and n m with n even , 2 π Λ n m 2 Λ n + m 2 if 0 < m n and ( n + m ) is even , 0 otherwise ,
where
Λ ( z ) Γ ( z + 1 2 ) Γ ( z + 1 ) ,
Γ ( · ) denoting the Euler gamma function.
(iii) The following recurrence relation holds for n = 1 , 2 , and 0 m < n :
k m , n = ( n 1 ) ( n m 1 ) n ( m + n ) k m , n 2 + m ( 2 n 1 ) n ( m + n ) k m 1 , n 1 .
(iv) The diagonal elements can be written as follows:
k m , m = 2 j = 1 m 1 1 2 j ( m = 1 , 2 , ) .
(v) The elements k 0 , 2 n of the first row can be written as follows:
k 0 , 2 n = 2 j = 1 n 1 1 2 j 2 ( n = 1 , 2 , ) .
Proof. 
Formula (25) follows from definition (20) by making the substitution cos u x into the integral and recalling the definition of the Chebyshev polynomials of the first kind: T m ( x ) cos ( m arccos x ) , ( m 0 ). Representation (ii) of the coefficients k m , n is well-known, and it is given, e.g., by Alpert and Rokhlin in [10](formula (20)) (where the matrix K is there named M). The recurrence relation (28) follows from representation (26) and from the following three-term recurrence relations holding, respectively, for the Legendre polynomials P n ( x ) and for Chebyshev polynomials T n ( x ) :
n P n ( x ) = ( 2 n 1 ) x P n 1 ( x ) ( n 1 ) P n 2 ( x ) ( n = 2 , 3 , ) ,
P 0 ( x ) = 1 and P 1 ( x ) = x ,
and
1 1 T n ( x ) = 2 x T n 1 ( x ) T n 2 ( x ) ( n = 2 , 3 , ) ,
T 0 ( x ) = 1 and T 1 ( x ) = x .
Finally, point (iv) is obtained by putting n = m into (29), and, similarly, point (v) follows by putting m = 0 into the relation (29). □
The algorithmic prescription provided by Theorem 2 for the computation of the values of a Legendre expansion is indeed very simple. It consists of a two-step procedure:
  • From the N-vector c = ( c 0 , c 1 , , c N 1 ) T of Legendre coefficients compute the N-vector φ = ( φ 0 , φ 1 , , φ N 1 ) T by φ = K N c , where the (known) upper triangular matrix K N = { k m , n } m , n = 0 N 1 is defined in (20) (see also Proposition 1);
  • Compute the cosine transform of length N of the vector φ to obtain values of f ( cos u ) at N selected points of the interval u [ 0 , π ] .
The second step of the algorithm presents no difficulties. It is fast since it can be implemented by a single FFT of length N, which requires O ( N log N ) operations. The standard FFT procedure provides the output on a uniform grid { u n } n = 0 N 1 of [ 0 , π ] , so that, according to formula (18), the final result consists of the set of function values { f ( cos u n ) } n = 0 N 1 at Chebyshev points.
The first step of the algorithm presents instead some aspects which deserve a few comments. The crux is that the matrix K N is dense and the direct calculation of the matrix-vector product K N c requires O ( N 2 ) operations (precisely, N ( N + 2 ) 4 multiplications). Therefore, this step can become a bottleneck for the algorithm when N becomes large. In some practical cases the question is not critical, e.g., when the triangular structure of K N can be exploited on some computer architectures (e.g., vector machines, parallel GPU) to drop significantly the complexity of the computation. Nevertheless, the reduction of the algorithmic complexity remains an issue. Approximate methods are the only tools to handle effectively the fast computation of the matrix-vector product when the matrix is not structured (i.e., when its entries depend only on O ( N ) parameters). The key to many of these fast methods is renouncing to exactness and accepting the result of the computation within an a-priori fixed level of accuracy. This allows for using approximations of the kernel K which, combined with a suitable subdivision of the matrix into panels, can reduce enormously the cost of computing. Among these algorithms it is worth citing the celebrated Fast Multipole Methods by L. Greengard and V. Rokhlin for the fast evaluation of N-body interactions [12,26,34], which are able to reduce the number of operations to O ( N log N ) (or even O ( N ) , depending on the matrix structure).
The specific problem we are dealing with here, that is, the fast computation of the matrix-vector product K N c (with { k m , n } m , n = 0 N 1 given by formula (25)) has been solved brilliantly by B. Alpert and V. Rokhlin in Ref. [10]. In that paper the matrix K N is first properly divided in square submatrices, and then the computation associated with each submatrix is performed efficiently approximating each entry of the submatrix by its finite Chebyshev expansion. The computational cost brought by a ν × ν submatrix is then reduced from order O ( ν 2 ) of the naive computation to O ( ν log 1 ϵ ) , ϵ being the fixed precision required in the Chebyshev interpolation of the submatrix entries. This basic building block allows thus constructing an algorithm for the fast computation of the matrix-vector product K N c with O ( N log N ) order of complexity.

3.2. A novel algorithm

In this subsection we present a novel algorithm for the inversion of the Legendre transform, which somewhat represents the natural dual algorithm of the one presented in Section 2 for the computation of the forward Legendre transform. In the next theorem we will show that a Legendre expansion can be represented as the Abel-type transform of a suitable Fourier series, the coefficients of the latter being the Legendre coefficients of f ( x ) (cf. Theorem 1).
Theorem 3. 
Let f ( x ) be the function given in (1). Assume that f ( x ) is such that the Legendre expansion (1) converges uniformly on x [ 1 , 1 ] . Then f ( cos u ) , u [ 0 , π ] , can be written as follows:
f ( cos u ) = u π χ ( t ) [ 2 ( cos u cos t ) ] 1 2 d t ( u [ 0 , π ] ) ,
where the function χ ( t ) is defined by
χ ( t ) 2 π n = 0 c n sin ( n + 1 2 ) t ( t [ 0 , π ] ) ,
c n denoting the Legendre coefficients associated with f ( x ) (see (3)).
Proof. 
First we show that the following integral representation holds for the Legendre polynomials P n ( cos u ) :
P n ( cos u ) = 2 π u π sin ( n + 1 2 ) t [ 2 ( cos u cos t ) ] 1 2 d t ( u [ 0 , π ] ) .
Formula (37) can be easily obtained from the Dirichlet-Murphy representation (7) by first splitting the interval of integration into two subintervals: [ u , 2 π u ] = [ u , π ] [ π , 2 π u ] , and then changing the integration variable t 2 π t in the second integral, i.e., we have:
P n ( cos u ) = i π u π + π 2 π u e i ( n + 1 2 ) t 2 ( cos u cos t ) 1 2 d t = i π u π e i ( n + 1 2 ) t 2 ( cos u cos t ) 1 2 d t u π e i ( n + 1 2 ) t 2 ( cos u cos t ) 1 2 d t = 2 π u π sin ( n + 1 2 ) t [ 2 ( cos u cos t ) ] 1 2 d t .
Now, we can plug formula (37) into Legendre expansion (1) and then, interchanging sum and integral (which is legitimate in view of the assumption of uniform convergence for expansion (1)), we get:
f ( cos u ) = 2 π n = 0 c n u π sin ( n + 1 2 ) t [ 2 ( cos u cos t ) ] 1 2 d t = u π 2 π n = 0 c n sin ( n + 1 2 ) t [ 2 ( cos u cos t ) ] 1 2 d t ,
which is indeed formula (35) with χ ( t ) defined by (36). □
Theorem 3 suggests the following algorithm for the computation of the values of a Legendre expansion:
  • From the input N-vector c = ( c 0 , c 1 , , c N 1 ) T of Legendre coefficients compute the N-term approximation χ N ( t ) of the function χ ( t ) (see (36)):
    χ N ( t ) 2 π n = 0 N 1 c n sin ( n + 1 2 ) t .
  • Compute the values of the N-term Legendre expansion
    f N ( cos u ) = n = 0 N 1 c n P n ( cos u ) ( u [ 0 , π ] ) ,
    at points u n ( n = 0 , 1 , ) by the Abel-type integral (see (35)):
    f N ( cos u n ) = u n π χ N ( t ) [ 2 ( cos u n cos t ) ] 1 2 d t ( u n [ 0 , π ] ) .
The first step is fast: the set of values { χ N ( t n ) } n = 0 N 1 of the function χ N ( t ) at N equidistant nodes of the interval [ 0 , π ] can be calculated in O ( N log N )  time by a single FFT.
For what concerns the second step, it should first be noted that the distribution of the nodes u n is not constrained and, therefore, we are free to calculate f N ( cos u ) at any set of points of the interval u [ 0 , π ] by means of formula (42).
The numerical computation of the Abel-type integral in (42), which presents a weak singularity at the left end-point (see also Section 2), is constrained by the fact that the integrand is known only on a uniform grid of the interval t [ 0 , π ] (see Step (1) of the algorithm) and, consequently, only quadrature formulae based on equally spaced knots can be used.
In general, the computation of f N ( cos u n ) at N points { u n } n = 0 N 1 requires O ( N 2 ) operations since the second step of the algorithm requires O ( N ) operations when all the N known values of the function χ N are used for the computation of the integral in (42). However, it is ought to note that for this computation it is not always necessary to implement a full N-knot quadrature procedure, in particular when N is large. The integral in (42) can usually be computed with an a-priori fixed precision by using much less (than N) quadrature knots, the number of knots depending on the implemented quadrature scheme and on the oscillatory characteristics of the integrand, which, ultimately, depend on the oscillatory characteristics of f ( x ) . An instance of a suitable quadrature scheme is given in Refs. [22,23], where quadratures rules are proposed, based on corrections to the trapezoidal rule, for integrands with end-point singularities of various types, including singularities of the form x γ , | γ | < 1 . The convergence rate of these quadrature formulae is proved to be at least κ (that is, the approximation error is of the order of N κ ) where κ denotes the order of the corrected quadrature rule [22,23]. Thus, in these cases and for N sufficiently large, the algorithm we propose for the evaluation of the Legendre expansion becomes convenient in terms of complexity since the number of operations of the second step is a constant independent of N and, for large values of N, the complexity of the entire algorithm will be dominated by the O ( N log N ) complexity of the FFT used in Step (1).

4. Conclusions

In summary, we have presented a new and fast, i.e., O ( N log N ) , algorithm for the computation of the coefficients of Legendre expansions. The algorithm is very simple to implement and computes the Legendre coefficients with just a single FFT of an Abel-type transform of the input function. This algorithm calls up a number of natural generalizations to other polynomials systems, for instance, associated Legendre polynomials and the related spherical harmonic expansions.
The dual problem of evaluating a Legendre expansion has been also considered, and two algorithms have been proposed. In the first algorithm the values of the expansion at appropriately chosen points of the interval x [ 1 , 1 ] are computed by simply performing a single (inverse) FFT of a sequence of coefficients, which are obtained by a suitable linear transformation of the given set of N Legendre coefficients. The rapid evaluation of the expansion values requires using approximate methods for the fast calculation of the matrix-vector product. The second algorithm for the calculation of values of Legendre expansions is novel and somehow inverts the logical steps of the algorithm we have proposed for the computation of the Legendre coefficients: the N-term Legendre expansion can be evaluated efficiently (for N sufficiently large) at any point of the interval x [ 1 , 1 ] by computing the Abel-type transform of a suitable Fourier series.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Not applicable.

Acknowledgments

The author heartily acknowledges many illuminating discussions had with the friend and collegue Giovanni Alberto Viano.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Cheney, C.W. Introduction to Approximation Theory; McGraw-Hill: New York, NY, USA, 1966. [Google Scholar]
  2. Rainville, E.D. Special Functions; MacMillan: New York, NY, USA, 1960. [Google Scholar]
  3. Canuto, C.; Hussaini, M.Y.; Quarteroni, A.; Zang, T.A. Spectral Methods: fundamentals in single domains; Springer-Verlag: Berlin, Germany, 2006. [Google Scholar]
  4. Davis, P.; Rabinowitz, P. Methods of Numerical Integration; Academic Press: New York, NY, USA, 1975. [Google Scholar]
  5. Brunner, H.; Iserles, A.; Nørsett, S. The computation of the spectra of highly oscillatory Fredholm integral operators. J. Integral Equations Appl. 2011, 23, 467–519. [Google Scholar] [CrossRef]
  6. Gallagher, N.; Wise, G.; Allen, J. A novel approach for the computation of Legendre polynomial expansions. IEEE Trans. Acoustic Speech Signal Process. 1978, 26, 105–106. [Google Scholar] [CrossRef]
  7. Piessens, R. Algorithm 473, Computation of Legendre series coefficients. Comm. ACM 1974, 17, 25–26. [Google Scholar] [CrossRef]
  8. Delic, G. The Legendre series and a quadrature formula for its coefficients. J. Comp. Phys. 1974, 14, 254–268. [Google Scholar] [CrossRef]
  9. Orszag, S.A. Fast eigenfunction transforms. In Science and Computers; Academic Press: New York, USA, 1986; pp. 13–30. [Google Scholar]
  10. Alpert, B.K.; Rokhlin, V. A fast algorithm for the evaluation of Legendre expansions. SIAM J. Sci. Stat. Comput. 1991, 12, 158–179. [Google Scholar] [CrossRef]
  11. O’Neil, M.; Woolfe, F.; Rokhlin, V. An algorithm for the rapid evaluation of special function transforms. Appl. Comput. Harmon. Anal. 2010, 28, 203–226. [Google Scholar] [CrossRef]
  12. Yarvin, N.; Rokhlin, V. An improved fast multipole method for potential fields on the line. SIAM J. Numer. Anal. 1999, 36, 629–666. [Google Scholar] [CrossRef]
  13. Hale, N.; Townsend, A. A fast, simple, and stable Chebyshev-Legendre transform using an asymptotic formula. SIAM J. Sci. Comput. 2014, 36, A148–A167. [Google Scholar] [CrossRef]
  14. Mori, A.; Suda, R.; Sugihara, M. An improvement on Orszag’s fast algorithm for Legendre polynomial transform. Trans. Info. Process. Soc. Japan 1999, 40, 3612–3615. [Google Scholar]
  15. Xiang, S. On fast algorithms for the evaluation of Legendre coefficients. Appl. Math. Lett. 2013, 26, 194–200. [Google Scholar] [CrossRef]
  16. Driscoll, J.R.; Healy, Jr., D. M. Computing Fourier transforms and convolutions on the 2-sphere. Adv. Appl. Math. 1994, 15, 202–250. [Google Scholar] [CrossRef]
  17. Potts, D.; Steidl, G.; Tasche, M. Fast algorithms for discrete polynomial transforms. Math. Comp. 1998, 67, 1577–1590. [Google Scholar] [CrossRef]
  18. Iserles, A. A fast and simple algorithm for the computation of Legendre coefficients. Numer. Math. 2011, 117, 529–553. [Google Scholar] [CrossRef]
  19. Erdélyi, A.; Magnus, W.; Oberhettinger, F.; Tricomi, F.G. Functions. In Bateman Manuscript Project; McGraw-Hill: New York, NY, USA, 1953; Volume 2. [Google Scholar]
  20. Vilenkin, N.I. Special Functions and the Theory of Group Representations. In Transl. Math. Monogr. 22; Amer. Math. Soc.: Providence, RI, USA, 1968; Volume 22. [Google Scholar]
  21. Monegato, G.; Scuderi, L. Numerical integration of functions with boundary singularities. J. Comp. Appl. Math. 1999, 112, 201–214. [Google Scholar] [CrossRef]
  22. Alpert, B.K. High-order quadratures for integral operators with singular kernels. J. Comp. Appl. Math. 1995, 60, 367–378. [Google Scholar] [CrossRef]
  23. Rokhlin, V. End-point corrected trapezoidal quadrature rules for singular functions. Comput. Math. Appl. 1990, 20, 51–62. [Google Scholar] [CrossRef]
  24. Calvetti, D. A stochastic roundoff error analysis for the fast Fourier transform. Math. Comp. 1991, 56, 755–774. [Google Scholar] [CrossRef]
  25. Kaneko, T.; Liu, B. Accumulation of round-off error in Fast Fourier Transforms. J. Assoc. Comp. Mach. 1970, 17, 637–654. [Google Scholar] [CrossRef]
  26. Greengard, L. The rapid evaluation of potential fields in particle systems; MIT Press: Cambridge, MA, USA, 1988. [Google Scholar]
  27. Gorenflo, R.; Vessella, S. Abel Integral Equations. In Lecture Notes in Math.; Springer: Berlin, Germany, 1991; Volume 1461. [Google Scholar]
  28. Galassi, M. et al, GNU Scientific Library Reference Manual, 3rd ed., ISBN 0954612078. Available online: http://www.gnu.org/software/gsl/.
  29. Mathematica, Version 12.0, Wolfram Research, Inc., Champaign, IL, 2008.
  30. Mohlenkamp, M.J. A fast transform for spherical harmonics. J. Fourier Anal. Appl. 1999, 5, 159–184. [Google Scholar] [CrossRef]
  31. Hille, E. On the absolute convergence of polynomial series. Amer. Math. Monthly 1938, 45, 220–226. [Google Scholar] [CrossRef]
  32. Young, W.H. On the connexion between Legendre series and Fourier series. Proc. London Math. Soc. s2 1920, 18, 141–162. [Google Scholar] [CrossRef]
  33. Hobson, E.W. The Theory of Spherical and Ellipsoidal Harmonics; Cambridge Univ. Press: Cambridge, UK, 1931. [Google Scholar]
  34. Greengard, L.; Rokhlin, V. A fast algorithm for particle simulations. J. Comp. Phys. 1987, 73, 325–348. [Google Scholar] [CrossRef]
Figure 1. (A) Maximum error E max ( N ) = max n [ 0 , N 1 ] E n versus the number N of computed Lagendre coefficients. The filled dots ( ) refer to the function f 1 ( x ) , the asterisks ( * ) to f 2 ( x ) , and the filled triangles ( ) to f 3 ( x ) (see text). (B) Execution time T versus N. The O ( N 2 ) line is plotted just for reference.
Figure 1. (A) Maximum error E max ( N ) = max n [ 0 , N 1 ] E n versus the number N of computed Lagendre coefficients. The filled dots ( ) refer to the function f 1 ( x ) , the asterisks ( * ) to f 2 ( x ) , and the filled triangles ( ) to f 3 ( x ) (see text). (B) Execution time T versus N. The O ( N 2 ) line is plotted just for reference.
Preprints 74162 g001
Table 1. Absolute error E n of the computed Legendre coefficients c n for four different functions with different degree of smoothness (see text). The reference “exact” values of c n have been computed with 30 significant figures by standard quadrature with Mathematica [29].
Table 1. Absolute error E n of the computed Legendre coefficients c n for four different functions with different degree of smoothness (see text). The reference “exact” values of c n have been computed with 30 significant figures by standard quadrature with Mathematica [29].
n E n [ f 1 ] E n [ f 2 ] E n [ f 3 ] E n [ f 4 ]
0 8.15 6 7.51 11 1.11 16 3.33 16
1 2.98 6 1.44 10 3.33 15 5.55 17
2 3.12 5 1.86 12 3.88 15 1.97 15
3 5.43 5 9.20 11 3.39 15 2.87 15
4 3.41 5 1.07 10 4.72 15 3.36 15
5 2.53 5 1.30 10 5.47 15 1.58 15
6 9.28 5 1.14 10 4.50 15 1.96 15
7 1.09 4 9.75 11 4.22 15 2.54 15
8 1.99 5 4.29 10 3.18 15 2.63 15
9 1.27 4 6.10 10 3.94 15 2.90 15
10 1.87 4 5.74 10 1.65 15 2.93 15
11 7.50 5 4.45 10 1.54 15 9.71 16
12 1.16 4 1.79 10 1.94 15 2.04 15
13 2.20 4 3.32 10 3.60 15 1.67 15
14 1.56 4 8.43 10 7.36 16 2.37 15
15 2.75 5 9.81 10 4.18 15 2.06 15
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.
Prerpints.org logo

Preprints.org is a free preprint server supported by MDPI in Basel, Switzerland.

Subscribe

Disclaimer

Terms of Use

Privacy Policy

Privacy Settings

© 2025 MDPI (Basel, Switzerland) unless otherwise stated