Exemplo n.º 1
0
  public Polynomial div(Polynomial poly) {
    if (!poly.isConstantPoly())
      throw new IllegalArgumentException(
          "Can currently only divide by numbers and not polynomials");

    int deg = coeffs.length - 1;
    Number lcoeffs[] = new Number[deg + 1];
    for (int i = 0; i < deg + 1; ++i)
      lcoeffs[i] = ((HasDivI) baseRing).div(coeffs[i], poly.getCoeff(0));

    return valueOf(lcoeffs);
  }
Exemplo n.º 2
0
  public Polynomial pow(int exp) {
    if (exp == 0) return valueOf(new Number[] {baseRing.getONE()});
    if (exp == 1) return valueOf(this.getCoeffs());
    if (exp < 0)
      throw new IllegalArgumentException("Tried to raise a Polynomial to a negative power");

    Polynomial res = valueOf(new Number[] {baseRing.getONE()});
    Polynomial currentPower = this;
    int ex = exp;
    while (ex != 0) {
      if ((ex & 1) == 1) res = res.mul(currentPower);
      ex >>= 1;
      if (ex == 0) break;
      currentPower = currentPower.mul(currentPower);
    }
    return res;
  }
Exemplo n.º 3
0
 public boolean equalsPoly(Polynomial n) {
   if (this.getDegree() != n.getDegree()) return false;
   for (int i = 0; i <= this.getDegree(); ++i)
     if (!baseRing.equals(this.getCoeff(i), n.getCoeff(i))) return false;
   return true;
 }