NAG Library Chapter Introduction
C06 – Summation of Series
1 Scope of the Chapter
This chapter is concerned with the following tasks.
(a) 
Calculating the discrete Fourier transform of a sequence of real or complex data values. 
(b) 
Calculating the discrete convolution or the discrete correlation of two sequences of real or complex data values using discrete Fourier transforms. 
(c) 
Calculating the inverse Laplace transform of a usersupplied function. 
(d) 
Direct summation of orthogonal series. 
(e) 
Acceleration of convergence of a sequence of real values. 
2 Background to the Problems
2.1 Discrete Fourier Transforms
2.1.1 Complex transforms
Most of the routines in this chapter calculate the finite
discrete Fourier transform (DFT) of a sequence of
$n$ complex numbers
${z}_{\mathit{j}}$, for
$\mathit{j}=0,1,\dots ,n1$. The direct transform is defined by
for
$k=0,1,\dots ,n1$. Note that equation
(1) makes sense for all integral
$k$ and with this extension
${\hat{z}}_{k}$ is periodic with period
$n$, i.e.,
${\hat{z}}_{k}={\hat{z}}_{k\pm n}$, and in particular
${\hat{z}}_{k}={\hat{z}}_{nk}$. Note also that the scalefactor of
$\frac{1}{\sqrt{n}}$ may be omitted in the definition of the DFT, and replaced by
$\frac{1}{n}$ in the definition of the inverse.
If we write
${z}_{j}={x}_{j}+i{y}_{j}$ and
${\hat{z}}_{k}={a}_{k}+i{b}_{k}$, then the definition of
${\hat{z}}_{k}$ may be written in terms of sines and cosines as
The original data values
${z}_{j}$ may conversely be recovered from the transform
${\hat{z}}_{k}$ by an
inverse discrete Fourier transform:
for
$j=0,1,\dots ,n1$. If we take the complex conjugate of
(2), we find that the sequence
${\stackrel{}{z}}_{j}$ is the DFT of the sequence
${\stackrel{}{\hat{z}}}_{k}$. Hence the inverse DFT of the sequence
${\hat{z}}_{k}$ may be obtained by taking the complex conjugates of the
${\hat{z}}_{k}$; performing a DFT, and taking the complex conjugates of the result. (Note that the terms
forward transform and
backward transform are also used to mean the direct and inverse transforms respectively.)
The definition
(1) of a onedimensional transform can easily be extended to multidimensional transforms. For example, in two dimensions we have
Note: definitions of the discrete Fourier transform vary. Sometimes
(2) is used as the definition of the DFT, and
(1) as the definition of the inverse.
2.1.2 Real transforms
If the original sequence is purely real valued, i.e.,
${z}_{j}={x}_{j}$, then
and
${\hat{z}}_{nk}$ is the complex conjugate of
${\hat{z}}_{k}$. Thus the DFT of a real sequence is a particular type of complex sequence, called a
Hermitian sequence, or
halfcomplex or
conjugate symmetric, with the properties
and, if
$n$ is even,
${b}_{n/2}=0$.
Thus a Hermitian sequence of $n$ complex data values can be represented by only $n$, rather than $2n$, independent real values. This can obviously lead to economies in storage, with
two schemes
being used in this chapter. In
the first
scheme, which will be referred to as the real storage format for Hermitian sequences, the real parts ${a}_{k}$ for $0\le k\le n/2$ are stored in normal order in the first $n/2+1$ locations of an array X of length $n$; the corresponding nonzero imaginary parts are stored in reverse order in the remaining locations of X. To clarify, if
X is declared with bounds $\left(0:n1\right)$ in your calling subroutine, the following two tables illustrate the storage of the real and imaginary parts of ${\hat{z}}_{k}$ for the two cases: $n$ even and $n$ odd.
If $n$ is even then the sequence has two purely real elements and is stored as follows:
Index of X 
0 
1 
2 
$\dots $ 
$n/2$ 
$\dots $ 
$n2$ 
$n1$ 
Sequence 
${a}_{0}$ 
${a}_{1}+{ib}_{1}$ 
${a}_{2}+{ib}_{2}$ 
$\dots $ 
${a}_{n/2}$ 
$\dots $ 
${a}_{2}{ib}_{2}$ 
${a}_{1}{ib}_{1}$ 
Stored values 
${a}_{0}$ 
${a}_{1}$ 
${a}_{2}$ 
$\dots $ 
${a}_{n/2}$ 
$\dots $ 
${b}_{2}$ 
${b}_{1}$ 
If $n$ is odd then the sequence has one purely real element and, letting $n=2s+1$, is stored as follows:
Index of X 
0 
1 
2 
$\dots $ 
$s$ 
$s+1$ 
$\dots $ 
$n2$ 
$n1$ 
Sequence 
${a}_{0}$ 
${a}_{1}+{ib}_{1}$ 
${a}_{2}+{ib}_{2}$ 
$\dots $ 
${a}_{s}+i{b}_{s}$ 
${a}_{s}i{b}_{s}$ 
$\dots $ 
${a}_{2}{ib}_{2}$ 
${a}_{1}{ib}_{1}$ 
Stored values 
${a}_{0}$ 
${a}_{1}$ 
${a}_{2}$ 
$\dots $ 
${a}_{s}$ 
${b}_{s}$ 
$\dots $ 
${b}_{2}$ 
${b}_{1}$ 
The second storage scheme, referred to in this chapter as the complex storage format for Hermitian sequences, stores the real and imaginary parts ${a}_{k},{b}_{k}$, for $0\le k\le n/2$, in consecutive locations of an array X of length $n+2$. If X is declared with bounds $\left(0:n+1\right)$ in your calling subroutine, the following two tables illustrate the storage of the real and imaginary parts of ${\hat{z}}_{k}$ for the two cases: $n$ even and $n$ odd.
If $n$ is even then the sequence has two purely real elements and is stored as follows:
Index of X 
0 
1 
2 
3 
$\dots $ 
$n2$ 
$n1$ 
$n$ 
$n+1$ 
Stored values 
${a}_{0}$ 
${b}_{0}=0$ 
${a}_{1}$ 
${b}_{1}$ 
$\dots $ 
${a}_{n/21}$ 
${b}_{n/21}$ 
${a}_{n/2}$ 
${b}_{n/2}=0$ 
If $n$ is odd then the sequence has one purely real element and, letting $n=2s+1$, is stored as follows:
Index of X 
0 
1 
2 
3 
$\dots $ 
$n2$ 
$n1$ 
$n$ 
$n+1$ 
Stored values 
${a}_{0}$ 
${b}_{0}=0$ 
${a}_{1}$ 
${b}_{1}$ 
$\dots $ 
${b}_{s1}$ 
${a}_{s}$ 
${b}_{s}$ 
$0$ 
Also, given a Hermitian sequence, the inverse (or backward) discrete transform produces a real sequence. That is,
where
${a}_{n/2}=0$ if
$n$ is odd.
For real data that is twodimensional or higher, the symmetry in the transform persists for the leading dimension only. So, using the notation of equation
(3) for the complex twodimensional discrete transform, we have that
${\hat{z}}_{{k}_{1}{k}_{2}}$ is the complex conjugate of
${\hat{z}}_{\left({n}_{1}{k}_{1}\right){k}_{2}}$. It is more convenient for transformed data of two or more dimensions to be stored as a complex sequence of length
$\left({n}_{1}/2+1\right)\times {n}_{2}\times \dots \times {n}_{d}$ where
$d$ is the number of dimensions. The inverse discrete Fourier transform operating on such a complex sequence (Hermitian in the leading dimension) returns a real array of full dimension (
${n}_{1}\times {n}_{2}\times \dots \times {n}_{d}$).
2.1.3 Real symmetric transforms
In many applications the sequence
${x}_{j}$ will not only be real, but may also possess additional symmetries which we may exploit to reduce further the computing time and storage requirements. For example, if the sequence
${x}_{j}$ is
odd,
$\left({x}_{j}={x}_{nj}\right)$, then the discrete Fourier transform of
${x}_{j}$ contains only sine terms. Rather than compute the transform of an odd sequence, we define the
sine transform of a real sequence by
which could have been computed using the Fourier transform of a real odd sequence of length
$2n$. In this case the
${x}_{j}$ are arbitrary, and the symmetry only becomes apparent when the sequence is extended. Similarly we define the
cosine transform of a real sequence by
which could have been computed using the Fourier transform of a real
even sequence of length
$2n$.
In addition to these ‘halfwave’ symmetries described above, sequences arise in practice with ‘quarterwave’ symmetries. We define the
quarterwave sine transform by
which could have been computed using the Fourier transform of a real sequence of length
$4n$ of the form
Similarly we may define the
quarterwave cosine transform by
which could have been computed using the Fourier transform of a real sequence of length
$4n$ of the form
2.1.4 Fourier integral transforms
The usual application of the discrete Fourier transform is that of obtaining an approximation of the
Fourier integral transform
when
$f\left(t\right)$ is negligible outside some region
$\left(0,c\right)$. Dividing the region into
$n$ equal intervals we have
and so
for
$k=0,1,\dots ,n1$, where
${f}_{j}=f\left(jc/n\right)$ and
${F}_{k}=F\left(k/c\right)$.
Hence the discrete Fourier transform gives an approximation to the Fourier integral transform in the region $s=0$ to $s=n/c$.
If the function $f\left(t\right)$ is defined over some more general interval $\left(a,b\right)$, then the integral transform can still be approximated by the discrete transform provided a shift is applied to move the point $a$ to the origin.
2.1.5 Convolutions and correlations
One of the most important applications of the discrete Fourier transform is to the computation of the discrete
convolution or
correlation of two vectors
$x$ and
$y$ defined (as in
Brigham (1974)) by
 convolution: ${z}_{k}={\displaystyle \sum _{j=0}^{n1}}{x}_{j}{y}_{kj}$
 correlation: ${w}_{k}={\displaystyle \sum _{j=0}^{n1}}{\stackrel{}{x}}_{j}{y}_{k+j}$
