Ejemplo n.º 1
0
 public Polynomial add(Polynomial poly) {
   int deg = degree > poly.degree ? degree : poly.degree;
   Number lcoeffs[] = new Number[deg + 1];
   for (int i = 0; i <= deg; ++i) {
     if (i <= degree && i <= poly.degree) lcoeffs[i] = baseRing.add(coeffs[i], poly.coeffs[i]);
     else if (i <= degree) lcoeffs[i] = coeffs[i];
     else lcoeffs[i] = poly.coeffs[i];
   }
   return valueOf(lcoeffs);
 }
Ejemplo n.º 2
0
  public Number calculateValue(Number rootVal) {
    Number val = coeffs[this.getDegree()];

    for (int i = this.getDegree() - 1; i >= 0; --i) {
      Number val2 = coeffs[i];
      Number prod = baseRing.mul(val, rootVal);
      val = baseRing.add(prod, val2);
    }
    return val;
  }
Ejemplo n.º 3
0
  public Polynomial mul(Polynomial poly) {
    int deg = degree + poly.degree;
    Number lcoeffs[] = new Number[deg + 1];
    for (int i = 0; i <= deg; ++i) lcoeffs[i] = baseRing.getZERO();

    for (int i = 0; i <= degree; ++i)
      for (int j = 0; j <= poly.degree; ++j) {
        lcoeffs[i + j] = baseRing.add(lcoeffs[i + j], baseRing.mul(coeffs[i], poly.coeffs[j]));
      }
    return valueOf(lcoeffs);
  }