I just started using SageMath to do some linear algebra computations. The exponential map $\exp$ is built in for matrices. Is the logarithm
$$\log(u) = (u-I) - \frac{1}{2}(u-I)^2 + \frac{1}{3}(u-I)^3 - \cdots$$
also built in? For nilpotent (unipotent) matrices, $\exp$ ($\log$) gives finite sums, and I want to make use of the identities
$$\exp \circ \log(u) = u, \log \circ \exp(X) = X$$
for unipotent $u$ and nilpotent $X$.
You can convert your matrix to numpy and use logm of SciPy:
To convert numpy array to Sage matrix use:
Obs: convert numpy array to sage matrix directly gave error in some cases, so one should convert to numpy matrix before converting to sage matrix.
If you need log often it may be convenient to do a function:
with Input and Output sage matrix.
Note that
exp(log_matrix(M))-Mandlog_matrix(exp(M))-Mdiffers from the null matrix with an error of the order of $1e-15$.