示例#1
0
 def test_multiply_complex(self):
     x, y = MVPolyDict.variables(2, dtype = complex)
     p = (x + y)*(x + 1j*y)
     q = x**2 + (1 + 1j)*x*y + 1j*y**2
     self.assertTrue(p == q,
                     "bad multiply:\n{0!s}\n{1!s}".format(repr(p.coef),
                                                repr(q.coef)))
示例#2
0
 def test_multiply_arithmetic(self):
     x, y = MVPolyDict.variables(2, dtype = int)
     p = (x + y)*(2*x - y)
     q = 2*x**2 + x*y - y**2
     self.assertTrue(p == q,
                     "bad multiply:\n{0!s}\n{1!s}".format(repr(p.coef),
                                                repr(q.coef)))
示例#3
0
 def test_nonzero_enumerate(self):
     x, y = MVPolyDict.variables(2)
     p = 3*x + y**2 + 7
     obt = p.nonzero
     exp = [((), 7.0), ((1,), 3.0), ((0, 2), 1.0)]
     self.assertTrue(sorted(obt) == sorted(exp),
                     "nonzero")
示例#4
0
 def test_construct_from_variables_zero_coefs(self):
     x, y = MVPolyDict.variables(2)
     p = 0*x + 0*y + 0
     exp = {}
     obt = p.coef
     self.assertTrue(exp == obt,
                     "bad constructor:\n{0!s} {1!s}".format(repr(obt), repr(exp)))
示例#5
0
 def test_diff_invariant(self):
     x, y = MVPolyDict.variables(2, dtype = int)
     p  = x + 2*y
     exp = p.coef.copy()
     q = p.diff(1,0)
     obt = p.coef
     self.assertTrue(exp == obt,
                     "polynomial modified by diff {0!s}".format( \
                         (repr(obt))))
示例#6
0
 def test_construct_from_variables(self):
     x, y = MVPolyDict.variables(2)
     p = x + 2*y + 3
     exp = {((0, 1),) : 1,
            ((1, 1),) : 2,
            ()        : 3}
     obt = p.coef
     self.assertTrue(exp == obt,
                     "bad constructor:\n{0!s} {1!s}".format(repr(obt), repr(exp)))
示例#7
0
 def test_euler_goldbach(self):
     """
     Euler's four-square identity, discussed in 1749 in a letter
     from Euler to Goldbach.
     """
     a1, a2, a3, a4, b1, b2, b3, b4 = MVPolyDict.variables(8, dtype = int)
     p = (a1**2 + a2**2 + a3**2 + a4**2) * (b1**2 + b2**2 + b3**2 + b4**2)
     q = (a1*b1 - a2*b2 - a3*b3 - a4*b4)**2 + \
         (a1*b2 + a2*b1 + a3*b4 - a4*b3)**2 + \
         (a1*b3 - a2*b4 + a3*b1 + a4*b2)**2 + \
         (a1*b4 + a2*b3 - a3*b2 + a4*b1)**2
     self.assertTrue(p == q,
                     "bad multiply:\n{0!s}\n{1!s}".format(repr(p.coef),
                                                repr(q.coef)))
示例#8
0
 def setUp(self):
     x, y = MVPolyDict.variables(2, dtype=int)
     self.p = self.makep(x, y)
     self.x = [1, 1, -1, 0,  7, 3,  -3, 1]
     self.y = [1, 0,  0, 3, -1, 2, -10, 2]
     self.n = len(self.x)