コード例 #1
0
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 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
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 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")
コード例 #3
0
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 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)))
コード例 #4
0
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 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
ファイル: base.py プロジェクト: jjgreen/mvpoly
 def bernstein(cls, i, n, **kwargs):
     """
     Return the output of :meth:`mvpoly.dict.MVPolyDict.bernstein`
     converted to other polynomial subclasess.
     """
     from mvpoly.dict import MVPolyDict
     return cls(MVPolyDict.bernstein(i, n, **kwargs), **kwargs)
コード例 #6
0
ファイル: base.py プロジェクト: jjgreen/mvpoly
 def bell_partial(cls, n, k, **kwargs):
     """
     Return the output of :meth:`mvpoly.dict.MVPolyDict.bell_partial`
     converted to other polynomial subclasess.
     """
     from mvpoly.dict import MVPolyDict
     return cls(MVPolyDict.bell_partial(n, k, **kwargs), **kwargs)
コード例 #7
0
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 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))))
コード例 #8
0
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 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)))
コード例 #9
0
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 def test_monomials_linear(self):
     L = MVPolyDict.monomials(2, 1)
     self.assertTrue(len(L) == 3,
                     "expected 3 monomials, got {0:d}".format(len(L)))
     E = [
         { ()        : 1 },
         { ((0, 1),) : 1 },
         { ((1, 1),) : 1 }
     ]
     for i in range(3):
         self.assertTrue(L[i].coef == E[i],
                         "{0!s} != {1!s}".format(repr(L[i].coef), repr(E[i])))
コード例 #10
0
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 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)))
コード例 #11
0
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 def test_monomials_quadratic(self):
     L = MVPolyDict.monomials(2, 2)
     self.assertTrue(len(L) == 6,
                     "expected 6 monomials, got {0:d}".format(len(L)))
     E = [
         { ()               : 1 },
         { ((0, 1),)        : 1 },
         { ((1, 1),)        : 1 },
         { ((0, 2),)        : 1 },
         { ((0, 1), (1, 1)) : 1 },
         { ((1, 2),)        : 1 },
     ]
     for i in range(5):
         self.assertTrue(L[i].coef == E[i],
                         "{0!s} != {1!s}".format(repr(L[i].coef), repr(E[i])))
コード例 #12
0
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 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)
コード例 #13
0
ファイル: test_mvpoly_dict.py プロジェクト: jjgreen/mvpoly
 def test_monomials_constant(self):
     L = MVPolyDict.monomials(2, 0)
     self.assertTrue(L[0].coef == { () : 1 },
                     "{0!s}".format(repr(L[0].coef)))