def test_Domain_get_ring(): assert ZZ.has_assoc_Ring is True assert QQ.has_assoc_Ring is True assert ZZ[x].has_assoc_Ring is True assert QQ[x].has_assoc_Ring is True assert ZZ[x, y].has_assoc_Ring is True assert QQ[x, y].has_assoc_Ring is True assert ZZ.frac_field(x).has_assoc_Ring is True assert QQ.frac_field(x).has_assoc_Ring is True assert ZZ.frac_field(x, y).has_assoc_Ring is True assert QQ.frac_field(x, y).has_assoc_Ring is True assert EX.has_assoc_Ring is False assert RR.has_assoc_Ring is False assert ALG.has_assoc_Ring is False assert ZZ.get_ring() == ZZ assert QQ.get_ring() == ZZ assert ZZ[x].get_ring() == ZZ[x] assert QQ[x].get_ring() == QQ[x] assert ZZ[x, y].get_ring() == ZZ[x, y] assert QQ[x, y].get_ring() == QQ[x, y] assert ZZ.frac_field(x).get_ring() == ZZ[x] assert QQ.frac_field(x).get_ring() == QQ[x] assert ZZ.frac_field(x, y).get_ring() == ZZ[x, y] assert QQ.frac_field(x, y).get_ring() == QQ[x, y] assert EX.get_ring() == EX raises(DomainError, lambda: RR.get_ring()) raises(DomainError, lambda: ALG.get_ring())
def test_Domain_get_ring(): assert ZZ.has_assoc_Ring is True assert QQ.has_assoc_Ring is True assert ZZ[x].has_assoc_Ring is True assert QQ[x].has_assoc_Ring is True assert ZZ[x, y].has_assoc_Ring is True assert QQ[x, y].has_assoc_Ring is True assert ZZ.frac_field(x).has_assoc_Ring is True assert QQ.frac_field(x).has_assoc_Ring is True assert ZZ.frac_field(x, y).has_assoc_Ring is True assert QQ.frac_field(x, y).has_assoc_Ring is True assert EX.has_assoc_Ring is False assert RR.has_assoc_Ring is False assert ALG.has_assoc_Ring is False assert ZZ.get_ring() == ZZ assert QQ.get_ring() == ZZ assert ZZ[x].get_ring() == ZZ[x] assert QQ[x].get_ring() == QQ[x] assert ZZ[x, y].get_ring() == ZZ[x, y] assert QQ[x, y].get_ring() == QQ[x, y] assert ZZ.frac_field(x).get_ring() == ZZ[x] assert QQ.frac_field(x).get_ring() == QQ[x] assert ZZ.frac_field(x, y).get_ring() == ZZ[x, y] assert QQ.frac_field(x, y).get_ring() == QQ[x, y] assert EX.get_ring() == EX assert RR.get_ring() == RR # XXX: This should also be like RR raises(DomainError, lambda: ALG.get_ring())
def from_sympy(self, a): """Convert SymPy's Integer to `dtype`. """ if a.is_Rational: return GMPYRationalType(a.p, a.q) elif a.is_Float: from sympy.polys.domains import RR return GMPYRationalType(*RR.as_integer_ratio(a)) else: raise CoercionFailed("expected `Rational` object, got %s" % a)
def from_sympy(self, a): """Convert SymPy's Rational to `dtype`. """ if a.is_Rational and a.q != 0: return a elif a.is_Real: from sympy.polys.domains import RR return SymPyRationalType(*RR.as_integer_ratio(a)) else: raise CoercionFailed("expected `Rational` object, got %s" % a)
def from_sympy(self, a): """Convert SymPy's Rational to `dtype`. """ if a.is_Rational: return PythonRational(a.p, a.q) elif a.is_Float: from sympy.polys.domains import RR p, q = RR.to_rational(a) return PythonRational(int(p), int(q)) else: raise CoercionFailed("expected `Rational` object, got %s" % a)
def test_Domain_get_exact(): assert EX.get_exact() == EX assert ZZ.get_exact() == ZZ assert QQ.get_exact() == QQ assert RR.get_exact() == QQ assert ALG.get_exact() == ALG assert ZZ[x].get_exact() == ZZ[x] assert QQ[x].get_exact() == QQ[x] assert ZZ[x,y].get_exact() == ZZ[x,y] assert QQ[x,y].get_exact() == QQ[x,y] assert ZZ.frac_field(x).get_exact() == ZZ.frac_field(x) assert QQ.frac_field(x).get_exact() == QQ.frac_field(x) assert ZZ.frac_field(x,y).get_exact() == ZZ.frac_field(x,y) assert QQ.frac_field(x,y).get_exact() == QQ.frac_field(x,y)
def test_Domain_get_field(): assert EX.has_assoc_Field == True assert ZZ.has_assoc_Field == True assert QQ.has_assoc_Field == True assert RR.has_assoc_Field == False assert ALG.has_assoc_Field == True assert ZZ[x].has_assoc_Field == True assert QQ[x].has_assoc_Field == True assert ZZ[x,y].has_assoc_Field == True assert QQ[x,y].has_assoc_Field == True assert EX.get_field() == EX assert ZZ.get_field() == QQ assert QQ.get_field() == QQ raises(DomainError, lambda: RR.get_field()) assert ALG.get_field() == ALG assert ZZ[x].get_field() == ZZ.frac_field(x) assert QQ[x].get_field() == QQ.frac_field(x) assert ZZ[x,y].get_field() == ZZ.frac_field(x,y) assert QQ[x,y].get_field() == QQ.frac_field(x,y)
def test_Domain_get_field(): assert EX.has_assoc_Field is True assert ZZ.has_assoc_Field is True assert QQ.has_assoc_Field is True assert RR.has_assoc_Field is True assert ALG.has_assoc_Field is True assert ZZ[x].has_assoc_Field is True assert QQ[x].has_assoc_Field is True assert ZZ[x, y].has_assoc_Field is True assert QQ[x, y].has_assoc_Field is True assert EX.get_field() == EX assert ZZ.get_field() == QQ assert QQ.get_field() == QQ assert RR.get_field() == RR assert ALG.get_field() == ALG assert ZZ[x].get_field() == ZZ.frac_field(x) assert QQ[x].get_field() == QQ.frac_field(x) assert ZZ[x, y].get_field() == ZZ.frac_field(x, y) assert QQ[x, y].get_field() == QQ.frac_field(x, y)
def test_construct_domain(): assert construct_domain([1, 2, 3]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)]) assert construct_domain( [1, 2, 3], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)]) assert construct_domain([S(1), S(2), S(3)]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)]) assert construct_domain( [S(1), S(2), S(3)], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)]) assert construct_domain([S(1)/2, S(2)]) == (QQ, [QQ(1, 2), QQ(2)]) assert construct_domain( [3.14, 1, S(1)/2]) == (RR, [RR(3.14), RR(1.0), RR(0.5)]) assert construct_domain( [3.14, sqrt(2)], extension=None) == (EX, [EX(3.14), EX(sqrt(2))]) assert construct_domain( [3.14, sqrt(2)], extension=True) == (EX, [EX(3.14), EX(sqrt(2))]) assert construct_domain( [1, sqrt(2)], extension=None) == (EX, [EX(1), EX(sqrt(2))]) alg = QQ.algebraic_field(sqrt(2)) assert construct_domain([7, S(1)/2, sqrt(2)], extension=True) == \ (alg, [alg.convert(7), alg.convert(S(1)/2), alg.convert(sqrt(2))]) alg = QQ.algebraic_field(sqrt(2) + sqrt(3)) assert construct_domain([7, sqrt(2), sqrt(3)], extension=True) == \ (alg, [alg.convert(7), alg.convert(sqrt(2)), alg.convert(sqrt(3))]) dom = ZZ[x] assert construct_domain([2*x, 3]) == \ (dom, [dom.convert(2*x), dom.convert(3)]) dom = ZZ[x, y] assert construct_domain([2*x, 3*y]) == \ (dom, [dom.convert(2*x), dom.convert(3*y)]) dom = QQ[x] assert construct_domain([x/2, 3]) == \ (dom, [dom.convert(x/2), dom.convert(3)]) dom = QQ[x, y] assert construct_domain([x/2, 3*y]) == \ (dom, [dom.convert(x/2), dom.convert(3*y)]) dom = RR[x] assert construct_domain([x/2, 3.5]) == \ (dom, [dom.convert(x/2), dom.convert(3.5)]) dom = RR[x, y] assert construct_domain([x/2, 3.5*y]) == \ (dom, [dom.convert(x/2), dom.convert(3.5*y)]) dom = ZZ.frac_field(x) assert construct_domain([2/x, 3]) == \ (dom, [dom.convert(2/x), dom.convert(3)]) dom = ZZ.frac_field(x, y) assert construct_domain([2/x, 3*y]) == \ (dom, [dom.convert(2/x), dom.convert(3*y)]) dom = RR.frac_field(x) assert construct_domain([2/x, 3.5]) == \ (dom, [dom.convert(2/x), dom.convert(3.5)]) dom = RR.frac_field(x, y) assert construct_domain([2/x, 3.5*y]) == \ (dom, [dom.convert(2/x), dom.convert(3.5*y)]) assert construct_domain(2) == (ZZ, ZZ(2)) assert construct_domain(S(2)/3) == (QQ, QQ(2, 3))
def test_dmp_gcd(): assert dmp_zz_heu_gcd([[]], [[]], 1, ZZ) == ([[]], [[]], [[]]) assert dmp_rr_prs_gcd([[]], [[]], 1, ZZ) == ([[]], [[]], [[]]) assert dmp_zz_heu_gcd([[2]], [[]], 1, ZZ) == ([[2]], [[1]], [[]]) assert dmp_rr_prs_gcd([[2]], [[]], 1, ZZ) == ([[2]], [[1]], [[]]) assert dmp_zz_heu_gcd([[-2]], [[]], 1, ZZ) == ([[2]], [[-1]], [[]]) assert dmp_rr_prs_gcd([[-2]], [[]], 1, ZZ) == ([[2]], [[-1]], [[]]) assert dmp_zz_heu_gcd([[]], [[-2]], 1, ZZ) == ([[2]], [[]], [[-1]]) assert dmp_rr_prs_gcd([[]], [[-2]], 1, ZZ) == ([[2]], [[]], [[-1]]) assert dmp_zz_heu_gcd([[]], [[2], [4]], 1, ZZ) == ([[2], [4]], [[]], [[1]]) assert dmp_rr_prs_gcd([[]], [[2], [4]], 1, ZZ) == ([[2], [4]], [[]], [[1]]) assert dmp_zz_heu_gcd([[2], [4]], [[]], 1, ZZ) == ([[2], [4]], [[1]], [[]]) assert dmp_rr_prs_gcd([[2], [4]], [[]], 1, ZZ) == ([[2], [4]], [[1]], [[]]) assert dmp_zz_heu_gcd([[2]], [[2]], 1, ZZ) == ([[2]], [[1]], [[1]]) assert dmp_rr_prs_gcd([[2]], [[2]], 1, ZZ) == ([[2]], [[1]], [[1]]) assert dmp_zz_heu_gcd([[-2]], [[2]], 1, ZZ) == ([[2]], [[-1]], [[1]]) assert dmp_rr_prs_gcd([[-2]], [[2]], 1, ZZ) == ([[2]], [[-1]], [[1]]) assert dmp_zz_heu_gcd([[2]], [[-2]], 1, ZZ) == ([[2]], [[1]], [[-1]]) assert dmp_rr_prs_gcd([[2]], [[-2]], 1, ZZ) == ([[2]], [[1]], [[-1]]) assert dmp_zz_heu_gcd([[-2]], [[-2]], 1, ZZ) == ([[2]], [[-1]], [[-1]]) assert dmp_rr_prs_gcd([[-2]], [[-2]], 1, ZZ) == ([[2]], [[-1]], [[-1]]) assert dmp_zz_heu_gcd([[1], [2], [1]], [[1]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[1]]) assert dmp_rr_prs_gcd([[1], [2], [1]], [[1]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[1]]) assert dmp_zz_heu_gcd([[1], [2], [1]], [[2]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[2]]) assert dmp_rr_prs_gcd([[1], [2], [1]], [[2]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[2]]) assert dmp_zz_heu_gcd([[2], [4], [2]], [[2]], 1, ZZ) == ([[2]], [[1], [2], [1]], [[1]]) assert dmp_rr_prs_gcd([[2], [4], [2]], [[2]], 1, ZZ) == ([[2]], [[1], [2], [1]], [[1]]) assert dmp_zz_heu_gcd([[2]], [[2], [4], [2]], 1, ZZ) == ([[2]], [[1]], [[1], [2], [1]]) assert dmp_rr_prs_gcd([[2]], [[2], [4], [2]], 1, ZZ) == ([[2]], [[1]], [[1], [2], [1]]) assert dmp_zz_heu_gcd([[2], [4], [2]], [[1], [1]], 1, ZZ) == ([[1], [1]], [[2], [2]], [[1]]) assert dmp_rr_prs_gcd([[2], [4], [2]], [[1], [1]], 1, ZZ) == ([[1], [1]], [[2], [2]], [[1]]) assert dmp_zz_heu_gcd([[1], [1]], [[2], [4], [2]], 1, ZZ) == ([[1], [1]], [[1]], [[2], [2]]) assert dmp_rr_prs_gcd([[1], [1]], [[2], [4], [2]], 1, ZZ) == ([[1], [1]], [[1]], [[2], [2]]) assert dmp_zz_heu_gcd([[[[1, 2, 1]]]], [[[[2, 2]]]], 3, ZZ) == ([[[[1, 1]]]], [[[[1, 1]]]], [[[[2]]]]) assert dmp_rr_prs_gcd([[[[1, 2, 1]]]], [[[[2, 2]]]], 3, ZZ) == ([[[[1, 1]]]], [[[[1, 1]]]], [[[[2]]]]) f, g = [[[[1, 2, 1], [1, 1], []]]], [[[[1, 2, 1]]]] h, cff, cfg = [[[[1, 1]]]], [[[[1, 1], [1], []]]], [[[[1, 1]]]] assert dmp_zz_heu_gcd(f, g, 3, ZZ) == (h, cff, cfg) assert dmp_rr_prs_gcd(f, g, 3, ZZ) == (h, cff, cfg) assert dmp_zz_heu_gcd(g, f, 3, ZZ) == (h, cfg, cff) assert dmp_rr_prs_gcd(g, f, 3, ZZ) == (h, cfg, cff) f, g, h = dmp_fateman_poly_F_1(2, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g H, cff, cfg = dmp_rr_prs_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g f, g, h = dmp_fateman_poly_F_1(4, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 4, ZZ) assert H == h and dmp_mul(H, cff, 4, ZZ) == f \ and dmp_mul(H, cfg, 4, ZZ) == g f, g, h = dmp_fateman_poly_F_1(6, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 6, ZZ) assert H == h and dmp_mul(H, cff, 6, ZZ) == f \ and dmp_mul(H, cfg, 6, ZZ) == g f, g, h = dmp_fateman_poly_F_1(8, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 8, ZZ) assert H == h and dmp_mul(H, cff, 8, ZZ) == f \ and dmp_mul(H, cfg, 8, ZZ) == g f, g, h = dmp_fateman_poly_F_2(2, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g H, cff, cfg = dmp_rr_prs_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g f, g, h = dmp_fateman_poly_F_3(2, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g H, cff, cfg = dmp_rr_prs_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g f, g, h = dmp_fateman_poly_F_3(4, ZZ) H, cff, cfg = dmp_inner_gcd(f, g, 4, ZZ) assert H == h and dmp_mul(H, cff, 4, ZZ) == f \ and dmp_mul(H, cfg, 4, ZZ) == g f = [[QQ(1, 2)], [QQ(1)], [QQ(1, 2)]] g = [[QQ(1, 2)], [QQ(1, 2)]] h = [[QQ(1)], [QQ(1)]] assert dmp_qq_heu_gcd(f, g, 1, QQ) == (h, g, [[QQ(1, 2)]]) assert dmp_ff_prs_gcd(f, g, 1, QQ) == (h, g, [[QQ(1, 2)]]) f = [[RR(2.1), RR(-2.2), RR(2.1)], []] g = [[RR(1.0)], [], [], []] assert dmp_ff_prs_gcd(f, g, 1, RR) == \ ([[RR(1.0)], []], [[RR(2.1), RR(-2.2), RR(2.1)]], [[RR(1.0)], [], []])
def test_dmp_factor_list(): assert dmp_factor_list([[]], 1, ZZ) == (ZZ(0), []) assert dmp_factor_list([[]], 1, QQ) == (QQ(0), []) assert dmp_factor_list([[]], 1, ZZ['y']) == (DMP([], ZZ), []) assert dmp_factor_list([[]], 1, QQ['y']) == (DMP([], QQ), []) assert dmp_factor_list_include([[]], 1, ZZ) == [([[]], 1)] assert dmp_factor_list([[ZZ(7)]], 1, ZZ) == (ZZ(7), []) assert dmp_factor_list([[QQ(1, 7)]], 1, QQ) == (QQ(1, 7), []) assert dmp_factor_list([[DMP([ZZ(7)], ZZ)]], 1, ZZ['y']) == (DMP([ZZ(7)], ZZ), []) assert dmp_factor_list([[DMP([QQ(1, 7)], QQ)]], 1, QQ['y']) == (DMP([QQ(1, 7)], QQ), []) assert dmp_factor_list_include([[ZZ(7)]], 1, ZZ) == [([[ZZ(7)]], 1)] f, g = [ZZ(1), ZZ(2), ZZ(1)], [ZZ(1), ZZ(1)] assert dmp_factor_list(dmp_nest(f, 200, ZZ), 200, ZZ) == \ (ZZ(1), [(dmp_nest(g, 200, ZZ), 2)]) assert dmp_factor_list(dmp_raise(f, 200, 0, ZZ), 200, ZZ) == \ (ZZ(1), [(dmp_raise(g, 200, 0, ZZ), 2)]) assert dmp_factor_list([ZZ(1),ZZ(2),ZZ(1)], 0, ZZ) == \ (ZZ(1), [([ZZ(1), ZZ(1)], 2)]) assert dmp_factor_list([QQ(1,2),QQ(1),QQ(1,2)], 0, QQ) == \ (QQ(1,2), [([QQ(1),QQ(1)], 2)]) assert dmp_factor_list([[ZZ(1)],[ZZ(2)],[ZZ(1)]], 1, ZZ) == \ (ZZ(1), [([[ZZ(1)], [ZZ(1)]], 2)]) assert dmp_factor_list([[QQ(1,2)],[QQ(1)],[QQ(1,2)]], 1, QQ) == \ (QQ(1,2), [([[QQ(1)],[QQ(1)]], 2)]) f = [[ZZ(4), ZZ(0)], [ZZ(4), ZZ(0), ZZ(0)], []] assert dmp_factor_list(f, 1, ZZ) == \ (ZZ(4), [([[ZZ(1),ZZ(0)]], 1), ([[ZZ(1)],[]], 1), ([[ZZ(1)],[ZZ(1),ZZ(0)]], 1)]) assert dmp_factor_list_include(f, 1, ZZ) == \ [([[ZZ(4),ZZ(0)]], 1), ([[ZZ(1)],[]], 1), ([[ZZ(1)],[ZZ(1),ZZ(0)]], 1)] f = [[QQ(1, 2), QQ(0)], [QQ(1, 2), QQ(0), QQ(0)], []] assert dmp_factor_list(f, 1, QQ) == \ (QQ(1,2), [([[QQ(1),QQ(0)]], 1), ([[QQ(1)],[]], 1), ([[QQ(1)],[QQ(1),QQ(0)]], 1)]) f = [[RR(2.0)], [], [-RR(8.0), RR(0.0), RR(0.0)]] assert dmp_factor_list(f, 1, RR) == \ (RR(2.0), [([[RR(1.0)],[-RR(2.0),RR(0.0)]], 1), ([[RR(1.0)],[ RR(2.0),RR(0.0)]], 1)]) f = [[DMP([ZZ(4), ZZ(0)], ZZ)], [DMP([ZZ(4), ZZ(0), ZZ(0)], ZZ)], [DMP([], ZZ)]] assert dmp_factor_list(f, 1, ZZ['y']) == \ (DMP([ZZ(4)],ZZ), [([[DMP([ZZ(1),ZZ(0)],ZZ)]], 1), ([[DMP([ZZ(1)],ZZ)],[]], 1), ([[DMP([ZZ(1)],ZZ)],[DMP([ZZ(1),ZZ(0)],ZZ)]], 1)]) f = [[DMP([QQ(1, 2), QQ(0)], ZZ)], [DMP([QQ(1, 2), QQ(0), QQ(0)], ZZ)], [DMP([], ZZ)]] assert dmp_factor_list(f, 1, QQ['y']) == \ (DMP([QQ(1,2)],QQ), [([[DMP([QQ(1),QQ(0)],QQ)]], 1), ([[DMP([QQ(1)],QQ)],[]], 1), ([[DMP([QQ(1)],QQ)],[DMP([QQ(1),QQ(0)],QQ)]], 1)]) K = FF(2) raises(DomainError, "dmp_factor_list([[K(1)],[],[K(1),K(0),K(0)]], 1, K)") raises(DomainError, "dmp_factor_list([[EX(sin(1))]], 1, EX)")
def test_Domain_unify(): F3 = GF(3) assert unify(F3, F3) == F3 assert unify(F3, ZZ) == ZZ assert unify(F3, QQ) == QQ assert unify(F3, ALG) == ALG assert unify(F3, RR) == RR assert unify(F3, CC) == CC assert unify(F3, ZZ[x]) == ZZ[x] assert unify(F3, ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(F3, EX) == EX assert unify(ZZ, F3) == ZZ assert unify(ZZ, ZZ) == ZZ assert unify(ZZ, QQ) == QQ assert unify(ZZ, ALG) == ALG assert unify(ZZ, RR) == RR assert unify(ZZ, CC) == CC assert unify(ZZ, ZZ[x]) == ZZ[x] assert unify(ZZ, ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(ZZ, EX) == EX assert unify(QQ, F3) == QQ assert unify(QQ, ZZ) == QQ assert unify(QQ, QQ) == QQ assert unify(QQ, ALG) == ALG assert unify(QQ, RR) == RR assert unify(QQ, CC) == CC assert unify(QQ, ZZ[x]) == QQ[x] assert unify(QQ, ZZ.frac_field(x)) == QQ.frac_field(x) assert unify(QQ, EX) == EX assert unify(RR, F3) == RR assert unify(RR, ZZ) == RR assert unify(RR, QQ) == RR assert unify(RR, ALG) == RR assert unify(RR, RR) == RR assert unify(RR, CC) == CC assert unify(RR, ZZ[x]) == RR[x] assert unify(RR, ZZ.frac_field(x)) == RR.frac_field(x) assert unify(RR, EX) == EX assert RR[x].unify(ZZ.frac_field(y)) == RR.frac_field(x, y) assert unify(CC, F3) == CC assert unify(CC, ZZ) == CC assert unify(CC, QQ) == CC assert unify(CC, ALG) == CC assert unify(CC, RR) == CC assert unify(CC, CC) == CC assert unify(CC, ZZ[x]) == CC[x] assert unify(CC, ZZ.frac_field(x)) == CC.frac_field(x) assert unify(CC, EX) == EX assert unify(ZZ[x], F3) == ZZ[x] assert unify(ZZ[x], ZZ) == ZZ[x] assert unify(ZZ[x], QQ) == QQ[x] assert unify(ZZ[x], ALG) == ALG[x] assert unify(ZZ[x], RR) == RR[x] assert unify(ZZ[x], CC) == CC[x] assert unify(ZZ[x], ZZ[x]) == ZZ[x] assert unify(ZZ[x], ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(ZZ[x], EX) == EX assert unify(ZZ.frac_field(x), F3) == ZZ.frac_field(x) assert unify(ZZ.frac_field(x), ZZ) == ZZ.frac_field(x) assert unify(ZZ.frac_field(x), QQ) == QQ.frac_field(x) assert unify(ZZ.frac_field(x), ALG) == ALG.frac_field(x) assert unify(ZZ.frac_field(x), RR) == RR.frac_field(x) assert unify(ZZ.frac_field(x), CC) == CC.frac_field(x) assert unify(ZZ.frac_field(x), ZZ[x]) == ZZ.frac_field(x) assert unify(ZZ.frac_field(x), ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(ZZ.frac_field(x), EX) == EX assert unify(EX, F3) == EX assert unify(EX, ZZ) == EX assert unify(EX, QQ) == EX assert unify(EX, ALG) == EX assert unify(EX, RR) == EX assert unify(EX, CC) == EX assert unify(EX, ZZ[x]) == EX assert unify(EX, ZZ.frac_field(x)) == EX assert unify(EX, EX) == EX
def test_dmp_factor_list(): R, x, y = ring("x,y", ZZ) assert R.dmp_factor_list(0) == (ZZ(0), []) assert R.dmp_factor_list(7) == (7, []) R, x, y = ring("x,y", QQ) assert R.dmp_factor_list(0) == (QQ(0), []) assert R.dmp_factor_list(QQ(1, 7)) == (QQ(1, 7), []) Rt, t = ring("t", ZZ) R, x, y = ring("x,y", Rt) assert R.dmp_factor_list(0) == (0, []) assert R.dmp_factor_list(7) == (ZZ(7), []) Rt, t = ring("t", QQ) R, x, y = ring("x,y", Rt) assert R.dmp_factor_list(0) == (0, []) assert R.dmp_factor_list(QQ(1, 7)) == (QQ(1, 7), []) R, x, y = ring("x,y", ZZ) assert R.dmp_factor_list_include(0) == [(0, 1)] assert R.dmp_factor_list_include(7) == [(7, 1)] R, X = xring("x:200", ZZ) f, g = X[0]**2 + 2 * X[0] + 1, X[0] + 1 assert R.dmp_factor_list(f) == (1, [(g, 2)]) f, g = X[-1]**2 + 2 * X[-1] + 1, X[-1] + 1 assert R.dmp_factor_list(f) == (1, [(g, 2)]) R, x = ring("x", ZZ) assert R.dmp_factor_list(x**2 + 2 * x + 1) == (1, [(x + 1, 2)]) R, x = ring("x", QQ) assert R.dmp_factor_list(QQ(1, 2) * x**2 + x + QQ(1, 2)) == (QQ(1, 2), [(x + 1, 2)]) R, x, y = ring("x,y", ZZ) assert R.dmp_factor_list(x**2 + 2 * x + 1) == (1, [(x + 1, 2)]) R, x, y = ring("x,y", QQ) assert R.dmp_factor_list(QQ(1, 2) * x**2 + x + QQ(1, 2)) == (QQ(1, 2), [(x + 1, 2)]) R, x, y = ring("x,y", ZZ) f = 4 * x**2 * y + 4 * x * y**2 assert R.dmp_factor_list(f) == \ (4, [(y, 1), (x, 1), (x + y, 1)]) assert R.dmp_factor_list_include(f) == \ [(4*y, 1), (x, 1), (x + y, 1)] R, x, y = ring("x,y", QQ) f = QQ(1, 2) * x**2 * y + QQ(1, 2) * x * y**2 assert R.dmp_factor_list(f) == \ (QQ(1,2), [(y, 1), (x, 1), (x + y, 1)]) R, x, y = ring("x,y", RR) f = 2.0 * x**2 - 8.0 * y**2 assert R.dmp_factor_list(f) == \ (RR(2.0), [(1.0*x - 2.0*y, 1), (1.0*x + 2.0*y, 1)]) f = 6.7225336055071 * x**2 * y**2 - 10.6463972754741 * x * y - 0.33469524022264 coeff, factors = R.dmp_factor_list(f) assert coeff == RR(1.0) and len(factors) == 1 and factors[0][0].almosteq( f, 1e-10) and factors[0][1] == 1 Rt, t = ring("t", ZZ) R, x, y = ring("x,y", Rt) f = 4 * t * x**2 + 4 * t**2 * x assert R.dmp_factor_list(f) == \ (4, [(t, 1), (x, 1), (x + t, 1)]) Rt, t = ring("t", QQ) R, x, y = ring("x,y", Rt) f = QQ(1, 2) * t * x**2 + QQ(1, 2) * t**2 * x assert R.dmp_factor_list(f) == \ (QQ(1, 2), [(t, 1), (x, 1), (x + t, 1)]) R, x, y = ring("x,y", FF(2)) raises(NotImplementedError, lambda: R.dmp_factor_list(x**2 + y**2)) R, x, y = ring("x,y", EX) raises(DomainError, lambda: R.dmp_factor_list(EX(sin(1))))
def test_dup_factor_list(): R, x = ring("x", ZZ) assert R.dup_factor_list(0) == (0, []) assert R.dup_factor_list(7) == (7, []) R, x = ring("x", QQ) assert R.dup_factor_list(0) == (0, []) assert R.dup_factor_list(QQ(1, 7)) == (QQ(1, 7), []) R, x = ring("x", ZZ['t']) assert R.dup_factor_list(0) == (0, []) assert R.dup_factor_list(7) == (7, []) R, x = ring("x", QQ['t']) assert R.dup_factor_list(0) == (0, []) assert R.dup_factor_list(QQ(1, 7)) == (QQ(1, 7), []) R, x = ring("x", ZZ) assert R.dup_factor_list_include(0) == [(0, 1)] assert R.dup_factor_list_include(7) == [(7, 1)] assert R.dup_factor_list(x**2 + 2 * x + 1) == (1, [(x + 1, 2)]) assert R.dup_factor_list_include(x**2 + 2 * x + 1) == [(x + 1, 2)] R, x = ring("x", QQ) assert R.dup_factor_list(QQ(1, 2) * x**2 + x + QQ(1, 2)) == (QQ(1, 2), [(x + 1, 2)]) R, x = ring("x", FF(2)) assert R.dup_factor_list(x**2 + 1) == (1, [(x + 1, 2)]) R, x = ring("x", RR) assert R.dup_factor_list(1.0 * x**2 + 2.0 * x + 1.0) == (1.0, [ (1.0 * x + 1.0, 2) ]) assert R.dup_factor_list(2.0 * x**2 + 4.0 * x + 2.0) == (2.0, [ (1.0 * x + 1.0, 2) ]) f = 6.7225336055071 * x**2 - 10.6463972754741 * x - 0.33469524022264 coeff, factors = R.dup_factor_list(f) assert coeff == RR(1.0) and len(factors) == 1 and factors[0][0].almosteq( f, 1e-10) and factors[0][1] == 1 Rt, t = ring("t", ZZ) R, x = ring("x", Rt) f = 4 * t * x**2 + 4 * t**2 * x assert R.dup_factor_list(f) == \ (4, [(t, 1), (x, 1), (x + t, 1)]) Rt, t = ring("t", QQ) R, x = ring("x", Rt) f = QQ(1, 2) * t * x**2 + QQ(1, 2) * t**2 * x assert R.dup_factor_list(f) == \ (QQ(1, 2), [(t, 1), (x, 1), (x + t, 1)]) R, x = ring("x", QQ.algebraic_field(I)) def anp(element): return ANP(element, [QQ(1), QQ(0), QQ(1)], QQ) f = anp([QQ(1, 1)]) * x**4 + anp([QQ(2, 1)]) * x**2 assert R.dup_factor_list(f) == \ (anp([QQ(1, 1)]), [(anp([QQ(1, 1)])*x, 2), (anp([QQ(1, 1)])*x**2 + anp([])*x + anp([QQ(2, 1)]), 1)]) R, x = ring("x", EX) raises(DomainError, lambda: R.dup_factor_list(EX(sin(1))))
def test_RealField_from_sympy(): assert RR.convert(S.Zero) == RR.dtype(0) assert RR.convert(S(0.0)) == RR.dtype(0.0) assert RR.convert(S.One) == RR.dtype(1) assert RR.convert(S(1.0)) == RR.dtype(1.0) assert RR.convert(sin(1)) == RR.dtype(sin(1).evalf())
def test_issue_18278(): assert str(RR(2).parent()) == 'RR' assert str(CC(2).parent()) == 'CC'
def test_construct_domain(): assert construct_domain([1, 2, 3]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)]) assert construct_domain([1, 2, 3], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)]) assert construct_domain([S.One, S(2), S(3)]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)]) assert construct_domain([S.One, S(2), S(3)], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)]) assert construct_domain([S.Half, S(2)]) == (QQ, [QQ(1, 2), QQ(2)]) result = construct_domain([3.14, 1, S.Half]) assert isinstance(result[0], RealField) assert result[1] == [RR(3.14), RR(1.0), RR(0.5)] result = construct_domain([3.14, I, S.Half]) assert isinstance(result[0], ComplexField) assert result[1] == [CC(3.14), CC(1.0j), CC(0.5)] assert construct_domain([1.0 + I]) == (CC, [CC(1.0, 1.0)]) assert construct_domain([2.0 + 3.0 * I]) == (CC, [CC(2.0, 3.0)]) assert construct_domain([1, I]) == (ZZ_I, [ZZ_I(1, 0), ZZ_I(0, 1)]) assert construct_domain([1, I / 2]) == (QQ_I, [QQ_I(1, 0), QQ_I(0, S.Half)]) assert construct_domain([3.14, sqrt(2)], extension=None) == (EX, [EX(3.14), EX(sqrt(2))]) assert construct_domain([3.14, sqrt(2)], extension=True) == (EX, [EX(3.14), EX(sqrt(2))]) assert construct_domain([1, sqrt(2)], extension=None) == (EX, [EX(1), EX(sqrt(2))]) assert construct_domain([x, sqrt(x)]) == (EX, [EX(x), EX(sqrt(x))]) assert construct_domain([x, sqrt(x), sqrt(y) ]) == (EX, [EX(x), EX(sqrt(x)), EX(sqrt(y))]) alg = QQ.algebraic_field(sqrt(2)) assert construct_domain([7, S.Half, sqrt(2)], extension=True) == \ (alg, [alg.convert(7), alg.convert(S.Half), alg.convert(sqrt(2))]) alg = QQ.algebraic_field(sqrt(2) + sqrt(3)) assert construct_domain([7, sqrt(2), sqrt(3)], extension=True) == \ (alg, [alg.convert(7), alg.convert(sqrt(2)), alg.convert(sqrt(3))]) dom = ZZ[x] assert construct_domain([2*x, 3]) == \ (dom, [dom.convert(2*x), dom.convert(3)]) dom = ZZ[x, y] assert construct_domain([2*x, 3*y]) == \ (dom, [dom.convert(2*x), dom.convert(3*y)]) dom = QQ[x] assert construct_domain([x/2, 3]) == \ (dom, [dom.convert(x/2), dom.convert(3)]) dom = QQ[x, y] assert construct_domain([x/2, 3*y]) == \ (dom, [dom.convert(x/2), dom.convert(3*y)]) dom = ZZ_I[x] assert construct_domain([2*x, I]) == \ (dom, [dom.convert(2*x), dom.convert(I)]) dom = ZZ_I[x, y] assert construct_domain([2*x, I*y]) == \ (dom, [dom.convert(2*x), dom.convert(I*y)]) dom = QQ_I[x] assert construct_domain([x/2, I]) == \ (dom, [dom.convert(x/2), dom.convert(I)]) dom = QQ_I[x, y] assert construct_domain([x/2, I*y]) == \ (dom, [dom.convert(x/2), dom.convert(I*y)]) dom = RR[x] assert construct_domain([x/2, 3.5]) == \ (dom, [dom.convert(x/2), dom.convert(3.5)]) dom = RR[x, y] assert construct_domain([x/2, 3.5*y]) == \ (dom, [dom.convert(x/2), dom.convert(3.5*y)]) dom = CC[x] assert construct_domain([I*x/2, 3.5]) == \ (dom, [dom.convert(I*x/2), dom.convert(3.5)]) dom = CC[x, y] assert construct_domain([I*x/2, 3.5*y]) == \ (dom, [dom.convert(I*x/2), dom.convert(3.5*y)]) dom = CC[x] assert construct_domain([x/2, I*3.5]) == \ (dom, [dom.convert(x/2), dom.convert(I*3.5)]) dom = CC[x, y] assert construct_domain([x/2, I*3.5*y]) == \ (dom, [dom.convert(x/2), dom.convert(I*3.5*y)]) dom = ZZ.frac_field(x) assert construct_domain([2/x, 3]) == \ (dom, [dom.convert(2/x), dom.convert(3)]) dom = ZZ.frac_field(x, y) assert construct_domain([2/x, 3*y]) == \ (dom, [dom.convert(2/x), dom.convert(3*y)]) dom = RR.frac_field(x) assert construct_domain([2/x, 3.5]) == \ (dom, [dom.convert(2/x), dom.convert(3.5)]) dom = RR.frac_field(x, y) assert construct_domain([2/x, 3.5*y]) == \ (dom, [dom.convert(2/x), dom.convert(3.5*y)]) dom = RealField(prec=336)[x] assert construct_domain([pi.evalf(100)*x]) == \ (dom, [dom.convert(pi.evalf(100)*x)]) assert construct_domain(2) == (ZZ, ZZ(2)) assert construct_domain(S(2) / 3) == (QQ, QQ(2, 3)) assert construct_domain(Rational(2, 3)) == (QQ, QQ(2, 3)) assert construct_domain({}) == (ZZ, {})
def test_construct_domain(): assert construct_domain([1, 2, 3]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)]) assert construct_domain([1, 2, 3], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)]) assert construct_domain([S(1), S(2), S(3)]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)]) assert construct_domain([S(1), S(2), S(3)], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)]) assert construct_domain([S(1) / 2, S(2)]) == (QQ, [QQ(1, 2), QQ(2)]) assert construct_domain([3.14, 1, S(1) / 2]) == (RR, [RR(3.14), RR(1.0), RR(0.5)]) assert construct_domain([3.14, sqrt(2)], extension=None) == (EX, [EX(3.14), EX(sqrt(2))]) assert construct_domain([3.14, sqrt(2)], extension=True) == (EX, [EX(3.14), EX(sqrt(2))]) assert construct_domain([1, sqrt(2)], extension=None) == (EX, [EX(1), EX(sqrt(2))]) alg = QQ.algebraic_field(sqrt(2)) assert construct_domain([7, S(1)/2, sqrt(2)], extension=True) == \ (alg, [alg.convert(7), alg.convert(S(1)/2), alg.convert(sqrt(2))]) alg = QQ.algebraic_field(sqrt(2) + sqrt(3)) assert construct_domain([7, sqrt(2), sqrt(3)], extension=True) == \ (alg, [alg.convert(7), alg.convert(sqrt(2)), alg.convert(sqrt(3))]) dom = ZZ[x] assert construct_domain([2*x, 3]) == \ (dom, [dom.convert(2*x), dom.convert(3)]) dom = ZZ[x, y] assert construct_domain([2*x, 3*y]) == \ (dom, [dom.convert(2*x), dom.convert(3*y)]) dom = QQ[x] assert construct_domain([x/2, 3]) == \ (dom, [dom.convert(x/2), dom.convert(3)]) dom = QQ[x, y] assert construct_domain([x/2, 3*y]) == \ (dom, [dom.convert(x/2), dom.convert(3*y)]) dom = RR[x] assert construct_domain([x/2, 3.5]) == \ (dom, [dom.convert(x/2), dom.convert(3.5)]) dom = RR[x, y] assert construct_domain([x/2, 3.5*y]) == \ (dom, [dom.convert(x/2), dom.convert(3.5*y)]) dom = ZZ.frac_field(x) assert construct_domain([2/x, 3]) == \ (dom, [dom.convert(2/x), dom.convert(3)]) dom = ZZ.frac_field(x, y) assert construct_domain([2/x, 3*y]) == \ (dom, [dom.convert(2/x), dom.convert(3*y)]) dom = RR.frac_field(x) assert construct_domain([2/x, 3.5]) == \ (dom, [dom.convert(2/x), dom.convert(3.5)]) dom = RR.frac_field(x, y) assert construct_domain([2/x, 3.5*y]) == \ (dom, [dom.convert(2/x), dom.convert(3.5*y)]) assert construct_domain(2) == (ZZ, ZZ(2)) assert construct_domain(S(2) / 3) == (QQ, QQ(2, 3)) assert construct_domain({}) == (ZZ, {})
def test_dup_factor_list(): assert dup_factor_list([], ZZ) == (ZZ(0), []) assert dup_factor_list([], QQ) == (QQ(0), []) assert dup_factor_list([], ZZ['y']) == (DMP([], ZZ), []) assert dup_factor_list([], QQ['y']) == (DMP([], QQ), []) assert dup_factor_list_include([], ZZ) == [([], 1)] assert dup_factor_list([ZZ(7)], ZZ) == (ZZ(7), []) assert dup_factor_list([QQ(1, 7)], QQ) == (QQ(1, 7), []) assert dup_factor_list([DMP([ZZ(7)], ZZ)], ZZ['y']) == (DMP([ZZ(7)], ZZ), []) assert dup_factor_list([DMP([QQ(1, 7)], QQ)], QQ['y']) == (DMP([QQ(1, 7)], QQ), []) assert dup_factor_list_include([ZZ(7)], ZZ) == [([ZZ(7)], 1)] assert dup_factor_list([ZZ(1),ZZ(2),ZZ(1)], ZZ) == \ (ZZ(1), [([ZZ(1), ZZ(1)], 2)]) assert dup_factor_list([QQ(1,2),QQ(1),QQ(1,2)], QQ) == \ (QQ(1,2), [([QQ(1),QQ(1)], 2)]) assert dup_factor_list_include([ZZ(1),ZZ(2),ZZ(1)], ZZ) == \ [([ZZ(1), ZZ(1)], 2)] K = FF(2) assert dup_factor_list([K(1),K(0),K(1)], K) == \ (K(1), [([K(1), K(1)], 2)]) assert dup_factor_list([RR(1.0),RR(2.0),RR(1.0)], RR) == \ (RR(1.0), [([RR(1.0),RR(1.0)], 2)]) assert dup_factor_list([RR(2.0),RR(4.0),RR(2.0)], RR) == \ (RR(2.0), [([RR(1.0),RR(1.0)], 2)]) f = [DMP([ZZ(4), ZZ(0)], ZZ), DMP([ZZ(4), ZZ(0), ZZ(0)], ZZ), DMP([], ZZ)] assert dup_factor_list(f, ZZ['y']) == \ (DMP([ZZ(4)],ZZ), [([DMP([ZZ(1),ZZ(0)],ZZ)], 1), ([DMP([ZZ(1)],ZZ),DMP([],ZZ)], 1), ([DMP([ZZ(1)],ZZ),DMP([ZZ(1),ZZ(0)],ZZ)], 1)]) f = [ DMP([QQ(1, 2), QQ(0)], ZZ), DMP([QQ(1, 2), QQ(0), QQ(0)], ZZ), DMP([], ZZ) ] assert dup_factor_list(f, QQ['y']) == \ (DMP([QQ(1,2)],QQ), [([DMP([QQ(1),QQ(0)],QQ)], 1), ([DMP([QQ(1)],QQ),DMP([],QQ)], 1), ([DMP([QQ(1)],QQ),DMP([QQ(1),QQ(0)],QQ)], 1)]) K = QQ.algebraic_field(I) h = [QQ(1, 1), QQ(0, 1), QQ(1, 1)] f = [ ANP([QQ(1, 1)], h, QQ), ANP([], h, QQ), ANP([QQ(2, 1)], h, QQ), ANP([], h, QQ), ANP([], h, QQ) ] assert dup_factor_list(f, K) == \ (ANP([QQ(1,1)], h, QQ), [([ANP([QQ(1,1)], h, QQ), ANP([], h, QQ)], 2), ([ANP([QQ(1,1)], h, QQ), ANP([], h, QQ), ANP([QQ(2,1)], h, QQ)], 1)]) raises(DomainError, "dup_factor_list([EX(sin(1))], EX)")
def test_RealField_from_sympy(): assert RR.convert(S(0)) == RR.dtype(0) assert RR.convert(S(0.0)) == RR.dtype(0.0) assert RR.convert(S(1)) == RR.dtype(1) assert RR.convert(S(1.0)) == RR.dtype(1.0) assert RR.convert(sin(1)) == RR.dtype(sin(1).evalf()) assert RR.convert(oo) == RR("+inf") assert RR.convert(-oo) == RR("-inf") raises(CoercionFailed, lambda: RR.convert(x))
def test_construct_domain(): assert construct_domain([1, 2, 3]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)]) assert construct_domain([1, 2, 3], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)]) assert construct_domain([S(1), S(2), S(3)]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)]) assert construct_domain([S(1), S(2), S(3)], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)]) assert construct_domain([S(1)/2, S(2)]) == (QQ, [QQ(1, 2), QQ(2)]) result = construct_domain([3.14, 1, S(1)/2]) assert isinstance(result[0], RealField) assert result[1] == [RR(3.14), RR(1.0), RR(0.5)] assert construct_domain([3.14, sqrt(2)], extension=None) == (EX, [EX(3.14), EX(sqrt(2))]) assert construct_domain([3.14, sqrt(2)], extension=True) == (EX, [EX(3.14), EX(sqrt(2))]) assert construct_domain([1, sqrt(2)], extension=None) == (EX, [EX(1), EX(sqrt(2))]) assert construct_domain([x, sqrt(x)]) == (EX, [EX(x), EX(sqrt(x))]) assert construct_domain([x, sqrt(x), sqrt(y)]) == (EX, [EX(x), EX(sqrt(x)), EX(sqrt(y))]) alg = QQ.algebraic_field(sqrt(2)) assert construct_domain([7, S(1)/2, sqrt(2)], extension=True) == \ (alg, [alg.convert(7), alg.convert(S(1)/2), alg.convert(sqrt(2))]) alg = QQ.algebraic_field(sqrt(2) + sqrt(3)) assert construct_domain([7, sqrt(2), sqrt(3)], extension=True) == \ (alg, [alg.convert(7), alg.convert(sqrt(2)), alg.convert(sqrt(3))]) dom = ZZ[x] assert construct_domain([2*x, 3]) == \ (dom, [dom.convert(2*x), dom.convert(3)]) dom = ZZ[x, y] assert construct_domain([2*x, 3*y]) == \ (dom, [dom.convert(2*x), dom.convert(3*y)]) dom = QQ[x] assert construct_domain([x/2, 3]) == \ (dom, [dom.convert(x/2), dom.convert(3)]) dom = QQ[x, y] assert construct_domain([x/2, 3*y]) == \ (dom, [dom.convert(x/2), dom.convert(3*y)]) dom = RR[x] assert construct_domain([x/2, 3.5]) == \ (dom, [dom.convert(x/2), dom.convert(3.5)]) dom = RR[x, y] assert construct_domain([x/2, 3.5*y]) == \ (dom, [dom.convert(x/2), dom.convert(3.5*y)]) dom = ZZ.frac_field(x) assert construct_domain([2/x, 3]) == \ (dom, [dom.convert(2/x), dom.convert(3)]) dom = ZZ.frac_field(x, y) assert construct_domain([2/x, 3*y]) == \ (dom, [dom.convert(2/x), dom.convert(3*y)]) dom = RR.frac_field(x) assert construct_domain([2/x, 3.5]) == \ (dom, [dom.convert(2/x), dom.convert(3.5)]) dom = RR.frac_field(x, y) assert construct_domain([2/x, 3.5*y]) == \ (dom, [dom.convert(2/x), dom.convert(3.5*y)]) dom = RealField(prec=336)[x] assert construct_domain([pi.evalf(100)*x]) == \ (dom, [dom.convert(pi.evalf(100)*x)]) assert construct_domain(2) == (ZZ, ZZ(2)) assert construct_domain(S(2)/3) == (QQ, QQ(2, 3)) assert construct_domain({}) == (ZZ, {})
def test_RealDomain_from_sympy(): RR = RR_mpmath() assert RR.convert(S(0)) == RR.dtype(0) assert RR.convert(S(0.0)) == RR.dtype(0.0) assert RR.convert(S(1)) == RR.dtype(1) assert RR.convert(S(1.0)) == RR.dtype(1.0) assert RR.convert(sin(1)) == RR.dtype(sin(1).evalf()) raises(CoercionFailed, lambda: RR.convert(x)) raises(CoercionFailed, lambda: RR.convert(oo)) raises(CoercionFailed, lambda: RR.convert(-oo)) RR = RR_sympy() assert RR.convert(S(0)) == RR.dtype(0) assert RR.convert(S(0.0)) == RR.dtype(0.0) assert RR.convert(S(1)) == RR.dtype(1) assert RR.convert(S(1.0)) == RR.dtype(1.0) assert RR.convert(sin(1)) == RR.dtype(sin(1).evalf()) assert RR.n(3, 2) == RR.evalf(3, 2) == Rational(3).n(2) raises(CoercionFailed, lambda: RR.convert(x)) raises(CoercionFailed, lambda: RR.convert(oo)) raises(CoercionFailed, lambda: RR.convert(-oo))
def test_RealDomain_from_sympy(): RR = RR_mpmath() assert RR.convert(S(0)) == RR.dtype(0) assert RR.convert(S(0.0)) == RR.dtype(0.0) assert RR.convert(S(1)) == RR.dtype(1) assert RR.convert(S(1.0)) == RR.dtype(1.0) assert RR.convert(sin(1)) == RR.dtype(sin(1).evalf()) raises(CoercionFailed, "RR.convert(x)") raises(CoercionFailed, "RR.convert(oo)") raises(CoercionFailed, "RR.convert(-oo)") RR = RR_sympy() assert RR.convert(S(0)) == RR.dtype(0) assert RR.convert(S(0.0)) == RR.dtype(0.0) assert RR.convert(S(1)) == RR.dtype(1) assert RR.convert(S(1.0)) == RR.dtype(1.0) assert RR.convert(sin(1)) == RR.dtype(sin(1).evalf()) raises(CoercionFailed, "RR.convert(x)") raises(CoercionFailed, "RR.convert(oo)") raises(CoercionFailed, "RR.convert(-oo)")