Skip to content

Commit

Permalink
Fix #205
Browse files Browse the repository at this point in the history
`np.arange()` needs `dtype=object` for large fields otherwise the exponentiation will overflow and result in 0.
  • Loading branch information
mhostetter committed Nov 16, 2021
1 parent 158f5ff commit 817ad94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion galois/_polys/_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def minimal_poly(element):
if field.is_prime_field:
return x - element
else:
conjugates = np.unique(element**(field.characteristic**np.arange(0, field.degree)))
conjugates = np.unique(element**(field.characteristic**np.arange(0, field.degree, dtype=field.dtypes[-1])))
poly = Poly.Roots(conjugates, field=field)
poly = Poly(poly.coeffs, field=field.prime_subfield)
return poly
8 changes: 8 additions & 0 deletions tests/polys/test_minimal_polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,11 @@ def test_minimal_poly(characteristic, degree):
e = GFpm(item[0])
poly = galois.Poly(item[1], field=GFp)
assert galois.minimal_poly(e) == poly


def test_minimal_poly_large_field():
# Test vectors generated with SageMath
GF = galois.GF(2**100)
galois.minimal_poly(GF(2)) == galois.Poly.String("x^100 + x^57 + x^56 + x^55 + x^52 + x^48 + x^47 + x^46 + x^45 + x^44 + x^43 + x^41 + x^37 + x^36 + x^35 + x^34 + x^31 + x^30 + x^27 + x^25 + x^24 + x^22 + x^20 + x^19 + x^16 + x^15 + x^11 + x^9 + x^8 + x^6 + x^5 + x^3 + 1")
galois.minimal_poly(GF(3)) == galois.Poly.String("x^100 + x^96 + x^68 + x^64 + x^57 + x^55 + x^54 + x^53 + x^51 + x^50 + x^48 + x^47 + x^42 + x^41 + x^38 + x^36 + x^31 + x^29 + x^26 + x^24 + x^15 + x^14 + x^12 + x^9 + x^8 + x^5 + x^2 + x + 1")
galois.minimal_poly(GF(6)) == galois.Poly.String("x^100 + x^78 + x^76 + x^74 + x^73 + x^71 + x^67 + x^66 + x^65 + x^62 + x^60 + x^55 + x^52 + x^51 + x^50 + x^48 + x^47 + x^45 + x^42 + x^41 + x^35 + x^34 + x^33 + x^31 + x^30 + x^29 + x^28 + x^27 + x^26 + x^23 + x^22 + x^21 + x^20 + x^19 + x^16 + x^14 + x^13 + x^12 + x^10 + x^9 + x^8 + x^6 + x^3 + x + 1")

0 comments on commit 817ad94

Please sign in to comment.