Пример #1
0
    def setUp(self):
        """
	create two different Fq's.
	"""
        self.F2 = FinitePrimeField.getInstance(2)
        f = FinitePrimeFieldPolynomial([(0, 1), (5, 1), (6, 1)], self.F2)
        self.F64 = FiniteExtendedField(2, f)
        self.F3 = FinitePrimeField.getInstance(3)
        f = FinitePrimeFieldPolynomial(enumerate([1, 2, 1, 2, 1]), self.F3)
        self.F81 = FiniteExtendedField(3, f)
Пример #2
0
 def testCreateElement(self):
     F125 = FiniteExtendedField(5, 3)
     self.assertEqual(
         F125.createElement(6),
         F125.createElement(
             FinitePrimeFieldPolynomial(enumerate([1, 1]),
                                        FinitePrimeField.getInstance(5))))
     self.assertEqual(F125.createElement(6), F125.createElement([1, 1]))
Пример #3
0
 def testInit(self):
     self.assertEqual(8, card(FiniteExtendedField(2, 3)))
     f = FinitePrimeFieldPolynomial(enumerate([1, 1, 0, 1]),
                                    FinitePrimeField.getInstance(2))
     self.assertEqual(8, card(FiniteExtendedField(2, f)))
     for i in range(10):  # 10 might be enough to check random moduli
         F8 = FiniteExtendedField(2, 3)
         defining_polynomial = F8.modulus
         self.assertTrue(defining_polynomial.degree() == 3)
         self.assertTrue(defining_polynomial.isirreducible())
Пример #4
0
 def testContains(self):
     # elements of the field
     F125 = FiniteExtendedField(5, 3)
     self.assertTrue(F125.one in F125)
     self.assertTrue(F125.createElement(17) in F125)
     # elements of prime fields
     self.assertTrue(FinitePrimeField.getInstance(5).one in F125)
     # different characteristic
     self.assertFalse(FinitePrimeFieldElement(3, 7) in F125)
     # elements of disjoint fields
     F25 = FiniteExtendedField(5, 2)
     self.assertFalse(F25.one in F125)
     self.assertFalse(F25.createElement(17) in F125)
     F625 = FiniteExtendedField(5, 4)
     self.assertFalse(F625.one in F125)
     self.assertFalse(F625.createElement(17) in F125)
     # we don't expect an element of extended fields be in the field
     # even if it actually is.
     F15625 = FiniteExtendedField(5, 6)
     self.assertFalse(F15625.one in F125)
Пример #5
0
class FinitePrimeFieldTest(unittest.TestCase):
    def setUp(self):
        self.F17 = FinitePrimeField(17)

    def testEq(self):
        self.assertEqual(self.F17, self.F17)

    def testNonZero(self):
        self.assertTrue(self.F17)
        self.assertTrue(FinitePrimeField(17L))

    def testConst(self):
        self.assertEqual(FinitePrimeFieldElement(1, 17), self.F17.one)
        self.assertEqual(FinitePrimeFieldElement(0, 17), self.F17.zero)
        self.assertEqual(self.F17.one, self.F17.one * self.F17.one)
        self.assertEqual(self.F17.one, self.F17.one + self.F17.zero)
        self.assertEqual(self.F17.zero, self.F17.zero * self.F17.zero)

    def testGetInstance(self):
        self.assertEqual(self.F17, FinitePrimeField.getInstance(17))
        self.assertTrue(
            FinitePrimeField.getInstance(17) is FinitePrimeField.getInstance(
                17))

    def testStrings(self):
        self.assertEqual("F_17", str(self.F17))
        self.assertEqual("FinitePrimeField(17)", repr(self.F17))

    def testSubring(self):
        self.assertTrue(self.F17.issubring(self.F17))
        self.assertTrue(self.F17.issuperring(self.F17))
        # polynomial ring
        import nzmath.poly.ring as ring
        F17X = ring.PolynomialRing(self.F17, 1)
        self.assertTrue(self.F17.issubring(F17X))
        self.assertFalse(self.F17.issuperring(F17X))
        # rational field
        self.assertFalse(self.F17.issuperring(theRationalField))
        self.assertFalse(self.F17.issubring(theRationalField))

    def testHash(self):
        dictionary = {}
        dictionary[self.F17] = 1
        self.assertEqual(1, dictionary[FinitePrimeField(17)])
Пример #6
0
 def setUp(self):
     self.F17 = FinitePrimeField(17)
Пример #7
0
 def testRepr(self):
     f = FinitePrimeFieldPolynomial(
         [(0, 2), (8, 1)], coeffring=FinitePrimeField.getInstance(311))
     self.assertEqual(0, repr(f).index("Finite"))
Пример #8
0
 def testSubring(self):
     F125 = FiniteExtendedField(5, 3)
     F5 = FinitePrimeField.getInstance(5)
     self.assertFalse(F125.issubring(F5))
Пример #9
0
 def setUp(self):
     self.F3 = FinitePrimeField.getInstance(3)
     self.F81 = FiniteExtendedField(3, 4)
Пример #10
0
 def testHash(self):
     dictionary = {}
     dictionary[self.F17] = 1
     self.assertEqual(1, dictionary[FinitePrimeField(17)])
Пример #11
0
 def testGetInstance(self):
     self.assertEqual(self.F17, FinitePrimeField.getInstance(17))
     self.assertTrue(
         FinitePrimeField.getInstance(17) is FinitePrimeField.getInstance(
             17))
Пример #12
0
 def testNonZero(self):
     self.assertTrue(self.F17)
     self.assertTrue(FinitePrimeField(17))
Пример #13
0
 def testGetGroup(self):
     assert (Group(PermGroup([1, 2, 3, 4]), 1) == a1.getGroup())
     assert (Group(IntegerResidueClassRing(30)) == b1.getGroup())
     assert (Group(FinitePrimeField(37)) == c1_a.getGroup())
     assert (Group(FinitePrimeField(37), 1) == c1_m.getGroup())
Пример #14
0
 def testEqual(self):
     assert (aa1 == Group(Permute([2, 4, 1, 3]), 1))
     assert (bb1 == Group(IntegerResidueClassRing(30)))
     assert (cc1_a == Group(FinitePrimeField(37)))
     assert (cc1_m == Group(FinitePrimeField(37), 1))