(Here
$x$ and
$y$ are assumed to be periodic with period
$n$.)
Under certain circumstances (see
Brigham (1974)) these can be used as approximations to the convolution or correlation integrals defined by
and
For more general advice on the use of Fourier transforms, see
Hamming (1962); more detailed information on the fast Fourier transform algorithm can be found in
Gentleman and Sande (1966) and
Brigham (1974).
2.1.6 Applications to solving partial differential equations (PDEs)
A further application of the fast Fourier transform, and in particular of the Fourier transforms of symmetric sequences, is in the solution of elliptic PDEs. If an equation is discretized using finite differences, then it is possible to reduce the problem of solving the resulting large system of linear equations to that of solving a number of tridiagonal systems of linear equations. This is accomplished by uncoupling the equations using Fourier transforms, where the nature of the boundary conditions determines the choice of transforms – see
Section 3.3. Full details of the Fourier method for the solution of PDEs may be found in
Swarztrauber (1977) and
Swarztrauber (1984).
2.2 Inverse Laplace Transforms
Let
$f\left(t\right)$ be a real function of
$t$, with
$f\left(t\right)=0$ for
$t<0$, and be piecewise continuous and of exponential order
$\alpha $, i.e.,
for large
$t$, where
$\alpha $ is the minimal such exponent.
The Laplace transform of
$f\left(t\right)$ is given by
where
$F\left(s\right)$ is defined for
$\mathrm{Re}\left(s\right)>\alpha $.
The inverse transform is defined by the Bromwich integral
The integration is performed along the line
$s=a$ in the complex plane, where
$a>\alpha $. This is equivalent to saying that the line
$s=a$ lies to the right of all singularities of
$F\left(s\right)$. For this reason, the value of
$\alpha $ is crucial to the correct evaluation of the inverse. It is not essential to know
$\alpha $ exactly, but an upper bound must be known.
The problem of determining an inverse Laplace transform may be classified according to whether (a) $F\left(s\right)$ is known for real values only, or (b) $F\left(s\right)$ is known in functional form and can therefore be calculated for complex values of $s$. Problem (a) is very illdefined and no routines are provided. Two methods are provided for problem (b).
2.3 Direct Summation of Orthogonal Series
For any series of functions
${\varphi}_{i}$ which satisfy a recurrence
the sum
is given by
where
This may be used to compute the sum of the series. For further reading, see
Hamming (1962).
2.4 Acceleration of Convergence
This device has applications in a large number of fields, such as summation of series, calculation of integrals with oscillatory integrands (including, for example, Hankel transforms), and rootfinding. The mathematical description is as follows. Given a sequence of values
$\left\{{s}_{n}\right\}$, for
$\mathit{n}=m,\dots ,m+2l$, then, except in certain singular cases, parameters,
$a$,
${b}_{i}$,
${c}_{i}$ may be determined such that
If the sequence
$\left\{{s}_{n}\right\}$ converges, then
$a$ may be taken as an estimate of the limit. The method will also find a pseudolimit of certain divergent sequences – see
Shanks (1955) for details.
To use the method to sum a series, the terms
${s}_{n}$ of the sequence should be the partial sums of the series, e.g.,
${s}_{n}={\displaystyle \sum _{k=1}^{n}}{t}_{k}$, where
${t}_{k}$ is the
$k$th term of the series. The algorithm can also be used to some advantage to evaluate integrals with oscillatory integrands; one approach is to write the integral (in this case over a semiinfinite interval) as
and to consider the sequence of values
where the integrals are evaluated using standard quadrature methods. In choosing the values of the
${a}_{k}$, it is worth bearing in mind that
C06BAF converges much more rapidly for sequences whose values oscillate about a limit. The
${a}_{k}$ should thus be chosen to be (close to) the zeros of
$f\left(x\right)$, so that successive contributions to the integral are of opposite sign. As an example, consider the case where
$f\left(x\right)=M\left(x\right)\mathrm{sin}x$ and
$M\left(x\right)>0$: convergence will be much improved if
${a}_{k}=k\pi $ rather than
${a}_{k}=2k\pi $.
3 Recommendations on Choice and Use of Available Routines
3.1 Onedimensional Fourier Transforms
The choice of routine is determined first of all by whether the data values constitute a real, Hermitian or general complex sequence. It is wasteful of time and storage to use an inappropriate routine.
The choice is next determined by how you prefer to store complex data. Real storage format routines store general complex sequences and Hermitian sequences in real arrays. In the case of general complex sequences, the real and imaginary parts are stored separately in two real arrays. Since Hermitian sequences contain some symmetries, these can be stored in a compact form in a single real array. Alternatively, complex storage format routines store the corresponding sequence as a complex array for general sequences, and with real and imaginary parts in contiguous locations of a real array for Hermitian sequences.
Two groups, each of three routines, are provided in real storage format and three groups of two routines are provided in complex storage format.
Group 1 routines compute a single transform of length
$n$, requiring one additional workspace array.
Some of these
(
C06FAF,
C06FBF and
C06FCF)
impose some restrictions on the value of
$n$, namely that no prime factor of
$n$ may exceed
$19$ and the total number of prime factors (including repetitions) may not exceed
$20$ (though the latter restriction only becomes relevant when
$n>{10}^{6}$).
Group 2 and Group 3
routines are all designed to perform several transforms in a single call, all with the same value of $n$. They are likely to be much faster than the Group 1 routines on modern acrchitectures. They do however require more working storage.
It is therefore recommended that, for real storage format, Group 2 routines be used in preference to Group 1 routines, even when only one transform is to be performed.
Group 2 and Group 3 routines differ in the way sequences are stored: Group 2 routines store sequences as rows of a twodimensional array while Group 3 routines store sequences as columns of a twodimensional array.
Group 2 and Group 3
routines impose no practical restrictions on the value of $n$; however, the fast Fourier transform algorithm ceases to be ‘fast’ if applied to values of $n$ which cannot be expressed as a product of small prime factors. All the above routines are particularly efficient if the only prime factors of $n$ are $2$, $3$ or $5$.
If extensive use is to be made of these routines and you are concerned about efficiency, you are advised to conduct your own timing tests.
To compute inverse (backward) discrete Fourier transforms the
real storage format
routines should be used in conjunction with the complex conjugate of a Hermitian or general sequence of complex data values.
In the case of complex storage format routines, there is a direction parameter which determines the direction of the transform; a call to such a routine in the forward direction followed by a call in the backward direction reproduces the original data.
3.2 Half and Quarterwave Transforms
Four routines are provided for computing fast Fourier transforms (FFTs) of real symmetric sequences.
C06RAF
computes multiple Fourier sine transforms,
C06RBF
computes multiple Fourier cosine transforms,
C06RCF
computes multiple quarterwave Fourier sine transforms, and
C06RDF
computes multiple quarterwave Fourier cosine transforms.
3.3 Application to Elliptic Partial Differential Equations
As described in
Section 2.1, Fourier transforms may be used in the solution of elliptic PDEs.
C06RAF
may be used to solve equations where the solution is specified along the boundary.
C06RBF
may be used to solve equations where the derivative of the solution is specified along the boundary.
C06RCF
may be used to solve equations where the solution is specified on the lower boundary, and the derivative of the solution is specified on the upper boundary.
C06RDF
may be used to solve equations where the derivative of the solution is specified on the lower boundary, and the solution is specified on the upper boundary.
For equations with periodic boundary conditions the fullrange Fourier transforms computed by
C06FPF and
C06FQF are appropriate.
3.4 Multidimensional Fourier Transforms
3.4.1 Complex data
The following routines compute multidimensional discrete Fourier transforms of complex data:
The real storage format routines store sequences of complex data in two real arrays containing the real and imaginary parts of the sequence respectively. The complex storage format routines store the sequences in
complex
arrays.
C06PUF and
C06FXF/
C06PXF should be used in preference to
C06FJF/
C06PJF for two and threedimensional transforms, as they are easier to use and are likely to be more efficient.
3.4.2 Real data
The transform of multidimensional real data is stored as a complex sequence that is Hermitian in its leading dimension. The inverse transform takes such a complex sequence and computes the real transformed sequence. Consequently, separate routines are provided for performing forward and inverse transforms.
C06PVF performs the forward twodimensionsal transform while
C06PWF performs the inverse of this transform.
C06PYF performs the forward threedimensional transform while
C06PZF performs the inverse of this transform.
The complex sequences computed by
C06PVF and
C06PYF contain roughly half of the Fourier coefficients; the remainder can be reconstructed by conjugation of those computed. For example, the Fourier coefficients of the twodimensional transform
${\hat{z}}_{\left({n}_{1}{k}_{1}\right){k}_{2}}$ are the complex conjugate of
${\hat{z}}_{{k}_{1}{k}_{2}}$ for
${k}_{1}=0,1,\dots ,{n}_{1}/2$, and
${k}_{2}=0,1,\dots ,{n}_{2}1$.
3.5 Convolution and Correlation
C06FKF
computes either the discrete convolution or the discrete correlation of two real vectors.
C06PKF computes either the discrete convolution or the discrete correlation of two complex vectors.
3.6 Inverse Laplace Transforms
Two methods are provided: Weeks' method (
C06LBF) and Crump's method (
C06LAF). Both require the function
$F\left(s\right)$ to be evaluated for complex values of
$s$. If in doubt which method to use, try Weeks' method (
C06LBF) first; when it is suitable, it is usually much faster.
Typically the inversion of a Laplace transform becomes harder as
$t$ increases so that all numerical methods tend to have a limit on the range of
$t$ for which the inverse
$f\left(t\right)$ can be computed.
C06LAF is useful for small and moderate values of
$t$.
It is often convenient or necessary to scale a problem so that
$\alpha $ is close to
$0$. For this purpose it is useful to remember that the inverse of
$F\left(s+k\right)$ is
$\mathrm{exp}\left(kt\right)f\left(t\right)$. The method used by
C06LAF is not so satisfactory when
$f\left(t\right)$ is close to zero, in which case a term may be added to
$F\left(s\right)$, e.g.,
$k/s+F\left(s\right)$ has the inverse
$k+f\left(t\right)$.
Singularities in the inverse function
$f\left(t\right)$ generally cause numerical methods to perform less well. The positions of singularities can often be identified by examination of
$F\left(s\right)$. If
$F\left(s\right)$ contains a term of the form
$\mathrm{exp}\left(ks\right)/s$ then a finite discontinuity may be expected in the inverse at
$t=k$.
C06LAF, for example, is capable of estimating a discontinuous inverse but, as the approximation used is continuous, Gibbs' phenomena (overshoots around the discontinuity) result. If possible, such singularities of
$F\left(s\right)$ should be removed before computing the inverse.
3.7 Direct Summation of Orthogonal Series
The only routine available is
C06DCF, which sums a finite Chebyshev series
depending on the choice of a parameter.
3.8 Acceleration of Convergence
The only routine available is
C06BAF.
4 Decision Trees
Tree 1: Fourier Transform of Discrete Complex Data
Is the data onedimensional? 
_ yes 
Multiple vectors? 
_ yes 
Stored as rows? 
_ yes 
C06PRF 
 

 

