Say, I want a finite field containing q^n
elements for some prime q
and positive n
. How to get its primitive element?
You can get some primitive element with the following code:
var = 'x; \\ sets a variable in the polynomial representation of finite field
f = ffgen(ffinit(q, n)); \\ GF(q^n) ~ GF(q)[x]/<f(x)>. Note `f` is just an irreducible
a = ffprimroot(f); \\ gets a root `a` of `f`
poly = minpoly(a, var); \\ finds a minimal polynomial for `a`
primitive_elt = ffgen(poly, var); \\ finds a root of the minimal polynomial
\\ assertion: check the order
fforder(primitive_elt) == q^n-1
Note, that the finite field can have certain primitive elements. The code above finds random any. Please, note that the code above assumes n
> 1. Otherwise, the function minpoly
crashes (tested with PARI/GP 2.7.2 32-bit).