The Action of the Matrix Exponential
#include <mtl/operation/expm_multiply.hpp>
auto F = mtl::expm_multiply(A, B, t); // e^{tA} B, without forming e^{tA}auto y = mtl::expm_multiply(A, b); // e^{A} b for a dense_vector bMany uses of the exponential need only its action on a few vectors:
- a step of a linear ODE
x' = A x; - an exponential integrator;
- a continuous-time Markov chain’s distribution
e^{tQ} p; - a quantum step
e^{−iHt} ψ.
For a large sparse A, e^{tA} is dense. Forming it costs O(n³) time and
O(n²) memory, while the action needs only products with A.
How it is computed
Section titled “How it is computed”Al-Mohy & Higham (2011), Algorithm 3.2, the algorithm of SciPy’s
expm_multiply:
- Shift.
A ← A − μI, withμ = trace(A)/n. This costs nothing, ande^{tμ}is put back at the end.A − μIis never formed: the products subtractμX. - Degree and steps (their Code Fragment 3.1). Choose the Taylor degree
m ≤ 55and the number of stepssthat minimize the number of productsm·s, subject toα_p(tA)/s ≤ θ_m. Hereα_p(X) = max(‖X^p‖₁^{1/p}, ‖X^{p+1}‖₁^{1/(p+1)}), withp ≤ 8.- Small
‖tA‖₁(their (3.13)):‖tA‖₁itself is used. - Otherwise: the norms of the powers come from
normest1, applied toX^paspproducts.
- Small
- The steps.
ssteps ofF ← T_m(tA/s) F. Each truncated Taylor series stops early once two consecutive terms are belowtol ‖F‖_∞, wheretolis the element type’s unit roundoff.
Sparse A. A is used only through its stored entries
(detail::for_each_entry), so a compressed2D costs O(nnz) per product. B is
a dense n × n0 block, or a dense_vector.
Precision: θ_m follows the element type
Section titled “Precision: θ_m follows the element type”The truncated Taylor series has the backward error T_m(X)^s = e^{sX + s h_{m+1}(X)},
with h_{m+1}(x) = log(e^{−x} T_m(x)) (Al-Mohy & Higham 2011, §3). θ_m is the
largest θ with Σ_k |c_k| θ^{k−1} ≤ u, where c_k are the coefficients of
h_{m+1}.
- The generator.
tools/expm_multiply_theta.py(mpmath) solves this for nine unit roundoffs, from bfloat16 to binary256, using the exact seriesg_k = (−1)^{k+m} C(k−1, m)/k!ofe^{−x} T_m(x). - Its self-checks:
θ_1 = 2uandθ_2 = (6u)^{1/2}to leading order;|c_4| = 1/24form = 3.
- The double row matches the published values to the digits printed, from
Higham (2008), Table A.3 for
m ≤ 30and Al-Mohy & Higham (2011), Table 3.1 beyond:θ_5 = 2.40·10⁻³,θ_10 = 0.144,θ_30 = 3.54,θ_40 = 5.97(6.0 there),θ_55 = 9.87(9.9 there);- the exception is
θ_1, 2.22·10⁻¹⁶ here, where Table A.3 prints 2.29·10⁻¹⁶. The value here is the leading-order value 2u, sinceh_2(x) = −x²/2 + O(x³).
- Selection.
expm_multiplyuses the table with the largestunot above the type’s own, asexpmdoes.
Element types. It is generic: + − × ÷, comparisons, abs, and exp of
the real type by ADL (with cos and sin for a complex element type, for
e^{tμ}). The p-th roots in step 2 are computed by Newton’s method in the
real type. t has the element type, so t = −i works for a complex A.
Errors:
- A non-square
A, aBwith the wrong number of rows, or a NaN or infinite entry inAthrowsstd::invalid_argument. - A
‖tA‖₁that would need more than 2^50 steps throwsstd::overflow_error. The step count is bounded so thatm·scannot overflow along.
tests/unit/operation/test_expm_multiply.cpp compares against expm(tA) B:
- Dense matrices: norms from 0 to 5,
n ≤ 12, one or three columns, andtof 1, −½ and 2. - The
normest1path: a skew-symmetric matrix of norm about 200. - The shift: a shift of 50.
- Sparse: the 1-D Laplacian as a
compressed2Dattfrom 0.1 to 10. - Complex: a Hermitian
Hwitht = −i. - The rest:
float, the vector overload, empty input and the errors.
References
Section titled “References”- A. H. Al-Mohy and N. J. Higham, “Computing the action of the matrix exponential, with an application to exponential integrators”, SIAM J. Sci. Comput. 33(2), 488–511, 2011.
- N. J. Higham and F. Tisseur, “A block algorithm for matrix 1-norm estimation”, SIAM J. Matrix Anal. Appl. 21(4), 1185–1201, 2000.
- N. J. Higham, Functions of Matrices: Theory and Computation, SIAM, 2008, Table A.3.