1 Introduction

Univariate orthogonal polynomials are a mainstay tool in numerical analysis and scientific computing. These polynomials serve as theoretical foundations for numerical algorithms involving approximation and quadrature [4, 12, 13, 22, 31]. Given a positive measure \(\mu \) on the real line \({\mathbb {R}}\), if \(\mu \) has finite polynomial moments of all orders along with an infinite number of points of increase, then a family of orthonormal polynomials \(\{p_n\}_{n=0}^\infty \) exists, satisfying \(\deg p_n = n\), and

$$\begin{aligned} \int _{\mathbb {R}}p_n(x) p_m(x) \mathrm {d}\mu (x) = \delta _{m,n}, \end{aligned}$$

where \(\delta _{m,n}\) is the Kronecker delta. If we further assume that each \(p_n\) has a positive leading coefficient, then these polynomials are unique. Such families are known to obey a three-term recurrence formula,

$$\begin{aligned} x p_n(x)&= b_n p_{n-1}(x) + a_{n+1} p_n(x) + b_{n+1} p_{n+1}(x),&n \ge 0, \end{aligned}$$
(1)

with the starting conditions \(p_{-1} \equiv 0\) and \(p_0(x) = 1/b_0\). The coefficients \((a_n)_{n=1}^\infty \subset {\mathbb {R}}\) and \((b_n)_{n=0}^\infty \subset (0, \infty )\) depend only on the (polynomial) moments of \(\mu \). In practical settings, knowledge of these coefficients is the only requirement for implementing stable, accurate algorithms that achieve evaluation and manipulation of polynomials that are core components of approximation and quadrature algorithms. For example, the n eigenvalues of the \(n \times n\) Jacobi matrix \(\varvec{J}_n\) are precisely the abscissae of a \(\mu \)-Gaussian quadrature rule, with \(J_n\) the symmetric tridiagonal matrix given by

$$\begin{aligned} \varvec{J}_n(\mu ) = \left( \begin{array}{ccccc} a_1 &{} b_1 &{} &{} &{} \\ b_1 &{} a_2 &{} b_2 &{} &{} \\ &{} \ddots &{} \ddots &{} \ddots &{} \\ &{} &{} b_{n-2} &{} a_{n-1} &{} b_{n-1} \\ &{} &{} &{} b_{n-1} &{} a_n \\ \end{array}\right) . \end{aligned}$$
(2)

Therefore, the recurrence coefficients \(a_n\) and \(b_n\) must be computed stably and accurately.

Some classical probability measures \(\mu \) give rise to classical families of orthogonal polynomials \(p_n\): A Gaussian measure results in Hermite polynomials; the uniform measure on a compact interval results in Legendre polynomials; a Beta measure corresponds with Jacobi polynomials; and a one-sided exponential measure gives rise to Laguerre polynomials. These classical polynomial families are among a few for which explicit formulas are available for the recurrence coefficients \(a_n\) and \(b_n\), see, e.g., [12, Tables 1.1, 1.2].

However, for even modestly complicated measures \(\mu \) outside this classical collection, the task of determining these coefficients can be quite difficult. For example, an application in which this situation arises is in polynomial Chaos methods, which are techniques in scientific computing problems for modeling the effect of uncertainty in a model [35, 38]. An output’s dependence on a finite number of random variable inputs is modeled with polynomial dependence on those inputs. With one random input, the polynomial approximation is typically constructed using a basis of polynomials orthogonal to the distribution of the random input, which requires building orthogonal polynomials with respect to a given, often nonclassical, probability measure.

A simple example that illustrates how computation of orthogonal polynomials is difficult for even fairly simple measures is furnished by the class of Freud weights,

$$\begin{aligned} \mathrm {d}\mu (x)&= \exp \left( - |x|^\alpha \right) \mathrm {d}x,&\alpha&> 0, \end{aligned}$$
(3)

with support equal to all of \({\mathbb {R}}\). (In what follows, we will refer to \(\mu \) as a measure and \(\mathrm {d}\mu \) as a weight.) When \(\alpha = 2\), corresponding to the Gaussian measure (and Hermite polynomial family), the three-term recurrence coefficients are known exactly. However, when \(\alpha = 1\), no closed-form analytical formula for the coefficients \(a_n\) and \(b_n\) exists, even though the moments of \(\mu \) are known explicitly in terms of well-studied special functions. (For example, note that under a change of variable, the moments of the measure above correspond to evaluations of the Euler Gamma function.)

In such general cases when no known closed-form expression for the three-term recurrence coefficients exists, numerical methods are employed to approximate them. The main goal of this article is to survey and extend existing methods for computing these recurrence coefficients associated to measures for which explicit formulas are not available.

1.1 Existing Approaches

When \(\mu \) is not a measure for which the coefficients have explicitly known formulas, one typically resorts to numerical methods to approximately compute these coefficients. A summary of the methods we consider in this article is presented in Table 1, which indicates later sections in this article where we give a formal description of each algorithm. A brief description of these procedures is given in Sect. 2, but an excellent and more detailed historical survey is provided in [12, Section 2.6]. Below we present a nontechnical summary of the approaches that we survey.

A classical approach to computing recurrence coefficients from moments is via determinants of Hankel matrices [12, Section 2.1.1]. A second classical approach, the Chebyshev algorithm, transforms monomial moments by expressing the recurrence coefficients in terms of moments involving monomials and \(p_n\) [2]. A more effective approach, the modified Chebyshev algorithm, uses moments involving \(p_n\) and another arbitrary set of polynomials [7, 26, 33]. Yet another procedure, the Stieltjes algorithm [28], computes recurrence coefficients directly assuming moments involving \(p_n\) can be computed. Finally, given a measure with discrete support, the Lanczos algorithm can be used to compute the Jacobi matrix for \(\mu \), yielding the recurrence coefficients; although this is typically unstable, a stable variant is given in [25].

For very special forms of weight functions, other procedures can be derived. A primary example of this are iterative recurrence-type algorithms resulting from discrete Painlevé equations when \(\mathrm {d}\mu (x) \propto \exp (-x^{\alpha })\) for \(\alpha /2 \in {\mathbb {N}}\). These Painlevé equations, which determine the recurrence coefficients for \(p_n\), are remarkably simple and direct to implement, but are quite unstable [32]. A final approach we consider amounts to using a linear orthogonalization procedure, such as (modified) Gram-Schmidt, to compute the expansion coefficients of \(p_n\) in terms of the monomials. However, this procedure is known to produce quite ill-conditioned matrices, especially for large n, making the computation of \(p_n\), and hence the recurrence coefficients, suffer roundoff errors. Therefore, although this approach has often been used [36, 37], it is less useful in the context of this article. Nevertheless, we consider one recent related approach, an “arbitrary polynomial chaos” approach suggested in [23], which amounts to solving a linear system involving a modified Hankel matrix.

Table 1 Abbreviation, subsection, and algorithm for each method

1.2 Contributions of this Article

Several algorithms exist to compute the recurrence coefficients, but a few clear and direct recommendations are available for researchers without substantial experience and/or knowledge of the field. The main contribution of this paper is to summarize, evaluate, and extend existing methods for computing recurrence coefficients for univariate orthogonal polynomial families. We first provide a survey and comparison of many existing algorithms (see Sect. 2). In Sect. 3.1 we propose a novel “predictor–corrector” algorithm and evaluate its utility. Finally, by modifying the “multiple component” approach in [8, 10], we consider a new hybrid algorithm in Sect. 3.3 that combines our predictor–corrector scheme with a stabilized Lanczos procedure. Our algorithm can be used to compute recurrence coefficients for the fairly general class of measures whose differentials are given by

$$\begin{aligned} \mathrm {d}\mu (x) = \sum _{j=1}^C w_j(x) \mathbb {1}_{I_j}(x) \mathrm {d}x + \sum _{j=1}^M \nu _j \delta _{\tau _j} \mathrm {d}x, \end{aligned}$$
(4)

