Esempio n. 1
0
 /**
  * GenPolynomial is absolute factorization.
  *
  * @param facs factors map container.
  * @return true if P = prod_{i=1,...,k} p_i**e_i , else false.
  */
 public boolean isAbsoluteFactorization(FactorsMap<C> facs) {
   if (facs == null) {
     throw new IllegalArgumentException("facs may not be null");
   }
   GenPolynomial<C> P = facs.poly;
   GenPolynomial<C> t = P.ring.getONE();
   for (GenPolynomial<C> f : facs.factors.keySet()) {
     long e = facs.factors.get(f);
     GenPolynomial<C> g = Power.<GenPolynomial<C>>positivePower(f, e);
     t = t.multiply(g);
   }
   if (P.equals(t) || P.equals(t.negate())) {
     return true;
   }
   if (facs.afactors == null) {
     return false;
   }
   for (Factors<C> fs : facs.afactors.keySet()) {
     if (!isAbsoluteFactorization(fs)) {
       return false;
     }
     long e = facs.afactors.get(fs);
     GenPolynomial<C> g = Power.<GenPolynomial<C>>positivePower(fs.poly, e);
     t = t.multiply(g);
   }
   boolean b = P.equals(t) || P.equals(t.negate());
   if (!b) {
     System.out.println("\nFactorsMap: " + facs);
     System.out.println("P = " + P);
     System.out.println("t = " + t);
   }
   return b;
 }
Esempio n. 2
0
 /**
  * GenPolynomial is absolute factorization.
  *
  * @param facs factors list container.
  * @return true if P = prod_{i=1,...,r} p_i, else false.
  */
 public boolean isAbsoluteFactorization(FactorsList<C> facs) {
   if (facs == null) {
     throw new IllegalArgumentException("facs may not be null");
   }
   GenPolynomial<C> P = facs.poly;
   GenPolynomial<C> t = P.ring.getONE();
   for (GenPolynomial<C> f : facs.factors) {
     t = t.multiply(f);
   }
   if (P.equals(t) || P.equals(t.negate())) {
     return true;
   }
   if (facs.afactors == null) {
     return false;
   }
   for (Factors<C> fs : facs.afactors) {
     if (!isAbsoluteFactorization(fs)) {
       return false;
     }
     t = t.multiply(facs.poly);
   }
   // return P.equals(t) || P.equals(t.negate());
   boolean b = P.equals(t) || P.equals(t.negate());
   if (!b) {
     System.out.println("\nFactorsList: " + facs);
     System.out.println("P = " + P);
     System.out.println("t = " + t);
   }
   return b;
 }
Esempio n. 3
0
 /**
  * Polynomial is char-th root.
  *
  * @param P polynomial.
  * @param F = [p_1 -&gt; e_1, ..., p_k -&gt; e_k].
  * @return true if P = prod_{i=1,...,k} p_i**(e_i*p), else false.
  */
 public boolean isCharRoot(GenPolynomial<C> P, SortedMap<GenPolynomial<C>, Long> F) {
   if (P == null || F == null) {
     throw new IllegalArgumentException("P and F may not be null");
   }
   if (P.isZERO() && F.size() == 0) {
     return true;
   }
   GenPolynomial<C> t = P.ring.getONE();
   long p = P.ring.characteristic().longValue();
   for (Map.Entry<GenPolynomial<C>, Long> me : F.entrySet()) {
     GenPolynomial<C> f = me.getKey();
     Long E = me.getValue(); // F.get(f);
     long e = E.longValue();
     GenPolynomial<C> g = Power.<GenPolynomial<C>>positivePower(f, e);
     if (!f.isConstant()) {
       g = Power.<GenPolynomial<C>>positivePower(g, p);
     }
     t = t.multiply(g);
   }
   boolean f = P.equals(t) || P.equals(t.negate());
   if (!f) {
     System.out.println("\nfactorization(map): " + f);
     System.out.println("P = " + P);
     System.out.println("t = " + t);
     P = P.monic();
     t = t.monic();
     f = P.equals(t) || P.equals(t.negate());
     if (f) {
       return f;
     }
     System.out.println("\nfactorization(map): " + f);
     System.out.println("P = " + P);
     System.out.println("t = " + t);
   }
   return f;
 }
  /** Test scalar multiplication. */
  public void testPolynomialMultiplication() {
    BigRational cfac = new BigRational(1);
    GenPolynomialRing<BigRational> pfac = new GenPolynomialRing<BigRational>(cfac, rl);

    GenVectorModul<GenPolynomial<BigRational>> mfac =
        new GenVectorModul<GenPolynomial<BigRational>>(pfac, ll);

    GenPolynomial<BigRational> r, s, t;
    GenVector<GenPolynomial<BigRational>> a, b, c, d, e;

    r = pfac.random(kl);
    // System.out.println("r = " + r);
    s = r.negate();
    // System.out.println("s = " + s);

    a = mfac.random(kl, q);
    // System.out.println("a = " + a);

    c = a.scalarMultiply(r);
    d = a.scalarMultiply(s);
    e = c.sum(d);
    // System.out.println("c = " + c);
    // System.out.println("d = " + d);
    // System.out.println("e = " + e);
    assertEquals("a*b + a*(-b) = 0", e, mfac.getZERO());

    b = mfac.random(kl, q);
    // System.out.println("b = " + b);

    t = pfac.getONE();
    // System.out.println("t = " + t);
    c = a.linearCombination(b, t);
    d = b.linearCombination(a, t);
    // System.out.println("c = " + c);
    // System.out.println("d = " + d);
    assertEquals("a+1*b = b+1*a", c, d);

    c = a.linearCombination(b, t);
    d = a.sum(b);
    // System.out.println("c = " + c);
    // System.out.println("d = " + d);
    assertEquals("a+1*b = b+1*a", c, d);

    s = t.negate();
    // System.out.println("s = " + s);
    c = a.linearCombination(b, t);
    d = c.linearCombination(b, s);
    // System.out.println("c = " + c);
    // System.out.println("d = " + d);
    assertEquals("a+1*b+(-1)*b = a", a, d);

    c = a.linearCombination(t, b, t);
    d = c.linearCombination(t, b, s);
    // System.out.println("c = " + c);
    // System.out.println("d = " + d);
    assertEquals("a+1*b+(-1)*b = a", a, d);

    t = pfac.getZERO();
    // System.out.println("t = " + t);
    c = a.linearCombination(b, t);
    // System.out.println("c = " + c);
    assertEquals("a+0*b = a", a, c);

    d = a.linearCombination(t, b, t);
    // System.out.println("d = " + d);
    assertEquals("0*a+0*b = 0", mfac.getZERO(), d);

    r = a.scalarProduct(b);
    s = b.scalarProduct(a);
    // System.out.println("r = " + r);
    // System.out.println("s = " + s);
    assertEquals("a.b = b.a", r, s);
  }