Skip to content

Commit

Permalink
Fixes error in calculating multiplication order #532
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Jan 29, 2024
1 parent 529ba26 commit f35836e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/galois/_fields/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ def multiplicative_order(self) -> int | np.ndarray:
k = np.log(x) # x as an exponent of α
order = (field.order - 1) // np.gcd(field.order - 1, k)
else:
d = np.array(divisors(field.order - 1)) # Divisors d such that d | p^m - 1
d = np.array(divisors(field.order - 1), dtype=field.dtypes[-1]) # Divisors d such that d | p^m - 1
y = np.power.outer(x, d) # x^d -- the first divisor d for which x^d == 1 is the order of x
idxs = np.argmin(y, axis=-1) # First index of divisors, which is the order of x
order = d[idxs] # The order of each element of x
Expand Down
10 changes: 10 additions & 0 deletions tests/fields/test_arithmetic_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import numpy as np
import pytest

import galois


def test_additive_order(field_additive_order):
GF, X, Z = field_additive_order["GF"], field_additive_order["X"], field_additive_order["Z"]
Expand Down Expand Up @@ -34,6 +36,14 @@ def test_multiplicative_order(field_multiplicative_order):
GF.Range(0, 2).multiplicative_order()


def test_issue_532():
"""
https://github.com/mhostetter/galois/issues/532
"""
GF = galois.GF(2**64 - 59)
assert GF(1).multiplicative_order() == 1


def test_characteristic_poly_element(field_characteristic_poly_element):
GF, X, Z = (
field_characteristic_poly_element["GF"],
Expand Down

0 comments on commit f35836e

Please sign in to comment.