where C and M are finite (either possibly 0), \(\delta _{\tau _j}\) is a Dirac mass located at \(\tau _j \in {\mathbb {R}}\), \(\{\nu _j\}_{j=1}^M\) are positive scalars, each \(I_j\) is a (possibly unbounded) nontrivial interval, and \(w_j\) is a continuous (ideally smooth) non-negative function on \(I_j\). Specification of the \(w_j\), \(I_j\), \(\tau _j\), and \(\nu _j\) is sufficient to utilize most of the algorithms we consider, but having extra information that characterizes \(w_j\), particularly prescribed behavior at finite endpoints of \(I_j\), will increase the accuracy of the procedures. In other words, with \(I_j = [\ell _j, r_j]\) and either of the endpoints \(\ell _j, r_j\) is finite, we assume knowledge of exponents \(\beta _j, \alpha _j > -1\) such that \(w_j\) has polynomial singular strength \(\beta _j\), \(\alpha _j\) at endpoints \(\ell _j, r_j\), i.e.,

$$\begin{aligned} 0<&\lim _{x \downarrow \ell _j} w_j(x) (x - \ell _j)^{-\beta _j}< \infty ,&0<&\lim _{x \uparrow r_j} w_j(x) (r_j - x)^{-\alpha _j} < \infty . \end{aligned}$$
(5)

Note that our assumption that \(\alpha _j, \beta _j > -1\) is natural since if the inequality above is true with, say, \(\alpha _j \le -1\), then \(\mu \) is not a finite measure and therefore is not a probability measure.

Note that the form of \(\mu \) we assume in (4) is quite general, and includes all classical measures, those with piecewise components, measures with discrete components, measures with unbounded support, and measures whose densities have integrable singularities.

This paper is structured as follows: In Sect. 2 we briefly survey the existing approaches summarized in Table 1. Section 3 contains the discussion that leads to our proposed hybrid “PCL” algorithm: Sect. 3.1 discusses the predictor–corrector scheme; Sect.  3.2 briefly describes how we compute moments, which leverages the specific form of the measure \(\mu \) assumed in (4) and (5); Sect. 3.3 combines these with a stabilized Lanczos procedure. Finally, we present a wide range of numerical examples in Sect. 4, which compares many of the techniques in Table 1, and demonstrates the accuracy and efficiency of the “PCL” algorithm.

2 Existing Approaches

We review here some existing methods for computing recurrence coefficients. In order to compute the required coefficients, having some knowledge about the measure \(\mu \) is neccessary. The following are two of the more common assumptions that one makes, with the latter assumption being stronger:

  • The (monomial) moments of all orders of \(\mu \) are known, i.e., the moment sequence

    $$\begin{aligned} m_n :=\int x^n \mathrm {d}\mu (x), \quad n \ge 0, \end{aligned}$$
    (6)

    is known and available. In practice, the integrals can be obtained by the composite quadrature approach introduced in Sect. 3.2, but sometimes they can also be computed directly in terms of special functions, such as Gamma function given the Freud weights.

  • General polynomial moments, i.e.,

    $$\begin{aligned} \int q(x) \mathrm {d}\mu (x), \end{aligned}$$
    (7)

    are computable for a general, finite-degree polynomial q that is often identified only partway through an algorithm.

No particular prescription exists for how the moments above are computed, but typically this is accomplished through a quadrature rule. In some “data-driven” scenarios, this quadrature rule often comes as a Monte Carlo rule from an empirical ensemble.

We discuss six procedures below; in practice, only the last two are computationally stable, but they are all useful for comparison purposes. The first procedure works only for very special Freud weights, i.e., those with exponential behavior.

2.1 DP: Freud Weights and Discrete Painlevé Equations

Freud weights, named after Géza Freud who studied them in the 1970s [5], have the following form:

$$\begin{aligned} \mathrm {d}\mu (x) = |x|^\rho \exp (-|x|^\alpha ) \mathrm {d}x, \quad \rho> -1, \alpha > 0. \end{aligned}$$
(8)

Observe that Freud weights are symmetric, which implies that \(a_n = 0\) for \(n \ge 0\), and therefore only the \(b_n\) coefficients need be computed. Freud gave a recurrence relation for the recurrence coefficients \(b_n\) when \(\alpha = 2, 4, 6\). The connection between Freud weights and discrete Painlevé equations was first pointed out by Magnus [21]. In the case of \(\alpha = 4\), one can derive the following recurrence relation for \(n \ge 1\) by letting \(x_n :=2 b_n^2\):

$$\begin{aligned} x_{n+1}&= \frac{1}{x_n} \left( n + \frac{\rho }{2} \left( 1 + (-1)^n\right) \right) - x_n - x_{n-1},&x_0&= 0,&\quad x_1&= \frac{2 \varGamma {(\frac{3+\rho }{4}})}{\varGamma {(\frac{1+\rho }{4}})}. \end{aligned}$$
(9)

See, e.g., [32, Section 2.2]. This recurrence relation is a discrete Painlevé I equation [21] that is useful for theoretical analysis. For example, it can be used to prove Freud’s conjecture, which is a statement about asymptotic behavior of the \(b_n\) coefficients. For \(\alpha = 4\) in this section, Freud’s conjecture states

$$\begin{aligned} \lim _{n\rightarrow \infty } \frac{b_n}{n^{1/4}} = \frac{1}{\root 4 \of {12}}. \end{aligned}$$
(10)

A more general resolution of Freud’s conjecture using alternative methods is provided in [20].

Similarly, when \(\alpha = 6\), by letting \(y_n :=b_n^2\), a fourth-order nonlinear recurrence relation for \(n\ge 2\) [32, Section 2.3] is given by

$$\begin{aligned} \begin{aligned}&6 y_n \left( y_{n-2} y_{n-1} + y_{n-1}^2 + 2 y_{n-1} y_n + y_{n-1} y_{n+1} + y_n^2 + 2 y_n y_{n+1} + y_{n+1}^2 + y_{n+1} y_{n+2}\right) \\&\quad = n + \frac{\rho }{2} \left( 1 + (-1)^n\right) , \end{aligned} \end{aligned}$$
(11)

with initial condition

$$\begin{aligned} y_0&= 0,&y_1&= \frac{\varGamma {(\frac{3+\rho }{6})}}{\varGamma {(\frac{1+\rho }{6})}},&\\ y_2&= \frac{\varGamma {(\frac{5+\rho }{6})}}{\varGamma {(\frac{3+\rho }{6})}} - y_1,&y_3&= \frac{\varGamma {(\frac{7+\rho }{6})}}{y_2 y_1 \varGamma {(\frac{1+\rho }{6})}} - \frac{2(y_1+y_2)\varGamma {(\frac{5+\rho }{6})}}{y_2 y_1 \varGamma {(\frac{1+\rho }{6})}} + \frac{(y_1+y_2)^2\varGamma {(\frac{3+\rho }{6})}}{y_2 y_1 \varGamma {(\frac{1+\rho }{6})}}. \end{aligned}$$

In this case, Freud’s conjecture states

$$\begin{aligned} \lim _{n\rightarrow \infty } \frac{b_n}{n^{1/6}} = \frac{1}{\root 6 \of {60}}. \end{aligned}$$
(12)

Note the computation of recursion coefficients via (9) and (11) is quite straightforward, but is also very unstable. Nevertheless, there is a unique positive solution [19]; hence, a small (e.g., machine roundoff) error in \(x_1\) or \(y_1\) quickly results in the loss of positivity of \(x_n\) or \(y_n\). Numerical solutions follow the exact asymptotic behavior well until large deviations from the true solution eventually appear, cf. Fig. 1.

2.2 HD: Hankel Determinants

Orthogonal polynomials as well as their recursion coefficients are expressible in determinantal form in terms of the moments of the underlying measure. Indeed, much of the classical theory of orthogonal polynomials is moment-oriented. One classical technique to express recurrence coefficients in terms of moments is via matrix determinants.

