From af18ab0b34864c49e21ac92694b0e5ea89a27e27 Mon Sep 17 00:00:00 2001 From: mhostetter Date: Thu, 5 Aug 2021 11:31:58 -0400 Subject: [PATCH] Update irreducible and primitive poly unit tests --- docs/api/polys.rst | 4 +- galois/_field/_poly_functions.py | 12 + tests/helper.py | 2 +- tests/polys/test_function.py | 346 ------------ tests/polys/test_irreducible_polys.py | 784 ++++++++++++++++++++++++++ tests/polys/test_primitive_polys.py | 615 ++++++++++++++++++++ tests/test_conway_polys.py | 41 -- 7 files changed, 1414 insertions(+), 390 deletions(-) create mode 100644 tests/polys/test_irreducible_polys.py create mode 100644 tests/polys/test_primitive_polys.py delete mode 100644 tests/test_conway_polys.py diff --git a/docs/api/polys.rst b/docs/api/polys.rst index 7f34d27b90..5258264b33 100644 --- a/docs/api/polys.rst +++ b/docs/api/polys.rst @@ -27,8 +27,8 @@ Polynomial functions poly_pow poly_factors -Special polynomial creation ---------------------------- +Special polynomials +------------------- .. rubric:: .. autosummary:: diff --git a/galois/_field/_poly_functions.py b/galois/_field/_poly_functions.py index fbbbbeb173..22934053fb 100644 --- a/galois/_field/_poly_functions.py +++ b/galois/_field/_poly_functions.py @@ -372,6 +372,12 @@ def irreducible_poly(characteristic, degree, method="min"): galois.is_irreducible(p) galois.is_irreducible(p * GF(3)) """ + if not isinstance(characteristic, (int, np.integer)): + raise TypeError(f"Argument `characteristic` must be an integer, not {type(characteristic)}.") + if not isinstance(degree, (int, np.integer)): + raise TypeError(f"Argument `degree` must be an integer, not {type(degree)}.") + if not degree >= 1: + raise ValueError(f"Argument `degree` must be at least 1, not {degree}.") if not method in ["min", "max", "random"]: raise ValueError(f"Argument `method` must be in ['min', 'max', 'random'], not {method!r}.") GF = GF_prime(characteristic) @@ -423,6 +429,12 @@ def irreducible_polys(characteristic, degree): galois.irreducible_polys(2, 5) """ + if not isinstance(characteristic, (int, np.integer)): + raise TypeError(f"Argument `characteristic` must be an integer, not {type(characteristic)}.") + if not isinstance(degree, (int, np.integer)): + raise TypeError(f"Argument `degree` must be an integer, not {type(degree)}.") + if not degree >= 1: + raise ValueError(f"Argument `degree` must be at least 1, not {degree}.") GF = GF_prime(characteristic) # Only search monic polynomials of degree m over GF(p) diff --git a/tests/helper.py b/tests/helper.py index 9ec812925e..514b419efd 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -18,6 +18,6 @@ def randint(low, high, shape, dtype): # For dtype=object array = np.empty(shape, dtype=dtype) iterator = np.nditer(array, flags=["multi_index", "refs_ok"]) - for i in iterator: + for _ in iterator: array[iterator.multi_index] = random.randint(low, high - 1) return array diff --git a/tests/polys/test_function.py b/tests/polys/test_function.py index 8084f01c41..8af403bcaf 100644 --- a/tests/polys/test_function.py +++ b/tests/polys/test_function.py @@ -188,252 +188,6 @@ def test_poly_factors(): assert multiplicities == [k0, k1, k2] -def test_irreducible_poly(): - p = galois.irreducible_poly(2, 3) - assert galois.is_monic(p) - assert galois.is_irreducible(p) - p = galois.irreducible_poly(2, 3, method="max") - assert galois.is_monic(p) - assert galois.is_irreducible(p) - p = galois.irreducible_poly(2, 3, method="random") - assert galois.is_monic(p) - assert galois.is_irreducible(p) - - p = galois.irreducible_poly(2, 8) - assert galois.is_monic(p) - assert galois.is_irreducible(p) - p = galois.irreducible_poly(2, 8, method="max") - assert galois.is_monic(p) - assert galois.is_irreducible(p) - p = galois.irreducible_poly(2, 8, method="random") - assert galois.is_monic(p) - assert galois.is_irreducible(p) - - p = galois.irreducible_poly(3, 5) - assert galois.is_monic(p) - assert galois.is_irreducible(p) - p = galois.irreducible_poly(3, 5, method="max") - assert galois.is_monic(p) - assert galois.is_irreducible(p) - p = galois.irreducible_poly(3, 5, method="random") - assert galois.is_monic(p) - assert galois.is_irreducible(p) - - -def test_irreducible_polys(): - """ - Generated with Octave: - primpoly(5, 'all') - primpoly(6, 'all') - primpoly(7, 'all') - primpoly(8, 'all') - """ - assert set([p.integer for p in galois.irreducible_polys(2, 1)]).issuperset(set([3])) - assert set([p.integer for p in galois.irreducible_polys(2, 2)]).issuperset(set([7])) - assert set([p.integer for p in galois.irreducible_polys(2, 3)]).issuperset(set([11, 13])) - assert set([p.integer for p in galois.irreducible_polys(2, 4)]).issuperset(set([19, 25])) - assert set([p.integer for p in galois.irreducible_polys(2, 5)]).issuperset(set([37, 41, 47, 55, 59, 61])) - assert set([p.integer for p in galois.irreducible_polys(2, 6)]).issuperset(set([67, 91, 97, 103, 109, 115])) - assert set([p.integer for p in galois.irreducible_polys(2, 7)]).issuperset(set([131, 137, 143, 145, 157, 167, 171, 185, 191, 193, 203, 211, 213, 229, 239, 241, 247, 253])) - assert set([p.integer for p in galois.irreducible_polys(2, 8)]).issuperset(set([285, 299, 301, 333, 351, 355, 357, 361, 369, 391, 397, 425, 451, 463, 487, 501])) - - # https://oeis.org/A001037 - # assert len(galois.irreducible_polys(2, 0)) == 1 - assert len(galois.irreducible_polys(2, 1)) == 2 - assert len(galois.irreducible_polys(2, 2)) == 1 - assert len(galois.irreducible_polys(2, 3)) == 2 - assert len(galois.irreducible_polys(2, 4)) == 3 - assert len(galois.irreducible_polys(2, 5)) == 6 - assert len(galois.irreducible_polys(2, 6)) == 9 - assert len(galois.irreducible_polys(2, 7)) == 18 - assert len(galois.irreducible_polys(2, 8)) == 30 - assert len(galois.irreducible_polys(2, 9)) == 56 - assert len(galois.irreducible_polys(2, 10)) == 99 - - -def test_irreducible_polys_product(): - GF = galois.GF2 - polys_1 = galois.irreducible_polys(2, 1) - polys_2 = galois.irreducible_polys(2, 2) - polys_4 = galois.irreducible_polys(2, 4) - g = galois.Poly.One(GF) - for p in polys_1 + polys_2 + polys_4: - g *= p - x = galois.Poly.Identity(GF) - assert g == x**(2**4) - x - - GF = galois.GF(3) - polys_1 = galois.irreducible_polys(3, 1) - polys_2 = galois.irreducible_polys(3, 2) - polys_4 = galois.irreducible_polys(3, 4) - g = galois.Poly.One(GF) - for p in polys_1 + polys_2 + polys_4: - g *= p - x = galois.Poly.Identity(GF) - assert g == x**(3**4) - x - - -def test_primitive_poly(): - p = galois.primitive_poly(2, 8) - assert galois.is_monic(p) - assert galois.is_irreducible(p) - assert galois.is_primitive(p) - assert p == galois.conway_poly(2, 8) - - p = galois.primitive_poly(2, 8, method="max") - assert galois.is_monic(p) - assert galois.is_irreducible(p) - assert galois.is_primitive(p) - - -def test_primitive_polys(): - """ - Generated with Octave: - primpoly(5, 'all') - primpoly(6, 'all') - primpoly(7, 'all') - primpoly(8, 'all') - """ - assert [p.integer for p in galois.primitive_polys(2, 1)] == [3] - assert [p.integer for p in galois.primitive_polys(2, 2)] == [7] - assert [p.integer for p in galois.primitive_polys(2, 3)] == [11, 13] - assert [p.integer for p in galois.primitive_polys(2, 4)] == [19, 25] - assert [p.integer for p in galois.primitive_polys(2, 5)] == [37, 41, 47, 55, 59, 61] - assert [p.integer for p in galois.primitive_polys(2, 6)] == [67, 91, 97, 103, 109, 115] - assert [p.integer for p in galois.primitive_polys(2, 7)] == [131, 137, 143, 145, 157, 167, 171, 185, 191, 193, 203, 211, 213, 229, 239, 241, 247, 253] - assert [p.integer for p in galois.primitive_polys(2, 8)] == [285, 299, 301, 333, 351, 355, 357, 361, 369, 391, 397, 425, 451, 463, 487, 501] - - # https://oeis.org/A011260 - assert len(galois.primitive_polys(2, 1)) == 1 - assert len(galois.primitive_polys(2, 2)) == 1 - assert len(galois.primitive_polys(2, 3)) == 2 - assert len(galois.primitive_polys(2, 4)) == 2 - assert len(galois.primitive_polys(2, 5)) == 6 - assert len(galois.primitive_polys(2, 6)) == 6 - assert len(galois.primitive_polys(2, 7)) == 18 - assert len(galois.primitive_polys(2, 8)) == 16 - assert len(galois.primitive_polys(2, 9)) == 48 - assert len(galois.primitive_polys(2, 10)) == 60 - - # https://baylor-ir.tdl.org/bitstream/handle/2104/8793/GF3%20Polynomials.pdf?sequence=1&isAllowed=y - GF = galois.GF(3) - assert galois.primitive_polys(3, 2) == [ - galois.Poly([1,1,2], field=GF), - galois.Poly([1,2,2], field=GF), - ] - assert galois.primitive_polys(3, 3) == [ - galois.Poly([1,0,2,1], field=GF), - galois.Poly([1,1,2,1], field=GF), - galois.Poly([1,2,0,1], field=GF), - galois.Poly([1,2,1,1], field=GF), - ] - assert galois.primitive_polys(3, 4) == [ - galois.Poly([1,0,0,1,2], field=GF), - galois.Poly([1,0,0,2,2], field=GF), - galois.Poly([1,1,0,0,2], field=GF), - galois.Poly([1,1,1,2,2], field=GF), - galois.Poly([1,1,2,2,2], field=GF), - galois.Poly([1,2,0,0,2], field=GF), - galois.Poly([1,2,1,1,2], field=GF), - galois.Poly([1,2,2,1,2], field=GF), - ] - assert galois.primitive_polys(3, 5) == [ - galois.Poly([1,0,0,0,2,1], field=GF), - galois.Poly([1,0,0,2,1,1], field=GF), - galois.Poly([1,0,1,0,1,1], field=GF), - galois.Poly([1,0,1,2,0,1], field=GF), - galois.Poly([1,0,1,2,2,1], field=GF), - galois.Poly([1,0,2,1,0,1], field=GF), - galois.Poly([1,0,2,2,1,1], field=GF), - galois.Poly([1,1,0,0,2,1], field=GF), - galois.Poly([1,1,0,1,0,1], field=GF), - galois.Poly([1,1,0,1,1,1], field=GF), - galois.Poly([1,1,1,0,1,1], field=GF), - galois.Poly([1,1,1,1,2,1], field=GF), - galois.Poly([1,1,1,2,1,1], field=GF), - galois.Poly([1,1,2,0,0,1], field=GF), - galois.Poly([1,1,2,1,1,1], field=GF), - galois.Poly([1,1,2,2,0,1], field=GF), - galois.Poly([1,2,0,0,0,1], field=GF), - galois.Poly([1,2,0,0,1,1], field=GF), - galois.Poly([1,2,0,2,2,1], field=GF), - galois.Poly([1,2,1,1,1,1], field=GF), - galois.Poly([1,2,2,0,2,1], field=GF), - galois.Poly([1,2,2,1,0,1], field=GF), - ] - - -def test_matlab_primitive_poly_GF2(): - """ - Generated with Matlab: - gfprimdf(m, 2) - """ - assert galois.matlab_primitive_poly(2, 1) == galois.Poly([1,1], order="asc") - assert galois.matlab_primitive_poly(2, 2) == galois.Poly([1,1,1], order="asc") - assert galois.matlab_primitive_poly(2, 3) == galois.Poly([1,1,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 4) == galois.Poly([1,1,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 5) == galois.Poly([1,0,1,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 6) == galois.Poly([1,1,0,0,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 7) == galois.Poly([1,0,0,1,0,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 8) == galois.Poly([1,0,1,1,1,0,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 9) == galois.Poly([1,0,0,0,1,0,0,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 10) == galois.Poly([1,0,0,1,0,0,0,0,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 11) == galois.Poly([1,0,1,0,0,0,0,0,0,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 12) == galois.Poly([1,1,0,0,1,0,1,0,0,0,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 13) == galois.Poly([1,1,0,1,1,0,0,0,0,0,0,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 14) == galois.Poly([1,1,0,0,0,0,1,0,0,0,1,0,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 15) == galois.Poly([1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], order="asc") - assert galois.matlab_primitive_poly(2, 16) == galois.Poly([1,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1], order="asc") - - -def test_matlab_primitive_poly_GF3(): - """ - Generated with Matlab: - gfprimdf(m, 3) - """ - GF = galois.GF(3) - assert galois.matlab_primitive_poly(3, 1) == galois.Poly([1,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(3, 2) == galois.Poly([2,1,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(3, 3) == galois.Poly([1,2,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(3, 4) == galois.Poly([2,1,0,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(3, 5) == galois.Poly([1,2,0,0,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(3, 6) == galois.Poly([2,1,0,0,0,0,1], field=GF, order="asc") - # assert galois.matlab_primitive_poly(3, 7) == galois.Poly([1,0,2,0,0,0,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(3, 8) == galois.Poly([2,0,0,1,0,0,0,0,1], field=GF, order="asc") - - -def test_matlab_primitive_poly_GF5(): - """ - Generated with Matlab: - gfprimdf(m, 5) - """ - GF = galois.GF(5) - assert galois.matlab_primitive_poly(5, 1) == galois.Poly([2,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(5, 2) == galois.Poly([2,1,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(5, 3) == galois.Poly([2,3,0,1], field=GF, order="asc") - # assert galois.matlab_primitive_poly(5, 4) == galois.Poly([2,2,1,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(5, 5) == galois.Poly([2,4,0,0,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(5, 6) == galois.Poly([2,1,0,0,0,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(5, 7) == galois.Poly([2,3,0,0,0,0,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(5, 8) == galois.Poly([3,2,1,0,0,0,0,0,1], field=GF, order="asc") - - -def test_matlab_primitive_poly_GF7(): - """ - Generated with Matlab: - gfprimdf(m, 7) - """ - GF = galois.GF(7) - assert galois.matlab_primitive_poly(7, 1) == galois.Poly([2,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(7, 2) == galois.Poly([3,1,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(7, 3) == galois.Poly([2,3,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(7, 4) == galois.Poly([5,3,1,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(7, 5) == galois.Poly([4,1,0,0,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(7, 6) == galois.Poly([5,1,3,0,0,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(7, 7) == galois.Poly([2,6,0,0,0,0,0,1], field=GF, order="asc") - assert galois.matlab_primitive_poly(7, 8) == galois.Poly([3,1,0,0,0,0,0,0,1], field=GF, order="asc") - - def test_minimal_poly(): GF = galois.GF(5) alpha = GF.primitive_element @@ -477,106 +231,6 @@ def test_is_monic_exceptions(): galois.is_monic(p.coeffs) -def test_is_irreducible_GF2(): - p = galois.conway_poly(2, 4) - assert galois.is_irreducible(p) - - p = galois.conway_poly(2, 5) - assert galois.is_irreducible(p) - - # Has no roots in GF(2) but is still reducible - p = galois.conway_poly(2, 4) * galois.conway_poly(2, 5) - assert not galois.is_irreducible(p) - - -def test_is_irreducible_GF7(): - GF = galois.GF(7) - - p = galois.conway_poly(7, 4) - assert galois.is_irreducible(p) - assert galois.is_irreducible(p * GF.Random(low=2)) - - p = galois.conway_poly(7, 5) - assert galois.is_irreducible(p) - assert galois.is_irreducible(p * GF.Random(low=2)) - - # Has no roots in GF(7) but is still reducible - p = galois.conway_poly(7, 4) * galois.conway_poly(7, 5) - assert not galois.is_irreducible(p) - - p = galois.conway_poly(7, 20) - assert galois.is_irreducible(p) - assert galois.is_irreducible(p * GF.Random(low=2)) - - p = galois.Poly.Roots([2, 3], field=GF) - assert not galois.is_irreducible(p) - - x = galois.Poly.Identity(GF) - p = galois.Poly.Random(20, field=GF) * x - assert not galois.is_irreducible(p) - - # x + a is always irreducible over any Galois field - p = galois.Poly([1, 0], field=GF) - assert galois.is_irreducible(p) - assert galois.is_irreducible(p * GF.Random(low=2)) - - p = galois.Poly([1, GF.Random(low=1)], field=GF) - assert galois.is_irreducible(p) - assert galois.is_irreducible(p * GF.Random(low=2)) - - -def test_is_irreducible_exceptions(): - with pytest.raises(TypeError): - galois.is_irreducible(galois.GF2.Random(5)) - with pytest.raises(ValueError): - galois.is_irreducible(galois.Poly.Random(0)) - with pytest.raises(ValueError): - galois.is_irreducible(galois.Poly.Random(5, field=galois.GF(2**8))) - - -def test_is_primitive(): - assert galois.is_primitive(galois.conway_poly(2, 1)) - assert galois.is_primitive(galois.conway_poly(2, 2)) - assert galois.is_primitive(galois.conway_poly(2, 3)) - assert galois.is_primitive(galois.conway_poly(2, 4)) - assert galois.is_primitive(galois.conway_poly(2, 5)) - assert galois.is_primitive(galois.conway_poly(2, 6)) - assert galois.is_primitive(galois.conway_poly(2, 7)) - assert galois.is_primitive(galois.conway_poly(2, 8)) - - # x^8 passes the primitivity tests but not irreducibility tests, needs to return False not True - assert not galois.is_primitive(galois.Poly.Degrees([8])) - - # The AES irreducible polynomial is not primitive - p = galois.Poly.Degrees([8,4,3,1,0]) - assert not galois.is_primitive(p) - - assert galois.is_primitive(galois.conway_poly(3, 1)) - assert galois.is_primitive(galois.conway_poly(3, 2)) - assert galois.is_primitive(galois.conway_poly(3, 3)) - assert galois.is_primitive(galois.conway_poly(3, 4)) - assert galois.is_primitive(galois.conway_poly(3, 5)) - - # x + 1 is irreducible over GF(5) but not primitive - GF = galois.GF(5) - p = galois.Poly([1, 1], field=GF) - assert not galois.is_primitive(p) - - # x + 2 is irreducible over GF(5) and primitive - GF = galois.GF(5) - p = galois.Poly([1, 2], field=GF) - assert galois.is_primitive(p) - - -def test_is_primitive_exceptions(): - with pytest.raises(TypeError): - galois.is_primitive(galois.GF2.Random(5)) - with pytest.raises(TypeError): - galois.is_primitive(galois.Poly.Random(0)) - with pytest.raises(ValueError): - galois.is_primitive(galois.Poly.Random(5, field=galois.GF(2**8))) - - def test_primitive_element(): x = galois.Poly.Identity() assert galois.primitive_element(galois.conway_poly(2, 2)) == x diff --git a/tests/polys/test_irreducible_polys.py b/tests/polys/test_irreducible_polys.py new file mode 100644 index 0000000000..3c8c2da2ec --- /dev/null +++ b/tests/polys/test_irreducible_polys.py @@ -0,0 +1,784 @@ +""" +A pytest module to test generating irreducible polynomials and testing irreducibility. + +Sage: + p = 3 + for degree in range(1, 7): + print(f"IRREDUCIBLE_POLYS_{p}_{degree} = [") + F = GF(p)["x"] + for f in F.polynomials(degree): + if f.is_monic() and f.is_irreducible(): + c = f.coefficients(sparse=False)[::-1] + print(f" galois.Poly({c}, field=GF{p}),") + print("]\n") +""" +import pytest +import numpy as np + +import galois + +GF2 = galois.GF(2) +GF3 = galois.GF(3) +GF5 = galois.GF(5) + +IRREDUCIBLE_POLYS_2_1 = [ + galois.Poly([1, 0], field=GF2), + galois.Poly([1, 1], field=GF2), +] + +IRREDUCIBLE_POLYS_2_2 = [ + galois.Poly([1, 1, 1], field=GF2), +] + +IRREDUCIBLE_POLYS_2_3 = [ + galois.Poly([1, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1], field=GF2), +] + +IRREDUCIBLE_POLYS_2_4 = [ + galois.Poly([1, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 1], field=GF2), +] + +IRREDUCIBLE_POLYS_2_5 = [ + galois.Poly([1, 0, 0, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 0, 1], field=GF2), +] + +IRREDUCIBLE_POLYS_2_6 = [ + galois.Poly([1, 0, 0, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 1, 0, 1], field=GF2), +] + +IRREDUCIBLE_POLYS_2_7 = [ + galois.Poly([1, 0, 0, 0, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 0, 0, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 0, 0, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 0, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 0, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 1, 1, 0, 1], field=GF2), +] + +IRREDUCIBLE_POLYS_2_8 = [ + galois.Poly([1, 0, 0, 0, 1, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 0, 0, 1, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 0, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 0, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 1, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 1, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 0, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 1, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 0, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 0, 0, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 0, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 1, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 1, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 1, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 0, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 0, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 0, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 1, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 0, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 0, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 1, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 1, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 0, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 0, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 1, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 1, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 0, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 1, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 1, 0, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 1, 1, 0, 0, 1], field=GF2), +] + +IRREDUCIBLE_POLYS_3_1 = [ + galois.Poly([1, 0], field=GF3), + galois.Poly([1, 1], field=GF3), + galois.Poly([1, 2], field=GF3), +] + +IRREDUCIBLE_POLYS_3_2 = [ + galois.Poly([1, 0, 1], field=GF3), + galois.Poly([1, 1, 2], field=GF3), + galois.Poly([1, 2, 2], field=GF3), +] + +IRREDUCIBLE_POLYS_3_3 = [ + galois.Poly([1, 0, 2, 1], field=GF3), + galois.Poly([1, 0, 2, 2], field=GF3), + galois.Poly([1, 1, 0, 2], field=GF3), + galois.Poly([1, 1, 1, 2], field=GF3), + galois.Poly([1, 1, 2, 1], field=GF3), + galois.Poly([1, 2, 0, 1], field=GF3), + galois.Poly([1, 2, 1, 1], field=GF3), + galois.Poly([1, 2, 2, 2], field=GF3), +] + +IRREDUCIBLE_POLYS_3_4 = [ + galois.Poly([1, 0, 0, 1, 2], field=GF3), + galois.Poly([1, 0, 0, 2, 2], field=GF3), + galois.Poly([1, 0, 1, 0, 2], field=GF3), + galois.Poly([1, 0, 1, 1, 1], field=GF3), + galois.Poly([1, 0, 1, 2, 1], field=GF3), + galois.Poly([1, 0, 2, 0, 2], field=GF3), + galois.Poly([1, 1, 0, 0, 2], field=GF3), + galois.Poly([1, 1, 0, 2, 1], field=GF3), + galois.Poly([1, 1, 1, 0, 1], field=GF3), + galois.Poly([1, 1, 1, 1, 1], field=GF3), + galois.Poly([1, 1, 1, 2, 2], field=GF3), + galois.Poly([1, 1, 2, 2, 2], field=GF3), + galois.Poly([1, 2, 0, 0, 2], field=GF3), + galois.Poly([1, 2, 0, 1, 1], field=GF3), + galois.Poly([1, 2, 1, 0, 1], field=GF3), + galois.Poly([1, 2, 1, 1, 2], field=GF3), + galois.Poly([1, 2, 1, 2, 1], field=GF3), + galois.Poly([1, 2, 2, 1, 2], field=GF3), +] + +IRREDUCIBLE_POLYS_3_5 = [ + galois.Poly([1, 0, 0, 0, 2, 1], field=GF3), + galois.Poly([1, 0, 0, 0, 2, 2], field=GF3), + galois.Poly([1, 0, 0, 1, 1, 2], field=GF3), + galois.Poly([1, 0, 0, 2, 1, 1], field=GF3), + galois.Poly([1, 0, 1, 0, 1, 1], field=GF3), + galois.Poly([1, 0, 1, 0, 1, 2], field=GF3), + galois.Poly([1, 0, 1, 1, 0, 2], field=GF3), + galois.Poly([1, 0, 1, 1, 2, 2], field=GF3), + galois.Poly([1, 0, 1, 2, 0, 1], field=GF3), + galois.Poly([1, 0, 1, 2, 2, 1], field=GF3), + galois.Poly([1, 0, 2, 1, 0, 1], field=GF3), + galois.Poly([1, 0, 2, 1, 1, 2], field=GF3), + galois.Poly([1, 0, 2, 1, 2, 2], field=GF3), + galois.Poly([1, 0, 2, 2, 0, 2], field=GF3), + galois.Poly([1, 0, 2, 2, 1, 1], field=GF3), + galois.Poly([1, 0, 2, 2, 2, 1], field=GF3), + galois.Poly([1, 1, 0, 0, 0, 2], field=GF3), + galois.Poly([1, 1, 0, 0, 1, 2], field=GF3), + galois.Poly([1, 1, 0, 0, 2, 1], field=GF3), + galois.Poly([1, 1, 0, 1, 0, 1], field=GF3), + galois.Poly([1, 1, 0, 1, 1, 1], field=GF3), + galois.Poly([1, 1, 0, 1, 2, 2], field=GF3), + galois.Poly([1, 1, 1, 0, 1, 1], field=GF3), + galois.Poly([1, 1, 1, 1, 2, 1], field=GF3), + galois.Poly([1, 1, 1, 2, 1, 1], field=GF3), + galois.Poly([1, 1, 1, 2, 1, 2], field=GF3), + galois.Poly([1, 1, 2, 0, 0, 1], field=GF3), + galois.Poly([1, 1, 2, 0, 2, 2], field=GF3), + galois.Poly([1, 1, 2, 1, 0, 2], field=GF3), + galois.Poly([1, 1, 2, 1, 1, 1], field=GF3), + galois.Poly([1, 1, 2, 2, 0, 1], field=GF3), + galois.Poly([1, 1, 2, 2, 0, 2], field=GF3), + galois.Poly([1, 2, 0, 0, 0, 1], field=GF3), + galois.Poly([1, 2, 0, 0, 1, 1], field=GF3), + galois.Poly([1, 2, 0, 0, 2, 2], field=GF3), + galois.Poly([1, 2, 0, 2, 0, 2], field=GF3), + galois.Poly([1, 2, 0, 2, 1, 2], field=GF3), + galois.Poly([1, 2, 0, 2, 2, 1], field=GF3), + galois.Poly([1, 2, 1, 0, 1, 2], field=GF3), + galois.Poly([1, 2, 1, 1, 1, 1], field=GF3), + galois.Poly([1, 2, 1, 1, 1, 2], field=GF3), + galois.Poly([1, 2, 1, 2, 2, 2], field=GF3), + galois.Poly([1, 2, 2, 0, 0, 2], field=GF3), + galois.Poly([1, 2, 2, 0, 2, 1], field=GF3), + galois.Poly([1, 2, 2, 1, 0, 1], field=GF3), + galois.Poly([1, 2, 2, 1, 0, 2], field=GF3), + galois.Poly([1, 2, 2, 2, 0, 1], field=GF3), + galois.Poly([1, 2, 2, 2, 1, 2], field=GF3), +] + +IRREDUCIBLE_POLYS_3_6 = [ + galois.Poly([1, 0, 0, 0, 0, 1, 2], field=GF3), + galois.Poly([1, 0, 0, 0, 0, 2, 2], field=GF3), + galois.Poly([1, 0, 0, 0, 1, 1, 1], field=GF3), + galois.Poly([1, 0, 0, 0, 1, 2, 1], field=GF3), + galois.Poly([1, 0, 0, 0, 2, 0, 1], field=GF3), + galois.Poly([1, 0, 0, 1, 0, 1, 2], field=GF3), + galois.Poly([1, 0, 0, 1, 0, 2, 1], field=GF3), + galois.Poly([1, 0, 0, 1, 1, 0, 1], field=GF3), + galois.Poly([1, 0, 0, 1, 1, 2, 2], field=GF3), + galois.Poly([1, 0, 0, 1, 2, 2, 1], field=GF3), + galois.Poly([1, 0, 0, 2, 0, 1, 1], field=GF3), + galois.Poly([1, 0, 0, 2, 0, 2, 2], field=GF3), + galois.Poly([1, 0, 0, 2, 1, 0, 1], field=GF3), + galois.Poly([1, 0, 0, 2, 1, 1, 2], field=GF3), + galois.Poly([1, 0, 0, 2, 2, 1, 1], field=GF3), + galois.Poly([1, 0, 1, 0, 2, 0, 1], field=GF3), + galois.Poly([1, 0, 1, 0, 2, 1, 2], field=GF3), + galois.Poly([1, 0, 1, 0, 2, 2, 2], field=GF3), + galois.Poly([1, 0, 1, 1, 0, 0, 1], field=GF3), + galois.Poly([1, 0, 1, 1, 0, 1, 1], field=GF3), + galois.Poly([1, 0, 1, 1, 0, 2, 2], field=GF3), + galois.Poly([1, 0, 1, 1, 1, 2, 2], field=GF3), + galois.Poly([1, 0, 1, 2, 0, 0, 1], field=GF3), + galois.Poly([1, 0, 1, 2, 0, 1, 2], field=GF3), + galois.Poly([1, 0, 1, 2, 0, 2, 1], field=GF3), + galois.Poly([1, 0, 1, 2, 1, 1, 2], field=GF3), + galois.Poly([1, 0, 2, 0, 0, 0, 1], field=GF3), + galois.Poly([1, 0, 2, 0, 1, 0, 1], field=GF3), + galois.Poly([1, 0, 2, 0, 1, 1, 2], field=GF3), + galois.Poly([1, 0, 2, 0, 1, 2, 2], field=GF3), + galois.Poly([1, 0, 2, 1, 0, 2, 1], field=GF3), + galois.Poly([1, 0, 2, 1, 1, 0, 2], field=GF3), + galois.Poly([1, 0, 2, 1, 1, 1, 2], field=GF3), + galois.Poly([1, 0, 2, 1, 1, 2, 1], field=GF3), + galois.Poly([1, 0, 2, 2, 0, 1, 1], field=GF3), + galois.Poly([1, 0, 2, 2, 1, 0, 2], field=GF3), + galois.Poly([1, 0, 2, 2, 1, 1, 1], field=GF3), + galois.Poly([1, 0, 2, 2, 1, 2, 2], field=GF3), + galois.Poly([1, 1, 0, 0, 0, 0, 2], field=GF3), + galois.Poly([1, 1, 0, 0, 0, 1, 2], field=GF3), + galois.Poly([1, 1, 0, 0, 1, 1, 1], field=GF3), + galois.Poly([1, 1, 0, 1, 0, 0, 2], field=GF3), + galois.Poly([1, 1, 0, 1, 0, 1, 1], field=GF3), + galois.Poly([1, 1, 0, 1, 1, 0, 1], field=GF3), + galois.Poly([1, 1, 0, 1, 1, 1, 2], field=GF3), + galois.Poly([1, 1, 0, 1, 2, 1, 2], field=GF3), + galois.Poly([1, 1, 0, 2, 0, 0, 1], field=GF3), + galois.Poly([1, 1, 0, 2, 1, 1, 1], field=GF3), + galois.Poly([1, 1, 0, 2, 1, 2, 1], field=GF3), + galois.Poly([1, 1, 0, 2, 2, 0, 1], field=GF3), + galois.Poly([1, 1, 0, 2, 2, 0, 2], field=GF3), + galois.Poly([1, 1, 1, 0, 0, 0, 1], field=GF3), + galois.Poly([1, 1, 1, 0, 0, 1, 1], field=GF3), + galois.Poly([1, 1, 1, 0, 1, 2, 2], field=GF3), + galois.Poly([1, 1, 1, 0, 2, 0, 2], field=GF3), + galois.Poly([1, 1, 1, 0, 2, 2, 1], field=GF3), + galois.Poly([1, 1, 1, 1, 0, 1, 2], field=GF3), + galois.Poly([1, 1, 1, 1, 0, 2, 1], field=GF3), + galois.Poly([1, 1, 1, 1, 1, 1, 1], field=GF3), + galois.Poly([1, 1, 1, 1, 1, 1, 2], field=GF3), + galois.Poly([1, 1, 1, 1, 2, 2, 2], field=GF3), + galois.Poly([1, 1, 1, 2, 0, 1, 1], field=GF3), + galois.Poly([1, 1, 1, 2, 2, 0, 1], field=GF3), + galois.Poly([1, 1, 1, 2, 2, 2, 2], field=GF3), + galois.Poly([1, 1, 2, 0, 1, 0, 2], field=GF3), + galois.Poly([1, 1, 2, 0, 1, 2, 1], field=GF3), + galois.Poly([1, 1, 2, 0, 2, 2, 2], field=GF3), + galois.Poly([1, 1, 2, 1, 0, 1, 2], field=GF3), + galois.Poly([1, 1, 2, 1, 1, 0, 2], field=GF3), + galois.Poly([1, 1, 2, 1, 1, 2, 2], field=GF3), + galois.Poly([1, 1, 2, 1, 2, 1, 2], field=GF3), + galois.Poly([1, 1, 2, 1, 2, 2, 1], field=GF3), + galois.Poly([1, 1, 2, 2, 0, 0, 1], field=GF3), + galois.Poly([1, 1, 2, 2, 0, 0, 2], field=GF3), + galois.Poly([1, 1, 2, 2, 1, 2, 2], field=GF3), + galois.Poly([1, 1, 2, 2, 2, 0, 2], field=GF3), + galois.Poly([1, 1, 2, 2, 2, 2, 1], field=GF3), + galois.Poly([1, 2, 0, 0, 0, 0, 2], field=GF3), + galois.Poly([1, 2, 0, 0, 0, 2, 2], field=GF3), + galois.Poly([1, 2, 0, 0, 1, 2, 1], field=GF3), + galois.Poly([1, 2, 0, 1, 0, 0, 1], field=GF3), + galois.Poly([1, 2, 0, 1, 1, 1, 1], field=GF3), + galois.Poly([1, 2, 0, 1, 1, 2, 1], field=GF3), + galois.Poly([1, 2, 0, 1, 2, 0, 1], field=GF3), + galois.Poly([1, 2, 0, 1, 2, 0, 2], field=GF3), + galois.Poly([1, 2, 0, 2, 0, 0, 2], field=GF3), + galois.Poly([1, 2, 0, 2, 0, 2, 1], field=GF3), + galois.Poly([1, 2, 0, 2, 1, 0, 1], field=GF3), + galois.Poly([1, 2, 0, 2, 1, 2, 2], field=GF3), + galois.Poly([1, 2, 0, 2, 2, 2, 2], field=GF3), + galois.Poly([1, 2, 1, 0, 0, 0, 1], field=GF3), + galois.Poly([1, 2, 1, 0, 0, 2, 1], field=GF3), + galois.Poly([1, 2, 1, 0, 1, 1, 2], field=GF3), + galois.Poly([1, 2, 1, 0, 2, 0, 2], field=GF3), + galois.Poly([1, 2, 1, 0, 2, 1, 1], field=GF3), + galois.Poly([1, 2, 1, 1, 0, 2, 1], field=GF3), + galois.Poly([1, 2, 1, 1, 2, 0, 1], field=GF3), + galois.Poly([1, 2, 1, 1, 2, 1, 2], field=GF3), + galois.Poly([1, 2, 1, 2, 0, 1, 1], field=GF3), + galois.Poly([1, 2, 1, 2, 0, 2, 2], field=GF3), + galois.Poly([1, 2, 1, 2, 1, 2, 1], field=GF3), + galois.Poly([1, 2, 1, 2, 1, 2, 2], field=GF3), + galois.Poly([1, 2, 1, 2, 2, 1, 2], field=GF3), + galois.Poly([1, 2, 2, 0, 1, 0, 2], field=GF3), + galois.Poly([1, 2, 2, 0, 1, 1, 1], field=GF3), + galois.Poly([1, 2, 2, 0, 2, 1, 2], field=GF3), + galois.Poly([1, 2, 2, 1, 0, 0, 1], field=GF3), + galois.Poly([1, 2, 2, 1, 0, 0, 2], field=GF3), + galois.Poly([1, 2, 2, 1, 1, 1, 2], field=GF3), + galois.Poly([1, 2, 2, 1, 2, 0, 2], field=GF3), + galois.Poly([1, 2, 2, 1, 2, 1, 1], field=GF3), + galois.Poly([1, 2, 2, 2, 0, 2, 2], field=GF3), + galois.Poly([1, 2, 2, 2, 1, 0, 2], field=GF3), + galois.Poly([1, 2, 2, 2, 1, 1, 2], field=GF3), + galois.Poly([1, 2, 2, 2, 2, 1, 1], field=GF3), + galois.Poly([1, 2, 2, 2, 2, 2, 2], field=GF3), +] + +IRREDUCIBLE_POLYS_5_1 = [ + galois.Poly([1, 0], field=GF5), + galois.Poly([1, 1], field=GF5), + galois.Poly([1, 2], field=GF5), + galois.Poly([1, 3], field=GF5), + galois.Poly([1, 4], field=GF5), +] + +IRREDUCIBLE_POLYS_5_2 = [ + galois.Poly([1, 0, 2], field=GF5), + galois.Poly([1, 0, 3], field=GF5), + galois.Poly([1, 1, 1], field=GF5), + galois.Poly([1, 1, 2], field=GF5), + galois.Poly([1, 2, 3], field=GF5), + galois.Poly([1, 2, 4], field=GF5), + galois.Poly([1, 3, 3], field=GF5), + galois.Poly([1, 3, 4], field=GF5), + galois.Poly([1, 4, 1], field=GF5), + galois.Poly([1, 4, 2], field=GF5), +] + +IRREDUCIBLE_POLYS_5_3 = [ + galois.Poly([1, 0, 1, 1], field=GF5), + galois.Poly([1, 0, 1, 4], field=GF5), + galois.Poly([1, 0, 2, 1], field=GF5), + galois.Poly([1, 0, 2, 4], field=GF5), + galois.Poly([1, 0, 3, 2], field=GF5), + galois.Poly([1, 0, 3, 3], field=GF5), + galois.Poly([1, 0, 4, 2], field=GF5), + galois.Poly([1, 0, 4, 3], field=GF5), + galois.Poly([1, 1, 0, 1], field=GF5), + galois.Poly([1, 1, 0, 2], field=GF5), + galois.Poly([1, 1, 1, 3], field=GF5), + galois.Poly([1, 1, 1, 4], field=GF5), + galois.Poly([1, 1, 3, 1], field=GF5), + galois.Poly([1, 1, 3, 4], field=GF5), + galois.Poly([1, 1, 4, 1], field=GF5), + galois.Poly([1, 1, 4, 3], field=GF5), + galois.Poly([1, 2, 0, 1], field=GF5), + galois.Poly([1, 2, 0, 3], field=GF5), + galois.Poly([1, 2, 1, 3], field=GF5), + galois.Poly([1, 2, 1, 4], field=GF5), + galois.Poly([1, 2, 2, 2], field=GF5), + galois.Poly([1, 2, 2, 3], field=GF5), + galois.Poly([1, 2, 4, 2], field=GF5), + galois.Poly([1, 2, 4, 4], field=GF5), + galois.Poly([1, 3, 0, 2], field=GF5), + galois.Poly([1, 3, 0, 4], field=GF5), + galois.Poly([1, 3, 1, 1], field=GF5), + galois.Poly([1, 3, 1, 2], field=GF5), + galois.Poly([1, 3, 2, 2], field=GF5), + galois.Poly([1, 3, 2, 3], field=GF5), + galois.Poly([1, 3, 4, 1], field=GF5), + galois.Poly([1, 3, 4, 3], field=GF5), + galois.Poly([1, 4, 0, 3], field=GF5), + galois.Poly([1, 4, 0, 4], field=GF5), + galois.Poly([1, 4, 1, 1], field=GF5), + galois.Poly([1, 4, 1, 2], field=GF5), + galois.Poly([1, 4, 3, 1], field=GF5), + galois.Poly([1, 4, 3, 4], field=GF5), + galois.Poly([1, 4, 4, 2], field=GF5), + galois.Poly([1, 4, 4, 4], field=GF5), +] + +IRREDUCIBLE_POLYS_5_4 = [ + galois.Poly([1, 0, 0, 0, 2], field=GF5), + galois.Poly([1, 0, 0, 0, 3], field=GF5), + galois.Poly([1, 0, 0, 1, 4], field=GF5), + galois.Poly([1, 0, 0, 2, 4], field=GF5), + galois.Poly([1, 0, 0, 3, 4], field=GF5), + galois.Poly([1, 0, 0, 4, 4], field=GF5), + galois.Poly([1, 0, 1, 0, 2], field=GF5), + galois.Poly([1, 0, 1, 1, 1], field=GF5), + galois.Poly([1, 0, 1, 2, 2], field=GF5), + galois.Poly([1, 0, 1, 2, 3], field=GF5), + galois.Poly([1, 0, 1, 3, 2], field=GF5), + galois.Poly([1, 0, 1, 3, 3], field=GF5), + galois.Poly([1, 0, 1, 4, 1], field=GF5), + galois.Poly([1, 0, 2, 0, 3], field=GF5), + galois.Poly([1, 0, 2, 2, 1], field=GF5), + galois.Poly([1, 0, 2, 2, 3], field=GF5), + galois.Poly([1, 0, 2, 3, 1], field=GF5), + galois.Poly([1, 0, 2, 3, 3], field=GF5), + galois.Poly([1, 0, 3, 0, 3], field=GF5), + galois.Poly([1, 0, 3, 1, 1], field=GF5), + galois.Poly([1, 0, 3, 1, 3], field=GF5), + galois.Poly([1, 0, 3, 4, 1], field=GF5), + galois.Poly([1, 0, 3, 4, 3], field=GF5), + galois.Poly([1, 0, 4, 0, 2], field=GF5), + galois.Poly([1, 0, 4, 1, 2], field=GF5), + galois.Poly([1, 0, 4, 1, 3], field=GF5), + galois.Poly([1, 0, 4, 2, 1], field=GF5), + galois.Poly([1, 0, 4, 3, 1], field=GF5), + galois.Poly([1, 0, 4, 4, 2], field=GF5), + galois.Poly([1, 0, 4, 4, 3], field=GF5), + galois.Poly([1, 1, 0, 0, 4], field=GF5), + galois.Poly([1, 1, 0, 1, 3], field=GF5), + galois.Poly([1, 1, 0, 2, 3], field=GF5), + galois.Poly([1, 1, 0, 2, 4], field=GF5), + galois.Poly([1, 1, 0, 3, 2], field=GF5), + galois.Poly([1, 1, 0, 4, 1], field=GF5), + galois.Poly([1, 1, 0, 4, 2], field=GF5), + galois.Poly([1, 1, 1, 0, 1], field=GF5), + galois.Poly([1, 1, 1, 1, 3], field=GF5), + galois.Poly([1, 1, 1, 1, 4], field=GF5), + galois.Poly([1, 1, 1, 2, 4], field=GF5), + galois.Poly([1, 1, 1, 3, 3], field=GF5), + galois.Poly([1, 1, 1, 4, 2], field=GF5), + galois.Poly([1, 1, 2, 0, 2], field=GF5), + galois.Poly([1, 1, 2, 1, 2], field=GF5), + galois.Poly([1, 1, 2, 1, 3], field=GF5), + galois.Poly([1, 1, 2, 2, 1], field=GF5), + galois.Poly([1, 1, 2, 2, 2], field=GF5), + galois.Poly([1, 1, 2, 3, 4], field=GF5), + galois.Poly([1, 1, 2, 4, 4], field=GF5), + galois.Poly([1, 1, 3, 0, 1], field=GF5), + galois.Poly([1, 1, 3, 0, 3], field=GF5), + galois.Poly([1, 1, 3, 2, 1], field=GF5), + galois.Poly([1, 1, 3, 4, 2], field=GF5), + galois.Poly([1, 1, 3, 4, 4], field=GF5), + galois.Poly([1, 1, 4, 0, 2], field=GF5), + galois.Poly([1, 1, 4, 1, 1], field=GF5), + galois.Poly([1, 1, 4, 1, 4], field=GF5), + galois.Poly([1, 1, 4, 4, 1], field=GF5), + galois.Poly([1, 1, 4, 4, 3], field=GF5), + galois.Poly([1, 2, 0, 0, 4], field=GF5), + galois.Poly([1, 2, 0, 1, 3], field=GF5), + galois.Poly([1, 2, 0, 1, 4], field=GF5), + galois.Poly([1, 2, 0, 2, 1], field=GF5), + galois.Poly([1, 2, 0, 2, 2], field=GF5), + galois.Poly([1, 2, 0, 3, 3], field=GF5), + galois.Poly([1, 2, 0, 4, 2], field=GF5), + galois.Poly([1, 2, 1, 0, 2], field=GF5), + galois.Poly([1, 2, 1, 2, 1], field=GF5), + galois.Poly([1, 2, 1, 2, 3], field=GF5), + galois.Poly([1, 2, 1, 3, 1], field=GF5), + galois.Poly([1, 2, 1, 3, 4], field=GF5), + galois.Poly([1, 2, 2, 0, 1], field=GF5), + galois.Poly([1, 2, 2, 0, 3], field=GF5), + galois.Poly([1, 2, 2, 1, 1], field=GF5), + galois.Poly([1, 2, 2, 2, 2], field=GF5), + galois.Poly([1, 2, 2, 2, 4], field=GF5), + galois.Poly([1, 2, 3, 0, 2], field=GF5), + galois.Poly([1, 2, 3, 1, 1], field=GF5), + galois.Poly([1, 2, 3, 1, 2], field=GF5), + galois.Poly([1, 2, 3, 2, 4], field=GF5), + galois.Poly([1, 2, 3, 3, 2], field=GF5), + galois.Poly([1, 2, 3, 3, 3], field=GF5), + galois.Poly([1, 2, 3, 4, 4], field=GF5), + galois.Poly([1, 2, 4, 0, 1], field=GF5), + galois.Poly([1, 2, 4, 1, 4], field=GF5), + galois.Poly([1, 2, 4, 2, 2], field=GF5), + galois.Poly([1, 2, 4, 3, 3], field=GF5), + galois.Poly([1, 2, 4, 3, 4], field=GF5), + galois.Poly([1, 2, 4, 4, 3], field=GF5), + galois.Poly([1, 3, 0, 0, 4], field=GF5), + galois.Poly([1, 3, 0, 1, 2], field=GF5), + galois.Poly([1, 3, 0, 2, 3], field=GF5), + galois.Poly([1, 3, 0, 3, 1], field=GF5), + galois.Poly([1, 3, 0, 3, 2], field=GF5), + galois.Poly([1, 3, 0, 4, 3], field=GF5), + galois.Poly([1, 3, 0, 4, 4], field=GF5), + galois.Poly([1, 3, 1, 0, 2], field=GF5), + galois.Poly([1, 3, 1, 2, 1], field=GF5), + galois.Poly([1, 3, 1, 2, 4], field=GF5), + galois.Poly([1, 3, 1, 3, 1], field=GF5), + galois.Poly([1, 3, 1, 3, 3], field=GF5), + galois.Poly([1, 3, 2, 0, 1], field=GF5), + galois.Poly([1, 3, 2, 0, 3], field=GF5), + galois.Poly([1, 3, 2, 3, 2], field=GF5), + galois.Poly([1, 3, 2, 3, 4], field=GF5), + galois.Poly([1, 3, 2, 4, 1], field=GF5), + galois.Poly([1, 3, 3, 0, 2], field=GF5), + galois.Poly([1, 3, 3, 1, 4], field=GF5), + galois.Poly([1, 3, 3, 2, 2], field=GF5), + galois.Poly([1, 3, 3, 2, 3], field=GF5), + galois.Poly([1, 3, 3, 3, 4], field=GF5), + galois.Poly([1, 3, 3, 4, 1], field=GF5), + galois.Poly([1, 3, 3, 4, 2], field=GF5), + galois.Poly([1, 3, 4, 0, 1], field=GF5), + galois.Poly([1, 3, 4, 1, 3], field=GF5), + galois.Poly([1, 3, 4, 2, 3], field=GF5), + galois.Poly([1, 3, 4, 2, 4], field=GF5), + galois.Poly([1, 3, 4, 3, 2], field=GF5), + galois.Poly([1, 3, 4, 4, 4], field=GF5), + galois.Poly([1, 4, 0, 0, 4], field=GF5), + galois.Poly([1, 4, 0, 1, 1], field=GF5), + galois.Poly([1, 4, 0, 1, 2], field=GF5), + galois.Poly([1, 4, 0, 2, 2], field=GF5), + galois.Poly([1, 4, 0, 3, 3], field=GF5), + galois.Poly([1, 4, 0, 3, 4], field=GF5), + galois.Poly([1, 4, 0, 4, 3], field=GF5), + galois.Poly([1, 4, 1, 0, 1], field=GF5), + galois.Poly([1, 4, 1, 1, 2], field=GF5), + galois.Poly([1, 4, 1, 2, 3], field=GF5), + galois.Poly([1, 4, 1, 3, 4], field=GF5), + galois.Poly([1, 4, 1, 4, 3], field=GF5), + galois.Poly([1, 4, 1, 4, 4], field=GF5), + galois.Poly([1, 4, 2, 0, 2], field=GF5), + galois.Poly([1, 4, 2, 1, 4], field=GF5), + galois.Poly([1, 4, 2, 2, 4], field=GF5), + galois.Poly([1, 4, 2, 3, 1], field=GF5), + galois.Poly([1, 4, 2, 3, 2], field=GF5), + galois.Poly([1, 4, 2, 4, 2], field=GF5), + galois.Poly([1, 4, 2, 4, 3], field=GF5), + galois.Poly([1, 4, 3, 0, 1], field=GF5), + galois.Poly([1, 4, 3, 0, 3], field=GF5), + galois.Poly([1, 4, 3, 1, 2], field=GF5), + galois.Poly([1, 4, 3, 1, 4], field=GF5), + galois.Poly([1, 4, 3, 3, 1], field=GF5), + galois.Poly([1, 4, 4, 0, 2], field=GF5), + galois.Poly([1, 4, 4, 1, 1], field=GF5), + galois.Poly([1, 4, 4, 1, 3], field=GF5), + galois.Poly([1, 4, 4, 4, 1], field=GF5), + galois.Poly([1, 4, 4, 4, 4], field=GF5), +] + + +def test_irreducible_poly_exceptions(): + with pytest.raises(TypeError): + galois.irreducible_poly(2.0, 3) + with pytest.raises(TypeError): + galois.irreducible_poly(2, 3.0) + with pytest.raises(ValueError): + galois.irreducible_poly(4, 3) + with pytest.raises(ValueError): + galois.irreducible_poly(2, 0) + with pytest.raises(ValueError): + galois.irreducible_poly(2, 3, method="invalid-argument") + + +def test_irreducible_poly_min(): + assert galois.irreducible_poly(2, 1) == IRREDUCIBLE_POLYS_2_1[0] + assert galois.irreducible_poly(2, 2) == IRREDUCIBLE_POLYS_2_2[0] + assert galois.irreducible_poly(2, 3) == IRREDUCIBLE_POLYS_2_3[0] + assert galois.irreducible_poly(2, 4) == IRREDUCIBLE_POLYS_2_4[0] + assert galois.irreducible_poly(2, 5) == IRREDUCIBLE_POLYS_2_5[0] + assert galois.irreducible_poly(2, 6) == IRREDUCIBLE_POLYS_2_6[0] + assert galois.irreducible_poly(2, 7) == IRREDUCIBLE_POLYS_2_7[0] + assert galois.irreducible_poly(2, 8) == IRREDUCIBLE_POLYS_2_8[0] + + assert galois.irreducible_poly(3, 1) == IRREDUCIBLE_POLYS_3_1[0] + assert galois.irreducible_poly(3, 2) == IRREDUCIBLE_POLYS_3_2[0] + assert galois.irreducible_poly(3, 3) == IRREDUCIBLE_POLYS_3_3[0] + assert galois.irreducible_poly(3, 4) == IRREDUCIBLE_POLYS_3_4[0] + assert galois.irreducible_poly(3, 5) == IRREDUCIBLE_POLYS_3_5[0] + assert galois.irreducible_poly(3, 6) == IRREDUCIBLE_POLYS_3_6[0] + + assert galois.irreducible_poly(5, 1) == IRREDUCIBLE_POLYS_5_1[0] + assert galois.irreducible_poly(5, 2) == IRREDUCIBLE_POLYS_5_2[0] + assert galois.irreducible_poly(5, 3) == IRREDUCIBLE_POLYS_5_3[0] + assert galois.irreducible_poly(5, 4) == IRREDUCIBLE_POLYS_5_4[0] + + +def test_irreducible_poly_max(): + assert galois.irreducible_poly(2, 1, method="max") == IRREDUCIBLE_POLYS_2_1[-1] + assert galois.irreducible_poly(2, 2, method="max") == IRREDUCIBLE_POLYS_2_2[-1] + assert galois.irreducible_poly(2, 3, method="max") == IRREDUCIBLE_POLYS_2_3[-1] + assert galois.irreducible_poly(2, 4, method="max") == IRREDUCIBLE_POLYS_2_4[-1] + assert galois.irreducible_poly(2, 5, method="max") == IRREDUCIBLE_POLYS_2_5[-1] + assert galois.irreducible_poly(2, 6, method="max") == IRREDUCIBLE_POLYS_2_6[-1] + assert galois.irreducible_poly(2, 7, method="max") == IRREDUCIBLE_POLYS_2_7[-1] + assert galois.irreducible_poly(2, 8, method="max") == IRREDUCIBLE_POLYS_2_8[-1] + + assert galois.irreducible_poly(3, 1, method="max") == IRREDUCIBLE_POLYS_3_1[-1] + assert galois.irreducible_poly(3, 2, method="max") == IRREDUCIBLE_POLYS_3_2[-1] + assert galois.irreducible_poly(3, 3, method="max") == IRREDUCIBLE_POLYS_3_3[-1] + assert galois.irreducible_poly(3, 4, method="max") == IRREDUCIBLE_POLYS_3_4[-1] + assert galois.irreducible_poly(3, 5, method="max") == IRREDUCIBLE_POLYS_3_5[-1] + assert galois.irreducible_poly(3, 6, method="max") == IRREDUCIBLE_POLYS_3_6[-1] + + assert galois.irreducible_poly(5, 1, method="max") == IRREDUCIBLE_POLYS_5_1[-1] + assert galois.irreducible_poly(5, 2, method="max") == IRREDUCIBLE_POLYS_5_2[-1] + assert galois.irreducible_poly(5, 3, method="max") == IRREDUCIBLE_POLYS_5_3[-1] + assert galois.irreducible_poly(5, 4, method="max") == IRREDUCIBLE_POLYS_5_4[-1] + + +def test_irreducible_poly_random(): + assert galois.irreducible_poly(2, 1, method="random") in IRREDUCIBLE_POLYS_2_1 + assert galois.irreducible_poly(2, 2, method="random") in IRREDUCIBLE_POLYS_2_2 + assert galois.irreducible_poly(2, 3, method="random") in IRREDUCIBLE_POLYS_2_3 + assert galois.irreducible_poly(2, 4, method="random") in IRREDUCIBLE_POLYS_2_4 + assert galois.irreducible_poly(2, 5, method="random") in IRREDUCIBLE_POLYS_2_5 + assert galois.irreducible_poly(2, 6, method="random") in IRREDUCIBLE_POLYS_2_6 + assert galois.irreducible_poly(2, 7, method="random") in IRREDUCIBLE_POLYS_2_7 + assert galois.irreducible_poly(2, 8, method="random") in IRREDUCIBLE_POLYS_2_8 + + assert galois.irreducible_poly(3, 1, method="random") in IRREDUCIBLE_POLYS_3_1 + assert galois.irreducible_poly(3, 2, method="random") in IRREDUCIBLE_POLYS_3_2 + assert galois.irreducible_poly(3, 3, method="random") in IRREDUCIBLE_POLYS_3_3 + assert galois.irreducible_poly(3, 4, method="random") in IRREDUCIBLE_POLYS_3_4 + assert galois.irreducible_poly(3, 5, method="random") in IRREDUCIBLE_POLYS_3_5 + assert galois.irreducible_poly(3, 6, method="random") in IRREDUCIBLE_POLYS_3_6 + + assert galois.irreducible_poly(5, 1, method="random") in IRREDUCIBLE_POLYS_5_1 + assert galois.irreducible_poly(5, 2, method="random") in IRREDUCIBLE_POLYS_5_2 + assert galois.irreducible_poly(5, 3, method="random") in IRREDUCIBLE_POLYS_5_3 + assert galois.irreducible_poly(5, 4, method="random") in IRREDUCIBLE_POLYS_5_4 + + +def test_irreducible_polys_exceptions(): + with pytest.raises(TypeError): + galois.irreducible_polys(2.0, 3) + with pytest.raises(TypeError): + galois.irreducible_polys(2, 3.0) + with pytest.raises(ValueError): + galois.irreducible_polys(4, 3) + with pytest.raises(ValueError): + galois.irreducible_polys(2, 0) + + +def test_irreducible_polys(): + assert galois.irreducible_polys(2, 1) == IRREDUCIBLE_POLYS_2_1 + assert galois.irreducible_polys(2, 2) == IRREDUCIBLE_POLYS_2_2 + assert galois.irreducible_polys(2, 3) == IRREDUCIBLE_POLYS_2_3 + assert galois.irreducible_polys(2, 4) == IRREDUCIBLE_POLYS_2_4 + assert galois.irreducible_polys(2, 5) == IRREDUCIBLE_POLYS_2_5 + assert galois.irreducible_polys(2, 6) == IRREDUCIBLE_POLYS_2_6 + assert galois.irreducible_polys(2, 7) == IRREDUCIBLE_POLYS_2_7 + assert galois.irreducible_polys(2, 8) == IRREDUCIBLE_POLYS_2_8 + + assert galois.irreducible_polys(3, 1) == IRREDUCIBLE_POLYS_3_1 + assert galois.irreducible_polys(3, 2) == IRREDUCIBLE_POLYS_3_2 + assert galois.irreducible_polys(3, 3) == IRREDUCIBLE_POLYS_3_3 + assert galois.irreducible_polys(3, 4) == IRREDUCIBLE_POLYS_3_4 + assert galois.irreducible_polys(3, 5) == IRREDUCIBLE_POLYS_3_5 + assert galois.irreducible_polys(3, 6) == IRREDUCIBLE_POLYS_3_6 + + assert galois.irreducible_polys(5, 1) == IRREDUCIBLE_POLYS_5_1 + assert galois.irreducible_polys(5, 2) == IRREDUCIBLE_POLYS_5_2 + assert galois.irreducible_polys(5, 3) == IRREDUCIBLE_POLYS_5_3 + assert galois.irreducible_polys(5, 4) == IRREDUCIBLE_POLYS_5_4 + + +def test_is_irreducible_exceptions(): + with pytest.raises(TypeError): + galois.is_irreducible([1, 0, 1, 1]) + with pytest.raises(ValueError): + galois.is_irreducible(galois.Poly([1])) + with pytest.raises(ValueError): + galois.is_irreducible(galois.Poly([1], field=galois.GF(2**2))) + + +def test_is_irreducible(): + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_2_1) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_2_2) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_2_3) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_2_4) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_2_5) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_2_6) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_2_7) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_2_8) + + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_3_1) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_3_2) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_3_3) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_3_4) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_3_5) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_3_6) + + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_5_1) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_5_2) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_5_3) + assert all(galois.is_irreducible(f) for f in IRREDUCIBLE_POLYS_5_4) + + +def test_is_not_irreducible(): + while True: + f = galois.Poly.Random(2, field=GF2) + if f not in IRREDUCIBLE_POLYS_2_2: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(3, field=GF2) + if f not in IRREDUCIBLE_POLYS_2_3: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(4, field=GF2) + if f not in IRREDUCIBLE_POLYS_2_4: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(5, field=GF2) + if f not in IRREDUCIBLE_POLYS_2_5: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(6, field=GF2) + if f not in IRREDUCIBLE_POLYS_2_6: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(7, field=GF2) + if f not in IRREDUCIBLE_POLYS_2_7: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(8, field=GF2) + if f not in IRREDUCIBLE_POLYS_2_8: + assert not galois.is_irreducible(f) + break + + while True: + f = galois.Poly.Random(2, field=GF3) + f /= f.coeffs[0] # Make monic + if f not in IRREDUCIBLE_POLYS_3_2: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(3, field=GF3) + f /= f.coeffs[0] # Make monic + if f not in IRREDUCIBLE_POLYS_3_3: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(4, field=GF3) + f /= f.coeffs[0] # Make monic + if f not in IRREDUCIBLE_POLYS_3_4: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(5, field=GF3) + f /= f.coeffs[0] # Make monic + if f not in IRREDUCIBLE_POLYS_3_5: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(6, field=GF3) + f /= f.coeffs[0] # Make monic + if f not in IRREDUCIBLE_POLYS_3_6: + assert not galois.is_irreducible(f) + break + + while True: + f = galois.Poly.Random(2, field=GF5) + f /= f.coeffs[0] # Make monic + if f not in IRREDUCIBLE_POLYS_5_2: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(3, field=GF5) + f /= f.coeffs[0] # Make monic + if f not in IRREDUCIBLE_POLYS_5_3: + assert not galois.is_irreducible(f) + break + while True: + f = galois.Poly.Random(4, field=GF5) + f /= f.coeffs[0] # Make monic + if f not in IRREDUCIBLE_POLYS_5_4: + assert not galois.is_irreducible(f) + break diff --git a/tests/polys/test_primitive_polys.py b/tests/polys/test_primitive_polys.py new file mode 100644 index 0000000000..89c9514cde --- /dev/null +++ b/tests/polys/test_primitive_polys.py @@ -0,0 +1,615 @@ +""" +A pytest module to test generating primitive polynomials and testing primitivity. + +Sage: + p = 3 + for degree in range(1, 7): + print(f"PRIMITIVE_POLY_{p}_{degree} = [") + F = GF(p)["x"] + for f in F.polynomials(degree): + # For some reason `is_primitive()` crashes on f(x) = x + if f.coefficients(sparse=False) == [0, 1]: + continue + if f.is_monic() and f.is_primitive(): + c = f.coefficients(sparse=False)[::-1] + print(f" galois.Poly({c}, field=GF{p}),") + print("]\n") + +References +---------- +* https://baylor-ir.tdl.org/bitstream/handle/2104/8793/GF3%20Polynomials.pdf?sequence=1&isAllowed=y +""" +import pytest +import numpy as np + +import galois + +GF2 = galois.GF(2) +GF3 = galois.GF(3) +GF5 = galois.GF(5) +GF7 = galois.GF(7) + +PRIMITIVE_POLYS_2_1 = [ + galois.Poly([1, 1], field=GF2), +] + +PRIMITIVE_POLYS_2_2 = [ + galois.Poly([1, 1, 1], field=GF2), +] + +PRIMITIVE_POLYS_2_3 = [ + galois.Poly([1, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1], field=GF2), +] + +PRIMITIVE_POLYS_2_4 = [ + galois.Poly([1, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 1], field=GF2), +] + +PRIMITIVE_POLYS_2_5 = [ + galois.Poly([1, 0, 0, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 0, 1], field=GF2), +] + +PRIMITIVE_POLYS_2_6 = [ + galois.Poly([1, 0, 0, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 0, 1, 1], field=GF2), +] + +PRIMITIVE_POLYS_2_7 = [ + galois.Poly([1, 0, 0, 0, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 0, 0, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 0, 0, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 0, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 0, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 1, 1, 0, 1], field=GF2), +] + +PRIMITIVE_POLYS_2_8 = [ + galois.Poly([1, 0, 0, 0, 1, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 0, 1, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 0, 1, 0, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 0, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 0, 1, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 0, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 0, 0, 1, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 0, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 0, 1, 1, 1, 0, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 0, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 0, 0, 0, 1, 1, 0, 1], field=GF2), + galois.Poly([1, 1, 0, 1, 0, 1, 0, 0, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 0, 0, 0, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 0, 0, 1, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 0, 0, 1, 1, 1], field=GF2), + galois.Poly([1, 1, 1, 1, 1, 0, 1, 0, 1], field=GF2), +] + +PRIMITIVE_POLYS_3_1 = [ + galois.Poly([1, 1], field=GF3), +] + +PRIMITIVE_POLYS_3_2 = [ + galois.Poly([1, 1, 2], field=GF3), + galois.Poly([1, 2, 2], field=GF3), +] + +PRIMITIVE_POLYS_3_3 = [ + galois.Poly([1, 0, 2, 1], field=GF3), + galois.Poly([1, 1, 2, 1], field=GF3), + galois.Poly([1, 2, 0, 1], field=GF3), + galois.Poly([1, 2, 1, 1], field=GF3), +] + +PRIMITIVE_POLYS_3_4 = [ + galois.Poly([1, 0, 0, 1, 2], field=GF3), + galois.Poly([1, 0, 0, 2, 2], field=GF3), + galois.Poly([1, 1, 0, 0, 2], field=GF3), + galois.Poly([1, 1, 1, 2, 2], field=GF3), + galois.Poly([1, 1, 2, 2, 2], field=GF3), + galois.Poly([1, 2, 0, 0, 2], field=GF3), + galois.Poly([1, 2, 1, 1, 2], field=GF3), + galois.Poly([1, 2, 2, 1, 2], field=GF3), +] + +PRIMITIVE_POLYS_3_5 = [ + galois.Poly([1, 0, 0, 0, 2, 1], field=GF3), + galois.Poly([1, 0, 0, 2, 1, 1], field=GF3), + galois.Poly([1, 0, 1, 0, 1, 1], field=GF3), + galois.Poly([1, 0, 1, 2, 0, 1], field=GF3), + galois.Poly([1, 0, 1, 2, 2, 1], field=GF3), + galois.Poly([1, 0, 2, 1, 0, 1], field=GF3), + galois.Poly([1, 0, 2, 2, 1, 1], field=GF3), + galois.Poly([1, 1, 0, 0, 2, 1], field=GF3), + galois.Poly([1, 1, 0, 1, 0, 1], field=GF3), + galois.Poly([1, 1, 0, 1, 1, 1], field=GF3), + galois.Poly([1, 1, 1, 0, 1, 1], field=GF3), + galois.Poly([1, 1, 1, 1, 2, 1], field=GF3), + galois.Poly([1, 1, 1, 2, 1, 1], field=GF3), + galois.Poly([1, 1, 2, 0, 0, 1], field=GF3), + galois.Poly([1, 1, 2, 1, 1, 1], field=GF3), + galois.Poly([1, 1, 2, 2, 0, 1], field=GF3), + galois.Poly([1, 2, 0, 0, 0, 1], field=GF3), + galois.Poly([1, 2, 0, 0, 1, 1], field=GF3), + galois.Poly([1, 2, 0, 2, 2, 1], field=GF3), + galois.Poly([1, 2, 1, 1, 1, 1], field=GF3), + galois.Poly([1, 2, 2, 0, 2, 1], field=GF3), + galois.Poly([1, 2, 2, 1, 0, 1], field=GF3), +] + +PRIMITIVE_POLYS_3_6 = [ + galois.Poly([1, 0, 0, 0, 0, 1, 2], field=GF3), + galois.Poly([1, 0, 0, 0, 0, 2, 2], field=GF3), + galois.Poly([1, 0, 0, 1, 0, 1, 2], field=GF3), + galois.Poly([1, 0, 0, 2, 0, 2, 2], field=GF3), + galois.Poly([1, 0, 1, 0, 2, 1, 2], field=GF3), + galois.Poly([1, 0, 1, 0, 2, 2, 2], field=GF3), + galois.Poly([1, 0, 1, 1, 0, 2, 2], field=GF3), + galois.Poly([1, 0, 1, 1, 1, 2, 2], field=GF3), + galois.Poly([1, 0, 1, 2, 0, 1, 2], field=GF3), + galois.Poly([1, 0, 1, 2, 1, 1, 2], field=GF3), + galois.Poly([1, 0, 2, 0, 1, 1, 2], field=GF3), + galois.Poly([1, 0, 2, 0, 1, 2, 2], field=GF3), + galois.Poly([1, 0, 2, 1, 1, 1, 2], field=GF3), + galois.Poly([1, 0, 2, 2, 1, 2, 2], field=GF3), + galois.Poly([1, 1, 0, 0, 0, 0, 2], field=GF3), + galois.Poly([1, 1, 0, 1, 0, 0, 2], field=GF3), + galois.Poly([1, 1, 0, 1, 1, 1, 2], field=GF3), + galois.Poly([1, 1, 0, 1, 2, 1, 2], field=GF3), + galois.Poly([1, 1, 0, 2, 2, 0, 2], field=GF3), + galois.Poly([1, 1, 1, 0, 1, 2, 2], field=GF3), + galois.Poly([1, 1, 1, 0, 2, 0, 2], field=GF3), + galois.Poly([1, 1, 1, 1, 0, 1, 2], field=GF3), + galois.Poly([1, 1, 1, 1, 1, 1, 2], field=GF3), + galois.Poly([1, 1, 1, 1, 2, 2, 2], field=GF3), + galois.Poly([1, 1, 1, 2, 2, 2, 2], field=GF3), + galois.Poly([1, 1, 2, 0, 1, 0, 2], field=GF3), + galois.Poly([1, 1, 2, 0, 2, 2, 2], field=GF3), + galois.Poly([1, 1, 2, 1, 0, 1, 2], field=GF3), + galois.Poly([1, 1, 2, 1, 1, 0, 2], field=GF3), + galois.Poly([1, 1, 2, 1, 2, 1, 2], field=GF3), + galois.Poly([1, 1, 2, 2, 2, 0, 2], field=GF3), + galois.Poly([1, 2, 0, 0, 0, 0, 2], field=GF3), + galois.Poly([1, 2, 0, 1, 2, 0, 2], field=GF3), + galois.Poly([1, 2, 0, 2, 0, 0, 2], field=GF3), + galois.Poly([1, 2, 0, 2, 1, 2, 2], field=GF3), + galois.Poly([1, 2, 0, 2, 2, 2, 2], field=GF3), + galois.Poly([1, 2, 1, 0, 1, 1, 2], field=GF3), + galois.Poly([1, 2, 1, 0, 2, 0, 2], field=GF3), + galois.Poly([1, 2, 1, 1, 2, 1, 2], field=GF3), + galois.Poly([1, 2, 1, 2, 0, 2, 2], field=GF3), + galois.Poly([1, 2, 1, 2, 1, 2, 2], field=GF3), + galois.Poly([1, 2, 1, 2, 2, 1, 2], field=GF3), + galois.Poly([1, 2, 2, 0, 1, 0, 2], field=GF3), + galois.Poly([1, 2, 2, 0, 2, 1, 2], field=GF3), + galois.Poly([1, 2, 2, 1, 2, 0, 2], field=GF3), + galois.Poly([1, 2, 2, 2, 0, 2, 2], field=GF3), + galois.Poly([1, 2, 2, 2, 1, 0, 2], field=GF3), + galois.Poly([1, 2, 2, 2, 2, 2, 2], field=GF3), +] + +PRIMITIVE_POLYS_5_1 = [ + galois.Poly([1, 2], field=GF5), + galois.Poly([1, 3], field=GF5), +] + +PRIMITIVE_POLYS_5_2 = [ + galois.Poly([1, 1, 2], field=GF5), + galois.Poly([1, 2, 3], field=GF5), + galois.Poly([1, 3, 3], field=GF5), + galois.Poly([1, 4, 2], field=GF5), +] + +PRIMITIVE_POLYS_5_3 = [ + galois.Poly([1, 0, 3, 2], field=GF5), + galois.Poly([1, 0, 3, 3], field=GF5), + galois.Poly([1, 0, 4, 2], field=GF5), + galois.Poly([1, 0, 4, 3], field=GF5), + galois.Poly([1, 1, 0, 2], field=GF5), + galois.Poly([1, 1, 1, 3], field=GF5), + galois.Poly([1, 1, 4, 3], field=GF5), + galois.Poly([1, 2, 0, 3], field=GF5), + galois.Poly([1, 2, 1, 3], field=GF5), + galois.Poly([1, 2, 2, 2], field=GF5), + galois.Poly([1, 2, 2, 3], field=GF5), + galois.Poly([1, 2, 4, 2], field=GF5), + galois.Poly([1, 3, 0, 2], field=GF5), + galois.Poly([1, 3, 1, 2], field=GF5), + galois.Poly([1, 3, 2, 2], field=GF5), + galois.Poly([1, 3, 2, 3], field=GF5), + galois.Poly([1, 3, 4, 3], field=GF5), + galois.Poly([1, 4, 0, 3], field=GF5), + galois.Poly([1, 4, 1, 2], field=GF5), + galois.Poly([1, 4, 4, 2], field=GF5), +] + +PRIMITIVE_POLYS_5_4 = [ + galois.Poly([1, 0, 1, 2, 2], field=GF5), + galois.Poly([1, 0, 1, 2, 3], field=GF5), + galois.Poly([1, 0, 1, 3, 2], field=GF5), + galois.Poly([1, 0, 1, 3, 3], field=GF5), + galois.Poly([1, 0, 4, 1, 2], field=GF5), + galois.Poly([1, 0, 4, 1, 3], field=GF5), + galois.Poly([1, 0, 4, 4, 2], field=GF5), + galois.Poly([1, 0, 4, 4, 3], field=GF5), + galois.Poly([1, 1, 0, 1, 3], field=GF5), + galois.Poly([1, 1, 0, 2, 3], field=GF5), + galois.Poly([1, 1, 0, 3, 2], field=GF5), + galois.Poly([1, 1, 0, 4, 2], field=GF5), + galois.Poly([1, 1, 1, 1, 3], field=GF5), + galois.Poly([1, 1, 2, 0, 2], field=GF5), + galois.Poly([1, 1, 2, 1, 2], field=GF5), + galois.Poly([1, 1, 3, 0, 3], field=GF5), + galois.Poly([1, 1, 3, 4, 2], field=GF5), + galois.Poly([1, 1, 4, 4, 3], field=GF5), + galois.Poly([1, 2, 0, 1, 3], field=GF5), + galois.Poly([1, 2, 0, 2, 2], field=GF5), + galois.Poly([1, 2, 0, 3, 3], field=GF5), + galois.Poly([1, 2, 0, 4, 2], field=GF5), + galois.Poly([1, 2, 1, 2, 3], field=GF5), + galois.Poly([1, 2, 2, 0, 3], field=GF5), + galois.Poly([1, 2, 2, 2, 2], field=GF5), + galois.Poly([1, 2, 3, 0, 2], field=GF5), + galois.Poly([1, 2, 3, 3, 2], field=GF5), + galois.Poly([1, 2, 4, 3, 3], field=GF5), + galois.Poly([1, 3, 0, 1, 2], field=GF5), + galois.Poly([1, 3, 0, 2, 3], field=GF5), + galois.Poly([1, 3, 0, 3, 2], field=GF5), + galois.Poly([1, 3, 0, 4, 3], field=GF5), + galois.Poly([1, 3, 1, 3, 3], field=GF5), + galois.Poly([1, 3, 2, 0, 3], field=GF5), + galois.Poly([1, 3, 2, 3, 2], field=GF5), + galois.Poly([1, 3, 3, 0, 2], field=GF5), + galois.Poly([1, 3, 3, 2, 2], field=GF5), + galois.Poly([1, 3, 4, 2, 3], field=GF5), + galois.Poly([1, 4, 0, 1, 2], field=GF5), + galois.Poly([1, 4, 0, 2, 2], field=GF5), + galois.Poly([1, 4, 0, 3, 3], field=GF5), + galois.Poly([1, 4, 0, 4, 3], field=GF5), + galois.Poly([1, 4, 1, 4, 3], field=GF5), + galois.Poly([1, 4, 2, 0, 2], field=GF5), + galois.Poly([1, 4, 2, 4, 2], field=GF5), + galois.Poly([1, 4, 3, 0, 3], field=GF5), + galois.Poly([1, 4, 3, 1, 2], field=GF5), + galois.Poly([1, 4, 4, 1, 3], field=GF5), +] + + +def test_primitive_poly_exceptions(): + with pytest.raises(TypeError): + galois.primitive_poly(2.0, 3) + with pytest.raises(TypeError): + galois.primitive_poly(2, 3.0) + with pytest.raises(ValueError): + galois.primitive_poly(4, 3) + with pytest.raises(ValueError): + galois.primitive_poly(2, 0) + with pytest.raises(ValueError): + galois.primitive_poly(2, 3, method="invalid-argument") + + +def test_primitive_poly_min(): + assert galois.primitive_poly(2, 1) == PRIMITIVE_POLYS_2_1[0] + assert galois.primitive_poly(2, 2) == PRIMITIVE_POLYS_2_2[0] + assert galois.primitive_poly(2, 3) == PRIMITIVE_POLYS_2_3[0] + assert galois.primitive_poly(2, 4) == PRIMITIVE_POLYS_2_4[0] + assert galois.primitive_poly(2, 5) == PRIMITIVE_POLYS_2_5[0] + assert galois.primitive_poly(2, 6) == PRIMITIVE_POLYS_2_6[0] + assert galois.primitive_poly(2, 7) == PRIMITIVE_POLYS_2_7[0] + assert galois.primitive_poly(2, 8) == PRIMITIVE_POLYS_2_8[0] + + assert galois.primitive_poly(3, 1) == PRIMITIVE_POLYS_3_1[0] + assert galois.primitive_poly(3, 2) == PRIMITIVE_POLYS_3_2[0] + assert galois.primitive_poly(3, 3) == PRIMITIVE_POLYS_3_3[0] + assert galois.primitive_poly(3, 4) == PRIMITIVE_POLYS_3_4[0] + assert galois.primitive_poly(3, 5) == PRIMITIVE_POLYS_3_5[0] + assert galois.primitive_poly(3, 6) == PRIMITIVE_POLYS_3_6[0] + + assert galois.primitive_poly(5, 1) == PRIMITIVE_POLYS_5_1[0] + assert galois.primitive_poly(5, 2) == PRIMITIVE_POLYS_5_2[0] + assert galois.primitive_poly(5, 3) == PRIMITIVE_POLYS_5_3[0] + assert galois.primitive_poly(5, 4) == PRIMITIVE_POLYS_5_4[0] + + +def test_primitive_poly_max(): + assert galois.primitive_poly(2, 1, method="max") == PRIMITIVE_POLYS_2_1[-1] + assert galois.primitive_poly(2, 2, method="max") == PRIMITIVE_POLYS_2_2[-1] + assert galois.primitive_poly(2, 3, method="max") == PRIMITIVE_POLYS_2_3[-1] + assert galois.primitive_poly(2, 4, method="max") == PRIMITIVE_POLYS_2_4[-1] + assert galois.primitive_poly(2, 5, method="max") == PRIMITIVE_POLYS_2_5[-1] + assert galois.primitive_poly(2, 6, method="max") == PRIMITIVE_POLYS_2_6[-1] + assert galois.primitive_poly(2, 7, method="max") == PRIMITIVE_POLYS_2_7[-1] + assert galois.primitive_poly(2, 8, method="max") == PRIMITIVE_POLYS_2_8[-1] + + assert galois.primitive_poly(3, 1, method="max") == PRIMITIVE_POLYS_3_1[-1] + assert galois.primitive_poly(3, 2, method="max") == PRIMITIVE_POLYS_3_2[-1] + assert galois.primitive_poly(3, 3, method="max") == PRIMITIVE_POLYS_3_3[-1] + assert galois.primitive_poly(3, 4, method="max") == PRIMITIVE_POLYS_3_4[-1] + assert galois.primitive_poly(3, 5, method="max") == PRIMITIVE_POLYS_3_5[-1] + assert galois.primitive_poly(3, 6, method="max") == PRIMITIVE_POLYS_3_6[-1] + + assert galois.primitive_poly(5, 1, method="max") == PRIMITIVE_POLYS_5_1[-1] + assert galois.primitive_poly(5, 2, method="max") == PRIMITIVE_POLYS_5_2[-1] + assert galois.primitive_poly(5, 3, method="max") == PRIMITIVE_POLYS_5_3[-1] + assert galois.primitive_poly(5, 4, method="max") == PRIMITIVE_POLYS_5_4[-1] + + +def test_primitive_poly_random(): + assert galois.primitive_poly(2, 1, method="random") in PRIMITIVE_POLYS_2_1 + assert galois.primitive_poly(2, 2, method="random") in PRIMITIVE_POLYS_2_2 + assert galois.primitive_poly(2, 3, method="random") in PRIMITIVE_POLYS_2_3 + assert galois.primitive_poly(2, 4, method="random") in PRIMITIVE_POLYS_2_4 + assert galois.primitive_poly(2, 5, method="random") in PRIMITIVE_POLYS_2_5 + assert galois.primitive_poly(2, 6, method="random") in PRIMITIVE_POLYS_2_6 + assert galois.primitive_poly(2, 7, method="random") in PRIMITIVE_POLYS_2_7 + assert galois.primitive_poly(2, 8, method="random") in PRIMITIVE_POLYS_2_8 + + assert galois.primitive_poly(3, 1, method="random") in PRIMITIVE_POLYS_3_1 + assert galois.primitive_poly(3, 2, method="random") in PRIMITIVE_POLYS_3_2 + assert galois.primitive_poly(3, 3, method="random") in PRIMITIVE_POLYS_3_3 + assert galois.primitive_poly(3, 4, method="random") in PRIMITIVE_POLYS_3_4 + assert galois.primitive_poly(3, 5, method="random") in PRIMITIVE_POLYS_3_5 + assert galois.primitive_poly(3, 6, method="random") in PRIMITIVE_POLYS_3_6 + + assert galois.primitive_poly(5, 1, method="random") in PRIMITIVE_POLYS_5_1 + assert galois.primitive_poly(5, 2, method="random") in PRIMITIVE_POLYS_5_2 + assert galois.primitive_poly(5, 3, method="random") in PRIMITIVE_POLYS_5_3 + assert galois.primitive_poly(5, 4, method="random") in PRIMITIVE_POLYS_5_4 + + +def test_primitive_polys_exceptions(): + with pytest.raises(TypeError): + galois.primitive_polys(2.0, 3) + with pytest.raises(TypeError): + galois.primitive_polys(2, 3.0) + with pytest.raises(ValueError): + galois.primitive_polys(4, 3) + with pytest.raises(ValueError): + galois.primitive_polys(2, 0) + + +def test_primitive_polys(): + assert galois.primitive_polys(2, 1) == PRIMITIVE_POLYS_2_1 + assert galois.primitive_polys(2, 2) == PRIMITIVE_POLYS_2_2 + assert galois.primitive_polys(2, 3) == PRIMITIVE_POLYS_2_3 + assert galois.primitive_polys(2, 4) == PRIMITIVE_POLYS_2_4 + assert galois.primitive_polys(2, 5) == PRIMITIVE_POLYS_2_5 + assert galois.primitive_polys(2, 6) == PRIMITIVE_POLYS_2_6 + assert galois.primitive_polys(2, 7) == PRIMITIVE_POLYS_2_7 + assert galois.primitive_polys(2, 8) == PRIMITIVE_POLYS_2_8 + + assert galois.primitive_polys(3, 1) == PRIMITIVE_POLYS_3_1 + assert galois.primitive_polys(3, 2) == PRIMITIVE_POLYS_3_2 + assert galois.primitive_polys(3, 3) == PRIMITIVE_POLYS_3_3 + assert galois.primitive_polys(3, 4) == PRIMITIVE_POLYS_3_4 + assert galois.primitive_polys(3, 5) == PRIMITIVE_POLYS_3_5 + assert galois.primitive_polys(3, 6) == PRIMITIVE_POLYS_3_6 + + assert galois.primitive_polys(5, 1) == PRIMITIVE_POLYS_5_1 + assert galois.primitive_polys(5, 2) == PRIMITIVE_POLYS_5_2 + assert galois.primitive_polys(5, 3) == PRIMITIVE_POLYS_5_3 + assert galois.primitive_polys(5, 4) == PRIMITIVE_POLYS_5_4 + + +def test_conway_poly_exceptions(): + with pytest.raises(TypeError): + galois.conway_poly(2.0, 3) + with pytest.raises(TypeError): + galois.conway_poly(2, 3.0) + with pytest.raises(ValueError): + galois.conway_poly(4, 3) + with pytest.raises(ValueError): + galois.conway_poly(2, 0) + with pytest.raises(LookupError): + # GF(2^409) is the largest 2-characteristic field in Frank Luebeck's database + galois.conway_poly(2, 410) + + +def test_conway_poly(): + assert galois.conway_poly(2, 8) == galois.Poly.Degrees([8, 4, 3, 2, 0]) + assert galois.conway_poly(3, 8) == galois.Poly.Degrees([8, 5, 4, 2, 1, 0], coeffs=[1, 2, 1, 2, 2, 2], field=GF3) + assert galois.conway_poly(5, 8) == galois.Poly.Degrees([8, 4, 2, 1, 0], coeffs=[1, 1, 3, 4, 2], field=GF5) + + +def test_matlab_primitive_poly_exceptions(): + with pytest.raises(TypeError): + galois.matlab_primitive_poly(2.0, 3) + with pytest.raises(TypeError): + galois.matlab_primitive_poly(2, 3.0) + with pytest.raises(ValueError): + galois.matlab_primitive_poly(4, 3) + with pytest.raises(ValueError): + galois.matlab_primitive_poly(2, 0) + + +def test_matlab_primitive_poly(): + """ + Matlab: + gfprimdf(m, 2) + gfprimdf(m, 3) + gfprimdf(m, 5) + gfprimdf(m, 7) + """ + assert galois.matlab_primitive_poly(2, 1) == galois.Poly([1,1], order="asc") + assert galois.matlab_primitive_poly(2, 2) == galois.Poly([1,1,1], order="asc") + assert galois.matlab_primitive_poly(2, 3) == galois.Poly([1,1,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 4) == galois.Poly([1,1,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 5) == galois.Poly([1,0,1,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 6) == galois.Poly([1,1,0,0,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 7) == galois.Poly([1,0,0,1,0,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 8) == galois.Poly([1,0,1,1,1,0,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 9) == galois.Poly([1,0,0,0,1,0,0,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 10) == galois.Poly([1,0,0,1,0,0,0,0,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 11) == galois.Poly([1,0,1,0,0,0,0,0,0,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 12) == galois.Poly([1,1,0,0,1,0,1,0,0,0,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 13) == galois.Poly([1,1,0,1,1,0,0,0,0,0,0,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 14) == galois.Poly([1,1,0,0,0,0,1,0,0,0,1,0,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 15) == galois.Poly([1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], order="asc") + assert galois.matlab_primitive_poly(2, 16) == galois.Poly([1,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1], order="asc") + + assert galois.matlab_primitive_poly(3, 1) == galois.Poly([1,1], field=GF3, order="asc") + assert galois.matlab_primitive_poly(3, 2) == galois.Poly([2,1,1], field=GF3, order="asc") + assert galois.matlab_primitive_poly(3, 3) == galois.Poly([1,2,0,1], field=GF3, order="asc") + assert galois.matlab_primitive_poly(3, 4) == galois.Poly([2,1,0,0,1], field=GF3, order="asc") + assert galois.matlab_primitive_poly(3, 5) == galois.Poly([1,2,0,0,0,1], field=GF3, order="asc") + assert galois.matlab_primitive_poly(3, 6) == galois.Poly([2,1,0,0,0,0,1], field=GF3, order="asc") + # assert galois.matlab_primitive_poly(3, 7) == galois.Poly([1,0,2,0,0,0,0,1], field=GF3, order="asc") + assert galois.matlab_primitive_poly(3, 8) == galois.Poly([2,0,0,1,0,0,0,0,1], field=GF3, order="asc") + + assert galois.matlab_primitive_poly(5, 1) == galois.Poly([2,1], field=GF5, order="asc") + assert galois.matlab_primitive_poly(5, 2) == galois.Poly([2,1,1], field=GF5, order="asc") + assert galois.matlab_primitive_poly(5, 3) == galois.Poly([2,3,0,1], field=GF5, order="asc") + # assert galois.matlab_primitive_poly(5, 4) == galois.Poly([2,2,1,0,1], field=GF5, order="asc") + assert galois.matlab_primitive_poly(5, 5) == galois.Poly([2,4,0,0,0,1], field=GF5, order="asc") + assert galois.matlab_primitive_poly(5, 6) == galois.Poly([2,1,0,0,0,0,1], field=GF5, order="asc") + assert galois.matlab_primitive_poly(5, 7) == galois.Poly([2,3,0,0,0,0,0,1], field=GF5, order="asc") + assert galois.matlab_primitive_poly(5, 8) == galois.Poly([3,2,1,0,0,0,0,0,1], field=GF5, order="asc") + + assert galois.matlab_primitive_poly(7, 1) == galois.Poly([2,1], field=GF7, order="asc") + assert galois.matlab_primitive_poly(7, 2) == galois.Poly([3,1,1], field=GF7, order="asc") + assert galois.matlab_primitive_poly(7, 3) == galois.Poly([2,3,0,1], field=GF7, order="asc") + assert galois.matlab_primitive_poly(7, 4) == galois.Poly([5,3,1,0,1], field=GF7, order="asc") + assert galois.matlab_primitive_poly(7, 5) == galois.Poly([4,1,0,0,0,1], field=GF7, order="asc") + assert galois.matlab_primitive_poly(7, 6) == galois.Poly([5,1,3,0,0,0,1], field=GF7, order="asc") + assert galois.matlab_primitive_poly(7, 7) == galois.Poly([2,6,0,0,0,0,0,1], field=GF7, order="asc") + assert galois.matlab_primitive_poly(7, 8) == galois.Poly([3,1,0,0,0,0,0,0,1], field=GF7, order="asc") + + +def test_is_primitive_exceptions(): + with pytest.raises(TypeError): + galois.is_primitive([1, 0, 1, 1]) + with pytest.raises(ValueError): + galois.is_primitive(galois.Poly([1])) + with pytest.raises(ValueError): + galois.is_primitive(galois.Poly([1], field=galois.GF(2**2))) + + +def test_is_primitive(): + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_2_1) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_2_2) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_2_3) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_2_4) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_2_5) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_2_6) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_2_7) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_2_8) + + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_3_1) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_3_2) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_3_3) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_3_4) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_3_5) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_3_6) + + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_5_1) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_5_2) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_5_3) + assert all(galois.is_primitive(f) for f in PRIMITIVE_POLYS_5_4) + + +def test_is_not_primitive(): + while True: + f = galois.Poly.Random(2, field=GF2) + if f not in PRIMITIVE_POLYS_2_2: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(3, field=GF2) + if f not in PRIMITIVE_POLYS_2_3: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(4, field=GF2) + if f not in PRIMITIVE_POLYS_2_4: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(5, field=GF2) + if f not in PRIMITIVE_POLYS_2_5: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(6, field=GF2) + if f not in PRIMITIVE_POLYS_2_6: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(7, field=GF2) + if f not in PRIMITIVE_POLYS_2_7: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(8, field=GF2) + if f not in PRIMITIVE_POLYS_2_8: + assert not galois.is_primitive(f) + break + + while True: + f = galois.Poly.Random(2, field=GF3) + f /= f.coeffs[0] # Make monic + if f not in PRIMITIVE_POLYS_3_2: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(3, field=GF3) + f /= f.coeffs[0] # Make monic + if f not in PRIMITIVE_POLYS_3_3: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(4, field=GF3) + f /= f.coeffs[0] # Make monic + if f not in PRIMITIVE_POLYS_3_4: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(5, field=GF3) + f /= f.coeffs[0] # Make monic + if f not in PRIMITIVE_POLYS_3_5: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(6, field=GF3) + f /= f.coeffs[0] # Make monic + if f not in PRIMITIVE_POLYS_3_6: + assert not galois.is_primitive(f) + break + + while True: + f = galois.Poly.Random(2, field=GF5) + f /= f.coeffs[0] # Make monic + if f not in PRIMITIVE_POLYS_5_2: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(3, field=GF5) + f /= f.coeffs[0] # Make monic + if f not in PRIMITIVE_POLYS_5_3: + assert not galois.is_primitive(f) + break + while True: + f = galois.Poly.Random(4, field=GF5) + f /= f.coeffs[0] # Make monic + if f not in PRIMITIVE_POLYS_5_4: + assert not galois.is_primitive(f) + break diff --git a/tests/test_conway_polys.py b/tests/test_conway_polys.py deleted file mode 100644 index dd85432273..0000000000 --- a/tests/test_conway_polys.py +++ /dev/null @@ -1,41 +0,0 @@ -""" -A pytest module to test the Conway polynomial function. -""" -import numpy as np -import pytest - -import galois - - -def test_valid(): - p = galois.conway_poly(2, 3) - poly = galois.Poly([1,0,1,1]) - assert p == poly - - -def test_non_integer_characteristic(): - with pytest.raises(TypeError): - p = galois.conway_poly(2.0, 3) - - -def test_non_integer_degree(): - with pytest.raises(TypeError): - p = galois.conway_poly(2, 3.0) - - -def test_non_prime_characteristic(): - with pytest.raises(ValueError): - p = galois.conway_poly(6, 3) - - -def test_non_positive_degree(): - with pytest.raises(ValueError): - p = galois.conway_poly(2, 0) - with pytest.raises(ValueError): - p = galois.conway_poly(2, -2) - - -def test_not_found(): - # GF(2^409) is the largest 2-characteristic field in Frank Luebeck's database - with pytest.raises(LookupError): - p = galois.conway_poly(2, 410)