isIrreducible property

bool get isIrreducible

Whether this polynomial is irreducible over GF(2).

Uses the Rabin irreducibility test. Constant polynomials are not irreducible; every degree-one polynomial is irreducible.

Implementation

bool get isIrreducible {
  if (degree <= 0) {
    return false;
  }
  if (degree == 1) {
    return true;
  }
  if (!coefficient(0)) {
    return false;
  }

  final x = BinaryPolynomial(BigInt.two);
  var frobeniusPower = x;
  for (var index = 1; index <= degree ~/ 2; index++) {
    frobeniusPower = (frobeniusPower * frobeniusPower) % this;
    if ((frobeniusPower + x).gcd(this) != one) {
      return false;
    }
  }

  frobeniusPower = x;
  for (var index = 0; index < degree; index++) {
    frobeniusPower = (frobeniusPower * frobeniusPower) % this;
  }
  return frobeniusPower == x;
}