no  

 
  

Stored as columns? 
_ yes 
C06PSF 
 

no  

 

C06PCF 
no  

Is the data twodimensional? 
_ yes 
C06PUF 
no  

Is the data threedimensional? 
_ yes 
C06PXF 
no  

Transform on one dimension only? 
_ yes 
C06PFF 
no  

Transform on all dimensions? 
_ yes 
C06PJF 
Tree 2: Fourier Transform of Real Data or Data in Complex Hermitian Form Resulting from the Transform of Real Data
Quarterwave sine (inverse) transform 
_ yes 
C06RCF 
no  

Quarterwave cosine (inverse) transform 
_ yes 
C06RDF 
no  

Sine (inverse) transform 
_ yes 
C06RAF 
no  

Cosine (inverse) transform 
_ yes 
C06RBF 
no  

Is the data threedimensional? 
_ yes 
Forward transform on real data 
_ yes 
C06PYF 
 

no  

 

Inverse transform on Hermitian data 
_ yes 
C06PZF 
no  

Is the data twodimensional? 
_ yes 
Forward transform on real data 
_ yes 
C06PVF 
 

no  

 

Inverse transform on Hermitian data 
_ yes 
C06PWF 
no  

Is the data multi onedimensional? 
_ yes 
Sequences stored by row 
_ yes 
C06PPF 
 

