void computeValue(Generic generic) { Debug.println("factorization"); Polynomial n[] = factory.valueOf(generic).gcdAndNormalize(); Monomial m = n[1].monomialGcd(); Polynomial s = n[1].divide(m); Generic a = JsclInteger.valueOf(1); Divisor d[] = new Divisor[2]; Monomial p[] = new Monomial[2]; Monomial q[] = new Monomial[2]; d[1] = new Divisor(s.head().monomial()); loop: while (d[1].hasNext()) { p[1] = (Monomial) d[1].next(); q[1] = d[1].complementary(); d[0] = new Divisor(s.tail().monomial()); while (d[0].hasNext()) { p[0] = (Monomial) d[0].next(); q[0] = d[0].complementary(); if (p[1].compareTo(p[0]) <= 0) continue loop; Debug.println(toString(p) + " * " + toString(q) + " = " + s); if (ArrayComparator.comparator.compare(q, p) < 0) { a = a.multiply(expression(s.genericValue())); break loop; } else { Debug.increment(); Polynomial r[] = remainder(s, polynomial(s, p), terminator(s)); Debug.decrement(); if (r[0].signum() == 0) { a = a.multiply(expression(r[1].genericValue())); s = r[2]; d[1].divide(); d[0].divide(); continue loop; } } } } result = a.multiply(n[0].multiply(m).genericValue()); }
static Polynomial substitute(Polynomial p, Generic a[], Variable unk[]) { Generic s[] = new Generic[] {p.genericValue()}; return p.valueOf( Basis.compute(Basis.augment(a, s), Basis.augmentUnknown(unk, s)).elements()[0]); }