evaluatePolynomial method

BigInt evaluatePolynomial(
  1. List<List<BigInt>> poly,
  2. int part,
  3. BigInt x
)

Compute the polynomial value using Horner's method. https://en.wikipedia.org/wiki/Horner%27s_method y = a + bx + cx^2 + dx^3 = ((dx + c)x + b)x + a

Implementation

BigInt evaluatePolynomial(List<List<BigInt>> poly, int part, BigInt x) {
  int last = poly[part].length - 1;
  BigInt accum = poly[part][last];
  for (int i = last - 1; i >= 0; --i) {
    accum = ((accum * x) + poly[part][i]) % prime;
  }
  return accum;
}