Keywords

1 Introduction

Clenshaw showed in 1955 that any polynomial given in the form

$$\begin{aligned} p(x) = \sum _{i=0}^n a_i T_i(x) \end{aligned}$$
(1)

can be evaluated on a value x with a single loop using the following functions defined by recurrence:

$$\begin{aligned} u_k(x) = {\left\{ \begin{array}{ll} 0 &{} \text {if } k = n+1\\ a_n &{} \text {if } k = n\\ 2xu_{k+1}(x) - u_{k+2}(x) + a_k &{} \text {if } 1\le k < n\\ x u_1(x) - u_2(x) + a_0 &{} \text {if } k = 0 \end{array}\right. } \end{aligned}$$
(2)

such that \(p(x) = u_0(x)\).

Unfortunately, if we use Eq. (2) with interval arithmetic directly, the result can be an interval of size exponentially larger than the input, as illustrated in Example 1.

Example 1

Let \(\varepsilon > 0\) be a positive real number, and let x be the interval \([\frac{1}{2} - \varepsilon , \frac{1}{2} + \varepsilon ]\) of width \(2\varepsilon \). Assuming that \(a_n = 1\), we can see that \(u_{n-1}\) is an interval of width \(4\varepsilon \). Then by recurrence, we observe that \(u_{n-k}\) is an interval of width at least \(4\varepsilon F_k\) where \({(F_n)}_{n\in \mathbb N}\) denotes the Fibonacci sequence, even if all \(a_i=0\) for \(i<n\).

Note that the constant below the exponent is even higher when x is closer to 1. These numerical instabilities also appear with floating point arithmetic near 1 and \(-1\) as analyzed in [4].

To work around the numerical instabilities near 1 and \(-1\), Reinsch suggested a variant of the Clenshaw algorithm [4, 7]. Let \(d_n(x) = a_n\) and \(u_n(x) = a_n\), and for k between 0 and \(n-1\), define \(d_k(x)\) and \(u_k(x)\) by recurrence as follows:

$$\begin{aligned} {\left\{ \begin{array}{ll} d_k(x) = 2(x-1)u_{k+1}(x) + d_{k+1}(x) + a_k\\ u_k(x) = d_k(x) + u_{k+1} \end{array}\right. } \end{aligned}$$
(3)

Computing p(x) with this recurrence is numerically more stable near 1. However, this algorithm does not solve the problem of exponential growth illustrated in Example 1.

Our first main result is a generalization of Eq. 3 for any value in the interval \([-1, 1]\). This leads to Algorithm 1 that returns intervals with tighter radii, as analyzed in Lemma 2. Our second main result is the use of classical backward error analysis to derive Algorithm 2 which gives an even better radii. Then in Sect. 3 we use the new evaluation algorithm to design a root solver for Chebyshev series, detailed in Algorithm 3.

2 Evaluation of Chebyshev Polynomials on Intervals

2.1 Forward Error Analysis

In this section we assume that we want to evaluate a Chebyshev polynomial on the interval I. Let a be the center of I and r be its radius. Furthermore, let \(\gamma \) and \(\overline{\gamma }\) be the 2 conjugate complex roots of the equation:

$$\begin{aligned} X^2 - 2aX + 1 = 0. \end{aligned}$$
(4)

In particular, using Vieta’s formulas that relate the coefficients to the roots of a polynomial, \(\gamma \) satisfies \(\gamma + \overline{\gamma }= 2a\) and \(\gamma \overline{\gamma }= 1\).

Let \(z_n(x) = a_n\) and \(u_n(x) = a_n\), and for k between 0 and \(n-1\), define \(z_k(x)\) and \(u_k(x)\) by recurrence as follows:

$$\begin{aligned} {\left\{ \begin{array}{ll} z_k(x) = 2(x-a)u_{k+1}(x) + \gamma z_{k+1}(x) + a_k\\ u_k(x) = z_k(x) + \overline{\gamma }u_{k+1}(x) \end{array}\right. } \end{aligned}$$
(5)

Using Eq. (4), we can check that the \(u_k\) satisfies the recurrence relation \(u_k(x) = 2xu_{k+1}(x) - u_{k+2}(x) + a_k\), such that \(p(x) = xu_1(x) - u_2(x) + a_0\).

Let \((e_k)\) and \((f_k)\) be two sequences of positive real numbers. Let \(\mathcal B_\mathbb R(a,r)\) and \(\mathcal B_\mathbb R(u_k(a), e_k)\) represent the intervals \([a-r, a+r]\) and \([u_k(a)-e_k, u_k(a)+e_k]\). Let \(\mathcal B_\mathbb C(z_k(a), f_k)\) be the complex ball of center \(z_k(a)\) and radius \(f_k\).

Our goal is to compute recurrence formulas on the \(e_k\) and the \(f_k\) such that:

$$\begin{aligned} {\left\{ \begin{array}{ll} \begin{aligned} z_k(\mathcal B_\mathbb R(a,r)) &{}\subset \mathcal B_\mathbb C(z_k(a), f_k)\\ u_k(\mathcal B_\mathbb R(a,r)) &{}\subset \mathcal B_\mathbb R(u_k(a), e_k). \end{aligned} \end{array}\right. } \end{aligned}$$
(6)

Lemma 1

Let \(e_n=0\) and \(f_n=0\) and for \(n > k \ge 1\):

$$\begin{aligned} {\left\{ \begin{array}{ll} f_k = 2r|u_{k+1}(a)| + 2re_{k+1} + f_{k+1}\\ e_k = \min (e_{k+1} + f_k, \frac{f_k}{\sqrt{1-a^2}}) \text { if |a|<1 else } e_{k+1} + f_k \end{array}\right. } \end{aligned}$$
(7)

Then, \((e_k)\) and \((f_k)\) satisfy Eq. (6).

Proof (sketch)

For the inclusion \(z_k(\mathcal B_\mathbb R(a,r)) \subset \mathcal B_\mathbb C(z_k(a), f_k)\), note that \(\gamma \) has modulus 1, such that the radius of \(\gamma z_{k+1}\) is the same as the radius of \(z_{k+1}\) when using ball arithmetics. The remaining terms bounding the radius of \(z_k\) follow from the standard rules of interval arithmetics.

For the inclusion \(u_k(\mathcal B_\mathbb R(a,r)) \subset \mathcal B_\mathbb C(u_k(a), e_k)\), note that the error segment on \(u_k\) is included in the Minkowski sum of a disk of radius \(f_k\) and a segment of radius \(e_{k+1}\), denoted by M. If \(\theta \) is the angle of the segment with the horizontal, we have \(\cos \theta = a\). We conclude that the intersection of M with a horizontal line is a segment of radius at most \(\min (e_{k+1} + f_k, \frac{f_k}{\sqrt{1-a^2}})\).

Corollary 1

Let \(\mathcal B_\mathbb R(u,e)=\mathtt {BallClenshawForward}((a_0, \ldots , a_n), a, r)\) be the result of Algorithm 1, then

$$\begin{aligned} p(\mathcal B_\mathbb R(a, r)) \subset \mathcal B_\mathbb R(u, e) \end{aligned}$$

Moreover, the following lemma bounds the radius of the ball returned by Algorithm 1.

Lemma 2

Let \(\mathcal B_\mathbb R(u,e)=\mathtt {BallClenshawForward}((a_0, \ldots , a_n), a, r)\) be the result of Algorithm 1, and let M be an upper bound on \(|u_k(a)|\) for \(1 \le k \le n\). Assume that \(\varepsilon _k < Mr\) for \(1 \le k \le n\), then

$$\begin{aligned} \left\{ \begin{array}{llll} e< 2Mn^2r &{}\text {if}\quad n< &{}\frac{1}{2\sqrt{1-a^2}}&{} \\ e< 9Mn\frac{r}{\sqrt{1-a^2}} &{}\text {if} &{}\frac{1}{2\sqrt{1-a^2}} \le n< &{}\frac{\sqrt{1-a^2}}{2r}\\ e< 2M\left[ (1+\frac{2r}{\sqrt{1-a^2}})^n-1\right] &{}\text {if} &{} &{}\frac{\sqrt{1-a^2}}{2r} < n \end{array} \right. \end{aligned}$$

Proof (sketch)

We distinguish 2 cases. First if \(n < \frac{1}{2\sqrt{1-a^2}}\), we focus on the relation \(e_k \le e_{k+1} + f_k + Mr\), and we prove by descending recurrence that \(e_k \le 2M(n-k)^2r\) and \(f_k \le 2Mr(2(n-k-1)+1)\).

For the case \(\frac{1}{2\sqrt{1-a^2}} \le n\), we use the relation \(e_k \le \frac{f_k}{\sqrt{1-a^2}} + Mr\), that we substitute in the recurrence relation defining \(f_k\) to get \(f_k \le 2rM + \frac{2r}{\sqrt{1-a^2}} f_{k+1} + f_{k+1} + Mr\sqrt{1-a^2}\). We can check by recurrence that \(f_k \le \frac{3}{2}M\sqrt{1-a^2}\left[ (1+\frac{2r}{\sqrt{1-a^2}})^n-1\right] \), which allows us to conclude for the case \(\frac{\sqrt{1-a^2}}{2r} \le n\). Finally, when \(\frac{1}{2\sqrt{1-a^2}} \le n < \frac{\sqrt{1-a^2}}{2r}\), we observe that \((1+\frac{2r}{\sqrt{1-a^2}})^n-1 \le n\exp (1)\frac{2r}{\sqrt{1-a^2}}\) which leads to the bound for the last case.

figure a

2.2 Backward Error Analysis

In the literature, we can find an error analysis of the Clenshaw algorithm [3]. The main idea is to add the errors appearing at each step of the Clenshaw algorithm to the input coefficients. Thus the approximate result correspond to the exact result of an approximate input. Finally, the error bound is obtained as the evaluation of a Chebyshev polynomial. This error analysis can be used directly to derive an algorithm to evaluate a polynomial in the Chebyshev basis on an interval in Algorithm 2.

Lemma 3

Let \(e_n=0\) and for \(n > k \ge 1\):

$$\begin{aligned} e_k = 2r|u_{k+1}(a)| + e_{k+1} \end{aligned}$$
(8)

and \(e_0 = r|u_1(a)| + e_1\). Then \((e_k)\) satisfies \(u_k(\mathcal B_\mathbb R(a,r)) \subset \mathcal B_\mathbb R(u_k(a), e_k)\).

Proof (sketch)

In the case where the computations are performed without errors, D. Elliott [3, Equation (4.9)] showed that for \(\gamma = \tilde{x} - x\) we have:

$$p(\tilde{x}) - p(x) = 2\gamma \sum _{i=0}^n u_i(\tilde{x}) T_i(x) - \gamma u_1(\tilde{x})$$

In the case where \(\tilde{x} = a\) and \(x \in \mathcal B_{\mathbb R}(a,r)\) we have \(\gamma \le r\) and \(|T(x)| \le 1\) which implies \(e_k \le r|u_1(a)| + \sum _{i=2}^n 2r|u_i(a)|\).

Corollary 2

Let \(\mathcal B_\mathbb R(u,e)=\mathtt {BallClenshawBackward}((a_0, \ldots , a_n), a, r)\) be the result of Algorithm 2, and let M be an upper bound on \(|u_k(a)|\) for \(1 \le k \le n\). Assume that \(\varepsilon _k < Mr\) for \(1 \le k \le n\), then \(e < 3Mnr\).

figure b

3 Application to Root Finding

For classical polynomials, numerous solvers exist in the literature, such as those described in [5] for example. For polynomials in the Chebyshev basis, several approaches exist that reduce the problem to polynomial complex root finding [1], or complex eigenvalue computations [2] among other.

In this section, we experiment a direct subdivision algorithm based on interval evaluation, detailed in Algorithm 3. This algorithm is implemented and publicly available in the software clenshaw [6].

figure c

We applied this approach to Chebyshev polynomials whose coefficients are independently and identically distributed with the normal distribution with mean 0 and variance 1.

As illustrated in Fig. 1 our code performs significantly better than the classical companion matrix approach. In particular, we could solve polynomials of degree 90000 in the Chebyshev basis in less than 5 s and polynomials of degree 5000 in 0.043 s on a quad-core Intel(R) i7-8650U cpu at 1.9 GHz. For comparison, the standard numpy function chebroots took more than 65 s for polynomials of degree 5000. Moreover, using least square fitting on the ten last values, we observe that our approach has an experimental complexity closer to \(\varTheta (n^{1.67})\), whereas the companion matrix approach has a complexity closer to \(\varTheta (n^{2.39})\).

Fig. 1.
figure 1

Time for isolating the roots of a random Chebyshev polynomial, on a quad-core Intel(R) i7-8650U cpu at 1.9 GHz, with 16G of ram