We introduce the Hankel determinant \(\varDelta _n\) of order n in terms of the finite moments (6), defined as

$$\begin{aligned} \varDelta _{-1}&= 1,&\varDelta _{0}&= 1,&\varDelta _n&= \det \varvec{H}_n,&\varvec{H}_n&:=\left( \begin{array}{cccc} m_0 &{} m_1 &{} \cdots &{} m_{n-1} \\ m_1 &{} m_2 &{} \cdots &{} m_{n} \\ \vdots &{} \vdots &{} \ddots &{} \vdots \\ m_{n-1} &{} m_{n} &{} \cdots &{} m_{2n-2} \end{array}\right) ,&n&\in {\mathbb {N}}. \end{aligned}$$
(13)

These determinants of Gram matrices are associated to the \(\mu \)-inner product, using a basis of monomials. In addition, we define determinants \(\varDelta _n^\prime \) of modified Hankel matrices, where the modification is to replace the last column of \(\varvec{H}_n\) by the last column of \(\varvec{H}_{n+1}\) with the trailing entry removed,

$$\begin{aligned} \varDelta _0^{\prime }&= 0,&\varDelta _1^{\prime }&= m_1,&\varDelta _n^{\prime }&= \begin{vmatrix} m_0&m_1&\cdots&m_{n-2}&m_{n} \\ m_1&m_2&\cdots&m_{n-1}&m_{n+1} \\ \vdots&\vdots&\vdots&\vdots&\vdots \\ m_{n-1}&m_{n}&\cdots&m_{2n-3}&m_{2n-1} \end{vmatrix},&n&= 2, 3, \dots \ . \end{aligned}$$

Along with \(b_0 = \sqrt{m_0}\), the orthogonal polynomial recurrence coefficients can be computed explicitly from these determinants, cf.[12, Theorem 2.2],

$$\begin{aligned} a_n&= \frac{\varDelta _{n}^{\prime }}{\varDelta _{n}} - \frac{\varDelta _{n-1}^{\prime }}{\varDelta _{n-1}},&b_n&= \sqrt{\frac{\varDelta _{n+1} \varDelta _{n-1}}{\varDelta _n^2}},&n\in {\mathbb {N}}. \end{aligned}$$
(14)

The formulas (14) are not practically useful as an algorithm to compute reucrrence coefficients since the Hankel matrices above are typically ill-conditioned. In particular, the map that computes recurrence coefficients from moments can be severely ill-conditioned [12, Section 2.1.6].

2.3 aPC: “Arbitrary” Polynomial Chaos Expansions

The arbitrary polynomial chaos (aPC), like all polynomial chaos expansion techniques, approximates the dependence of simulation model output on model parameters by expansion in an orthogonal polynomial basis. As shown in [23], aPC at finite expansion order demands the existence of only a finite number of moments and does not require the complete knowledge of a probability density function. Once we construct the polynomials such that they form an orthonormal basis for arbitrary distributions from the moment-based analysis, the recurrence coefficients can be derived using the aPC expansion coefficients.

Our goal is, firstly, to construct the polynomials in (15) such that they form an orthonormal basis for arbitrary distributions. Instead of the normality condition, we will first introduce an intermediate auxiliary condition by demanding that the leading coefficients of all polynomials be equal to 1.

We define the monic orthogonal polynomial \(\pi _n(x)\) as

$$\begin{aligned} \pi _n(x) = \sum _{i=0}^n c_i^{(n)} x^i, \end{aligned}$$
(15)

where \(c_i^{(n)}\) are expansion coefficients, and specifically, \(c_n^{(n)} = 1, \forall n\). The general conditions of orthogonality for \(\pi _n(x)\) with respect to all lower order polynomials can be written in the following form [23, Section 3.1]:

$$\begin{aligned} \int _{\Omega } x^k \left( \sum _{i=0}^n c_i^{(n)} x^i \right) \mathrm {d}\mu (x)&= 0,&k&= 0, 1, \dots , n-1. \end{aligned}$$
(16)

For each n, the system of equations given by (16) defines the unknown polynomial expansion coefficients in (15). Using finite moments in (6), the system can be reduced to

$$\begin{aligned} \sum _{i=0}^n c_i^{(n)} m_{i+k}&= 0. \end{aligned}$$

Alternatively, the system of linear equations can be written in the more convenient matrix form,

$$\begin{aligned} \left( \begin{array}{cccc} m_0 &{} m_1 &{} \cdots &{} m_{n} \\ m_1 &{} m_2 &{} \cdots &{} m_{n+1} \\ \vdots &{} \vdots &{} \ddots &{} \vdots \\ m_{n-1} &{} m_{n} &{} \cdots &{} m_{2n-1} \\ 0 &{} 0 &{} \cdots &{} 1 \end{array}\right) \left( \begin{array}{c} c_0^{(n)} \\ c_1^{(n)} \\ \vdots \\ c_{n-1}^{(n)} \\ c_n^{(n)} \end{array}\right) = \left( \begin{array}{c} 0 \\ 0 \\ \vdots \\ 0 \\ 1 \end{array}\right) . \end{aligned}$$
(17)

By defining the coefficient vector \({\varvec{c}^{(n)}} = \left( c_0^{(n)}, c_1^{(n)}, \dots , c_n^{(n)}\right) ^T\), the normalized coefficients \(\bar{c}_i^{(n)}\) can be expressed in terms of \(\varvec{c}^{(n)}\) and Hankel matrices \(\varvec{H}_{n+1}\),

$$\begin{aligned} \bar{c}_i^{(n)} = \frac{c_i^{(n)}}{\sqrt{{\varvec{c}^{(n)}}^T \varvec{H}_{n+1} \varvec{c}^{(n)}}}. \end{aligned}$$
(18)

Together with \(b_0 = \sqrt{m_0}\) and \(c_{-1}^{(0)} :=0\), the recurrence coefficients can be obtained from (18) using (1),

$$\begin{aligned} a_n&= \frac{\bar{c}_{n-2}^{(n-1)} - b_n \bar{c}_{n-1}^{(n)}}{\bar{c}_{n-1}^{(n-1)}},&b_n&= \frac{\bar{c}_{n-1}^{(n-1)}}{\bar{c}_n^{(n)}},&n&\in {\mathbb {N}}. \end{aligned}$$
(19)

Thus, given the moments \(m_i\), we first solve for the \(c^{(n)}_k\) via (17) and subsequently uses (19) to compute the recurrence coefficients. As with the Hankel determinant procedure in Sect. 2.2, this procedure is susceptible to instability since the moment matrices in (17) are typically unstable.

2.4 MC: Modified Chebyshev Algorithm

The previous techniques have used (monomial) moments directly and suffer from numerical stability issues. The classical Chebyshev algorithm [2] still uses monomial moments, but it employs them through an iterative recursive approach to compute the recurrence coefficients. The technique in this section modifies the classical Chebyshev algorithm by using \(\mu \)-moments computed with respect to some other set of polynomials \(\{q_k\}\). Typically, \(q_k\) is chosen as a sequence of polynomials that are orthogonal with respect to another measure \(\lambda \), where we require that the recurrence coefficients \(c_n, d_n\) for \(\lambda \) are known. The Modified Chebyshev algorithm is effective when \(\lambda \) is chosen “close” to \(\mu \).

We define the “mixed” moments as

$$\begin{aligned} \sigma _{n,k}&= \int \pi _n(x) q_k(x) \mathrm {d}\mu (x),&n,k > -1, \end{aligned}$$
(20)

where \(\pi _n(x)\) are the monic orthogonal polynomials with respect to \(\mu \). We denote \(a_n, b_n\) as the recurrence coefficients of orthonormal polynomials \(p_n(x)\) with respect to \(\mu \). They can be used to formulate the three-term recurrence relation for monic orthogonal polynomials \(\pi _n(x)\),

$$\begin{aligned} \pi _{n+1}(x) = (x - a_{n+1}) \pi _n(x) - b_n^2 \pi _{n-1}(x). \end{aligned}$$
(21)

