JuliaAlgebra / DynamicPolynomials.jl

Multivariate polynomials implementation of commutative and non-commutative variables
Other
60 stars 21 forks source link

Multiplication with 0 discards of coefficients. #80

Closed manuelbb-upb closed 3 years ago

manuelbb-upb commented 3 years ago

I use DynamicPolynomials.jl for a muliti-variate interpolation task, where I was thrown off guard when the resulting interpolant equates to the constant 0 polynomial. Then the variable information is lost. In my case, I am not able to differentiate properly and obtain the zero gradient.

Consider

@polyvar x[1:2]
p1 = x[1] * 0.0
p2 = x[1] * 0.0 + x[2] * 0.0
p3 = ( x[1] + x[2] ) * 0.0

All polynomials are the constant zero polynomial. Using DynamicPolynomials i get

variables(p1) == [x[1],]
variables(p2) == [x[1],x[2],]

but variables(p3) is empty. When using TypedPolynomials we get variables(p3) == [x[1],x[2],].

p1 is a Term and p2 is a sum of two Terms. In contrast, p3 is the product of a Polynomial and a Term. Hence I suspect this behavior is due to lines 62-63 in the file mult.jl.