示例#1
0
 def testReduce(self):
     F = (multiutil.polynomial(
         {
             (2, 0): rational.Integer(1),
             (1, 2): rational.Integer(2)
         }, rational.theRationalField, 2),
          multiutil.polynomial(
              {
                  (1, 1): rational.Integer(1),
                  (0, 3): rational.Integer(2),
                  (0, 0): rational.Integer(-1)
              }, rational.theRationalField, 2))
     rgb_expected = [
         multiutil.polynomial({(1, 0): rational.Integer(1)},
                              rational.theRationalField, 2),
         multiutil.polynomial(
             {
                 (0, 3): rational.Integer(1),
                 (0, 0): rational.Rational(-1, 2)
             }, rational.theRationalField, 2)
     ]
     G_from_F = groebner.normal_strategy(F, self.lex)
     rgb = groebner.reduce_groebner(G_from_F, self.lex)
     self.assertEqual(2, len(rgb))
     self.assertEqual(rgb_expected, rgb)
示例#2
0
    def testBuchberger(self):
        """
        test Buchberger's algorithm.

        http://www.geocities.com/famancin/buchberger.html
        """
        F = (multiutil.polynomial(
            {
                (2, 0): rational.Integer(1),
                (1, 2): rational.Integer(2)
            }, rational.theRationalField, 2),
             multiutil.polynomial(
                 {
                     (1, 1): rational.Integer(1),
                     (0, 3): rational.Integer(2),
                     (0, 0): rational.Integer(-1)
                 }, rational.theRationalField, 2))
        G_from_F = groebner.buchberger(F, self.lex)
        G_expected = list(F + (multiutil.polynomial(
            {(1, 0): rational.Integer(1)}, rational.theRationalField, 2),
                               multiutil.polynomial(
                                   {
                                       (0, 3): rational.Integer(2),
                                       (0, 0): rational.Integer(-1)
                                   }, rational.theRationalField, 2)))
        self.assertEqual(len(G_expected), len(G_from_F))
        for p, q in zip(G_expected, G_from_F):
            self.assertEqualUptoUnit(p, q)
示例#3
0
    def testNormalStrategy(self):
        """
        test Buchberger's algorithm (normal strategy).

        same example with testBuchberger.
        """
        F = (multiutil.polynomial(
            {
                (2, 0): rational.Integer(1),
                (1, 2): rational.Integer(2)
            }, rational.theRationalField, 2),
             multiutil.polynomial(
                 {
                     (1, 1): rational.Integer(1),
                     (0, 3): rational.Integer(2),
                     (0, 0): rational.Integer(-1)
                 }, rational.theRationalField, 2))
        G_from_F = groebner.normal_strategy(F, self.lex)
        G_expected = list(F + (multiutil.polynomial(
            {(1, 0): rational.Integer(1)}, rational.theRationalField, 2),
                               multiutil.polynomial(
                                   {
                                       (0, 3): rational.Integer(2),
                                       (0, 0): rational.Integer(-1)
                                   }, rational.theRationalField, 2)))
        self.assertEqual(len(G_expected), len(G_from_F))
        for p, q in zip(G_expected, G_from_F):
            self.assertEqualUptoUnit(p, q)
示例#4
0
 def __mul__(self, other):
     """
     Output composite field of self and other.
     """
     common_options = {"coeffring": rational.theIntegerRing,
                       "number_of_variables": 2}
     flist = [((d, 0), c) for (d, c) in enumerate(self.polynomial)]
     f = multiutil.polynomial(flist, **common_options)
     g = zpoly(other.polynomial)
     diff = multiutil.polynomial({(1, 0): 1, (0, 1):-1}, **common_options)
     compos = f.resultant(g(diff), 0)
     return NumberField([compos[i] for i in range(compos.degree() + 1)])
示例#5
0
 def __mul__(self, other):
     """
     Output composite field of self and other.
     """
     common_options = {"coeffring": rational.theIntegerRing,
                       "number_of_variables": 2}
     flist = [((d, 0), c) for (d, c) in enumerate(self.polynomial)]
     f = multiutil.polynomial(flist, **common_options)
     g = zpoly(other.polynomial)
     diff = multiutil.polynomial({(1, 0): 1, (0, 1):-1}, **common_options)
     compos = f.resultant(g(diff), 0)
     return NumberField([compos[i] for i in range(compos.degree() + 1)])
示例#6
0
 def _zero_polynomial(self):
     """
     Return the zero polynomial in the polynomial ring.
     """
     if self.number_of_variables == 1:
         import nzmath.poly.uniutil as uniutil
         return uniutil.polynomial((), self._coefficient_ring)
     else:
         import nzmath.poly.multiutil as multiutil
         return multiutil.polynomial((), coeffring=self._coefficient_ring, number_of_variables=self.number_of_variables)
示例#7
0
 def _prepared_polynomial(self, preparation):
     """
     Return a polynomial from given preparation, which is suited
     for the first argument of uni-/multi-variable polynomials.
     """
     if self.number_of_variables == 1:
         import nzmath.poly.uniutil as uniutil
         return uniutil.polynomial(preparation, self._coefficient_ring)
     else:
         import nzmath.poly.multiutil as multiutil
         return multiutil.polynomial(preparation, self._coefficient_ring)
示例#8
0
 def testXYZ(self):
     ctx = {}
     multiutil.prepare_indeterminates("S T X Y", ctx)
     self.assertTrue("X" in ctx)
     for var in ctx:
         exec "self.%s = ctx['%s']" % (var, var)
     self.assertTrue(self.S)
     self.assertTrue(self.T)
     Z = rational.theIntegerRing
     self.XY = multiutil.polynomial({(0, 0, 1, 1): 1}, Z)
     self.assertEqual(self.XY, self.X * self.Y)
示例#9
0
 def _constant_polynomial(self, seed):
     """
     Return a constant polynomial made from a constant seed.
     seed should not be zero.
     """
     if self.number_of_variables == 1:
         import nzmath.poly.uniutil as uniutil
         return uniutil.polynomial({0: seed}, self._coefficient_ring)
     else:
         import nzmath.poly.multiutil as multiutil
         const = (0,) * self.number_of_variables
         return multiutil.polynomial({const: seed}, self._coefficient_ring)
示例#10
0
 def testZero(self):
     zero = multiutil.polynomial({}, self.Z, 2)
     self.assertEqual(zero, self.Z2.zero)
示例#11
0
 def testOne(self):
     one = multiutil.polynomial({(0, 0): 1}, self.Z)
     self.assertEqual(one, self.Z2.one)
示例#12
0
 def testCreateElement(self):
     """
     createElement method is tweaked in uniutil.
     """
     one = multiutil.polynomial({(0, 0): 1}, self.Z)
     self.assertEqual(one, self.Z2.createElement(1))