no  

 

Sequences stored by column 
_ yes 
C06PQF 
no  

Is the data onedimensional? 
_ yes 
C06PAF 
no  

Transform in onedimension only 
_ yes 
C06FFF 
no  

C06FJF 
5 Functionality Index
Acceleration of convergence   C06BAF 
Convolution or Correlation,   
Discrete Fourier Transform,   
multiple half and quarterwave transforms,   
Fourier cosine transforms,   
quarterwave cosine transforms,   
quarterwave sine transforms,   
complex storage by columns   C06PSF 
complex storage by rows   C06PRF 
complex storage by columns   C06PQF 
complex storage by rows   C06PPF 
Inverse Laplace Transform,   
compute coefficients of solution   C06LBF 
Summation of Chebyshev series   C06DCF 
6 Auxiliary Routines Associated with Library Routine Parameters
None.
7 Routines Withdrawn or Scheduled for Withdrawal
The following lists all those routines that have been withdrawn since Mark 17 of the Library or are scheduled for withdrawal at one of the next two marks.
8 References
Brigham E O (1974) The Fast Fourier Transform Prentice–Hall
Davies S B and Martin B (1979) Numerical inversion of the Laplace transform: A survey and comparison of methods J. Comput. Phys. 33 1–32
Fox L and Parker I B (1968) Chebyshev Polynomials in Numerical Analysis Oxford University Press
Gentleman W S and Sande G (1966) Fast Fourier transforms for fun and profit Proc. Joint Computer Conference, AFIPS 29 563–578
Hamming R W (1962) Numerical Methods for Scientists and Engineers McGraw–Hill
Shanks D (1955) Nonlinear transformations of divergent and slowly convergent sequences J. Math. Phys. 34 1–42
Swarztrauber P N (1977) The methods of cyclic reduction, Fourier analysis and the FACR algorithm for the discrete solution of Poisson's equation on a rectangle SIAM Rev. 19(3) 490–501
Swarztrauber P N (1984) Fast Poisson solvers Studies in Numerical Analysis (ed G H Golub) Mathematical Association of America
Swarztrauber P N (1986) Symmetric FFT's Math. Comput. 47(175) 323–346
Wynn P (1956) On a device for computing the ${e}_{m}\left({S}_{n}\right)$ transformation Math. Tables Aids Comput. 10 91–96