We define \(c_k, d_k\) as recurrence coefficients of orthonormal polynomials \(q_k(x)\). Plugging (21) into (20), the mixed moments \(\sigma _{n,k}\), in turn, satisfies the recurrence relation below:

$$\begin{aligned} \sigma _{0,k}&= m_k, \nonumber \\ \sigma _{n,k}&= d_k \sigma _{n-1,k-1} + (c_{k+1} - a_n) \sigma _{n-1,k} + d_{k+1} \sigma _{n-1,k+1} - b_{n-1}^2 \sigma _{n-2,k}. \end{aligned}$$
(22)

(22) gives a routine to compute the first N recurrence coefficients, which requires as input the first \(2N-1\) modified moments \(\{m_k\}_{k=0}^{2N-2}\) and \(\{c_k, d_k\}_{k=0}^{2N-1}\).

Together with (21), (22) and the fact that \(\sigma _{-1,k} = 0\), we have the expression of the recurrence coefficients,

$$\begin{aligned} a_1&= c_1 + \frac{d_1 \sigma _{0,1}}{\sigma _{0,0}},&a_n&= c_n + \frac{d_n \sigma _{n-1,n}}{\sigma _{n-1,n-1}} - \frac{d_{n-1} \sigma _{n-2,n-1}}{\sigma _{n-2,n-2}},&n&= 2, 3, ..., \nonumber \\ b_0&= \sqrt{d_0 m_0},&b_n&= \sqrt{\frac{d_{n} \sigma _{n,n}}{\sigma _{n-1,n-1}}},&n&\in {\mathbb {N}}. \end{aligned}$$
(23)

Given a positive measure \(\mu \) on \({\mathbb {R}}\), by choosing \(\lambda \) near \(\mu \) in some sense, we expect the algorithm is well, or better, conditioned [12, Section 2.1.3].

2.5 SP: The Stieltjies Procedure

The previous procedures have used either monomial moments or general (mixed) moments with respect to a prescribed, fixed alternative basis \(q_k\). In constrast, the Stieltjes procedure [8, 29] requires “on-demand” computation of moments, i.e., the moments required are determined during the algorithm. Starting with \(b_0 = \left( \int \mathrm {d}\mu \right) ^{1/2}\) and \(p_0(x) = 1/b_0\), \(a_1\) can be computed from (7) with \(q(x) = x p_0(x)^2\), which allows us to evaluate \(p_1(x)\) by means of (1). \(p_1(x)\), in turn, can be used to generate \(b_1\). The formulae [12, Section 2.2.3]

$$\begin{aligned} a_n&= \int x p_{n-1}^2(x) \mathrm {d}\mu ,&b_n&= \left( \int ( (x - a_n) p_{n-1}(x) - b_{n-1} p_{n-2}(x) )^2 \mathrm {d}\mu \right) ^{\frac{1}{2}},&n&\in {\mathbb {N}}, \end{aligned}$$
(24)

for the recursion coefficients provides a natural iterative framework for computing them.

2.6 LZ: A Lanczos-Type Algorithm

We assume that the measure \(\mathrm {d}\mu \) is a discrete measure with finite support, i.e., (4) holds with \(C = 0\) and \(0< M < \infty \). We wish to compute recurrence coefficients \((a_n,b_n)\) up to \(n < M\), ensuring that orthogonal polynomials up to this degree exist. We could also consider applying this procedure to a finite discretization of a continuous measure; see [12, Section 2.2.3.2 and Theorem 2.32].

The Lanczos procedure produces recurrence coefficients for the discrete measure \(\mu \), and utilizes the Lanczos algorithm that unitarily triangularizes a symmetric matrix. With \((\tau _j, \nu _j)_{j=1}^M\) the quadrature rule associated to the measure \(\mu \) in (4), we define

$$\begin{aligned} \sqrt{\varvec{\nu }}&:=\left( \sqrt{\nu _1}, \; \sqrt{\nu _2}, \; \ldots \;, \sqrt{\nu _M} \right) ^T,&\varvec{D}&:=\mathrm {diag}\left( \tau _1, \; \tau _2, \; \ldots , \; \tau _M \right) . \end{aligned}$$

We define \(\varvec{Q}\) as a scaled \(M \times M\) Vandermonde-like matrix,

$$\begin{aligned} \varvec{Q}&= \mathrm {diag}\left( \sqrt{\varvec{\nu }}\right) \varvec{V},&\left( \varvec{V}\right) _{j,k} = p_{j-1}(\tau _k), \end{aligned}$$

for \(j, k = 1, \ldots , M\). Then, \(\varvec{Q}\) is an orthogonal matrix by orthonormality of \(p_n\). The orthogonality and the three-term recurrence further imply that,

$$\begin{aligned} \left( \begin{array}{cc} 1 &{} \varvec{0}^T \\ \varvec{0} &{} \varvec{Q} \end{array}\right) \left( \begin{array}{cc} 1 &{} \sqrt{\varvec{\nu }}^T \\ \sqrt{\varvec{\nu }} &{} \varvec{D} \end{array}\right) \left( \begin{array}{cc} 1 &{} \varvec{0}^T \\ \varvec{0} &{} \varvec{Q}^T \end{array}\right) = \left( \begin{array}{cc} 1 &{} b_0 \varvec{e}_1^T \\ b_0 \varvec{e}_1 &{} \varvec{J}_M(\mu ) \end{array}\right) , \end{aligned}$$

where \(\varvec{e}_1 = (1, 0, 0, \ldots )^T \in {\mathbb {R}}^{M}\). The Lanczos algorithm, given the middle matrix on the left-hand side, computes the unitary triangularization above and outputs the right-hand side, which identifies the Jacobi matrix \(\varvec{J}_M\) in (2), and, hence, the recurrence coefficients. See [12, Section 2.2.3.2] for more details. It is well known that the standard Lanczos algortihm is numerically unstable, so that stabilization procedures must be employed [16, 25]. We use a “double orthogonalization” stabilization technique to avoid instability. Our results suggest that, for discrete measures, this procedure is more accurate than all the alternatives, see Sect. 4.3.

3 PCL: A Hybrid Predictor–Corrector Lanczos Procedure

The main goal of this section is to describe a procedure by which we compute recurrence coefficients for \(\mu \) of the form (4). The procedure entails knowledge of the continuous weights \(\{w_j\}_{j=1}^C\) and their respective supporting intervals, \(\{I_j\}_{j=1}^C\), along with the discrete part of the measure encoded by the nodes and weights \(\left( \tau _j, \nu _j\right) _{j=1}^M\). In Sect. 3.2, we will also utilize the singularity behavior of the weights \(w_j\) dictated by the constants \(\alpha _j\) and \(\beta _j\) in (5) to compute moments.

Section 3.1 first introduces a new procedure to compute recurrence coefficients for a measure with a continuous density using polynomial moments. Section 3.2 then discusses our particular strategy for computing these moments. Finally, Sect. 3.3 introduces a procedure based on the multiple component approach in [8] for computing recurrence coefficients for a measure of general form (4).

3.1 PC: Predictor–Corrector Method

In this section, we describe a Stieltjes-like procedure for computing recurrence coefficients. Although this works for general measures, we are mainly interested in applying this technique for measures \(\mu \) that have a continuous density. The high-level algorithm, like the previous ones we have discussed, is iterative. Suppose for some \(n \ge 0\) we know the coefficient tableau,

$$\begin{aligned} \begin{array}{cccccc} &{} a_1(\mu ) &{} a_2(\mu ) &{} \cdots &{} a_{n}(\mu ) \\ b_0(\mu ) &{} b_1(\mu ) &{} b_2(\mu ) &{} \cdots &{} b_{n}(\mu ). \end{array} \end{aligned}$$

