Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex missing Euler's formula #591

Closed
AshtonSBradley opened this issue May 2, 2022 · 5 comments
Closed

Complex missing Euler's formula #591

AshtonSBradley opened this issue May 2, 2022 · 5 comments

Comments

@AshtonSBradley
Copy link

Symbolics doesn't seem to be able to evaluate/define complex exponentials

@variables x 

exp(im*x)

MethodError: no method matching decompose(::Symbolics.Num)

Closest candidates are:

decompose(!Matched::Integer) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/float.jl:642

decompose(!Matched::Rational) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/rational.jl:515

decompose(!Matched::FixedPointNumbers.Normed) at ~/.julia/packages/FixedPointNumbers/HAGk2/src/normed.jl:296

...

isfinite(::Symbolics.Num)@float.jl:538
exp(::Complex{Symbolics.Num})@complex.jl:663
top-level scope@[Local: 1](http://localhost:1235/edit?id=a6a8d612-c9ba-11ec-173e-49370558ac76#)

Defining the function

t(x) = cos(x)+im*sin(x)

and trying to simplify gives the right result, but fails to express it as complex exponential:

simplify(t(x)^2)

im*sin(2x) + cos(2x)

Also, higher order tests are slow to generate correct but needlessly complicated expressions

simplify(t(x)^6)

im*((cos(2x)^2 - 4(cos(x)^2)*(sin(x)^2))*sin(2x) + (2//1)*(cos(2x)^2)*sin(2x)) + (cos(2x)^2 - 4(cos(x)^2)*(sin(x)^2))*cos(2x) - 8(cos(x)^2)*(sin(x)^2)*cos(2x)
@AshtonSBradley
Copy link
Author

This seems to me to be required if complex numbers are to become first-class citizens of Symbolics

@AshtonSBradley AshtonSBradley changed the title Symbolics doesn't know Euler's formula Complex missing Euler's formula May 2, 2022
@AshtonSBradley
Copy link
Author

#558

@shashi
Copy link
Member

shashi commented May 2, 2022

@YingboMa any thoughts on this?

@AshtonSBradley
Copy link
Author

Using @syms gives quite different results. The exponential definition seems to work this time:

julia> @syms x
(x,)

julia> exp(im*x)
exp((im)*x)

but then the simplify step doesn't seem to work at all:

julia> t(x) = cos(x)+im*sin(x)
t (generic function with 1 method)

julia> simplify(t(x)^2)
((0 + 1im)*sin(x) + cos(x))^2

and yet

julia> simplify(exp(im*x)^2)
exp((0 + 2im)*x)

Not sure what the right way to handle this is - my knowledge of Symbolics is weak.

My intention is that I want to register some basic identities like exp(im*x) = cos(x)+im*sin(x) and the inverses for trig cos(x) = (exp(im*x)+exp(-im*x))/2, etc, and then I would expect to be able to derive identities by examining the real and imaginary parts of powers etc.

@oameye
Copy link

oameye commented Aug 2, 2024

I think this is somewhat resolved.

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

julia> exp(im*a)
cos(a) + im*sin(a)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants