<<

A practical framework for infinite-dimensional linear

Sheehan Olver∗ Alex Townsend†

ABSTRACT as discretize-then-solve. That is, the underlying infinite- We describe a framework for solving a broad class of infinite- dimensional is first approximated by a finite-dimensional dimensional linear equations, consisting of almost banded matrix, before the resulting linear system is solved by a stan- operators, which can be used to resepresent linear ordinary dard linear algebra method that is either direct, such as differential equations with general boundary conditions. The Gaussian elimination, or iterative, such as conjugate gradi- framework contains a data structure on which row opera- ent. tions can be performed, allowing for the solution of linear In contrast, we advocate an entirely different approach equations by the adaptive QR approach. The that solves the equation as an infinite-dimensional problem achieves Onopt complexity, where nopt is the number of and never discretizes the operator itself. To accomplish this degrees of freedom required to achieve a desired accuracy, task, we represent the (infinite-dimensional) operator by a which is determined adaptively. In addition, special suitable data structure that supports row manipulations di- product equations, such as partial differential equations on rectly on the representation of the operator, using lazy eval- rectangles, can be solved by truncating the operator in the uation to automatically extend the data in the representa- tion as needed. The row operations can be used to partially y-direction with ny degrees of freedom and using a general- ized Schur decomposition to upper triangularize, before ap- upper-triangularize the operator, and, for a large class of plying the adaptive QR approach to the x-direction, requir- problems (in particular non-singular ODEs), we can at some ing On2 nopt operations. The framework is implemented in point perturb the right-hand side by a small amount so that y x the still infinite-dimensional problem can be solved exactly the ApproxFun package written in the Julia programming language, which achieves highly competitive computational via a (finite-dimensional) back substitution step. The mathematical ground work for this approach is (F. costs by exploiting unique features of Julia. W. J.) Olver’s algorithm [11], which considers the solution of inhomogeneous three-term recurrence relationship. This Keywords is equivalent to solving an infinite-dimensional linear system Chebyshev, ultraspherical, partial differential equation, spec- involving a rank-1 perturbation of a tridiagonal operator: tral method, Julia       b0 b1 b2 b3 ··· u0 f0 γ1 α1 β1  u1 f1 1. INTRODUCTION        γ2 α2 β2  u  f  Linear equations play a fundamental role in scientific com-    2 =  2 .  ..      puting, with the classical examples including the numerical  γ3 α3 . u3 f3       solution of boundary value ordinary differential equations, ...... elliptic partial differential equations and singular integral . . . . equations. Practically all numerical methods for solving lin- The key observation is that the infinite-dimensional linear ear differential equations — e.g., finite difference, finite ele- system can be solved by Gaussian elimination without piv- arXiv:1409.5529v1 [math.NA] 19 Sep 2014 ment, collocation and Galerkin methods — can be described oting and that convergence to the minimal solution of the ∗School of and , The University of system — roughly, the solution (provided it exists) with the Sydney, Sydney, Australia. ([email protected]) fastest decaying entries — can be inferred as part of the † Department of Mathematics, Massachusetts Institute of algorithm. Back substitution then proceeds by perturbing Technology, 77 Massachusetts Avenue Cambridge, MA the right-hand side, as opposed to changing the infinite- 02139-4307. ([email protected]) dimensional operator. In the setting, where the operator is assumed to be invertible between two spaces, the minimal solution is the unique solution to the lin- ear equation. This approach was extended by Lozier to more Permission to make digital or hard copies of all or part of this work for general banded operators [9]. However, Gaussian elimina- personal or classroom use is granted without fee provided that copies are tion without pivoting is prone to numerical instability, and not made or distributed for profit or commercial advantage and that copies with this in mind the authors derived an adaptive QR ap- bear this notice and the full citation on the first page. To copy otherwise, to proach [13], using Givens rotations for the solution of linear republish, to post on servers or to redistribute to lists, requires prior specific ordinary differential equations (ODEs). The complexity of permission and/or a fee. opt Copyright 20XX ACM X-XXXXX-XX-X/XX/XX ...$15.00. Olver’s algorithm and the adaptive QR approach is O n , where nopt is the number of coefficients calculated, as deter- which returns a vector of the entries in the columns specified mined automatically by the convergence criteria. (Through- by cr. Similarly, each subtype of BandedOperator overrides out, an with a superscript “opt” is a number that is a routine called addentries!, which adds entries to specified determined adaptively as dictated by the particular prob- rows of a (finite) banded array1, and overrides a routine lem.) called bandinds that returns the range of the operator Similar in spirit to the current work is Hansen [7], which represented as a tuple (a, b). investigated the infinite-dimensional QR algorithm for spec- As an example, consider representing functionals and op- tral problems, though focusing on theoretical rather than erators that act on vectors of Taylor series coefficients, i.e., > practical matters. Our operator algebraic framework is heav- vectors of the form (u0, u1, u2,...) that correspond to the P∞ k ily influenced by the chebop system [4], which is part of series k=0 ukz . Evaluation at a point z is the functional 2 Chebfun [5], and provides an infinite-dimensional feel to Bz , [1, z, z ,... ] and thus we can create a subtype Tay- the user, though the underlying collocation method is the lorEvaluation, with single field z, that implements traditional approach of discretize-then-solve. Finally, the second author and Trefethen investigated continuous ana- getindex(B::TaylorEvaluation,cr)=B.z.^(cr-1). logues of matrix [16], where the emphasis is on We can also implement a TaylorDerivative operator to rep- representing smooth bivariate functions rather than opera- resent the banded operator, defined by e>De = k and tors. k k+1 zero otherwise, with band range 0 : 1. Finally, we can rep- In this work, we exploit the applicability of the adaptive resent multiplication by a polynomial of finite degree, says QR method for a general class of linear operators: banded Pm−1 k a(z) = k=0 akz with the Toeplitz operator defined by operators except for possibly a finite number of dense rows. > However, to make this competitive and useful for general ek T [a]ej = ak−j for 0 ≤ k − j ≤ m − 1, and zero otherwise. problems requires the following components: This is encoded in a TaylorMultiplication operator, which has a single field containing the coefficients of a as a vector 1. Abstract data types that can be overriden to represent of length m and a band range (1 − m):0. arbitrary (typically unbounded) banded operators and While our operators always act on infinite-dimensional dense functionals, as well as data structures to allow vectors, the entries of those vectors can represent coeffi- their algebraic manipulation. cients in many different bases. For example, in [13] vectors 2. Fast linear algebra on infinite-dimensional operators. represent expansion coefficients in the Chebyshev or ultras- This requires a carefully managed data structure that pherical basis. To ensure that the domain and range of two can encapsulate the full infinite-dimensional operator operators are consistent when, for instance, adding them to- at each stage of the linear algebra routines. gether, each operator must know the basis of its domain and range. This also allows us to automatically convert between Unfortunately, the specialized data structures that we de- bases to ensure that any operation can be performed in a velop also require very specific implementations of linear consistent manner. Therefore, we have a FunctionSpace algebra routines, prohibiting the traditional approach of re- abstract type so that operators can override domainspace ducing the problem to finite-dimensional linear algebra solv- and rangespace routines that return specific domain and able by LAPack. In [13], the C++ language was used to range spaces. When it exists, a banded conversion operator partially implement the framework for some simple exam- is implemented to convert between two spaces. ples; however, adding new operators required a complete re- The final components are structures that allow functional compilation, which is prohibitively time consuming for prac- and operator algebra. This consists of a PlusOperator, which tical use. As an alternative, the Julia programming lan- contains a list of BandedOperators that have the same range guage [2] provides a natural environment for implementing and domain spaces. The command “+” is then overridden both data structures and linear algebra algorithms. Fur- for BandedOperators, with an additional step of promoting thermore, the support for multiple dispatch allows for the the domain and range space whenever a banded conversion easy construction of data structures, and linear algebra can operator is available. Similarly, a TimesOperator is con- be performed remarkably efficiently due to on-the-fly com- structed to represent multiplication of operators, and “∗” is pilation. The ApproxFun package [12] implements the pro- similarly overloaded to promote spaces to ensure compati- posed framework in Julia. bility. Note that, if A and B have band range a : b and c : d, respectively, then the band range of A*B is (a + c):(b + d). 2. DATA STRUCTURES FOR OPERATORS To determine the entries of A*B up to row k, we determine We represent operators by one of the following fundamen- A up to row k, B up to row k+b and multiply as appropriate. tal abstract types: Similarly, a PlusFunctional is implement to represent ad- dition of Functionals and a TimesFunctional to represent 1. Functional: A data structure representing an opera- a times a . tor of size 1 × ∞. Functional BandedOperator As operators are manipulated algebraically, a tree struc- 2. BandedOperator: A data structure representing an op- ture is automatically constructed. Returning to the Taylor erator of size ∞ × ∞ that has a finite bandwidth with series example, we can represent the differential operator the bands ranging from a : b, where a ≤ 0 ≤ b. That 1 is, the kth row only has (possibly) nonzero entries in The use of the “!” suffix is a Julia convention that signi- columns a + k, . . . , b + k. fies a method that modifies one of its inputs, in this case, a banded array. We add, as opposed to overwrite, to make ad- A new functional, say NewFunctional, which is a subtype of dition of operators more efficient. The details of the banded Functional, must override a routine called getindex, array data structure are immaterial, but an n × n banded array with bands ranging from a : b can be represented by getindex(F::NewFunctional,cr::Range), an n × (b − a + 1) array. 1. F: A list of K Functionals.

