# Testing Matrix Function Algorithms Using Identities

*Edvin Deadman and Nick Higham (University of Manchester) write:*

In a previous blog post we explained how testing new algorithms is difficult. We discussed the *forward error* (how far from the actual solution are we?) and the *backward error* (what problem have we actually solved?) and how we'd like the backward error to be close to the unit roundoff, *u*.

For matrix functions, we also mentioned the idea of using identities such as sin* ^{2}A + *cos

^{2}*A = I*to test algorithms. In practice, rather than

*I*, we might find that we obtain a matrix

*R*close to

*I*, perhaps with

*||R-I||*10

^{-13}. What does this tell us about how the algorithms for sin

*A*and cos

*A*are performing? In particular, does it tell us anything about the backward errors? We've just written a paper which aims to answer these questions. This work is an output of NAG's Knowledge Transfer Partnership with the University of Manchester, so we thought we'd blog about it here.

Let's consider the identity exp*(*log *A) - A = 0*. Suppose that when we evaluate the left-hand side in floating point arithmetic we get a nonzero residual *R* rather than *0*. We'll assume that this residual is caused by some backward errors *E _{1}* and

*E*so that exp

_{2}*(*log

*(A + E*

_{1}) +*E*. We'd like to investigate how big

_{2}) = R*R*can be when

*E*and

_{1}*E*are small, so we expand the left-hand side in a Taylor series to linear order. After a bit of algebra, the result is a

_{2}*linear operator*relating

*R*to

*E*and

_{1}*E*:

_{2}*R = L(*

*E*,

_{1}*E*

_{2}*)*. The operator is different for each identity considered, but it always involves the Fréchet derivatives of the matrix functions in the identity (the full gory details, including formulae for the linear operators associated with various identities, are in our paper).

We now have two options. The first option is to estimate the norm of the linear operator. This enables us to determine the maximum value of *||R|| *consistent with backward errors of size *u*. The second option is to use the linear operator to explicitly estimate *E _{1}* and

*E*. This works just as well, but it is more expensive.

_{2}Our paper contains several examples demonstrating our approach in practice, so we'll just pick one here, involving the matrix exponential. The 10 x 10 Forsythe matrix is

*u =*2

^{-53}

*10*

^{-16}(the unit roundoff). It's known that the Schur-Parlett general-purpose matrix function algorithm struggles with this matrix, whereas algorithms based on scaling and squaring have no such problems. Does our approach reflect this behaviour? Using the identity

*e*, the maximum normwise residual consistent with backward stability is found to be 7.1 x 10

^{A }e^{-A}= I^{-15}. The Schur-Parlett approach gives a normwise residual of 7.7 x 10

^{-11}, but the scaling and squaring algorithm gives a residual of 2.2 x 10

^{-15}. Consistent with this, the backward error estimates are 2.5 x 10

^{-11}and 4.5 x 10

^{-16}respectively. So our approach has correctly identified the preferred algorithm.