These coefficients, via (1), define \(p_0, \ldots , p_n\) that are orthonormal under a \(\mathrm {d}\mu \)-weighted integral. In order to compute \(a_{n+1}\) and \(b_{n+1}\), we make educated guesses for these coefficients, and correct them using computed moments. The procedure is mathematically equivalent to the Stieltjes procedure: We define a new set of recurrence coefficients \(\{\widetilde{a}_j, \widetilde{b}_j\}_{j=0}^{n+1}\), where

$$\begin{aligned} \widetilde{a}_{j}&= a_{j},&\widetilde{b}_{j}&= b_{j}, j = 0, \ldots , n, \end{aligned}$$
(25a)
$$\begin{aligned} \widetilde{a}_{n+1}&= a_{n},&\widetilde{b}_{n+1}&= b_{n}, \end{aligned}$$
(25b)

In particular, corrections \(\varDelta a_{n+1} \in {\mathbb {R}}\) and \(\varDelta b_{n+1} > 0\) exist such that

$$\begin{aligned} a_{n+1}&= \widetilde{a}_{n+1} + \varDelta a_{n+1},&b_{n+1}&= \widetilde{b}_{n+1} \varDelta b_{n+1}. \end{aligned}$$
(25c)

Our procedure will compute the corrections \(\varDelta a_{n+1}\) and \(\varDelta b_{n+1}\). The tableau of coefficients \(\widetilde{a}_{n+1}\) and \(\widetilde{b}_{n+1}\)

$$\begin{aligned} \begin{array}{ccccc} &{} a_1(\mu ) &{} \cdots &{} a_{n}(\mu ) &{} \widetilde{a}_{n+1}(\mu ) \\ b_0(\mu ) &{} b_1(\mu ) &{} \cdots &{} b_{n}(\mu ) &{} \widetilde{b}_{n+1}(\mu ), \end{array} \end{aligned}$$

can be used with (1) to generate the polynomials \(p_0, \ldots , p_n\), along with \(\widetilde{p}_{n+1}\), defined as

$$\begin{aligned} \widetilde{b}_{n+1} \widetilde{p}_{n+1}&:=(x - \widetilde{a}_{n+1}) p_n - b_n p_{n-1}. \end{aligned}$$
(26)

Since \(\widetilde{p}_{n+1}\) and \(p_{n+1}\) were generated using the same coefficients \((a_j, b_j)\) up to index \(j = n\), then they are both orthogonal to all polynomials of degree \(n-1\) or less. However, \(\widetilde{p}_{n+1}\) is not orthogonal to \(p_n\) in general. We can choose \(\varDelta a_{n+1}\) to enforce this orthogonality, which requires computing a polynomial moment.

Once \(a_{n+1} = \widetilde{a}_{n+1} + \varDelta a_{n+1}\) is successfully computed, we can similarly define another degree-\((n+1)\) polynomial \(\widehat{p}_{n+1}\) through the relation,

$$\begin{aligned} \widetilde{b}_{n+1} \hat{p}_{n+1}&:=(x - a_{n+1}) p_n - b_n p_{n-1}. \end{aligned}$$
(27)

This polynomial differs from \(p_{n+1}\) by only a multiplicative constant, which can again be determined through a moment computation and used to compute \(\varDelta b_{n+1}\). We formalize the discussion above through the following result:

Lemma 1

With \(\widetilde{p}_{n+1}\) and \(\hat{p}_{n+1}\) defined as in (26) and (27), respectively, let

$$\begin{aligned} G_{n,n+1}&:=\int _{{\mathbb {R}}} p_n(x) \widetilde{p}_{n+1} (x) \mathrm {d}\mu (x), \end{aligned}$$
(28a)
$$\begin{aligned} G_{n+1,n+1}&:=\int _{{\mathbb {R}}} \hat{p}^2_{n+1} (x) \mathrm {d}\mu (x), \end{aligned}$$
(28b)

then,

$$\begin{aligned} \varDelta a_{n+1}&= G_{n,n+1} b_n,&\varDelta b_{n+1}&= \sqrt{ G_{n+1,n+1}}. \end{aligned}$$
(29)

Proof

Starting from the definition (26) for \(\widetilde{p}_{n+1}\), we replace \(x p_n\) with the right-hand side of (1), yielding,

$$\begin{aligned} \widetilde{p}_{n+1}&= \varDelta b_{n+1} \left[ \frac{1}{b_{n+1}} \left( x - a_{n+1} \right) p_n - b_n p_{n-1} + \varDelta a_{n+1} \frac{1}{b_{n+1}} p_n\right] \nonumber \\&= \varDelta b_{n+1} p_{n+1} + \frac{\varDelta a_{n+1} \varDelta b_{n+1}}{b_{n+1}} p_n. \end{aligned}$$
(30)

Thus, due to orthogonality of \(\{p_j\}_{j \ge 0}\), we have

$$\begin{aligned} G_{n, n+1}&= \int p_n(x) \widetilde{p}_{n+1}(x) \mathrm {d}\mu (x) {\mathop {=}\limits ^{(30)}} \frac{\varDelta a_{n+1} \varDelta b_{n+1}}{b_{n+1}} {\mathop {=}\limits ^{(25c)}} \frac{\varDelta a_{n+1}}{b_n}, \end{aligned}$$

which shows the first relation in (29). To show the second relation, first we combine (1) and (27) to show,

$$\begin{aligned} \widetilde{b}_{n+1} \hat{p}_{n+1}(x) = (x - a_{n+1}) p_n - b_n p_{n-1} = b_{n+1} p_{n+1}, \end{aligned}$$

so that

$$\begin{aligned} G_{n+1,n+1} = \int \hat{p}_{n+1}^2(x) \mathrm {d}\mu (x) = \left( \frac{b_{n+1}}{\widetilde{b}_{n+1}}\right) ^2 \int p_{n+1}^2(x) \mathrm {d}\mu (x) = (\varDelta b_{n+1})^2, \end{aligned}$$

proving the second relation. \(\square \)

The results (29) and (29) are the proposed approach: The moments \(G_{n,n+1}\) and \(G_{n+1,n+1}\) in (28a) and (28b) are polynomial moments that can be computed. We can subsequently use (29) and (25c) to compute the desired \(a_{n+1}\) and \(b_{n+1}\).

The methodology of this section can then be iterated in order to compute as many recurrence coefficients \(a_n\) and \(b_n\) as desired. However, we must compute the \(G_{n,n+1}\) and \(G_{n+1,n+1}\) coefficients (which are similar to the moments required by the Stieltjes procedure). The main difference in our algorithm is that we use moments to compute \(a_{n+1} - a_n\) and \(b_{n+1}/b_n\) that are typically close to 0 and 1, respectively, instead of simply \(a_n\) and \(b_n\), which in general can be arbitrarily small or large numbers. We next summarize one particular strategy for computing these moments assuming that a type of characterization of \(\mu \) is available.

3.2 Computation of Polynomial Moments

The previous section shows that we can compute recurrence coefficients for the measure \(\mu \) if we can compute some of its moments, in particular \(G_{n,n+1}\) and \(G_{n+1,n+1}\). We briefly describe in this section how we compute moments for measures of the form (4) with knowledge of the singularity behavior in (5). The moment of a polynomial q for \(\mu \) can be written as

$$\begin{aligned} \int q(x) \mathrm {d}\mu (x) = \sum _{j=1}^C \int _{I_j} q(x) w_j(x) \mathrm {d}x + \sum _{j=1}^M \nu _j q(\tau _j), \end{aligned}$$

so that the only difficult part is to compute \(\int _{I_j} q(x) w_j(x) \mathrm {d}x\) for each j.

Suppose first that \(I_j\) is compact, i.e., that \(I_j = [\ell , r]\) for finite \(\ell , r\). Then we rewrite the integral as

$$\begin{aligned} \int _{I_j} q(x) w_j(x) \mathrm {d}x&= \frac{r-\ell }{2} \int _{-1}^1 q(A(u)) w_j(A(u)) \mathrm {d}u,&A(u) :=\left( \frac{r-\ell }{2}\right) u + \frac{r + \ell }{2}. \end{aligned}$$