2. B: A single BandedOperator of band range a:b. PlusOperator 3. bcdata:A K×(b−a+K) array containing the mutable entries of the boundary rows, where only the entries on and below the b − a super diagonal are used. T [b] TimesOperator 4. bcfilldata:A K × K array which dictates how the first K rows are filled in.

5. data: An n × n banded array with band range a : D D (b−a+K) containing the mutable entries of the banded T [a] operator. 6. filldata:A n×K array which dictates how the (K + Figure 1: General banded operators can be built up from 1)th through (K + n)th rows are filled in. elementary operators using PlusOperator and TimesOpera- If A is a MutableAlmostBandedOperator, then it represents tor. This tree represents the operator d a(z) d +b(z) being dz dz the ∞ × ∞ operator with the k, jth entry given by built up from differentiation operator D and multiplication  operators T . bcdata[k, j],   for 1 ≤ k ≤ K, 1 ≤ j < M + k,   K d d P a(z) +b(z) as DT [a]D +T [b], which has the tree struc-  i=1 bcfilldata[k, i]F[i][j], dz dz  ture as depicted in Figure 1. We expect the tree to be small  for 1 ≤ k ≤ K,M + k ≤ j,  in most cases, providing a SavedOperator type that wraps data[k − K, j], a banded operator to save its entries as they are computed. A[k, j] =  for K < k ≤ n + K, 1 ≤ j < M + k, We finally mention that there is an interlace operator that  K P filldata[k − K, i]F[i][j], takes two or more operators and alternates their entries.  i=1  This facilitates a natural extension to (small) systems of  for K < k ≤ n + K,M + k ≤ j,  differential equations, as well as problems posed on multiple B[k − K, j],  domains, where the continuity conditions are represented as  for n + K < k, functionals. This also allows us to work with doubly-infinite operators (e.g., operators acting on Fourier series), via in- where M = b − a + K. terlacing the non-negative and negative entries. We perform row operations that column-by-column intro- duce zeros below the diagonal. Therefore, when acting on 3. INFINITE-DIMENSIONAL LINEAR AL- rows k1 and k2 (with k1 < k2) the first k1 − 1 entries in both rows are already zero. Under such circumstances, K GEBRA remains fixed and the complexity of introducing zeros in the Using the above structure, we can represent quite general first n columns is O((K − a)2 n), with an O(n) growth of operators with boundary conditions by a list of K Func- data storage. We refer the reader to [13] for a precise de- tionals and a single BandedOperator. For example, scription on how this is achieved using Givens rotations. For solving linear equations, we also apply row operations d du 0 a(z) + b(z)u = f(z), u(1) = c1, u (1) = c2 to the right-hand side. If the initial right-hand side has dz dz a finite number of nonzero entries, then this can be done represented with Taylor series becomes adaptively. Suppose that, after introducing zeros below the  B  c  diagonal in the first n columns, the right-hand side happens 1 1 to have has zeros apart from its first n entries. Then it lies  B1D u = c2. DT [a]D + T [b] f in the span of the upper triangular component of A, and we can proceed with back-substitution, in O(n) operations, Here, the first entry is a TaylorEvaluation, the second en- see [13]. If the entries past the nth entry are small, we can try is a TimesFunctional with leaf nodes TaylorEvalua- truncate them to produce a new right-hand side, close to tion and TaylorDerivative, and the third entry is a Plu- the original right-hand side, so that the resulting equation sOperator, which is the root node of the tree structure de- is solvable by back substitution. We emphasize this is a dis- picted in Figure 1. This is an almost-banded operator, in tinct process from changing the operator: we can control the sense that it is a banded operator (with band range the effect of changing the right-hand side, and avoid issues (a − K):(b − K)) except for the first K dense rows. of causing an invertible operator to become non-invertible. We now wrap this operator by a MutableAlmostBande- We expect well-posed problems to converge via this method- dOperator, a mutable data structure that allows for row ology, see [13] for a proof in the case of non-singular ordinary operations, i.e., the addition of one row to the other. In this differential equations. case, the represented operator is an almost-banded operator Other linear algebra routines are also applicable in infinite where the first (K + n) rows are dense and n is an integer dimensions using row manipulations on the same data struc- that is selected adaptively. The remaining rows have band ture. For example, the null space of a banded operator can range (a − K):(b − a). More specifically, its fields are as be calculated by applying Givens rotations to the transpose follows: of the operator, see the null command in ApproxFun [12]. Still under investigation is whether the infinite-dimensional QL algorithm2 with Wilkinson shifts can be implemented � for calculating spectrum of operators. � �� �� � 4. INFINITE-DIMENSIONAL TENSOR EQUA- ��� ��� TIONS �

