JuliaAlgebra / MultivariatePolynomials.jl

Multivariate polynomials interface
https://juliaalgebra.github.io/MultivariatePolynomials.jl/stable/
Other
135 stars 27 forks source link

Complex polynomials #212

Open projekter opened 2 years ago

projekter commented 2 years ago

I would like to discuss your thoughts and possibilities to add more support for complex-valued variables to the polynomials. This was already partially mentioned in #11 (conjugation). In #116, it was mentioned that conjugation of variables is not an algebraic operation and therefore should not be considered at all; but while this is a package in JuliaAlgebra, the package description is quite general and support for this would be helpful in some instances, so I hope we can have a fruitful discussion.

Let me first give the example why this is important for me: Of course, one can easily say that every complex variable is just the sum of two real variables with complex coefficients (and since coefficients are generic, this is already implemented). However, in some instances it might be helpful to consider the complex variables and their conjugates instead of the real and imaginary part as the "intrinsic" variables of the polynomial. In particular, there is a relatively recent approach to polynomial optimization, where different relaxation hierarchies arise depending on whether the one or the other way of seeing things are used.

Here are some thoughts on what I think would be useful to have (in fact, I implemented all of this and hacked an extension to DynamicPolynomials; and I am using it successfully in my optimization code - but it is a hack, is architecture-dependent at the moment, is not terribly efficient, and would be pretty impossible to define in a package, so I just provide the code in this Gist):

The reason why I implemented this in such a hacky way is that pretty much all the functions that work perfectly for PolyVar would work in the exact same way for the complex PolyVar - so subtyping it would be the best "noninvasive" way, were it an abstract type. The reason why performance is suboptimal is mainly the inefficient conj function for monomials.

blegat commented 2 years ago

Hi, implementing this would be great. it could be part of a new implementation of MultivariatePolynomials, a proof of concept would be great. Creating new implementaitons of MultivariatePolynomials is now much easier thanks to https://github.com/JuliaAlgebra/MultivariatePolynomials.jl/pull/199

projekter commented 2 years ago

Ok, I created #213 as a first draft for these ideas, only the MultivariatePolynomial side. Some (debatable) design decisions:

Once/if the design decisions for the MultivariatePolynomial interface are sufficiently clear, I can also provide a draft for a possible DynamicPolynomials implementation (I don't think a "new" implementation would be needed, as this should really seamlessly integrates with the existing ones without any compatibility-breaking change - so a new implementation would include lots of redundant code from whatever it builds on).