Full text
mathematics Article Computing the Matrix Exponential with an Optimized Taylor Polynomial Approximation Philipp Bader 1, Sergio Blanes 2,* and Fernando Casas 3 1Departament de Matemàtiques, Universitat Jaume I, 12071 Castellón, Spain; [email protected] 2Instituto de Matemática Multidisciplinar, Universitat Politècnica de València, 46022 Valencia, Spain 3IMAC and Departament de Matemàtiques, Universitat Jaume I, 12071 Castellón, Spain; [email protected] *Correspondence: [email protected].es Received: 11 November 2019; Accepted: 21 November 2019; Published: 3 December 2019 Abstract: A new way to compute the Taylor polynomial of a matrix exponential is presented which reduces the number of matrix multiplications in comparison with the de-facto standard Paterson-Stockmeyer method for polynomial evaluation. Combined with the scaling and squaring procedure, this reduction is sufficient to make the Taylor method superior in performance to Padé approximants over a range of values of the matrix norms. An efficient adjustment to make the method robust against overscaling is also introduced. Numerical experiments show the superior performance of our method to have a similar accuracy in comparison with state-of-the-art implementations, and thus, it is especially recommended to be used in conjunction with Lie-group and exponential integrators where preservation of geometric properties is at issue. Keywords: exponential of a matrix; scaling and squaring; matrix polynomials 1. Introduction Many differential equations arising in applications are most appropriately formulated as evolving on Lie groups or on manifolds acted upon Lie groups. Examples include fields such as rigid mechanics, Hamiltonian dynamics and quantum mechanics. In all these cases, it is of paramount importance that the corresponding approximations obtained when discretizing the equation also belong to the same Lie group. Only in this way are important qualitative properties of the continuous system inherited by the numerical approximations. For instance, in quantum mechanics, any approximation to the solution of the time-dependent Schrödinger equation has to evolve in the special unitary group, so as to guarantee that the total transition probability is preserved. Lie-group methods are a class of numerical integration schemes especially designed for this task, since they render by construction numerical approximations evolving in the same Lie group as the original differential equation [ 1 , 2 ]. In this sense, they belong to the domain of geometric numerical integration [ 3 , 4 ]. Here one is not only concerned with the classical accuracy and stability of the numerical algorithm, but in addition, the method must also incorporate into its very formulation the geometric properties of the system. This gives the integrator not only an improved qualitative behavior, but also allows for a significantly more accurate long-time integration than is the case with general-purpose methods. Geometric numerical integration has been an active area of research during the few last decades, and in fact, very efficient geometric integrators have been designed and applied in a variety of contexts where preserving qualitative characteristics is at issue. In the particular case of Lie-group methods, some of the most widely used are the Runge–Kutta–Munthe-Kaas family of schemes [ 2 ], and, in the case of explicitly time-dependent matrix linear ordinary differential equations, Y0=A(t , Y)Y , integrators Mathematics 2019,7, 1174; doi:10.3390/math7121174 www.mdpi.com/journal/mathematics
Mathematics 2019,7, 1174 2 of 19 based on the Magnus expansion [ 5 , 6 ]. In both instances, the discrete approximation is obtained as the exponential of linear combination of nested commutators, and it is this feature which guarantees that the approximation rests in the relevant Lie group. There are also other families of Lie-group methods that do not involve commutators at the price of requiring more exponentials per step [ 7 , 8 ]. It is then, of prime importance to compute, numerically, the matrix exponential as accurately and as fast as possible to render truly efficient integrators. Another class of schemes that have received considerable attention in the literature, especially in the context of stiff problems, is that formed by exponential integrators, both for ordinary differential equations and for the time-integration of partial differential equations [ 9 ]. For them, the numerical approximation also requires computing the exponential of matrices at every time step, and this represents, sometimes, a major factor in the overall computational cost of the method. One is thus led, when considering these types of methods, to the problem of computing the matrix exponential in an efficient way, and this was precisely the goal of the present work. As a matter of fact, the search for efficient algorithms to compute the exponential of a square matrix has a long history in numerical mathematics, given the wide range of its applications in many branches of science. Its importance is clearly showcased by the great impact achieved by various reviews devoted to the subject, e.g., [ 10 – 13 ], and the variety of proposed techniques. Our approach here consists of combining the scaling and squaring procedure with an optimized way of evaluating the Taylor polynomial of the matrix exponential function. With the ensuing cost reduction, a method for computing ehA , where h is the time step, is proposed using 2, 3, 4 and 5 matrix-matrix products to reach accuracy up to hp for p= 4, 8, 12 and 18, respectively. In combination with the scaling and squaring technique, this yields a procedure to compute the matrix exponential up to the desired accuracy at lower computational cost than the standard Padé method for a wide range of matrices hA . We also present a modification of the procedure designed to reduce overscaling that is still more efficient than state-of-the-art implementations. The algorithm has been implemented in MATLAB and is recommended to be used in conjunction with Lie-group and exponential integrators where preservation of geometric properties is at issue. Moreover, although our original motivation for this work comes from Lie-group methods, it turns out that the procedure we present here can also be used in a more general setting where it is necessary to compute the exponential of an arbitrary matrix. The plan of the paper is the following. In Section 2we summarize the basic facts of the standard procedure based on scaling and squaring with Padé approximants. In Section 3, we outline the new procedure to compute matrix polynomials, reducing the number of matrix products, whereas in Section 4we apply it to the Taylor polynomial of the exponential and discuss maximal attainable degrees at a given number of matrix multiplications. Numerical experiments in Section 5show the superior performance of the new scheme when compared to a standard Padé implementation using scaling and squaring (cf. MATLAB Release R2013a) (The MathWorks, Inc., Natick, MA, USA). Section 6 is dedicated to error estimates and adaptations to reduce overscaling along the lines of the more recent algorithms [ 14 ] (cf. MATLAB from Release R2016a), including execution times of several methods. Finally, Section 7contains some concluding remarks. This work is an improved and expanded version of the preprint [ 15 ], where the ideas and procedures developed here were presented for the first time. 2. Approximating the Exponential Scaling and squaring is perhaps the most popular procedure to compute the exponential of a square matrix when its dimensions runs well into the hundreds. As a matter of fact, this technique is incorporated in popular computing packages such as MATLAB ( expm ) and MATHEMATICA ( MatrixExp ) in combination with Padé approximants [10,14,16]. Specifically, for a given matrix A∈CN×N , the scaling and squaring technique is based on the key property eA=eA/2s2s ,s∈N. (1)
Mathematics 2019,7, 1174 3 of 19 The exponential eA/2s is then replaced by a rational approximation rm(A/ 2 s) ; namely, the [m/m] diagonal Padé approximant to ex . The optimal choice of both parameters, s and m , is determined in such a way that full machine accuracy is achieved with the minimal computational cost [14]. Diagonal [m/m]Padé approximants have the form (see, e.g., [17] and references therein) rm(A) = pm(−A)−1pm(A), (2) where the polynomial pm(x)is given by pm(x) = m ∑ j=0 (2m−j)!m! (2m)!(m−j)! xj j!, (3) so that rm(A) = eA+O(A2m+1) . In practice, the evaluation of pm(A) , pm(−A) is carried out trying to minimize the number of matrix products. For estimating the computational effort required, the cost of the inverse is taken as 4 / 3 the cost of one matrix product. For illustration, the computation procedure for r5(A)is given by [10] u5=Ab5A4+b3A2+b1I, v5=b4A4+b2A2+b0I, (−u5+v5)r5(A) = u5+v5 (4) with appropriate coefficients bj, whereas for r13(A), one has u13 =AA6b13A6+b11A4+b9A2+b7A6+b5A4+b3A2+b1I, v13 =A6b12A6+b10A4+b8A2+b6A6+b4A4+b2A2+b0I, (−u13 +v13)r13(A) = u13 +v13. (5) Here A2=A2 , A4=A2 2 and A6=A2A4 . Written in this form, it is clear that only three and six matrix multiplications and one inversion are required to obtain approximations of order 10 and 26 to the exponential, respectively. Diagonal Padé approximants rm(A) with m= 3, 5, 7, 9 and 13 are used, in fact, by the function expm in MATLAB. In the implementation of the scaling and squaring algorithm, the choice of the optimal order of the approximation and the scaling parameter for a given matrix A are based on the control of the backward error [ 10 ]. More specifically, given an approximation tn(A) to the exponential of order n , i.e., tn(A) = eA+O(An+1) , if one defines the function hn+1(x) = log(e−xtn(x)) , then tn(2−sA) = e2−sA+hn+1(2−sA)and tn(2−sA)2s=eA+2shn+1(2−sA)≡eA+∆A, where ∆A= 2 shn+1( 2 −sA) is the backward error originating in the approximation of eA . If in addition hn+1has a power series expansion hn+1(x) = ∞ ∑ k=n+1 ckxk with radius of convergence ω, then it is clear that khn+1(A)k ≤ ehn+1(kAk), where ehn+1(x) = ∞ ∑ k=n+1|ck|xk, and thus k∆Ak kAk=khn+1(2−sA)k k2−sAk≤ehn+1(k2−sAk) k2−sAk. (6)
Mathematics 2019,7, 1174 4 of 19 Given a prescribed accuracy u (for instance, u= 2 −53 ≃ 1.1 × 10 −16 , the unit roundoff in double precision), one computes θn=max{θ:ehn+1(θ)/θ≤u}. (7) Then, k∆Ak ≤ ukAk if s is chosen so that k 2 −sAk ≤ θn and (tn(2−sA))2s is used to approximate eA. In the particular case that tn is the [m/m] diagonal Padé approximant rm , then n= 2 m , and the values of θ2m are collected in Table 1when u is the unit roundoff in single and double precision for m= 1, 2, 3, 5, 7, 9, 13. According to Higham [ 10 ], m= 13 and therefore r13 , is the optimal choice in double precision when scaling is required. When kAk ≤ θ26 , the algorithm in [ 10 ] takes the first m∈ {3, 5, 7, 9, 13}such that kAk ≤ θ2m. This algorithm is later referred to as expm2005. Table 1. Values of θ2mfor the diagonal Padé approximant rmof order 2mwith the minimum number of products π for single and double precision. In bold, we have highlighted the asymptotically optimal order at which it is advantageous to apply scaling and squaring since the increase of θ per extra product is smaller than the factor 2 from squaring. The values for double precision are taken from ([16], Table A.1). π: 0 1 2 3 4 5 6 2m: 2 4 6 10 14 18 26 u≤2−24 8.46 ×10−48.09 ×10−24.26 ×10−11.88 3.93 6.25 11.2 u≤2−53 3.65 ×10−85.32 ×10−41.50 ×10−22.54 ×10−19.50 ×10−12.10 5.37 Padé approximants of the form (2) are not, of course, the only option one has in this setting. Another approach to the problem consists of using the Taylor polynomial of degree m as the underlying approximation Tnto the exponential; i.e., taking Tm(A) = ∑m k=0Ak/k! computed in an efficient way. Early attempts for efficiently evaluating matrix Taylor polynomials trace back to the work by Paterson and Stockmeyer [ 18 ]. When Tm(A) is computed according to the Paterson-Stockmeyer (P-S) procedure, the number of matrix products is reduced and the overall performance is improved for matrices of small norm, although it is less efficient for matrices with large norms [16,19–22]. In more detail, if the P–S technique is carried out in a Horner-like fashion; the maximal attainable degree is m= (k+ 1 )2 by using 2 k matrix products. The optimal choices for most cases then correspond to k= 2 (four products) and k= 3 (six products); i.e., to degree m= 9 and m= 16, respectively. The corresponding polynomials are then computed as T9(A) = 9 ∑ i=0 ciAi=f0+f1+ (f2+c9A3)A3A3, T16(A) = 16 ∑ i=0 ciAi=g0+g1+ (g2+ (g3+c16A4)A4)A4A4, (8) where ci=1/i! and fi= 2 ∑ k=0 c3i+kAk,i=0, 1, 2, gi= 3 ∑ k=0 c4i+kAk,i=0, 1, 2, 3, respectively. Here, A0=I , A1=A , and, as before, A2=A2 , A3=A2A , A4=A2A2 . In Table 2, we collect the values for the corresponding thresholds θm in (7) needed to select the best scheme for a given accuracy. They are computed by truncating the series of the corresponding functions ehm+1(θ) after 150 terms.
Mathematics 2019,7, 1174 5 of 19 Table 2. Values of θm in (7) for the Taylor polynomial Tm of degree m with the minimum number of products π for single and double precision. In bold, we have highlighted the asymptotically optimal order at which it is advantageous to apply scaling and squaring, since the increase of θ per extra product is smaller than the factor 2 from squaring. We have included degree 24 to illustrate that the gain is marginal over scaling and squaring for double precision ( θ24 − 2 θ18 = 0.04) and negative for single precision. π0 1 2 3 4 5 6 m1 2 4 8 12 18 24 u≤2−24 1.19 ×10−75.98 ×10−45.12 ×10−25.80 ×10−11.46 3.01 4.65 u≤2−53 2.22 ×10−16 2.58 ×10−83.40 ×10−44.99 ×10−22.99 ×10−11.09 2.22 In this work we show that it is indeed possible to organize the computation of the Taylor polynomial of the matrix exponential function in a more efficient way than the Paterson-Stockmeyer technique, so that with the same number of matrix products one can construct a polynomial of higher degree. When combined with scaling and squaring, this procedure allows us to construct a more efficient scheme than with Padé approximants. 3. A Generalized Recursive Algorithm Clearly, the most economic way to construct polynomials of degree 2 k is by applying the following sequence, which involves only kproducts: A1=A, A2= (x1I+x2A1)(x3I+x4A1), A4= (x5I+x6A1+x7A2)(x8I+x9A1+x10 A2), (9) A8= (x11I+x12A1+x13A2+x14A4)(x15I+x16A1+x17A2+x18 A4), . . . Notice the obvious redundancies in the coefficients since some can be absorbed by others through factoring them out from the sums. These polynomials are then linearly combined to form T2k=y0I+y1A1+y2A2+y3A4+y4A8+···+yk+1A2k. Here the indices in A , A2k , are chosen to indicate the highest attainable power; i.e., A2k= O(A2k) . A simple counting tells us that with k products one has (k+ 1 )2+ 1 parameters to construct a polynomial of degree 2 k containing 2 k+ 1 coefficients. It is then clear that the number of coefficients grows faster than the number of parameters, so that this procedure cannot be used to obtain high degree polynomials, as already noticed in [ 18 ]. Even worse, in general, not all parameters are independent and this simple estimate does not suffice to guarantee the existence of solutions with real coefficients. Nevertheless, this procedure can be modified in such a way that additional parameters are introduced, at the price, of course, of including some extra products. In particular, we could include new terms of the form (γ1I+z1A1)(γ2I+z2A1+z3A2), not only in the previous Ak , k> 2, but also in T2k , which would allow us to introduce a cubic term and an additional parameter. Although the Paterson-Stockmeyer technique is arguably the most efficient procedure to evaluate ageneral polynomial, there are relevant classes of polynomials for which the P–S rule involves more products than strictly necessary. To illustrate this feature, let us consider the evaluation of Ψ(k,A) = I+A+···+Ak−1, (10)
Mathematics 2019,7, 1174 6 of 19 a problem addressed in [ 23 ]. Polynomial (10) appears in connection with the integral of the state transition matrix and the analysis of multirate sampled data systems. In [ 23 ] it is shown that with three matrix products one can evaluate Ψ( 7, A) (as with the P–S rule), whereas with four products it is possible to compute Ψ( 11, A) (one degree higher than using the P–S rule). In general, the savings with respect to the P–S technique grow with the degree k . The procedure was further improved and analyzed in [ 24 ], where the following conjecture was posed: the minimum number of products to evaluate Ψ(k , A) is 2 blog2kc− 2 +ij−1 , where N= (ij , ij−1 , . . . , i1 , i0)2 (written in binary); i.e., ij−1 is the second most significant bit. This conjecture is not true in general, as is illustrated by the following algorithm of type (9) , that allows one to compute Ψ(9, A)by using only three matrix products: A2=A2,B=x1I+x2A+x3A2, A4=x4I+x5A+B2, (11) A8= (x6A2+A4)A4, Ψ(9, A) = x7I+x8A+x9A2+A8, with x1=−5+6√7 32 ,x2=−1 4,x3=−1, x4=3(169 +20√7) 1024 , x5=3(5+2√7) 64 ,x6=3√7 4,x7=1695 4096,x8=267 512,x9=21 64. These coefficients are obtained by equating the expression for Ψ( 9, A) in (11) with the corresponding polynomial (10) with k= 9 and solving the resulting nine equations in xi , i= 1, . . . 9. Notice that, since these equations are nonlinear, the coefficients are irrational numbers. Although by following this approach it is not possible to achieve degree 16 with four products, there are other polynomials of degree 16 that can indeed be computed with only four products. This is the case, in particular, of the truncated Taylor expansion of the function cos(A): T16 = 8 ∑ i=0 (−1)iA2i (2i)!=cos(A) + O(A17). Taking B=A2 we obtain a polynomial of degree 8 in B that can be evaluated with three additional products in a similar way as in the computation of Ψ(9, A), but with different coefficients. 4. An Efficient Procedure to Evaluate the Taylor Polynomial Approximation Tn(A) Algorithm (9) can be conveniently modified along the lines exposed in the previous section to compute the truncated Taylor expansion of the matrix exponential function Tn(A) = n ∑ i=0 Ai i!=eA+O(An+1), (12) for different values of n using the minimum number of products. In practice, we proceed in the reverse order: given a number k , we find a convenient (modified) sequence of type (9) that allows one to construct the highest degree polynomial Tn(A) using only k matrix products. The coefficients in the sequence satisfy a relatively large system of algebraic nonlinear equations. Here, several possibilities may occur: (i) the system has no solution; (ii) there is a finite number of real and/or complex solutions, or (iii) there are families of solutions depending on parameters. In addition, if there are several solutions we take a solution with small coefficients to avoid large round off errors due to products of large and small numbers.
Mathematics 2019,7, 1174 7 of 19 Remark 1. Notice that in general, there are a multitude of ways to decompose a given polynomial but for our purposes, we only need one solution with real coefficients. Furthermore, the procedure described in (9) is modified below using an additional product A3=A2A to reach degrees higher than eight. With k= 0, 1, 2 products we can evaluate Tn for n= 1, 2, 4, in a similar way as the P–S rule, whereas for k=3, 4, 5 and six products, the situation is detailed next. k=3 products In this case, only T6 can be determined with the P–S rule, whereas the following algorithm allows one to evaluate T8: A2=A2, A4=A2(x1A+x2A2), A8= (x3A2+A4)(x4I+x5A+x6A2+x7A4), T8(A) = y0I+y1A+y2A2+A8. (13) Algorithm (13) is a particular example of the sequence (9) with some of the coefficients fixed to zero to avoid unnecessary redundancies. The parameters xi , yi are then determined of course by requiring that T8(A) = ∑8 i=0Ai/i! and solving the corresponding nonlinear equations. With this sequence we get two families of solutions depending on a free parameter, x3 , which is chosen to (approximately) minimize the 1-norm of the vector of parameters. The reasoning behind this approach is to avoid multiplications of high powers of A by large coefficients, in a similar vein as in the Horner procedure. The coefficients in (13) are given by x1=x3 1+√177 88 ,x2=1+√177 352 x3,x4=−271 +29√177 315x3 , x5=11(−1+√177) 1260x3 ,x6=11(−9+√177) 5040x3 ,x7=89 −√177 5040x2 3 , y0=1, y1=1, y2=857 −58√177 630 , x3=2/3. Perhaps surprisingly, T7(A) requires at least four products, so T8 may be considered a singular polynomial. k=4 products Although polynomials up to degree 16 can in principle be constructed by applying the sequence (9) , our analysis suggests that the Taylor polynomial (12) corresponding to eA does not belong to that family. The reason can be traced back to the fact that our procedure with four products to build polynomials only provides up to five independent parameters into the coefficients in T16 multiplying the matrices A11 , A12 , . . . , A16 . In other words, we have to solve a system of six equations with five independent variables, which have no solution in general, and this is precisely what happens for this particular problem. In consequence, as pointed out previously, some variations in our strategy have to be introduced. More specifically, we take Tn(A) for a given value of n and decompose it as a product of two polynomials of lower degrees plus a lower degree polynomial (that will be used to evaluate the higher degree polynomials). The highest value we have managed to reach is n= 12. It is important to note that this ansatz gives many different ways to write the sought polynomial. The following sequence, in particular, is comparable to Padé and Horner methods with respect to relative errors.
Mathematics 2019,7, 1174 8 of 19 A2=A2, A3=A2A, B1=a0,1I+a1,1A+a2,1A2+a3,1A3, B2=a0,2I+a1,2A+a2,2A2+a3,2A3, B3=a0,3I+a1,3A+a2,3A2+a3,3A3, B4=a0,4I+a1,4A+a2,4A2+a3,4A3, A6=B3+B2 4 T12(A) = B1+ (B2+A6)A6. (14) This ansatz has four families of solutions with three free parameters which can be obtained in closed form with a symbolic algebra package. Using the free parameters, we have minimized the 1-norm of the coefficients ∑i,j|ai,j|and obtained a0,1 =−0.01860232051462055322, a0,2 =4.60000000000000000000, a0,3 =0.21169311829980944294, a0,4 =0, a1,1 =−0.00500702322573317730, a1,2 =0.99287510353848683614, a1,3 =0.15822438471572672537, a1,4 =−0.13181061013830184015, a2,1 =−0.57342012296052226390, a2,2 =−0.13244556105279963884, a2,3 =0.16563516943672741501, a2,4 =−0.02027855540589259079, a3,1 =−0.13339969394389205970, a3,2 =0.00172990000000000000, a3,3 =0.01078627793157924250, a3,4 =−0.00675951846863086359. Although we report here 20 digits for the coefficients, they can be in fact determined with arbitrary accuracy. k=5 products With five products, n= 18 is the highest value we have been able to achieve. We write T18 as the product of two polynomials of degree 9, that are further decomposed into polynomials of lower degree. The polynomial is evaluated through the following sequence: A2=A2,A3=A2A,A6=A2 3, B1=a0,1I+a1,1A+a2,1A2+a3,1A3, B2=b0,1I+b1,1A+b2,1A2+b3,1A3+b6,1A6, B3=b0,2I+b1,2A+b2,2A2+b3,2A3+b6,2A6, B4=b0,3I+b1,3A+b2,3A2+b3,3A3+b6,3A6, B5=b0,4I+b1,4A+b2,4A2+b3,4A3+b6,4A6, A9=B1B5+B4, T18(A) = B2+ (B3+A9)A9. (15) Proceeding in an analogous way, i.e., requiring that T18(A) in (15) agrees with the Taylor expansion of the exponential, ∑18 i=0Ai/i!, we get the coefficients
Mathematics 2019,7, 1174 9 of 19 a0,1 =0, a1,1 =−0.10036558103014462001, a2,1 =−0.00802924648241156960, a3,1 =−0.00089213849804572995, b0,1 =0, b1,1 =0.39784974949964507614, b2,1 =1.36783778460411719922, b3,1 =0.49828962252538267755, b6,1 =−0.00063789819459472330, b0,2 =−10.9676396052962062593, b1,2 =1.68015813878906197182, b2,2 =0.05717798464788655127, b3,2 =−0.00698210122488052084, b6,2 =0.00003349750170860705, b0,3 =−0.09043168323908105619, b1,3 =−0.06764045190713819075, b2,3 =0.06759613017704596460, b3,3 =0.02955525704293155274, b6,3 =−0.00001391802575160607, b0,4 =0, b1,4 =0, b2,4 =−0.09233646193671185927, b3,4 =−0.01693649390020817171, b6,4 =−0.00001400867981820361. k=6 products With six products we can reconstruct the Taylor polynomial up to degree n= 22 by applying the same strategy. We have also explored different alternatives, considering decompositions based on the previous computation of low powers of the matrix— A2 , A3 , A4 , A8 , etc., to achieve degree n= 24, but all our attempts have been in vain. Nevertheless, we should remark that even if one could construct T24(A) with only six products, this would not lead to a significant advantage with respect to considering one scaling and squaring (s=1 in Equation (1)) applied to the previous decomposition for T18. In Table 3we show the number of products required to evaluate Tn by applying the P–S rule and the new decomposition strategy. The improvement for k≥3 products is apparent. Remark 2. As it should be clear from Tables 1and 2, T18 (for the Taylor method) and r13 (for the Padé scheme) are the default choices when scaling and squaring is needed. Remark 3. A seemingly obvious observation would be that the same optimization technique we have presented here for polynomial evaluation could also be applied to the numerator and denominator of Padé approximants. That this is not the case for the exponential can be grasped by noticing that the Padé scheme rn(A) = pn(−A)−1pn(A) requires the simultaneous evaluation of two polynomials for which better optimizations exist; cf. (4) (three products), (5) (six products). Notice that if our improvements for polynomial evaluation start from degree 8, then we could compute p17(−A)−1p17(A) = u8(B)−Av8(B)−1[u8(B) + Av8(B)],B=A2, for some polynomials of degree eight, u8 , v8 ,which requires seven products ( A2 , Av8 , three products for u8(B) and only two for v8 since B2 is reused). At one extra product, we thus increase the threshold to θ17 = 9.44 which is less than 2θ13 =10.74 at the same cost. The addition of this method to a scheme could, therefore, only improve the stability because it would avoid scaling for θ13 <kAk ≤ θ17 but does not have an impact on the computational cost and is, therefore, not examined further in this work. For completeness, using T12 , r25 can be computed using eight products, but again, θ25 = 18.7 < 2 θ17 = 18.9 < 4 θ13 = 21.5. With T18 , we can compute r37, but then θ37 =33.7 <22θ17 =37.8 <23θ13 =41.3. Remark 4. Concerning the effects of rounding errors on the evaluation of the Taylor polynomials for the exponential with the new decomposition, it is not difficult to obtain error bounds similar to those existing when applying the Horner and Paterson-Stockmeyer techniques ([ 25 ]; Theorem 4.5 of [ 19 ]). If we apply (13)–(15), then we determine polynomials ˆ Tm , m= 8, 12, 18, respectively, as Tm , but with the coefficients slightly perturbed
Mathematics 2019,7, 1174 16 of 19 Remark 6. For small matrix dimensions, it can be more efficient to explicitly compute matrix powers instead of using a sophisticated norm estimation algorithm. This is implemented in MATLAB for dimensions smaller than 150 ×150. We point out that the additional products that are computed in this case can be used to increase the order of the Taylor methods following the procedures described in this work. The new problem formulation is then: given a set of matrix powers, which is the largest degree (Taylor) polynomial which can be computed at a given number of extra matrix products? Algorithm expm3 is compared next with the refined method expm2009 [ 14 ], which is based on Theorem 1(b) for the Padé approximants and additionally implements further estimates to refine the scaling parameter. The experimental setup is identical to the one of Figure 2. Recall that the computational cost of matrix norm estimates is not taken into account for either algorithm. The results are shown in Figure 4. The relative errors of the two methods are very similar. From the lower left panel, a clear cost advantage over the algorithm based on Padé approximants is apparent. −4−2 0 2 4 −20 −18 −16 −14 −12 log10(exp. condition number) log10 krelative errork2 expm2009[2] expm3 024 0 2 4 6 8 10 12 log10(exp. condition number) Scalings −4−2 0 2 4 −2 −1 0 1 2 log10(exp. condition number) log10 rel. error: expm3/expm2009 −4−2 0 2 4 0.6 0.8 1 1.2 1.4 log10(exp. condition number) rel. cost: expm3/expm2009 Figure 4. Comparison of algorithms expm3 and expm2009 [ 14 ] for matrices of dimension ≤ 16 × 16. Cf. Figure 2. Finally, we have made a more extensive comparison of a variety of implementations tabulated in Table 4. The performance profiles of the stated methods on a larger test set of special and random matrices predominantly of dimension n×n/ 1024 × 1024 are displayed in Figure 5. Since the computation of the exact solution for this large test set was too costly, we only illustrated the performance plots for the number of required matrix products and the corresponding run times. The gain in computational speed is evident but less pronounced for some matrices because of the overhead from the norm estimations, which scale with O(n2) . For example, we can deduce that for 50% of the test matrices, the Padé methods require at least 50% more computational time.
Mathematics 2019,7, 1174 17 of 19 Table 4. Algorithms used for Figure 5grouped as: simple algorithms without norm estimates of type dk incorporated ( expm2005 , expm2 ); sophisticated algorithms to avoid overscaling ( expm2009 [ 14 ], expm3 ); and an optimized official implementation from MATLAB ( expm2016 ), which contains several additional tweaks and modifications for expm2009 [14]. expm2005 Padé algorithm [10] as expm in MATLAB Release R2013a. expm2 Our Algorithm 1using the decomposition of this work. expm3 Our Algorithm 2modified to avoid overscaling. expm2009 [14] Algorithm 3.2 from [ 14 ], based on Padé approximants and norm estimations through Theorem 1. expm2016 Padé algorithm from [ 14 ] as expm in MATLAB Release R2016a. This implementation contains special tweaks for small matrices, symmetric matrices Schur-decompositions and block structures. A highly relevant application of the matrix exponential is the (numerical) solution of matrix differential equations. Numerical methods such as exponential integrators, Magnus expansions or splitting methods typically force small matrix norms due to the small time-step inherent to the methods. In this case, the proposed algorithm expm2 should be highly advantageous. 1 1.2 1.41.61.8 2 0 0.2 0.4 0.6 0.8 1 factor probability # products expm2005 expm2 expm3 expm2009[2] expm2016 11.522.53 0 0.2 0.4 0.6 0.8 1 factor comput. time Figure 5. Performance profiles for matrices of dimensions ≤ 1024 × 1024. We have used 2500 matrices from the MATLAB matrix gallery, special matrices that are prone to overscaling, nilpotent matrices and random matrices, as indicated in Remark 5. 7. Concluding Remarks We have presented a new way to construct the Taylor polynomial, approximating the matrix exponential function up to degree 18, requiring less products than the Paterson-Stockmeyer technique. This reduction of matrix products is due to a particular factorization of the polynomial in terms of polynomials of lower degrees, where the coefficients of the factorization satisfy a system of algebraic equations. The algorithm requires 2, 3, 4 and 5 matrix-matrix products to reach accuracy up to order 4, 8, 12 and 18, respectively, showing similar cost to 1–2.5 commutators. In combination with scaling and squaring, this yields a procedure to compute the matrix exponential up to the desired accuracy at lower computational cost than the standard Padé method for a wide range of matrices. Based on estimates of the form kAkk1/k and the use of scaling and squaring, we have presented a modification of our algorithm to reduce overscaling that is still more efficient than state-of-the-art implementations with a slightly lower accuracy for some matrices but higher accuracy
Mathematics 2019,7, 1174 18 of 19 for others. The loss in accuracy can be attributed to possible overscalings due to a reduced number of norm estimations compared with Padé methods. In practice, the maximal degree considered for the Taylor polynomial is 18 and the reduction in the number of matrix products required is due to a particular factorization of the polynomial in terms of polynomials of lower degrees whose coefficients satisfy an algebraic system of nonlinear equations. The overall algorithm has been implemented as two different MATLAB codes, available at [ 27 ]. The function expm2 corresponds to the simplest implementation based on the previous factorizations of the Taylor polynomials, whereas expm3 incorporates additional tools to deal with overscaling. Both are designed to be used in all circumstances where the standard MATLAB function expm is called, and should provide equivalent results but requiring less computation time. Although the technique developed here, combined with scaling and squaring, can be applied in principle to any matrix, it is clear that, in some cases, one can take advantage of the very particular structure of the matrix A , and then design especially tailored (and very often more efficient) methods for such problems [ 2 , 31 , 32 ]. For example, if one can find an additive decomposition A=B+C such that kCk is small and B is easy to exponentiate, i.e., eB is sparse and exactly solvable (or can be accurately and cheaply approximated numerically), and C is a dense matrix, then more efficient methods can be found in [ 12 , 33 ]. Exponentials of upper or lower triangular matrices A have been treated in [ 14 ], where it is shown that it is advantageous to exploit the fact that the diagonal elements of the exponential are exactly known. It is then, more efficient to replace the diagonal elements obtained numerically by the exact solution before squaring the matrix. This technique can also be extended to the first super or sub-diagonal elements. We plan to adapt this technique to other special classes of matrices appearing in physics, and in particular to compute in an efficient way the exponential of skew-Hermitian matrices, of great relevance in the context of quantum physics and chemistry problems. For the convenience of the reader, we provide in [ 27 ], in addition to the MATLAB implementations of the proposed schemes, the codes generating all the experiments and results reported here. Author Contributions: All authors have contributed in the same proportion to this work. Funding: This work was funded by Ministerio de Economía, Industria y Competitividad (Spain) through project MTM2016-77660-P (AEI/FEDER, UE). P.B. was additionally supported by a contract within the Program Juan de la Cierva Formación (Spain). Conflicts of Interest: The authors declare no conflict of interest. References 1. Celledoni, E.; Marthinsen, H.; Owren, B. An introduction to Lie group integrators: Basics, new developments and applications. J. Comput. Phys. 2014,257 Pt B, 1040–1061. [CrossRef] 2. Iserles, A.; Munthe-Kaas, H.Z.; Nørsett, S.P.; Zanna, A. Lie group methods. Acta Numer. 2000 ,9, 215–365. [CrossRef] 3. Blanes, S.; Casas, F. A Concise Introduction to Geometric Numerical Integration; CRC Press: Boca Raton, FL, USA, 2016. 4. Hairer, E.; Lubich, C.; Wanner, G. Geometric Numerical Integration. Structure-Preserving Algorithms for Ordinary Differential Equations, 2nd ed.; Springer: Berlin, Germany, 2006. 5. Blanes, S.; Casas, F.; Oteo, J.A.; Ros, J. The Magnus expansion and some of its applications. Phys. Rep. 2009, 470, 151–238. [CrossRef] 6. Casas, F.; Iserles, A. Explicit Magnus expansions for nonlinear equations. J. Phys. A Math. Gen. 2006 ,39, 5445–5461. [CrossRef] 7. Celledoni, E.; Marthinsen, A.; Owren, B. Commutator-free Lie group methods. Future Gener. Comput. Syst. 2003,19, 341–352. [CrossRef] 8. Crouch, P.E.; Grossman, R. Numerical integration of ordinary differential equations on manifolds. J. Nonlinear Sci. 1993,3, 1–33. [CrossRef] 9. Hochbruck, M.; Ostermann, A. Exponential integrators. Acta Numer. 2010,19, 209–286. [CrossRef]
Mathematics 2019,7, 1174 19 of 19 10. Higham, N.J. The scaling and squaring method for the matrix exponential revisited. SIAM J. Matrix Anal. Appl. 2005,26, 1179–1193. [CrossRef] 11. Moler, C.B.; Van Loan, C.F. Nineteen dubious ways to compute the exponential of a matrix, twenty-five years later. SIAM Rev. 2003,45, 3–49. [CrossRef] 12. Najfeld, I.; Havel, T.F. Derivatives of the matrix exponential and their computation. Adv. Appl. Math. 1995 , 16, 321–375. [CrossRef] 13. Sidje, R.B. Expokit: A software package for computing matrix exponentials. ACM Trans. Math. Softw. 1998 , 24, 130–156. [CrossRef] 14. Al-Mohy, A.H.; Higham, N.J. A new scaling and squaring algorithm for the matrix exponential. SIAM J. Matrix Anal. Appl. 2009,31, 970–989. [CrossRef] 15. Bader, P.; Blanes, S.; Casas, F. An improved algorithm to compute the exponential of a matrix. arXiv 2017 , arXiv:1710.10989. 16. Higham, N.J.; Al-Mohy, A.H. Computing matrix functions. Acta Numer. 2010,19, 159–208. [CrossRef] 17. Baker, G.A., Jr.; Graves-Morris, P. Padé Approximants, 2nd ed.; Cambridge University Press: Cambridge, UK, 1996. 18. Paterson, M.S.; Stockmeyer, L.J. On the number of nonscalar multiplications necessary to evaluate polynomials. SIAM J. Comput. 1973,2, 60–66. [CrossRef] 19. Higham, N.J. Functions of Matrices: Theory and Computation; Society for Industrial and Applied Mathematics: Philadelphia, PA, USA, 2008. 20. Ruiz, P.; Sastre, J.; Ibáñez, J.; Defez, E. High perfomance computing of the matrix exponential. J. Comput. Appl. Math. 2016,291, 370–379. [CrossRef] 21. Sastre, J.; Ibáñez, J.; Ruiz, P.; Defez, E. New scaling-squaring Taylor algorithms for computing the matrix exponential. SIAM J. Sci. Comput. 2015,37, A439–A455. [CrossRef] 22. Sastre, J. Efficient evaluation of matrix polynomials. Linear Algebra Its Appl. 2018,539, 229–250. [CrossRef] 23. Westreich, D. Evaluating the matrix polynomial I+A+···+AN−1 .IEEE Trans. Circuits Sys. 1989 ,36, 162–164. [CrossRef] 24. Lei, L.; Nakamura, T. A fast algorithm for evaluating the matrix polynomial I+A+···+AN−1 .IEEE Trans. Circuits Sys. I Fundam. Theory Appl. 1992,39, 299–300. [CrossRef] 25. Higham, N.J. Accuracy and Stability of Numerical Algorithms; Society for Industrial and Applied Mathematics: Philadelphia, PA, USA, 1996. 26. Arioli, M.; Codenotti, B.; Fassino, C. The Padé method for computing the matrix exponential. Linear Algebra Its Appl. 1996,240, 111–130. [CrossRef] 27. Bader, P.; Blanes, S.; Casas, F. An Efficient Alternative to the Function Expm of Matlab for the Computation of the Exponential of a Matrix. Available online: http://www.gicas.uji.es/Research/MatrixExp.html (accessed on 1 November 2019). 28. Kenney, C.S.; Laub, A.J. A Schur-Fréchet algorithm for computing the logarithm and the exponential of a matrix. SIAM J. Matrix. Anal. Appl. 1998,19, 640–663. [CrossRef] 29. Dieci, L.; Papini, A. Padé approximation for the exponential of a block triangular matrix. Linear Algebra Its Appl. 2000,308, 183–202. [CrossRef] 30. Higham, N.J.; Tisseur, F. A block algorithm for matrix 1-norm estimation, with an application to 1-norm pseudospectra. SIAM J. Matrix Anal. Appl. 2000,21, 1185–1201. [CrossRef] 31. Celledoni, E.; Iserles, A. Approximating the exponential from a Lie algebra to a Lie group. Math. Comput. 2000,69, 1457–1480. [CrossRef] 32. Celledoni, E.; Iserles, A. Methods for the approximation of the matrix exponential in a Lie-algebraic setting. IMA J. Numer. Anal. 2001,21, 463–488. [CrossRef] 33. Bader, P.; Blanes, S.; Seydao˘glu, M. The scaling, splitting and squaring method for the exponential of perturbed matrices. SIAM J. Matrix Anal. Appl. 2015,36, 594–614. [CrossRef] c 2019 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).