We finally consider general tensor equations with two terms �������������� � — that is, splitting rank 2 in the terminology of [14] — with � � � � � boundary conditions. We represent such equations as acting � ������ ������ ������ ������ ������ on an unknown ∞ × ∞ matrix X that satisfies: �� > > > > LXM + N XS = F,XBy = gy, BxX = gx , where F is an ∞×∞ matrix corresponding to a forcing term,

gx and gy are ∞ × Kx and ∞ × Ky matrices corresponding Figure 2: Computational time to solve Helmholtz equation to boundary condtions, Bx and By are vectors of Kx and with homogenous Dirichlet conditions and a forcing term Ky functionals, and L, M, N and S are banded operators. having nx × ny ones, ignoring the time for the QZ step. The Many standard linear PDEs on rectangles with boundary complexity is linear in nx. It takes less than 4 seconds to conditions — e.g., Helmholtz equation, Poisson equation, solve a PDE with 2.5 million unknowns. linear KdV and the semi-classical Schr¨odinger equation with a time-independent potential — can be written in this form using the ultraspherical to obtain banded for suitable matrices M˜ , S˜ and F˜ . We now modify the differential operators [14]. n n n Bartels–Stewart algorithm [1]. Using the generalized Schur The equation we wish to solve is an infinite-dimensional decomposition, we simultaneously quasi-upper triangular- analogue of a generalized Sylvester equation [6]. We adapt ize3 M˜ and S˜ via unitary matrices Q and Z that satisfy the approach of [14], which solved this equation by discretiz- n n QUZ> = M˜ and QT Z> = S˜ . Thus, writing Y = X(2)Z> ing and upper triangularizing in both dimensions, to now n n n (which is still ∞ × n) we have only discretizing in one dimension. Define the projection operator P : ∞ → n as n C C > > ˜ LYU + N YT = FnQ, BxY = gxQ. > > Pn(u0, u1,...) = (u0, u1, . . . , un−1) , For simplicity, assume that U and T are upper triangular and consider Xn, the ∞ × n(≡ ny) solution to the semi- (the adaption to quasi-upper triangular can be found in [1]). discretized equation: By multiplying the equation by en, we observe that the last > >  LXnMn + N XnSn = Fn, column of Y = y1 | · · · | yn satisfies > > BxXn = gxn,XnBn = gy, ˜ (UnnL + TnnN )yn = FnQen, Bxyn = gx. > > > where Mn = PnMPn , Sn = PnSPn , Bn = ByPn , gxn = > This equation has the form considered in the previous sec- Png and Fn = F Pn . x   tion and hence is solvable in Onopt operations with the Assume without loss of generality that B = (2) , x n IKy | Bn adaptive QR method (assuming that the sub-problem con- i.e., the principle Ky × Ky block of Bn is the identity ma- verges according to the convergence criteria). The next col- trix, see [14] for the procedure to ensure that this is true. umn satisfies Bxyn−1 = gxQen−1 and We incorporate the discretized boundary conditions into the

