fn

matrix_exp

Tensor
matrix_exp(A: Tensor)
source

Matrix exponential eAe^A.

Returns the matrix exponential

eA=k=0Akk!,e^A \,=\, \sum_{k=0}^{\infty} \frac{A^k}{k!},

which solves the matrix ODE Y˙=AY\dot Y = A Y with initial condition Y(0)=IY(0) = I. Computed by the scaling-and-squaring algorithm of Higham (2005) with a Padé [6/6] rational approximant:

  1. Scale A=A/2sA' = A / 2^s so that Aθ6\|A'\| \le \theta_6.
  2. Approximate ReAR \approx e^{A'} via Padé [6/6] using the even/odd polynomial splitting R=D1NR = D^{-1} N.
  3. Square RR a total of ss times to recover eA=R2se^A = R^{2^s}.

Parameters

ATensor
Square matrix of shape (*, n, n).

Returns

Tensor

eAe^A, shape (*, n, n).

Notes

Computational cost is O((s+6)n3)O((s + 6)\, n^3) where the scaling parameter s=log2(A/θ6)s = \lceil \log_2 (\|A\| / \theta_6) \rceil. The Frobenius norm is used here as a (conservative) proxy for the 1-norm — this may add one extra squaring step but keeps the result correct.

Differentiable: built entirely on matmul and inv, so autograd flows naturally. Batched inputs (ndim > 2) are handled element-wise.

Examples

>>> import lucid
>>> from lucid.linalg import matrix_exp
>>> A = lucid.tensor([[0.0, 1.0], [-1.0, 0.0]])  # 90-deg rotation generator
>>> matrix_exp(A)
Tensor([[ 0.5403,  0.8415],
        [-0.8415,  0.5403]])