# Why doesn't $(e^{A})^{-1} = e^{-A}$ hold for a symmetric matrix in Python?

$$e^A$$ is just the $$A$$ matrix with all of its elements exponentiated, called a matrix exponential.

It follows that the inverse $$(e^{A})^{-1} = e^{-A}$$ for square matrices, although I could find nothing on whether this is supposed to still hold for symmetric matrices. In my case $$A$$ is a symmetric matrix.

In Python, I try to test the previous equality, but found that it doesn't hold for a symmetric matrix. not sure why or if I've done something wrong

import numpy as np

A = np.array([[1.4,0.02,0.01],
[0.02,1.5,0.03],
[0.01,0.03,1.6]])
print(A)

print(np.linalg.inv(np.exp(A)))
print(np.exp(-A))


which outputs

[[1.4  0.02 0.01]
[0.02 1.5  0.03]
[0.01 0.03 1.6 ]]

[[ 0.27060306 -0.05136872 -0.04449588]
[-0.05136872  0.24409113 -0.04030659]
[-0.04449588 -0.04030659  0.21935596]]

[[0.24659696 0.98019867 0.99004983]
[0.98019867 0.22313016 0.97044553]
[0.99004983 0.97044553 0.20189652]]


The last two matrices should be equal to each other, but they're not

• I think your reasoning ultimately implies that the inverse of a matrix should equal the original matrix with each element inverted, and this is not the case even for symmetric matrices. – Richard Hardy Dec 11 '20 at 19:07
• no i wasn't going to take it that far. i will have to look for a way to disambiguate the matrix whose elements are exponentiated from the matrix exponential though. there doesn't seem to be a symbol for it since $e^A$ only can be used for the second – develarist Dec 11 '20 at 19:18
• I guessed you were not going to take it that far, but if you follow through your argumentation, I think you will end up at what I indicated. At least I ended up there following the post. (Possibly by mistake.) – Richard Hardy Dec 11 '20 at 19:21
• worth watching out that I don't do that nevertheless. thanks for pointing it out – develarist Dec 11 '20 at 19:23
• It would answer your question, because this is where the argument leads us to, and we know this cannot be correct. I was going to write this up, but you have already accepted another answer, so I will spare the effort. – Richard Hardy Dec 11 '20 at 19:25

This is a case of reasoning from a false premise.

1. The matrix exponential is not defined as the exponentiation of each element of a matrix. Instead, the definition of a matrix exponential is $$\exp(X) = \sum_{k=0}^\infty \frac{1}{k!} X^k$$ for a square matrix $$X$$.

If you want to exponentiate a matrix, you'll need to use a function like scipy.linalg.expm. However, note that matrix exponentials are not easily done in general. See: Cleve Moler, Charles Van Loan. "Nineteen Dubious Ways to Compute the Exponential of a Matrix, Twenty-Five Years Later". Society for Industrial and Applied Mathematics, Vol. 45, No. 1

2. The function np.exp doesn't compute a matrix exponential. Instead, it's a function that exponentiates the elements of A. The documentation tells you as much.

• but the function np.exp(A) does exponentiate the elements of $A$ – develarist Dec 11 '20 at 19:04
• Yes, it does exponentiate the elements of A. That's because np.exp is not a matrix exponential. Instead, it's a function that exponentiates the elements of A. The documentation tells you as much. – Sycorax Dec 11 '20 at 19:05
• (+1) Matrix exponent is scipy.linalg.expm – gunes Dec 11 '20 at 19:05
• @develarist It seems you have an outstanding question about the difference between a matrix exponential and exponentiating the elements of a matrix. This is perfectly fine, but it's a question of mathematics, not statistics. You'd best ask a question in math.SE, and be sure to explain what, specifically, is giving you trouble. – Sycorax Dec 11 '20 at 19:08
• I'm not going to troubleshoot your python problems, but the function has a documentation page. docs.scipy.org/doc/scipy/reference/generated/… so I don't think the problem lies with scipy. – Sycorax Dec 11 '20 at 19:11