generalized Sylvester equation by removing the dependence (U(n−1)(n−1)L + T(n−1)(n−1)N )yn−1 = on the first Ky columns of Xn, i.e., introducing zeros in the ˜   > > FnQen−1 − U(n−1)nL + T(n−1)nN yn. first Ky rows of Mn and Sn via > > > > > > Thus, we can also calculate y . The procedure continues, LXn(Mn − Bn Mn,Ky ) + N Xn(Sn − Bn Sn,Ky ) = n−1 calculating each column of Y in turn. Afterwards, we recover Fn − Lgy − N gy, (2) (1) (2) (2)> Xn = YZ, and then Xn = gy − Xn Bn . 3 2 opt where Mn,Ky and Sn,Ky are the n × Ky principle subblocks The resulting method has a complexity of O ny + nynx , of M and S , respectively. opt n n where nx is the number of degrees of freedom needed to  (1) (2)  (1) 3  Partitioning Xn = Xn | Xn so that Xn is ∞ × Ky calculate the worst case column of Y . The O ny term (2) (2) is for the QZ algorithm used to determine the generalized and Xn is ∞ × (n − Ky), we see that Xn satisfies 2 opt Schur decomposition [10] and the O nynx term is for the (2) ˜ > (2) ˜> ˜ modified Bartels–Stewart algorithm. If ny  nx then this LXn Mn + N Xn Sn = Fn approach has a lower complexity than the fully discretized 2 3 3  In finite dimensions, the QL and QR algorithms are equiv- approach of [14], which achieved O ny + nx complexity for alent. In infinite dimensions this is no longer the case, and it fixed n and n . In Figure 2, we plot the time to solve is likely that only an infinite-dimensional QL algorithm can y x support shifts to induce faster convergence. The infinite- dimensional QL algorithm does not appear to have been in- 3A quasi-upper triangular is 2 × 2 block upper triangular, vestigated, unlike the the infinite-dimensional QR algorithm though generically the blocks on the diagonal are also upper [7] and the infinite-dimensional Toda flow [3]. triangular. Helmholtz’s equation [12] S. Olver, ApproxFun.jl v0.0.3, https://github.com/dlfivefifty/ApproxFun.jl, nx−1 ny−1 X X (2014). u + u + 100u = T (x)T (y), xx yy k j [13] S. Olver and A. Townsend, A fast and k=0 j=0 well-conditioned spectral method, SIAM Review, 55 u(±1, y) = u(x, ±1) = 0, (2013), pp. 462–489.

