[Math] Algorithm to find the irreducible polynomial

algorithmsfield-theoryfinite-fieldsirreducible-polynomialspolynomials

What algorithm can be used find an irreducible polynomial of degree $n$ over the field $GF(p)$ for prime $p$. The reason I ask is I want to make a program for finite field arithmetic, but creating a field $GF(p^k)$ requires finding a irreducible polynomial. (I'm mostly interested in $GF(2^k)$.)

Best Answer

As others indicated, you can find irreducible polynomials of degree $n$ by factoring $x^{p^n}-x$ modulo $p$, and throwing away factors that have too small a degree. The algorithms by Cantor-Zassenhaus and Berlekamp are useful to that end. Do note that the characteristic zero factor in Hagen's answer is very far from being irreducible modulo $2$.

But, observe that factoring $x^{p^m}-x$ is not an option, when $p^m$ is too big. If that is a concern for you then the easiest to comprehend test I can imagine would be to generate random monic polynomials $p(x)$ of degree $m$. The probability for such a polynomial to be irreducible is roughly $1/m$ (the exact number is given by a Möbius formula). You can then either

A) Proceed with Berlekamp or Cantor-Zassenhaus and try to factor your candidate. If none are found you know the polynomial is irreducible. Or,

B) For each positive integer $d\le m/2$ calculate the greatest common divisor $$\gcd(p(x),x^{p^d}-x).$$ If no common divisors are found, then you know $p(x)$ has no factors of degree $d$, so if no factors are found with $d$ up to $m/2$, you know that $p(x)$ must be irreducible. Observe that calculating gcd's like this is quite fast. Only in the first step of Euclid's algorithm will you have high degree polynomials. That high degree polynomial is a binomial, so calculating its remainder modulo $p(x)$ is fast with the aid of square-and-multiply.

For small $k$ there are tables. I use this table when $p=2$, because it gives primitive polynomials, i.e. minimal polynomials of a generator of the multiplicative group of $GF(2^k)$. For other small $p$ and small $k$ Lidl & Niederreiter have more extensive tables. The book is a bit pricy (and also recommended for hardcore enthusiasts on finite fields only), so go to a university library near you rather than order one from Amazon. Also, they put more effort into listing all the irreducible polynomials rather than giving sample irreducibles of several degrees. Depending on what you want to do a given table may not be useful to you.

Related Question