Symbolics.jl icon indicating copy to clipboard operation
Symbolics.jl copied to clipboard

Derivative of `exp(im*x)` fails

Open SebastianM-C opened this issue 4 years ago • 4 comments

MWE

using Symbolics
Symbolics.derivative(exp(im*x),x)

gives

ERROR: MethodError: no method matching decompose(::Num)
Closest candidates are:
  decompose(::Integer) at float.jl:555
  decompose(::Float16) at float.jl:557
  decompose(::Float32) at float.jl:568
  ...
Stacktrace:
 [1] isfinite(x::Num)
   @ Base ./float.jl:453
 [2] exp(z::Complex{Num})
   @ Base ./complex.jl:642
 [3] top-level scope
   @ REPL[10]:1

Is this just a matter of defining a isfinite for Num? Edit: with

Base.isfinite(::Num) = true

it gives 0.

I'm using Symbolics v0.1.25

┆Issue is synchronized with this Trello card by Unito

SebastianM-C avatar May 13 '21 13:05 SebastianM-C

It does not fail at all, you could be more explicit. If you add @syms x::Real before, this would be the output

julia> Symbolics.derivative(exp(im*x),x)
(0 + 1im)*exp((im)*x)

leonandonayre avatar May 18 '21 22:05 leonandonayre

I defined x using the @variables macro. Using @syms like you pointed out works. Thank you. What is the difference between @variables and @syms (and when should I use each)?

SebastianM-C avatar May 18 '21 23:05 SebastianM-C

How to implement complex expand and use it to simplify? Like exp(im*x)=cos(x)+im*sin(x)

Lightup1 avatar Apr 21 '22 13:04 Lightup1

How to implement complex expand and use it to simplify? Like exp(im*x)=cos(x)+im*sin(x)

also my question https://github.com/JuliaSymbolics/Symbolics.jl/issues/591

AshtonSBradley avatar May 02 '22 10:05 AshtonSBradley