Skip to content

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 b

Many 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.

Al-Mohy & Higham (2011), Algorithm 3.2, the algorithm of SciPy’s expm_multiply:

  1. Shift. A ← A − μI, with μ = trace(A)/n. This costs nothing, and e^{tμ} is put back at the end. A − μI is never formed: the products subtract μX.
  2. Degree and steps (their Code Fragment 3.1). Choose the Taylor degree m ≤ 55 and the number of steps s that minimize the number of products m·s, subject to α_p(tA)/s ≤ θ_m. Here α_p(X) = max(‖X^p‖₁^{1/p}, ‖X^{p+1}‖₁^{1/(p+1)}), with p ≤ 8.
    • Small ‖tA‖₁ (their (3.13)): ‖tA‖₁ itself is used.
    • Otherwise: the norms of the powers come from normest1, applied to X^p as p products.
  3. The steps. s steps of F ← T_m(tA/s) F. Each truncated Taylor series stops early once two consecutive terms are below tol ‖F‖_∞, where tol is 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.

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 series g_k = (−1)^{k+m} C(k−1, m)/k! of e^{−x} T_m(x).
  • Its self-checks:
    • θ_1 = 2u and θ_2 = (6u)^{1/2} to leading order;
    • |c_4| = 1/24 for m = 3.
  • The double row matches the published values to the digits printed, from Higham (2008), Table A.3 for m ≤ 30 and 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, since h_2(x) = −x²/2 + O(x³).
  • Selection. expm_multiply uses the table with the largest u not above the type’s own, as expm does.

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, a B with the wrong number of rows, or a NaN or infinite entry in A throws std::invalid_argument.
  • A ‖tA‖₁ that would need more than 2^50 steps throws std::overflow_error. The step count is bounded so that m·s cannot overflow a long.

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, and t of 1, −½ and 2.
  • The normest1 path: a skew-symmetric matrix of norm about 200.
  • The shift: a shift of 50.
  • Sparse: the 1-D Laplacian as a compressed2D at t from 0.1 to 10.
  • Complex: a Hermitian H with t = −i.
  • The rest: float, the vector overload, empty input and the errors.
  • 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.