galois.primitive_elements¶
- class galois.primitive_elements(irreducible_poly, start=None, stop=None, reverse=False)¶
Finds all primitive elements \(g(x)\) of the Galois field \(\mathrm{GF}(p^m)\) with degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(p)\).
The number of primitive elements of \(\mathrm{GF}(p^m)\) is \(\phi(p^m - 1)\), where \(\phi(n)\) is the Euler totient function. See :obj:galois.euler_totient`.
- Parameters
irreducible_poly (galois.Poly) – The degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(p)\) that defines the extension field \(\mathrm{GF}(p^m)\).
start (int, optional) – Starting value (inclusive, integer representation of the polynomial) in the search for primitive elements \(g(x)\) of \(\mathrm{GF}(p^m)\). The default is
None
which represents \(p\), which corresponds to \(g(x) = x\) over \(\mathrm{GF}(p)\).stop (int, optional) – Stopping value (exclusive, integer representation of the polynomial) in the search for primitive elements \(g(x)\) of \(\mathrm{GF}(p^m)\). The default is
None
which represents \(p^m\), which corresponds to \(g(x) = x^m\) over \(\mathrm{GF}(p)\).reverse (bool, optional) – Search for primitive elements in reverse order, i.e. largest to smallest. Default is
False
.
- Returns
List of all primitive elements of \(\mathrm{GF}(p^m)\) with irreducible polynomial \(f(x)\). Each primitive element \(g(x)\) is a polynomial over \(\mathrm{GF}(p)\) with degree less than \(m\).
- Return type
Examples
In [629]: GF = galois.GF(3) In [630]: f = galois.Poly([1,1,2], field=GF); f Out[630]: Poly(x^2 + x + 2, GF(3)) In [631]: galois.is_irreducible(f) Out[631]: True In [632]: galois.is_primitive(f) Out[632]: True In [633]: g = galois.primitive_elements(f); g Out[633]: [Poly(x, GF(3)), Poly(x + 1, GF(3)), Poly(2x, GF(3)), Poly(2x + 2, GF(3))] In [634]: len(g) == galois.euler_totient(3**2 - 1) Out[634]: True
In [635]: GF = galois.GF(3) In [636]: f = galois.Poly([1,0,1], field=GF); f Out[636]: Poly(x^2 + 1, GF(3)) In [637]: galois.is_irreducible(f) Out[637]: True In [638]: galois.is_primitive(f) Out[638]: False In [639]: g = galois.primitive_elements(f); g Out[639]: [Poly(x + 1, GF(3)), Poly(x + 2, GF(3)), Poly(2x + 1, GF(3)), Poly(2x + 2, GF(3))] In [640]: len(g) == galois.euler_totient(3**2 - 1) Out[640]: True