galois.primitive_element

galois.primitive_element(irreducible_poly: Poly, method: Literal['min', 'max', 'random'] = 'min') Poly

Finds a primitive element \(g\) of the Galois field \(\mathrm{GF}(q^m)\) with degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(q)\).

Parameters
irreducible_poly

The degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(q)\) that defines the extension field \(\mathrm{GF}(q^m)\).

method

The search method for finding the primitive element.

Returns

A primitive element \(g\) of \(\mathrm{GF}(q^m)\) with irreducible polynomial \(f(x)\). The primitive element \(g\) is a polynomial over \(\mathrm{GF}(q)\) with degree less than \(m\).

Examples

Find the smallest primitive element for the degree \(5\) extension of \(\mathrm{GF}(7)\).

In [1]: f = galois.conway_poly(7, 5); f
Out[1]: Poly(x^5 + x + 4, GF(7))

In [2]: g = galois.primitive_element(f); g
Out[2]: Poly(x, GF(7))

Construct the extension field \(\mathrm{GF}(7^5)\). Note, by default, GF() uses a Conway polynomial as its irreducible polynomial.

In [3]: GF = galois.GF(7**5)

In [4]: print(GF.properties)
Galois Field:
  name: GF(7^5)
  characteristic: 7
  degree: 5
  order: 16807
  irreducible_poly: x^5 + x + 4
  is_primitive_poly: True
  primitive_element: x

In [5]: int(g) == GF.primitive_element
Out[5]: True

Find the largest primitive element for the degree \(5\) extension of \(\mathrm{GF}(7)\).

In [6]: f = galois.conway_poly(7, 5); f
Out[6]: Poly(x^5 + x + 4, GF(7))

In [7]: g = galois.primitive_element(f, method="max"); g
Out[7]: Poly(6x^4 + 6x^3 + 6x^2 + 6x + 3, GF(7))

Construct the extension field \(\mathrm{GF}(7^5)\). Note, by default, GF() uses a Conway polynomial as its irreducible polynomial.

In [8]: GF = galois.GF(7**5)

In [9]: print(GF.properties)
Galois Field:
  name: GF(7^5)
  characteristic: 7
  degree: 5
  order: 16807
  irreducible_poly: x^5 + x + 4
  is_primitive_poly: True
  primitive_element: x

In [10]: int(g) in GF.primitive_elements
Out[10]: True

Find a random primitive element for the degree \(5\) extension of \(\mathrm{GF}(7)\).

In [11]: f = galois.conway_poly(7, 5); f
Out[11]: Poly(x^5 + x + 4, GF(7))

In [12]: g = galois.primitive_element(f, method="random"); g
Out[12]: Poly(4x^4 + x^3 + 6x^2 + 6x + 2, GF(7))

Construct the extension field \(\mathrm{GF}(7^5)\). Note, by default, GF() uses a Conway polynomial as its irreducible polynomial.

In [13]: GF = galois.GF(7**5)

In [14]: print(GF.properties)
Galois Field:
  name: GF(7^5)
  characteristic: 7
  degree: 5
  order: 16807
  irreducible_poly: x^5 + x + 4
  is_primitive_poly: True
  primitive_element: x

In [15]: int(g) in GF.primitive_elements
Out[15]: True

Last update: May 18, 2022