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); }
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; }
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); }