PoslavskySV/rings

Invalid canonicalization of PolynomialFactorDecomposition

tueda opened this issue · 3 comments

tueda commented

If I understand correctly, PolynomialFactorDecomposition<Poly>.canonical() just sorts the factors and should not change the polynomial, but in the following case the result changes:

$ rings.repl
OpenJDK 64-Bit Server VM warning: Option AggressiveOpts was deprecated in version 11.0 and will likely be removed in a future release.
Loading...
Running Ammonite Repl
Rings 2.5.5: efficient Java/Scala library for polynomial rings.
@ implicit val ring = MultivariateRing(Z, Array("x", "y"))
ring: MultivariateRing[IntZ] = MultivariateRing(Z, Array("x", "y"), GREVLEX)

@ val p = ring("x^3 + x^2*y")
p: MultivariatePolynomial[IntZ] = x^2*y+x^3

@ Factor(p)
res2: PolynomialFactorDecomposition[MultivariatePolynomial[IntZ]] = (x)^2*(y+x)

@ Factor(p).canonical()
res3: PolynomialFactorDecomposition[MultivariatePolynomial[IntZ]] = (x^2)^2*(y+x)

@ Factor(p).canonical().canonical()
res4: PolynomialFactorDecomposition[MultivariatePolynomial[IntZ]] = (x^4)^2*(y+x)

I guess in the following code (x)^2 is expected to be translated to (x^2)^1

Poly poly = fTmp[i];
if (poly.isMonomial() && eTmp[i] != 1) {
poly = PolynomialMethods.polyPow(poly, eTmp[i], false);
assert poly.isMonomial();
}

but indeed eTmp[i] is not changed accordingly, leading to (x^2)^2.

That's a bug. Thanks for reporting! Will fix it today.

@tueda I've just made a release with the fix, it is now available from brew.

tueda commented

Thanks for your quick fix!