galois.primitive_polys¶
-
galois.primitive_polys(order: int, degree: int, reverse: bool =
False
) Iterator[Poly] ¶ Iterates through all monic primitive polynomials
over with degree .- Parameters
- Returns
An iterator over all degree-
monic primitive polynomials over .
See also
Notes
If
is a primitive polynomial over and , then is also primitive.In addition to other applications,
produces the field extension of . Since is primitive, is a primitive element of such that .Examples
All monic primitive polynomials over
with degree . You may also usetuple()
on the returned generator.In [1]: list(galois.primitive_polys(3, 4)) Out[1]: [Poly(x^4 + x + 2, GF(3)), Poly(x^4 + 2x + 2, GF(3)), Poly(x^4 + x^3 + 2, GF(3)), Poly(x^4 + x^3 + x^2 + 2x + 2, GF(3)), Poly(x^4 + x^3 + 2x^2 + 2x + 2, GF(3)), Poly(x^4 + 2x^3 + 2, GF(3)), Poly(x^4 + 2x^3 + x^2 + x + 2, GF(3)), Poly(x^4 + 2x^3 + 2x^2 + x + 2, GF(3))]
Loop over all the polynomials in reversed order, only finding them as needed. The search cost for the polynomials that would have been found after the
break
condition is never incurred.In [2]: for poly in galois.primitive_polys(3, 4, reverse=True): ...: if poly.coeffs[1] < 2: # Early exit condition ...: break ...: print(poly) ...: x^4 + 2x^3 + 2x^2 + x + 2 x^4 + 2x^3 + x^2 + x + 2 x^4 + 2x^3 + 2
Or, manually iterate over the generator.
In [3]: generator = galois.primitive_polys(3, 4, reverse=True); generator Out[3]: <generator object primitive_polys at 0x7fb711af4ba0> In [4]: next(generator) Out[4]: Poly(x^4 + 2x^3 + 2x^2 + x + 2, GF(3)) In [5]: next(generator) Out[5]: Poly(x^4 + 2x^3 + x^2 + x + 2, GF(3)) In [6]: next(generator) Out[6]: Poly(x^4 + 2x^3 + 2, GF(3))
Last update:
May 16, 2022