-
Notifications
You must be signed in to change notification settings - Fork 153
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
Is it possible to get rid of Complex{Num}
?
#884
Comments
Personally, I think The great thing about To say the truth, I also couldn't work out how to use julia> @variables z::Complex
1-element Vector{Complex{Num}}:
z
julia> Symbolics.substitute(z, Dict(z => 1+im))
1 + im But the following is broken: julia> Symbolics.substitute(2*z, Dict(z => 1+im))
ERROR: type ComplexTerm has no field metadata
Stacktrace:
[1] getproperty
@ ./Base.jl:38 [inlined]
[2] metadata(s::Symbolics.ComplexTerm{Real})
@ SymbolicUtils ~/.julia/packages/SymbolicUtils/H684H/src/types.jl:599
[3] substitute(expr::Symbolics.ComplexTerm{Real}, dict::Dict{Symbolics.ComplexTerm{Real}, Complex{Int64}}; fold::Bool)
@ SymbolicUtils ~/.julia/packages/SymbolicUtils/H684H/src/substitute.jl:34
[4] substitute
@ ~/.julia/packages/SymbolicUtils/H684H/src/substitute.jl:16 [inlined]
[5] #16#17
@ ~/.julia/dev/Symbolics/src/num.jl:87 [inlined]
[6] (::Symbolics.var"#16#19"{Symbolics.var"#16#17#20"{Dict{Symbolics.ComplexTerm{Real}, Complex{Int64}}}})(expr::Symbolics.ComplexTerm{Real})
@ Symbolics ~/.julia/dev/Symbolics/src/num.jl:87
[7] substitute(expr::Complex{Num}, s::Dict{Complex{Num}, Complex{Int64}}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Symbolics ~/.julia/dev/Symbolics/src/Symbolics.jl:156
[8] substitute(expr::Complex{Num}, s::Dict{Complex{Num}, Complex{Int64}})
@ Symbolics ~/.julia/dev/Symbolics/src/Symbolics.jl:156
[9] top-level scope
@ REPL[6]:1 See also #883 |
I think it's problematic to separate real and imaginary parts by default - there is specialized code for handling numerical operations on complex numbers natively. Where this exists, I want to use it! It would be nice if splitting into |
@shashi comments? |
Piggybacking this thread to say that the ComplexTerm bug would be fixed by #789 and this being unmerged is the last remaining blocker that I know of to solving complex PDEs like the Schrödinger equation in MOL |
Hello everyone! I'm new to GitHub, so I didn't quite understand if the pull request (is this a right name?) from the last comment already have effect on the package, but this piece of code: @variables a::Complex{Num}
a_c = conj(a)
substitute(a_c, Dict([a => 1im])) gives the same error to OP
So, can you clarify for me please if it's still WIP fix or am I doing something wrong? |
I merged that PR which fixes this "no field metadata" issue. I think |
After updating to v5.5.3 such that I have the fix from #789, performing substitute on a complex expression no longer fails, but it does not work as expected: using Symbolics;
@variables z::Complex{Num};
substitute(2 * z, Dict(z => 1)) The output is
|
I think I also met the problem when I'm trying to obtain the coefficient matrix of a series of complex linear equations. For example,
Because
|
The insistance of Symbolics.jl to separate the real and the imaginary parts of complex numbers is causing a host of issues when we expect complex numbers to be mere numbers. (Being a bit provocative, you could declare
Complex <: Real
, that should not cause too much problems...)Two examples.
First, a substitution that does not work as expected.
Second, a example that shows that separating real and imaginary parts may not be the good way for computations, so Symbolics.jl should not impose it.
Is there any way to avoid this behavior and have complex numbers behave the same hay as real numbers?
The text was updated successfully, but these errors were encountered: