PolynomialMethods.Factor() not working?
archiecobbs opened this issue · 2 comments
archiecobbs commented
I'm probably doing this wrong, but I can't get PolynomialMethods.Factor()
to work correctly.
Test program:
import cc.redberry.rings.*;
import cc.redberry.rings.bigint.*;
import cc.redberry.rings.poly.*;
import cc.redberry.rings.poly.univar.*;
import cc.redberry.rings.poly.multivar.*;
import cc.redberry.rings.bigint.BigInteger;
import java.util.*;
public class FactorSums {
// input consecutive coefficients starting with x^0
public static void main(String[] args) throws Exception {
final List<Integer> coeffs = new ArrayList<>(args.length);
for (int i = 0; i < args.length; i++)
coeffs.add(Integer.parseInt(args[i].replaceAll("[^0-9]", "")));
final StringBuilder buf = new StringBuilder();
for (int i = 0; i < args.length; i++) {
final int coeff = coeffs.get(i);
if (coeff == 0)
continue;
if (buf.length() > 0)
buf.append("+");
if (i > 0) {
if (coeff > 1)
buf.append(coeff).append('*');
buf.append("x");
if (i > 1)
buf.append('^').append(i);
} else
buf.append(coeff);
}
System.out.println(" buf = " + buf);
//final UnivariateRing<UnivariatePolynomialZp64> r = Rings.UnivariateRingZp64(p);
final Integers z = Rings.Z;
UnivariatePolynomial<BigInteger> poly = UnivariatePolynomial.parse(buf.toString(), z, "x");
System.out.println("poly = " + poly);
Object factors = PolynomialMethods.Factor(poly);
System.out.println("factors = " + factors);
}
}
Test input:
$ java FactorSums FactorSums 1 1 3 4 5 6 6 6 4
buf = 1+x+3*x^2+4*x^3+5*x^4+6*x^5+6*x^6+6*x^7+4*x^8
poly = 1+x+3*x^2+4*x^3+5*x^4+6*x^5+6*x^6+6*x^7+4*x^8
factors = (1+x+3*x^2+4*x^3+5*x^4+6*x^5+6*x^6+6*x^7+4*x^8)
But 1+x+3*x^2+4*x^3+5*x^4+6*x^5+6*x^6+6*x^7+4*x^8
can actually be factored as (x+1)^2(3x^6+3x^4+2x^2+1)
(at least, according to this).
I must be missing something...
PoslavskySV commented
Hi,
the polynomial is irreducible and 1+x+3*x^2+4*x^3+5*x^4+6*x^5+6*x^6+6*x^7+4*x^8
is not equal to (x+1)^2(3x^6+3x^4+2x^2+1)
. So, it seems that the link gives you a wrong result )
archiecobbs commented
Ah - actually it's my mistake, I entered the formula wrong on that website. Thanks & sorry for the noise.