static Generic factorize(JsclInteger integer) {
   Generic n[] = integer.gcdAndNormalize();
   Generic s = n[1];
   Generic a = JsclInteger.valueOf(1);
   Generic p = JsclInteger.valueOf(2);
   while (s.compareTo(JsclInteger.valueOf(1)) > 0) {
     Generic q[] = s.divideAndRemainder(p);
     if (q[0].compareTo(p) < 0) {
       p = s;
       q = s.divideAndRemainder(p);
     }
     if (q[1].signum() == 0) {
       a = a.multiply(expression(p, true));
       s = q[0];
     } else p = p.add(JsclInteger.valueOf(1));
   }
   return a.multiply(n[0]);
 }
 static Generic terminator(Generic generic, Variable var, boolean tail) {
   Generic x = var.expressionValue();
   Generic a = JsclInteger.valueOf(1);
   Iterator it = IntegerDivisor.create(generic.integerValue());
   while (it.hasNext()) {
     Generic s = (Generic) it.next();
     a = a.multiply(x.subtract(s));
     if (!tail) a = a.multiply(x.add(s));
   }
   return a;
 }
 static Polynomial polynomial(Polynomial s, Monomial monomial[]) {
   Polynomial p = s.valueOf(JsclInteger.valueOf(0));
   Iterator it = monomial[1].iterator(monomial[0]);
   for (int i = 0; it.hasNext(); i++) {
     Monomial m = (Monomial) it.next();
     Variable t =
         it.hasNext() ? new TechnicalVariable(ter, new int[] {i}) : new TechnicalVariable(ter);
     p = p.add(p.valueOf(m).multiply(t.expressionValue()));
   }
   return p;
 }
 static Polynomial[] linearize(Polynomial polynomial, Variable variable) {
   List l = new ArrayList();
   Generic x = variable.expressionValue();
   Polynomial s = polynomial;
   try {
     Polynomial r = s.valueOf(x);
     s = s.divide(r);
     l.add(r);
     while (true) s = s.divide(r);
   } catch (NotDivisibleException e) {
   }
   IntegerDivisor d[] = new IntegerDivisor[2];
   Generic p[] = new Generic[2];
   Generic q[] = new Generic[2];
   d[1] = IntegerDivisor.create(JsclInteger.valueOf(1));
   loop:
   while (d[1].hasNext()) {
     p[1] = (Generic) d[1].next();
     q[1] = d[1].integer(d[1].complementary());
     d[0] = IntegerDivisor.create(s.tail().coef().integerValue());
     while (d[0].hasNext()) {
       p[0] = (Generic) d[0].next();
       q[0] = d[0].integer(d[0].complementary());
       if (ArrayComparator.comparator.compare(q, p) < 0) break loop;
       for (int i = 0; i < 2; i++) {
         Polynomial r =
             s.valueOf(i == 0 ? p[1].multiply(x).subtract(p[0]) : p[1].multiply(x).add(p[0]));
         for (boolean flag = true; true; flag = false) {
           try {
             s = s.divide(r);
           } catch (NotDivisibleException e) {
             break;
           }
           d[1].divide();
           d[0].divide();
           if (flag) l.add(r);
         }
       }
     }
   }
   return (Polynomial[]) ArrayUtils.toArray(l, new Polynomial[l.size()]);
 }
 static Polynomial[] remainder(Polynomial s, Polynomial p, Generic t[]) {
   Polynomial zero = s.valueOf(JsclInteger.valueOf(0));
   Generic a[] = Basis.augment(t, s.remainderUpToCoefficient(p).elements());
   Variable unk[] = Basis.augmentUnknown(new Variable[] {}, p.elements());
   {
     Variable u = unk[unk.length - 1];
     System.arraycopy(unk, 0, unk, 1, unk.length - 1);
     unk[0] = u;
   }
   Generic be[][] =
       Linearization.compute(
           Basis.compute(a, unk, Monomial.lexicographic, 0, Basis.DEGREE).elements(), unk);
   for (int i = 0; i < be.length; i++) {
     Polynomial r = substitute(p, be[i], unk);
     try {
       return new Polynomial[] {zero, r, s.divide(r)};
     } catch (NotDivisibleException e) {
     }
   }
   return new Polynomial[] {s, zero, zero};
 }
 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 Generic expression(Generic generic, boolean integer) {
   if (generic.compareTo(JsclInteger.valueOf(1)) == 0) return generic;
   else return GenericVariable.valueOf(generic, integer).expressionValue();
 }