Skip to content

Commit

Permalink
Use IrreduciblePolyDatabase with terms="min"
Browse files Browse the repository at this point in the history
Similar to the changes in primitive_poly(), try to fetch nonzero degrees
and coefficients from the database when irreducible_poly() is called
with terms="min". If poly is not in the database, fallback to compute
it.
  • Loading branch information
iyanmv authored and mhostetter committed Feb 1, 2023
1 parent bf6010b commit 89d8086
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/galois/_polys/_irreducible.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from typing_extensions import Literal

from .._databases import IrreduciblePolyDatabase
from .._domains import _factory
from .._helper import export, method_of, verify_isinstance
from .._prime import factors, is_prime_power
Expand Down Expand Up @@ -128,6 +129,7 @@ def irreducible_poly(
degree: int,
terms: int | str | None = None,
method: Literal["min", "max", "random"] = "min",
use_database: bool = True,
) -> Poly:
r"""
Returns a monic irreducible polynomial :math:`f(x)` over :math:`\mathrm{GF}(q)` with degree :math:`m`.
Expand Down Expand Up @@ -215,6 +217,16 @@ def irreducible_poly(
if not method in ["min", "max", "random"]:
raise ValueError(f"Argument 'method' must be in ['min', 'max', 'random'], not {method!r}.")

if terms == "min" and method == "min" and use_database:
try:
db = IrreduciblePolyDatabase()
degrees, coeffs = db.fetch(order, degree)
field = _factory.FIELD_FACTORY(order)
poly = Poly.Degrees(degrees, coeffs, field=field)
return poly
except LookupError:
pass

try:
if method == "min":
return next(irreducible_polys(order, degree, terms))
Expand Down

0 comments on commit 89d8086

Please sign in to comment.