JuliaHomotopyContinuation / HomotopyContinuation.jl

A Julia package for solving systems of polynomials via homotopy continuation.
https://www.JuliaHomotopyContinuation.org
MIT License
185 stars 30 forks source link

`conj` of `Expression` silently ignored #499

Closed baggepinnen closed 2 years ago

baggepinnen commented 2 years ago

Hello! I found a potential bug when calling conj on a complex expression

julia> b[1]*im
im*b₁

julia> conj(b[1]*im)
im*b₁

the expected result would be

julia> conj(b[1]*im)
-im*b₁
saschatimme commented 2 years ago

This is intentional (see also https://github.com/JuliaHomotopyContinuation/HomotopyContinuation.jl/issues/402). Complex conjugation is not algebraic and by defining it correctly we could not use any of the default linear algebra methods like dot

baggepinnen commented 2 years ago

I'm not sure I understand, if the package doesn't support conj, wouldn't an error be more appropriate than returning the wrong result?

ChrisRackauckas commented 6 months ago

Yes I'm not sure I understand, why does this not error?

PBrdng commented 6 months ago

Yes I'm not sure I understand, why does this not error?

Hi @ChrisRackauckas, the motivation for this is that on computational algebraic geometry one often encounters expressions like $\langle f,g\rangle$ where $f,g$ are systems of real polynomials and $\langle f,g\rangle = f^Tg$ is the usual Euclidean inner product. Since we compute over the complex numbers, we complexify and also look at $f^Tg$ for complex polynomials. Then, it is convenient to being able to write dot(f,g).

Furthermore, even if we defined conj( x* im) = -im * x, dot(f,g) will still not give the Hermitian inner product of f and g, because variables are not conjugated. This is, in fact, not possible to implement, since complex conjugation is not algebraic and so this case would not be covered by our algorithms.

Nevertheless, I see your point that it can cause confusion. In what context do you encounter this issue?

ChrisRackauckas commented 6 months ago

I'm seeing reports of HomotopyContinuation giving wrong values. It seems if there's an issue with supporting complex numbers due to this that you should just error if complex conjugation is used, rather than giving the wrong result.

PBrdng commented 6 months ago

Erroring if complex conjugation is used is not an option, because then we would not be able to use dot. A warning could be an option.

Can you specify where the errors are reported? I'm sure users wanted to use Hermitian inner product, but this is not algebraic and can't be solved (this is a theoretical obstruction!)

ChrisRackauckas commented 6 months ago

Erroring if complex conjugation is used is not an option, because then we would not be able to use dot. A warning could be an option.

That's unrelated. Why not make the error dispatch only for Complex?

PBrdng commented 6 months ago

This might work when implementing dot directly (note that Expression is <: Number). But, let me check if this would break anything else...

A warning message would not be a solution?

PBrdng commented 6 months ago

By the way, if you receive errors reports please invite people to send me an email. There could also be other reasons fpr errors and I am happy to help.