symengine / SymEngine.jl

Julia wrappers of SymEngine
MIT License
192 stars 43 forks source link

implement fallback `conj` to fix `dot` #233

Closed ranocha closed 2 years ago

ranocha commented 2 years ago

Right now on master,

julia> using SymEngine

julia> @vars x
(x,)

julia> using LinearAlgebra

julia> dot([1, x], [x, 0])
ERROR: MethodError: no method matching conj(::Basic)

real etc. is not really working properly right now, see #110 and

julia> using SymEngine

julia> @vars x
(x,)

julia> x == real(x)
true

julia> iszero(x - real(x))
true

Thus, this implemented fallback conj(x) = x is in accordance with the sensible definition

conj(x) = real(x) - (x - real(x))

for complex numbers.

I would like to get this merged into a new release of SymEngine.jl to allow further working with dot products of symbolic variables (which seem to be mostly real). Extensions to a proper support of complex numbers and further fixes should be discussed in #110 etc.

This fixes a problem reported by @ketch (dot product involving SymEngine.Basic variables representing real numbers).

isuruf commented 2 years ago

Thus, this implemented fallback conj(x) = x is in accordance with the sensible definition conj(x) = real(x) - (x - real(x))

This is almost true. For 2*IM, real(2*IM) == 0. (There's a definition for complex numbers further up in the file)

ranocha commented 2 years ago

What about the updated version? I get

julia> using SymEngine

julia> conj(2 * IM)
-2*im
ranocha commented 2 years ago

This should also make #196 obsolete

isuruf commented 2 years ago

Thanks

ranocha commented 2 years ago

Well, thank you for this nice package - great work!