2 −1 [14] A. Townsend and S. Olver, The automatic solution on [−1, 1] , where Tk(x) = cos(k cos x) are Chebyshev of partial differential equations using a global spectral polynomials. We use the ultraspherical method to repre- method, submitted. sent the partial differential operator as a tensor product of [15] A. Townsend and L. N. Trefethen, An extension banded operators. of Chebfun to two dimensions, SIAM J. Sci. Comput., Remark If the operator is not of splitting rank 2, then 35 (2013), pp. C495–C518. in the discrete setting the approach of [14] is to represent [16] A. Townsend and L. N. Trefethen, Continuous the generalized Sylvester equation via a Kronecker product analogues of matrix factorizations, submitted. of the underlying matrices. This approach extends to the semi-discrete equations as well by interlacing the entries, but results in a substantially higher computational complexity.

Acknowledgments We acknowledge the support of the Australian Research Council through the Discovery Early Career Research Award (SO).

5. REFERENCES [1] R. H. Bartels and G. W. Stewart, Solution of the matrix equation AX + XB = C, Comm. ACM, 15 (1972), pp. 820–826. [2] J. Bezanson, S. Karpinski, V. B. Shah, and A. Edelman, Julia: A Fast Dynamic Language for Technical Computing, arXiv:1209.5145, (2012). [3] P. Deift, L. C. Li, and C. Tomei, Toda flows with infinitely many variables, J. Funct. Anal., 64 (1985) 358–402 [4] T. A. Driscoll, F. Bornemann, and L. N. Trefethen, The chebop system for automatic solution of differential equations, BIT Numer. Math., 48 (2008), pp. 701–723. [5] T. A. Driscoll, N. Hale, and L. N. Trefethen, editors, Chebfun Guide, Pafnuty Publications, Oxford, 2014. [6] J. D. Gardiner, A. J. Laub, J. J. Amato, and C. B. Moler, Solution of the Sylvester matrix equation AXBT + CXDT = E, ACM Trans. Math. Softw., 18 (1992), pp. 223–231. [7] A. C. Hansen, Infinite dimensional ; theory and applications, Proc. R. Soc. Lond. Ser. A, 466 (2008) pp. 3539–3559. [8] K. Julien and M. Watson, Efficient multi-dimensional solution of PDEs using Chebyshev spectral methods, J. Comp. Phys., 228 (2009), pp. 1480–1503. [9] D. W. Lozier, Numerical Solution of Linear Difference Equations, NBSIR Technical Report 80-1976, National Bureau of Standards, (1980). [10] C. B. Moler and G. W. Stewart, An algorithm for generalized matrix eigenvalue problems, SIAM J. Numer. Anal., 10 (1973), pp. 241–256. [11] F. W. J. Olver, Numerical solution of second-order linear difference equations, J. Res. Nat. Bur. Standards Sect. B, 71 (1967), pp. 111–129.