def test_ANP_properties(): mod = [QQ(1), QQ(0), QQ(1)] assert ANP([QQ(0)], mod, QQ).is_zero is True assert ANP([QQ(1)], mod, QQ).is_zero is False assert ANP([QQ(1)], mod, QQ).is_one is True assert ANP([QQ(2)], mod, QQ).is_one is False
def test___hash__(): # issue sympy/sympy#5571 assert DMP([[1, 2], [3]], ZZ) == DMP([[int(1), int(2)], [int(3)]], ZZ) assert hash(DMP([[1, 2], [3]], ZZ)) == hash(DMP([[int(1), int(2)], [int(3)]], ZZ)) assert DMF( ([[1, 2], [3]], [[1]]), ZZ) == DMF(([[int(1), int(2)], [int(3)]], [[int(1)]]), ZZ) assert hash(DMF(([[1, 2], [3]], [[1]]), ZZ)) == hash(DMF(([[int(1), int(2)], [int(3)]], [[int(1)]]), ZZ)) assert ANP([1, 1], [1, 0, 1], ZZ) == ANP([int(1), int(1)], [int(1), int(0), int(1)], ZZ) assert hash( ANP([1, 1], [1, 0, 1], ZZ)) == hash(ANP([int(1), int(1)], [int(1), int(0), int(1)], ZZ))
def test_ANP___eq__(): a = ANP([QQ(1), QQ(1)], [QQ(1), QQ(0), QQ(1)], QQ) b = ANP([QQ(1), QQ(1)], [QQ(1), QQ(0), QQ(2)], QQ) assert (a == a) is True assert (a != a) is False assert (a == b) is False assert (a != b) is True b = ANP([QQ(1), QQ(2)], [QQ(1), QQ(0), QQ(1)], QQ) assert (a == b) is False assert (a != b) is True
def test_pickling_polys_polyclasses(): for c in (DMP, DMP([[ZZ(1)], [ZZ(2)], [ZZ(3)]], ZZ)): check(c) for c in (DMF, DMF(([ZZ(1), ZZ(2)], [ZZ(1), ZZ(3)]), ZZ)): check(c) for c in (ANP, ANP([QQ(1), QQ(2)], [QQ(1), QQ(2), QQ(3)], QQ)): check(c)
def test_dmp_lift(): q = [QQ(1, 1), QQ(0, 1), QQ(1, 1)] f = [ ANP([QQ(1, 1)], q, QQ), ANP([], q, QQ), ANP([], q, QQ), ANP([QQ(1, 1), QQ(0, 1)], q, QQ), ANP([QQ(17, 1), QQ(0, 1)], q, QQ) ] assert dmp_lift(f, 0, QQ.algebraic_field(I)) == \ [QQ(1), QQ(0), QQ(0), QQ(0), QQ(0), QQ(0), QQ(2), QQ(0), QQ(578), QQ(0), QQ(0), QQ(0), QQ(1), QQ(0), QQ(-578), QQ(0), QQ(83521)] pytest.raises(DomainError, lambda: dmp_lift([EX(1), EX(2)], 0, EX))
def test_ANP_unify(): mod = [QQ(1), QQ(0), QQ(-2)] a = ANP([QQ(1)], mod, QQ) b = ANP([ZZ(1)], mod, ZZ) assert a.unify(b)[0] == QQ assert b.unify(a)[0] == QQ assert a.unify(a)[0] == QQ assert b.unify(b)[0] == ZZ
def test_ANP___init__(): rep = [QQ(1), QQ(1)] mod = [QQ(1), QQ(0), QQ(1)] f = ANP(rep, mod, QQ) assert f.rep == [QQ(1), QQ(1)] assert f.mod == [QQ(1), QQ(0), QQ(1)] assert f.domain == QQ rep = {1: QQ(1), 0: QQ(1)} mod = {2: QQ(1), 0: QQ(1)} f = ANP(rep, mod, QQ) assert f.rep == [QQ(1), QQ(1)] assert f.mod == [QQ(1), QQ(0), QQ(1)] assert f.domain == QQ f = ANP(1, mod, QQ) assert f.rep == [QQ(1)] assert f.mod == [QQ(1), QQ(0), QQ(1)] assert f.domain == QQ
def anp(element): return ANP(element, [QQ(1), QQ(0), QQ(1)], QQ)
def anp(x): return ANP(x, [QQ(1), QQ(0), QQ(1)], QQ)
def test_ANP_arithmetics(): mod = [QQ(1), QQ(0), QQ(0), QQ(-2)] a = ANP([QQ(2), QQ(-1), QQ(1)], mod, QQ) b = ANP([QQ(1), QQ(2)], mod, QQ) c = ANP([QQ(-2), QQ(1), QQ(-1)], mod, QQ) assert a.neg() == -a == c c = ANP([QQ(2), QQ(0), QQ(3)], mod, QQ) assert a.add(b) == a + b == c assert b.add(a) == b + a == c c = ANP([QQ(2), QQ(-2), QQ(-1)], mod, QQ) assert a.sub(b) == a - b == c c = ANP([QQ(-2), QQ(2), QQ(1)], mod, QQ) assert b.sub(a) == b - a == c c = ANP([QQ(3), QQ(-1), QQ(6)], mod, QQ) assert a.mul(b) == a * b == c assert b.mul(a) == b * a == c c = ANP([QQ(-1, 43), QQ(9, 43), QQ(5, 43)], mod, QQ) assert a.pow(0) == a**(0) == ANP(1, mod, QQ) assert a.pow(1) == a**(1) == a assert a.pow(-1) == a**(-1) == c assert a.quo(a) == a.mul(a.pow(-1)) == a * a**(-1) == ANP(1, mod, QQ)
def test_ANP___bool__(): assert bool(ANP([], [QQ(1), QQ(0), QQ(1)], QQ)) is False assert bool(ANP([QQ(1)], [QQ(1), QQ(0), QQ(1)], QQ)) is True