\(w_j\) obeying the limiting conditions (5) with constants \(\alpha _j,\beta _j\) implies that \(w_j(A(u))\) behaves like \((1 - u^{\alpha _j})\) near \(u = 1\), and like \((1 + u^{\beta _j})\) near \(u = -1\). When \(\alpha _j = \beta _j = 0\), then a global \(\mathrm {d}x\)-Gaussian quadrature rule will be efficient in evaluating this integral, but the accuracy will suffer when either constant differs from 0. To address this problem, we can further rewrite the integral as:

$$\begin{aligned} \int _{I_j} q(x) w_j(x) \mathrm {d}x = \frac{r-\ell }{2} \int _{-1}^1 q(A(u)) \omega _j(u) \mathrm {d}\mu ^{(\alpha _j,\beta _j)}(u), \end{aligned}$$

where \(\mu ^{(\alpha _j,\beta _j)}\) is a Jacobi measure on \([-1,1]\), and \(\omega _j\) is \(w_j\) multiplied by the appropriate factors,

$$\begin{aligned} \mathrm {d}\mu ^{(\alpha _j,\beta _j)}(u)&= (1-u)^{\alpha _j} (1+u)^{\beta _j} \mathrm {d}x,&\omega _j(u)&:=w_j(A(u)) (1-u)^{-\alpha _j} (1+u)^{-\beta _j}. \end{aligned}$$

The advantage of this formulation is that \(\omega _j\) is now smooth at the boundaries \(u = \pm 1\), and if in addition it is smooth on the interior of \([-1,1]\), then a Jacobi \((\alpha _j,\beta _j)\)-Gaussian quadrature rule will efficiently evaluate the integral. Therefore, if \(\left( u_k, \lambda _k\right) _{k=1}^K\) is a K-point Jacobi \((\alpha _j, \beta _j)\)-Gaussian quadrature rule, we approximate the integral as

$$\begin{aligned} \int _{I_j} q(x) w_j(x) \mathrm {d}x \approx \sum _{k=1}^K \lambda _k \omega _j(u_k) q(A(u_k)), \end{aligned}$$

where the nodes and weights can be computed through the spectrum of \(J_K(\mu ^{(\alpha _j, \beta _j)})\) since the recurrence coefficients of these measures are explicitly known. In particular, all the quadrature nodes \(u_k\) lie interior to \([-1,1]\), so that the above procedure does not require evaluation of \(\omega _j\) at \(u = \pm 1\). We adaptively choose K, i.e., increasing K until the difference between approximations is sufficiently small.

3.3 PCL: A Hybrid Predictor–Corrector Lanczos Method

The full procedure we describe in this section combines the strategies in Sects. 3.1 and 3.2, along with the (stabilized) Lanczos procedure in Sect. 2.6. Assuming that we a proiri know that the first N recurrence coefficients \(\{a_n, b_n\}_{n=0}^{N-1}\) are required for \(\mu \), then the main idea here is to construct a fully discrete measure \(\nu \) whose moments up to degree \(2N-2\) match those of \(\mu \).

We accomplish this as follows: Recall that the continuous densities \(\{w_j\}_{j=1}^C\) of the measure \(\mu \) in (4) are known, along with their boundary singularity behavior in (5). Then for each j, the PC procedure in Sects. 3.1 and 3.2 can be used to compute the first \(N+1\) recurrence coefficients for \(w_j\), \(\{a_{j,n}, b_{j,n}\}_{n=0}^{N}\). Using these recurrence coefficients, an N-point Gaussian quadrature rule \((x_{j,k}, \lambda _{j,k})_{k=1}^N\) can be computed that exactly integrates all polynomials up to degree \(2N-1\) with respect to the weight \(w_j\):

$$\begin{aligned} \int _{I_j} q(x) w_j(x) \mathrm {d}x&= \sum _{k=1}^N \lambda _{j,k} q\left( x_{j,k}\right) ,&\deg q&\le 2N-1. \end{aligned}$$

After this quadrature rule is computed for every \(j = 1, \ldots , C\), the discrete measure \(\nu \), defined as

$$\begin{aligned} \nu :=\sum _{j=1}^C \sum _{k=1}^N \lambda _{j,k} \delta _{x_{j,k}} + \sum _{j=1}^M \nu _j \delta _{\tau _j}, \end{aligned}$$
(31)

and has moments that match those of \(\mu \) up to degree \(2N-1\). Once this procedure is completed, we employ the Lanczos procedure in Sect. 2.6 to compute the first N recurrence coefficients for \(\nu \), which equal those for \(\mu \). The main reason we employ the Lanczos scheme (as opposed to any other approach) is that, for discrete measures, the Lanczos procedure appears more empirically stable than all other procedures we consider, cf. Sect. 4.5.

Note that if \(C = 1\) and \(M=0\), then the Lanczos procedure is not needed at all since \((a_{1,n}, b_{1,n})_{n=0}^{N-1}\) are the desired coefficients, and if \(C = 0\), then only the Lanczos procedure need be queried since no quadrature is required.

The above is essentially a complete description of the PCL algorithm. However, we include one additional adaptive procedure to ensure correct computation of the moments. Let \(\{N_s\}_{s \ge 0}\) be an increasing sequence of positive integers. A strategy for determining the sequence of \(N_s\) can be found in [11, 12],

$$\begin{aligned} N_0&= N,&N_s&= N_{s-1} + \varDelta _s,&s&= 1, 2, \dots , \\ \varDelta _1&= 1,&\varDelta _s&= 2^{\lfloor \frac{s}{5}\rfloor } N,&s&= 2, 3, \dots \ . \end{aligned}$$

We define \(\nu _s\) as the measure (31) with \(N \leftarrow N_s\). We use PCL to compute numerical approximations \(\{a_n^{[s]}, b_n^{[s]} \}_{n \ge 0}\) to the recurrence coefficients for \(\nu _s\). (I.e., we use PC to compute the \(N_s\)-point quadrature rule \((x_{j,k}, \lambda _{j,k})_{k=1}^{N_s}\) and subsequently use LZ to compute the recurrence coefficients for \(\nu _s\).) With the (approximate) coefficients for \(\nu _s\) and \(\nu _{s-1}\), if the condition

$$\begin{aligned} \left| b_n^{[s]} - b_n^{[s-1]} \right|&\le \epsilon |b_n^{[s]}|,&n&= 0, 1, \dots , N-1, \end{aligned}$$

is satisfied, then we return the computed coefficients for \(\nu _s\). Otherwise, we set \(s \leftarrow s+1\) and test the condition above again. This adaptive procedure is similar to those employed in [11, 12]. In our computations we set \(\epsilon = 10^{-12}\), and we set an upper limit of \(N_s\) as \(N_s^{\max } = 10 N\) for all s, which will usually be satisfactory.

4 Numerical Experiments

We now present numerical examples to illustrate the performance of our algorithm by computing the first N three-term recurrence coefficients for different types of measures \(\mu \). Our results will consider all the algorithms in Table 1: the first six in Sect. 2 and the last two new procedures proposed in Sect. 3. We implement all the algorithms in Python. All the computations are carried out on a MacBook Pro laptop with a 3.1 GHz Intel(R) Core(TM) i5 processor and 8 GB of RAM.

Examples can be classified according to whether we have a way to compute the exact recurrence coefficients. When this is the case, we define \(\{\hat{a}_n, \hat{b}_n\}_{n=0}^{N-1}\) as the first N exact coefficients and \(\{a_n, b_n\}_{n=0}^{N-1}\) as coefficients that are computed from any particular algorithm. The error \(e_N\) can be denoted by an \(\ell ^2\)-type norm,

$$\begin{aligned} e_N = \left( \sum _{n=0}^{N-1} \left[ \left( a_n - \hat{a}_n\right) ^2 + \left( b_n - \hat{b}_n\right) ^2\right] \right) ^{\frac{1}{2}}. \end{aligned}$$
(32)

If the exact coefficients are not available, we consider another error metric. If \(\{p_n(x)\}_{n=0}^{N-1}\) is a polynomial basis produced through the three-term recurrence (1) using the computed coefficients by \(\{a_n, b_n\}_{n=0}^{N-1}\), then let \(\varvec{A}\) be an \(N \times N\) matrix with entries

$$\begin{aligned} \left( \varvec{A}\right) _{m,n}&= \int _{{\mathbb {R}}} p_{n-1}(x)p_{m-1}(x) \mathrm {d}\mu (x),&n, m&= 1, \ldots , N, \end{aligned}$$

which equals \(\delta _{n,m}\) if \(\hat{a}_n = a_n\) and \(\hat{b}_n = b_n\). The new error indicator \(f_N\) we compute is

$$\begin{aligned} f_N = \left\| \varvec{A} - \varvec{I} \right\| _F, \end{aligned}$$
(33)

where \(\Vert \cdot \Vert _F\) is the Frobenius norm on matrices and \(\varvec{I}\) is the \(N \times N\) identity matrix.

The computational timing results that measure efficiency are averaged over 100 runs of any particular algorithm.

4.1 Freud Weights

One computational strategy for determining the recurrence coefficients for Freud weights of the form (3) on the entire real line is to use the (“non-modified”) Chebyshev algorithm, which requires monomial moments and employs a recurrence similar to (22). The monomial moments of (3) are explicitly computable as simple evaluations of the Euler Gamma function, but numerical instabilities typically develop in such an approach due to roundoff error; to combat this limitation, computations may be completed in variable precision arithmetic, resulting in a procedure that correctly computes the recurrence coefficients [14]. In this section, we use this VPA procedure to generate recurrence coefficients treated as “exact” for use in computing errors. In particular, we employ the sr_freud.m routine from [6] that utilizes variable-precision arithmetic in Matlab [17].

Fig. 1
figure 1

Example for Sect. 2.1: the top two plots are recursion coefficients \(b_N\) computed by DP, HD, aPC, MC and Freud conjecture in (10) and (12). The two plots at the bottom show errors \(e_N\) of SP and PC

We compute recurrence coefficients using the DP, HD, aPC, and MC methods for Freud exponents \(\alpha = 4, 6\). The DP recursion for each of the two cases is simple, given by (9) and (11), respectively. For the MC method, we use Hermite orthogonal family for \(q_k\) in (20) that is orthogonal with respect to \(\lambda \). The top two plots in Fig. 1 show that each of these methods is not computationally useful since instabilities develop quickly. In contrast, both the SP and PC approaches can effectively compute recurrence coefficients, which we show in the bottom two plots of Fig. 1. In terms of efficiency, Table 2 illustrates that the “exact” VPA procedure is several orders of magnitude more expensive than all other approaches, and that SP and PC are competitive. Code that reproduces this example is available in the routine ex_freud_4.py and ex_freud_6.py from [18].

Table 2 Example for Sect. 2.1: elapsed time (s) for Freud weight when \(\alpha = 4\) (subcolumns on the left) and \(\alpha = 6\) (subcolumns on the right)

4.2 Piecewise Smooth Weight

We consider the measure \(\mathrm {d}\mu (x) = w(x) \mathrm {d}x\) on \([-1,1]\), where

$$\begin{aligned} \omega (x) = {\left\{ \begin{array}{ll} \mid x\mid ^\gamma (x^2 - \xi ^2)^p (1 - t^2)^q, &{} x \in [-1, -\xi ] \cup [\xi , 1] \\ 0, elsewhere, &{} 0<\xi <1, p>-1, q>-1, \gamma \in {\mathbb {R}}. \end{array}\right. } \end{aligned}$$

For certain choices of \(\gamma , p, q\), there is theory regarding the resulting orthogonal polynomials [1], and such weights arise in applications [34]. In the special cases \(\gamma = \pm 1, p = q = \pm 1/2\), closed-form representations for the recurrence coefficients can be computed [9]. For example, the exact formula for the recurrence coefficients for the case \(\gamma = 1, p = q = -1/2, \eta = (1 - \xi )/(1 + \xi )\) is given by

$$\begin{aligned} \hat{b}_0&= \sqrt{\pi },&\hat{b}_1&= \sqrt{\frac{1 + \xi ^2}{2}}, \\ \hat{b}_{2n}&= \sqrt{\frac{(1 - \xi ^2) (1 + \eta ^{2n-2})}{4(1 + \eta ^{2n})}},&\hat{b}_{2n+1}&= \sqrt{\frac{(1 + \xi ^2) (1 + \eta ^{2n+2})}{4(1 + \eta ^{2n})}},&n \in {\mathbb {N}}, \end{aligned}$$

with \(\hat{a}_n = 0\) for all n.

Table 3 Example for Sect. 4.2: errors \(e_N\) (subcolumns on the left) and elapsed time (s) (subcolumns on the right) when \(\gamma = 1, p = q = -1/2\)

A Legendre orthogonal family for \(q_k\) in (20) that is orthogonal with respect to \(\lambda \) is chosen for the MC method. For the choice \(\gamma = 1, p = q = -1/2\) and \(\xi = 1/10\), Table 3 illustrates the accuracy and cost of the algorithms HD, aPC, MC, SP, and PC. We observe that only the SP and PC approaches yield reasonable accuracy, with PC being slightly more accurate. We omit results for other choices of \((\gamma , p, q)\), which produce nearly identical results. The results from this table can be produced from ex_pws.py in [18].

4.3 Transformed Discrete Chebyshev

In the previous example, we compute the recurrence coefficients of “continuous” orthogonal polynomials with respect to \(\mu \) on bounded or unbounded supports. We now consider the support of \(\mu \) that consists of a discrete set of points.

Given a positive number M, we define the nodes \(\tau _j = (j-1)/M\) and \(\nu _j = 1/M\) for \(j = 1, 2, \dots , M\). Then, the transformed discrete Chebyshev [12, Example 2.26] measure is given as

$$\begin{aligned} \mathrm {d}\mu (x)&= \sum _{j=1}^M \frac{1}{M} \delta _{\frac{j-1}{M}} \mathrm {d}x,&j = 1, 2, \dots , M, \end{aligned}$$

i.e., an equally spaced and equally weighted discrete measure on [0, 1). The recurrence coefficients are known explicitly if a linear transformation of variables is applied to the discrete Chebyshev measure with canonical support points [12, Section 1.5.2]. For a given size of supports, M, with \(\hat{b}_0 = 1\),

$$\begin{aligned} \hat{a}_n&= \frac{M-1}{2M},&\hat{b}_n&= \sqrt{\frac{1 - {(\frac{n}{M})}^2}{4(4 - {(\frac{n}{M})}^2)}},&n = 1, 2, \dots , M-1. \end{aligned}$$
Fig. 2
figure 2

Example for Sect. 4.3: the first three plots compute errors \(e_N\) for different N portion of distinct M and the last two plots for the same N but for distinct M

In Fig. 2, the methods HD, aPC and MC are omitted since their instabilities develop very quickly. An NaN value appears when the required number of recurrence coefficients, N, is less than 20. We compare the SP, LZ and PC approaches on measure support sizes \(M = 40, 80, 160, 320\). We observe that the LZ approach is effective for all choices of M, and when N is comparable to M, the SP and PC approaches become inaccurate. The lower two plots of Fig. 2 show that when M is notably larger than N, all three approaches produce good results. In particular, all the numerical results in this subsection are produced by ex_discrete_cheb.py in [18].

4.4 Discrete Probability Density Function

High-dimensional integration is a common problem in scientific computing arising from, for example, the need to estimate expectations in uncertainty quantification [27, 30]. Many integrands for such integrals found in scientific computing applications map a large number of input variables to an output quantity of interest, but admit low-dimensional ridge structure that can be exploited to accelerate integration. A ridge function [24] is a function \(f: {\mathbb {R}}^m \rightarrow {\mathbb {R}}\) of the form

$$\begin{aligned} f(\varvec{x}) = g(\varvec{a}^T \varvec{x}), \end{aligned}$$

where \(\varvec{a} \in {\mathbb {R}}^m\) is a constant vector called the ridge direction and \(g: {\mathbb {R}}\rightarrow {\mathbb {R}}\) is the ridge profile. For such functions, we clearly have that f depends only on a scalar variable \(y :=\varvec{a}^T \varvec{x}\). In applications, we frequently wish to integrate f with respect to some m-dimensional probability measure \(\rho \) on \(\varvec{x}\), which can be simplified by integrating over the scalar variable y with respect to the univariate measure \(\mu \) that is the push-forward of \(\rho \) under the map \(\varvec{x} \mapsto \varvec{a}^T \varvec{x}\). Thus, the goal is to compute recurrence coefficients for \(\mu \).

In practice the multivariate measure \(\rho \) is known, but computing the univariate measure \(\mu \) exactly is typically not feasible. However, an approximation to \(\mu \) can be furnished using the procedure in [15, Section 2.2] that randomly generates M i.i.d. samples \(\{\varvec{x}_j\}_{j=1}^M\) from \(\rho \), and defines \(\mu \) as a discrete measure supported on the projection of these samples onto the real line:

$$\begin{aligned} \mathrm {d}\mu (x)&= \sum _{j=1}^M \frac{1}{M} \delta _{\tau _j} \mathrm {d}x,&\tau _j&:=\varvec{a}^T \varvec{x}_j. \end{aligned}$$

To compute quadrature rules with respect to this measure, we take \(\rho \) as the uniform measure on the m-dimensional hypercube \([-1,1]^m\). Let \(m = 25\), and \(\varvec{a} \in {\mathbb {R}}^{25}\) is chosen randomly. We then test for \(M = 100, 300\).

Table 4 Example for Sect. 4.4: errors \(f_N\) when \(M = 100\) (subcolumns on the left) and \(M = 300\) (subcolumns on the right)

Since we do not have an expression for the exact recurrence coefficients, we measure errors using the metric \(f_N\) in (33). As shown in Table 4, the computed recursion coefficients are not as accurate when N is closer to M, no matter what method is used. However, the methods SP, LZ and PC all perform better when M is large enough.Code that reproduces this example is available in the routine ex_discrete_convolution.py in [18].

4.5 Multiple Component: Chebyshev Weight Function Plus a Discrete Measure

The measure to be considered is the normalized Jacobi weight function on \([-1,1]\) with a discrete M-point measure added to it,

$$\begin{aligned} \mathrm {d}\mu (x)&= (\beta _0^J)^{-1} (1-x)^{\alpha } (1+x)^{\beta } \mathrm {d}x + \sum _{j=1}^M \nu _j \delta _{\tau _j} \mathrm {d}x,&\alpha , \beta&> -1,&\nu _j&> 0, \end{aligned}$$
(34)

where \(\beta _0^J = \int _{-1}^1 (1-x)^{\alpha } (1+x)^{\beta } \mathrm {d}x\). The orthogonal polynomials belonging to the measure (34) are explicitly known only in very special cases. The case of one mass point at one end point, that is, \(M = 1, \tau _1 = -1\), has been studied and the recurrence coefficients can be computed with rather technical formulas [3, 11]. The exact recursion coefficients for \(N = 1, 7, 18, 40\) are given in [12, Table 2.11]. For each of these particular N, we compute the fixed-N error, donated by \(e_N^{f} = \left( \left( a_N - \hat{a}_N\right) ^2 + \left( b_N - \hat{b}_N\right) ^2\right) ^{1/2}\).

Table 5 shows results for the HD, aPC, MC, SP, and PC approaches for the measure \(\mu \) above. In addition, we compute results using the LZ approach; note that the LZ approach cannot directly be utilized on the measure (34) since this measure has an infinite number of support points. Instead, the LZ results shown in Table 5 first use the discretization approach as described in Sect. 2.6, which replaces the continuous part of \(\mu \) with a discrete Gaussian quadrature measure. The reason we include this test in Table 5 is that it motivates the PCL algorithm: if one can discretize measures, then the LZ approach is frequently more accurate than alternative methods.

Table 5 Example for Sect. 4.5: errors \(e_{N}^{f}\) with one mass at \(\tau _1 = -1\) with \(\nu _1 = 0.5\) (subcolumns on the left) and \(\tau _1 = 2\) with \(\nu _1 = 1\) (subcolumns on the right)

We generate the first 40 recursion coefficients for \(\alpha = -0.6, \beta = 0.4\) of the Jacobi parameters in two cases: one mass at \(\tau _1 = -1\) with strength \(\nu _1 = 0.5\) and a single mass point of strength \(\nu _1 = 1\) at \(\tau _1 = 2\). The results, produced by routine ex_multi_component.py from [18], are shown in Table 5. SP, LZ, PC and even MC produce essentially identical results within machine precision in the first case. However, matters change significantly when a mass point is placed outside \([-1, 1]\), regardless of whether or not the other mass points on \([-1, 1]\) are retained [12, Example 2.39]. SP and PC become extremely unstable; this empirical superiority of the LZ approach for discrete measures is the reason why the last step of the PCL algorithm in Sect. 3.3 is to utilize the Lanczos algorithm.

Table 6 Example for Sect. 4.6: errors \(f_N\) by procedure in 3.3 with \(N_s = N\) for all s (subcolumns on the left) and by PCL, i.e. with a adaptive procedure (subcolumns on the right) when \(M = 20, 40, 80, 160, 320\)

4.6 General Multiple Component: Continuous Weight Function Plus a Discrete Measure

In the previous example, we studied the case of a combination of Chebyshev weight and discrete measure. A quadrature for Chebyshev is trivial because it is one of the classical weights so that we can obtain the quadrature by known recursion coefficients. However, if the continuous weight is not of classical form, then we employ the PCL algorithm in Sect. 3.3: We use PC to compute recursion coefficients, leading to Gaussian quadrature nodes and weights for the continuous part, which is then combined with the discrete part as input to the LZ algorithm.

We consider the positive half-range Hermite measure plus a transformed discrete Chebyshev measure defined on \((-1,0]\),

$$\begin{aligned} \mathrm {d}\mu (x)&= e^{-x^2} + \sum _{j=1}^{M} \nu _j \delta _{\tau _j} \mathrm {d}x,&\tau _j&:=-\frac{j-1}{M},&\nu _j&:=\frac{1}{M}. \end{aligned}$$

Using the PCL algorithm, for \(M = 20, 40, 80, 160, 320\), we generate the first 100 recursion coefficients. Table 6 shows that the coefficients are more accurate when an adaptive procedure is applied to determine \(N_s\), no matter what M is. The results here are produced by routine ex_gmulti_component.py in [18].

5 Summary and Extensions

In this paper, we summarize several existing numerical methods for computing these recurrence coefficients associated to measures for which explicit formulas are not available. We propose a novel “predictor–corrector” algorithm and study the accuracy and efficiency by comparing with existing methods for fairly general measures. The method makes predictions for the next coefficients and correct them iteratively. Finally, we introduce a hybrid algorithm that combines the “predictor–corrector” algorithm and the (stabilized) Lanczos procedure. It can be used to compute recurrence coefficients for a general measure with multiple continuous and discrete components.

The predictor–corrector algorithm outperforms many other methods and is competitive with the Stieltjes procedure when a continuous measure is given. For a discrete measure, it can compute accurate coefficients only when the discrete support M is large enough. However, the (stabilized) Lanczos procedure requires empirically appears to be superior for discrete measures. Based on this observation, we propose a “predictor–corrector-Lanczos” algorithm is that is a hybrid of the predictor–corrector and Lanczos schemes, and applies to a fairly general class of measures.

We focus on the computation of recurrence coefficients for univariate orthogonal polynomial families. Thus, a natural extension of this work would be to adapt the approaches to address the same problem for multivariate polynomials, for which the formulations can be substantially more complex. Such investigations are the focus of ongoing work.