Symbolics.jl
Symbolics.jl copied to clipboard
Prevent canonical form for complex equations
Expressions are brought to a canonical form automatically. Recently, the ::LiteralReal type was introduced to prevent this when it is desired to keep an expressions as it is for some reason (see here) . It would be nice if it was possible to also prevent changes for complex equations. At the moment, a complex equations is separated into two equations (real and imaginary part) automatically and this is not always desirable.
I'm not sure whether this should be an issue of Symbolics.jl or SymolicUtils.jl.
I had a similar problem in MOL, would be nice to have this.
Just so you know, LiteralReals work inside Complex numbers, although they do this annoying thing where they store a multiplication by false...
julia> @variables x::LiteralReal y::LiteralReal
2-element Vector{Num}:
x
y
julia> z = x*x + y * im
x*x + y*false + im*(y*true)
julia> z ~ 0
2-element Vector{Equation}:
x*x + (y*y)*false ~ 0
(y*y)*true ~ 0
@ChrisRackauckas I think this is old code you might have written. https://github.com/JuliaSymbolics/Symbolics.jl/blob/master/src/equations.jl#L90-L91
I can see how this is good for equation-based modeling though.
Currently the only representation of Complex numbers in Symbolics is Complex{Num} and internally it unwraps to ComplexTerm but that is not exposed to any user code. If this can be made better while also keeping the nice dispatch properties of Complex, that could be nice.
@YingboMa did all of the complex number handling.