JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://docs.sciml.ai/Symbolics/stable/
Other
1.35k stars 151 forks source link

Exponential / Logrithmic of Matrix{Num} not handled #220

Open Moelf opened 3 years ago

Moelf commented 3 years ago

Not sure if this is already accounted for in some roadmap/mega issue thread but,

julia> using Symbolics

julia> @variables t
1-element Vector{Num}:
 t

julia> a = rand(2,2);

julia> exp(a*t)
ERROR: MethodError: no method matching exp(::Matrix{Num})

┆Issue is synchronized with this Trello card by Unito

anandijain commented 3 years ago

i think there is an issue linking all the LA methods that need to be implemented

YingboMa commented 3 years ago

We don't have symbolic eigenvalue solvers. Also, I am not sure if it will be worth the time to implement it anyway. Maybe we can hard code matrix exponentials for N x N for N <= 3.

Moelf commented 3 years ago

I'm trying to obtain the time evolution (exp(-imtH)) given a Hamiltonian(H) in matrix representation so often the matrix is bigger than 3x3. (although for pedagogical purpose usually not much bigger)

leonandonayre commented 3 years ago

Since a is a matrix you need to use exp.() instead of exp()

YingboMa commented 3 years ago

Matrix exponential is not the same thing as exp..

raphaelchinchilla commented 3 years ago

Coming here from #259 because I have a similar issue.

Although there isn't (as far as I am aware) a method to symbolic compute eigen and eigvals and matrix exponential, one might still be interested in its symbolic representation, for instance for calculus or to use in a larger symbolic problem.

A possible solution would be to leave it "uncomputed" until one calls build_function on the expression.

YingboMa commented 3 years ago

Yes, that's good idea, and we can even write derivative rules on matrix exponentials.

raphaelchinchilla commented 3 years ago

There a lot of operations (especially with matrices) that could benefit of having a way to leave them uncomputed. The classical example in estimation problems is the derivative of log det(A) which is significantly easier to compute than log det.

Edit: Apparently with the new updates, when using the type Symbolic.Arr it leaves log det(A) uncomputed