Skip to content

Commit

Permalink
Modify primitive_poly() to use the database
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanmv committed Jan 18, 2023
1 parent 244fd16 commit 1a9d1d0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/galois/_polys/_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from typing_extensions import Literal

from .._databases import ConwayPolyDatabase
from .._databases import ConwayPolyDatabase, PrimitivePolyDatabase
from .._domains import _factory
from .._helper import export, verify_isinstance
from .._prime import is_prime, is_prime_power
Expand Down Expand Up @@ -96,8 +96,15 @@ def primitive_poly(order: int, degree: int, method: Literal["min", "max", "rando
if not method in ["min", "max", "random"]:
raise ValueError(f"Argument 'method' must be in ['min', 'max', 'random'], not {method!r}.")

field = _factory.FIELD_FACTORY(order)

if method == "min":
poly = next(primitive_polys(order, degree))
try:
db = PrimitivePolyDatabase()
degrees, coeffs = db.fetch(order, degree)
poly = Poly.Degrees(degrees, coeffs, field=field)
except LookupError:
poly = next(primitive_polys(order, degree))
elif method == "max":
poly = next(primitive_polys(order, degree, reverse=True))
else:
Expand Down

0 comments on commit 1a9d1d0

Please sign in to comment.