MultivariatePolynomials.jl icon indicating copy to clipboard operation
MultivariatePolynomials.jl copied to clipboard

Promote Variables

Open blegat opened this issue 8 years ago • 0 comments

For implemented an operation op on polynomials, we are always tempted to do

op(p::AbstractPolynomialLike, q::AbstractPolynomialLike) = op(promote(p, q)...)

and then only define op for two polynomials p and q of the same concrete type. However, this is problematic since it promotes the coefficient type to the same type. Therefore, multiplying a polynomial with Float64 coefficients with a polynomial with JuMP.AffExpr coefficients will give a polynomials with JuMP.QuadExpr while it should be JuMP.AffExpr.

It is however important to promote p and q to a common type without promoting coefficients. For example, div currently fails if the two polynomials do not have the same variables since it incorrectly infers the return type. I suggest having something like

promote_variables(p::AbstractPolynomialLike, q::AbstractPolynomialLike)

which returns a tuple (p2, q2) where p == p2 and q == q2 but p2 and q2 both have the same variables. What do you think ?

blegat avatar Oct 13 '17 07:10 blegat