def test_PolynomialRing_is_(): R = QQ.poly_ring("x") assert R.is_univariate is True assert R.is_multivariate is False R = QQ.poly_ring("x", "y", "z") assert R.is_univariate is False assert R.is_multivariate is True
def test_PolynomialRing_is_(): R = QQ.poly_ring("x") assert R.is_univariate is True assert R.is_multivariate is False R = QQ.poly_ring("x", "y", "z") assert R.is_univariate is False assert R.is_multivariate is True
def test_Domain___eq__(): assert (ZZ.poly_ring(x, y) == ZZ.poly_ring(x, y)) is True assert (QQ.poly_ring(x, y) == QQ.poly_ring(x, y)) is True assert (ZZ.poly_ring(x, y) == QQ.poly_ring(x, y)) is False assert (QQ.poly_ring(x, y) == ZZ.poly_ring(x, y)) is False assert (ZZ.frac_field(x, y) == ZZ.frac_field(x, y)) is True assert (QQ.frac_field(x, y) == QQ.frac_field(x, y)) is True assert (ZZ.frac_field(x, y) == QQ.frac_field(x, y)) is False assert (QQ.frac_field(x, y) == ZZ.frac_field(x, y)) is False
def test_Domain___eq__(): assert (ZZ.poly_ring(x, y) == ZZ.poly_ring(x, y)) is True assert (QQ.poly_ring(x, y) == QQ.poly_ring(x, y)) is True assert (ZZ.poly_ring(x, y) == QQ.poly_ring(x, y)) is False assert (QQ.poly_ring(x, y) == ZZ.poly_ring(x, y)) is False assert (ZZ.frac_field(x, y) == ZZ.frac_field(x, y)) is True assert (QQ.frac_field(x, y) == QQ.frac_field(x, y)) is True assert (ZZ.frac_field(x, y) == QQ.frac_field(x, y)) is False assert (QQ.frac_field(x, y) == ZZ.frac_field(x, y)) is False
def test_conversion(): L = QQ.poly_ring(x, y, order="ilex") G = QQ.poly_ring(x, y) assert L.convert(x) == L.convert(G.convert(x), G) assert G.convert(x) == G.convert(L.convert(x), L) pytest.raises(CoercionFailed, lambda: G.convert(L.convert(1 / (1 + x)), L)) R = ALG.poly_ring(x, y) assert R.convert(ALG(1), ALG) == R(1) pytest.raises(CoercionFailed, lambda: R.convert(ALG(1), QQ.algebraic_field(sqrt(2))))
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.poly_ring(x).get_exact() == ZZ.poly_ring(x) assert QQ.poly_ring(x).get_exact() == QQ.poly_ring(x) assert ZZ.poly_ring(x, y).get_exact() == ZZ.poly_ring(x, y) assert QQ.poly_ring(x, y).get_exact() == QQ.poly_ring(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_ring(): assert ZZ.has_assoc_Ring is True assert QQ.has_assoc_Ring is True assert ZZ.poly_ring(x).has_assoc_Ring is True assert QQ.poly_ring(x).has_assoc_Ring is True assert ZZ.poly_ring(x, y).has_assoc_Ring is True assert QQ.poly_ring(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.ring == ZZ assert QQ.ring == ZZ assert ZZ.poly_ring(x).ring == ZZ.poly_ring(x) assert QQ.poly_ring(x).ring == QQ.poly_ring(x) assert ZZ.poly_ring(x, y).ring == ZZ.poly_ring(x, y) assert QQ.poly_ring(x, y).ring == QQ.poly_ring(x, y) assert ZZ.frac_field(x).ring == ZZ.poly_ring(x) assert QQ.frac_field(x).ring == QQ.poly_ring(x) assert ZZ.frac_field(x, y).ring == ZZ.poly_ring(x, y) assert QQ.frac_field(x, y).ring == QQ.poly_ring(x, y) assert EX.ring == EX pytest.raises(AttributeError, lambda: RR.ring) pytest.raises(AttributeError, lambda: ALG.ring)
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.poly_ring(x).get_exact() == ZZ.poly_ring(x) assert QQ.poly_ring(x).get_exact() == QQ.poly_ring(x) assert ZZ.poly_ring(x, y).get_exact() == ZZ.poly_ring(x, y) assert QQ.poly_ring(x, y).get_exact() == QQ.poly_ring(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_ring(): assert ZZ.has_assoc_Ring is True assert QQ.has_assoc_Ring is True assert ZZ.poly_ring(x).has_assoc_Ring is True assert QQ.poly_ring(x).has_assoc_Ring is True assert ZZ.poly_ring(x, y).has_assoc_Ring is True assert QQ.poly_ring(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.ring == ZZ assert QQ.ring == ZZ assert ZZ.poly_ring(x).ring == ZZ.poly_ring(x) assert QQ.poly_ring(x).ring == QQ.poly_ring(x) assert ZZ.poly_ring(x, y).ring == ZZ.poly_ring(x, y) assert QQ.poly_ring(x, y).ring == QQ.poly_ring(x, y) assert ZZ.frac_field(x).ring == ZZ.poly_ring(x) assert QQ.frac_field(x).ring == QQ.poly_ring(x) assert ZZ.frac_field(x, y).ring == ZZ.poly_ring(x, y) assert QQ.frac_field(x, y).ring == QQ.poly_ring(x, y) assert EX.ring == EX pytest.raises(AttributeError, lambda: RR.ring) pytest.raises(AttributeError, lambda: ALG.ring)
def test_units(): R = QQ.poly_ring(x) assert R.convert(1) == R.one assert R.convert(x) != R.one assert R.convert(1 + x) != R.one R = QQ.poly_ring(x, order='ilex') assert R.convert(1) == R.one assert R.convert(x) != R.one R = ZZ.poly_ring(x) assert R.convert(1) == R.one assert R.convert(2) != R.one assert R.convert(x) != R.one assert R.convert(1 + x) != R.one
def test___eq__(): assert not QQ.poly_ring(x) == ZZ.poly_ring(x) assert not QQ.frac_field(x) == ZZ.frac_field(x) assert EX(1) != EX(2) F11 = FF(11) assert F11(2) != F11(3) assert F11(2) != object()
def test___eq__(): assert not QQ.poly_ring(x) == ZZ.poly_ring(x) assert not QQ.frac_field(x) == ZZ.frac_field(x) assert EX(1) != EX(2) F11 = FF(11) assert F11(2) != F11(3) assert F11(2) != object()
def test_PolynomialRing(): sT(ZZ.poly_ring("x"), "PolynomialRing(%s, (Symbol('x'),), " "LexOrder())" % repr(ZZ)) sT(QQ.poly_ring("x", "y", order=grlex), "PolynomialRing(%s, (Symbol('x'), Symbol('y')), " "GradedLexOrder())" % repr(QQ)) sT(ZZ.poly_ring("t").poly_ring("x", "y", "z"), "PolynomialRing(PolynomialRing(%s, (Symbol('t'),), " "LexOrder()), (Symbol('x'), Symbol('y'), Symbol('z')), " "LexOrder())" % repr(ZZ))
def test_Domain_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.poly_ring(x).has_assoc_Field is True assert QQ.poly_ring(x).has_assoc_Field is True assert ZZ.poly_ring(x, y).has_assoc_Field is True assert QQ.poly_ring(x, y).has_assoc_Field is True assert EX.field == EX assert ZZ.field == QQ assert QQ.field == QQ assert RR.field == RR assert ALG.field == ALG assert ZZ.poly_ring(x).field == ZZ.frac_field(x) assert QQ.poly_ring(x).field == QQ.frac_field(x) assert ZZ.poly_ring(x, y).field == ZZ.frac_field(x, y) assert QQ.poly_ring(x, y).field == QQ.frac_field(x, y)
def test_Domain_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.poly_ring(x).has_assoc_Field is True assert QQ.poly_ring(x).has_assoc_Field is True assert ZZ.poly_ring(x, y).has_assoc_Field is True assert QQ.poly_ring(x, y).has_assoc_Field is True assert EX.field == EX assert ZZ.field == QQ assert QQ.field == QQ assert RR.field == RR assert ALG.field == ALG assert ZZ.poly_ring(x).field == ZZ.frac_field(x) assert QQ.poly_ring(x).field == QQ.frac_field(x) assert ZZ.poly_ring(x, y).field == ZZ.frac_field(x, y) assert QQ.poly_ring(x, y).field == QQ.frac_field(x, y)
def test_PolynomialRing(): sT(ZZ.poly_ring("x"), "PolynomialRing(%s, (Symbol('x'),), " "LexOrder())" % repr(ZZ)) sT( QQ.poly_ring("x", "y", order=grlex), "PolynomialRing(%s, (Symbol('x'), Symbol('y')), " "GradedLexOrder())" % repr(QQ)) sT( ZZ.poly_ring("t").poly_ring("x", "y", "z"), "PolynomialRing(PolynomialRing(%s, (Symbol('t'),), " "LexOrder()), (Symbol('x'), Symbol('y'), Symbol('z')), " "LexOrder())" % repr(ZZ))
def test_sring(): x, y, z, t = symbols("x,y,z,t") R = ZZ.poly_ring("x", "y", "z") assert sring(x + 2*y + 3*z) == (R, R.x + 2*R.y + 3*R.z) R = QQ.poly_ring("x", "y", "z") assert sring(x + 2*y + z/3) == (R, R.x + 2*R.y + R.z/3) assert sring([x, 2*y, z/3]) == (R, [R.x, 2*R.y, R.z/3]) Rt = ZZ.poly_ring("t") R = Rt.poly_ring("x", "y", "z") assert sring(x + 2*t*y + 3*t**2*z, x, y, z) == (R, R.x + 2*Rt.t*R.y + 3*Rt.t**2*R.z) Rt = QQ.poly_ring("t") R = Rt.poly_ring("x", "y", "z") assert sring(x + t*y/2 + t**2*z/3, x, y, z) == (R, R.x + Rt.t*R.y/2 + Rt.t**2*R.z/3) Rt = ZZ.frac_field("t") R = Rt.poly_ring("x", "y", "z") assert sring(x + 2*y/t + t**2*z/3, x, y, z) == (R, R.x + 2*R.y/Rt.t + Rt.t**2*R.z/3) R = QQ.poly_ring("x", "y") assert sring(x + y, domain=QQ) == (R, R.x + R.y)
def test_sring(): x, y, z, t = symbols("x,y,z,t") R = ZZ.poly_ring("x", "y", "z") assert sring(x + 2*y + 3*z) == (R, R.x + 2*R.y + 3*R.z) R = QQ.poly_ring("x", "y", "z") assert sring(x + 2*y + z/3) == (R, R.x + 2*R.y + R.z/3) assert sring([x, 2*y, z/3]) == (R, [R.x, 2*R.y, R.z/3]) Rt = ZZ.poly_ring("t") R = Rt.poly_ring("x", "y", "z") assert sring(x + 2*t*y + 3*t**2*z, x, y, z) == (R, R.x + 2*Rt.t*R.y + 3*Rt.t**2*R.z) Rt = QQ.poly_ring("t") R = Rt.poly_ring("x", "y", "z") assert sring(x + t*y/2 + t**2*z/3, x, y, z) == (R, R.x + Rt.t*R.y/2 + Rt.t**2*R.z/3) Rt = ZZ.frac_field("t") R = Rt.poly_ring("x", "y", "z") assert sring(x + 2*y/t + t**2*z/3, x, y, z) == (R, R.x + 2*R.y/Rt.t + Rt.t**2*R.z/3) R = QQ.poly_ring("x", "y") assert sring(x + y, domain=QQ) == (R, R.x + R.y)
def test_localring(): Qxy = QQ.frac_field(x, y) R = QQ.poly_ring(x, y, order="ilex") X = R.convert(x) Y = R.convert(y) assert x in R assert 1 / x not in R assert Y in R assert X.ring == R.ring assert X + Y == R.convert(x + y) assert X - Y == R.convert(x - y) assert X + 1 == R.convert(x + 1) assert X**2 // X == X assert R.convert(ZZ.poly_ring(x, y).convert(x), ZZ.poly_ring(x, y)) == X assert R.convert(Qxy.convert(x), Qxy) == X
def test_methods(): R = QQ.poly_ring(x) X = R.convert(x) assert R.is_negative(-X) is True assert R.is_positive(X) is True assert R.gcdex(X**3 - X, X**2) == (-1, X, X) assert R.factorial(3) == 6 F = QQ.frac_field(y) Y = F.convert(y) assert F.is_negative(-Y) is True assert F.is_positive(Y) is True assert F.factorial(3) == 6
def test_globalring(): Qxy = QQ.frac_field(x, y) R = QQ.poly_ring(x, y) X = R.convert(x) Y = R.convert(y) assert x in R assert 1 / x not in R assert 1 / (1 + x) not in R assert Y in R assert X.ring == R.ring assert X * (Y**2 + 1) == R.convert(x * (y**2 + 1)) assert X * Y == R.convert(x * y) assert X + Y == R.convert(x + y) assert X - Y == R.convert(x - y) assert X + 1 == R.convert(x + 1) assert X**2 // X == X assert R.convert(ZZ.poly_ring(x, y).convert(x), ZZ.poly_ring(x, y)) == X assert R.convert(Qxy.convert(x), Qxy) == X
def test_PrettyPoly(): F = QQ.frac_field(x, y) R = QQ.poly_ring(x, y) assert sstr(F.convert(x/(x + y))) == sstr(x/(x + y)) assert sstr(R.convert(x + y)) == sstr(x + y)
def test_build_order(): R = QQ.poly_ring(x, y, order=build_product_order((("lex", x), ("ilex", y)), (x, y))) assert R.order((1, 5)) == ((1, ), (-5, ))
def test_Domain_unify(): F3 = GF(3) assert unify(F3, F3) == F3 assert unify(F3, ZZ) == F3 assert unify(F3, QQ) == QQ assert unify(F3, ALG) == ALG assert unify(F3, RR) == RR assert unify(F3, CC) == CC assert unify(F3, ZZ.poly_ring(x)) == F3.poly_ring(x) assert unify(F3, ZZ.frac_field(x)) == F3.frac_field(x) assert unify(F3, EX) == EX assert unify(ZZ, F3) == F3 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.poly_ring(x)) == ZZ.poly_ring(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.poly_ring(x)) == QQ.poly_ring(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.poly_ring(x)) == RR.poly_ring(x) assert unify(RR, ZZ.frac_field(x)) == RR.frac_field(x) assert unify(RR, EX) == EX 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.poly_ring(x)) == CC.poly_ring(x) assert unify(CC, ZZ.frac_field(x)) == CC.frac_field(x) assert unify(CC, EX) == EX CC2 = ComplexField(prec=20) assert unify(CC, CC2) == unify(CC2, CC) == ComplexField(prec=CC.precision, tol=CC2.tolerance) RR2 = RealField(prec=20) assert unify(RR, RR2) == unify(RR2, RR) == RealField(prec=RR.precision, tol=RR2.tolerance) assert unify(ZZ.poly_ring(x), F3) == F3.poly_ring(x) assert unify(ZZ.poly_ring(x), ZZ) == ZZ.poly_ring(x) assert unify(ZZ.poly_ring(x), QQ) == QQ.poly_ring(x) assert unify(ZZ.poly_ring(x), ALG) == ALG.poly_ring(x) assert unify(ZZ.poly_ring(x), RR) == RR.poly_ring(x) assert unify(ZZ.poly_ring(x), CC) == CC.poly_ring(x) assert unify(ZZ.poly_ring(x), ZZ.poly_ring(x)) == ZZ.poly_ring(x) assert unify(ZZ.poly_ring(x), ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(ZZ.poly_ring(x), EX) == EX assert unify(ZZ.frac_field(x), F3) == F3.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.poly_ring(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.poly_ring(x)) == EX assert unify(EX, ZZ.frac_field(x)) == EX assert unify(EX, EX) == EX
def test_PolynomialRing(): assert str(ZZ.poly_ring("x")) == "ZZ[x]" assert str(QQ.poly_ring("x", "y", order=grlex)) == "QQ[x,y]" assert str(ZZ.poly_ring("t").poly_ring("x", "y", "z")) == "ZZ[t][x,y,z]"
def test_PrettyPoly(): F = QQ.frac_field(x, y) R = QQ.poly_ring(x, y) assert sstr(F.convert(x / (x + y))) == sstr(x / (x + y)) assert sstr(R.convert(x + y)) == sstr(x + y)
def test_PolynomialRing(): assert str(ZZ.poly_ring("x")) == "ZZ[x]" assert str(QQ.poly_ring("x", "y", order=grlex)) == "QQ[x,y]" assert str(ZZ.poly_ring("t").poly_ring("x", "y", "z")) == "ZZ[t][x,y,z]"
def test_Domain_unify_composite(): assert unify(ZZ.poly_ring(x), ZZ) == ZZ.poly_ring(x) assert unify(ZZ.poly_ring(x), QQ) == QQ.poly_ring(x) assert unify(QQ.poly_ring(x), ZZ) == QQ.poly_ring(x) assert unify(QQ.poly_ring(x), QQ) == QQ.poly_ring(x) assert unify(ZZ, ZZ.poly_ring(x)) == ZZ.poly_ring(x) assert unify(QQ, ZZ.poly_ring(x)) == QQ.poly_ring(x) assert unify(ZZ, QQ.poly_ring(x)) == QQ.poly_ring(x) assert unify(QQ, QQ.poly_ring(x)) == QQ.poly_ring(x) assert unify(ZZ.poly_ring(x, y), ZZ) == ZZ.poly_ring(x, y) assert unify(ZZ.poly_ring(x, y), QQ) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x, y), ZZ) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x, y), QQ) == QQ.poly_ring(x, y) assert unify(ZZ, ZZ.poly_ring(x, y)) == ZZ.poly_ring(x, y) assert unify(QQ, ZZ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(ZZ, QQ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(QQ, QQ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(ZZ.frac_field(x), ZZ) == ZZ.frac_field(x) assert unify(ZZ.frac_field(x), QQ) == QQ.frac_field(x) assert unify(QQ.frac_field(x), ZZ) == QQ.frac_field(x) assert unify(QQ.frac_field(x), QQ) == QQ.frac_field(x) assert unify(ZZ, ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(QQ, ZZ.frac_field(x)) == QQ.frac_field(x) assert unify(ZZ, QQ.frac_field(x)) == QQ.frac_field(x) assert unify(QQ, QQ.frac_field(x)) == QQ.frac_field(x) assert unify(ZZ.frac_field(x, y), ZZ) == ZZ.frac_field(x, y) assert unify(ZZ.frac_field(x, y), QQ) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x, y), ZZ) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x, y), QQ) == QQ.frac_field(x, y) assert unify(ZZ, ZZ.frac_field(x, y)) == ZZ.frac_field(x, y) assert unify(QQ, ZZ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(ZZ, QQ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(QQ, QQ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(ZZ.poly_ring(x), ZZ.poly_ring(x)) == ZZ.poly_ring(x) assert unify(ZZ.poly_ring(x), QQ.poly_ring(x)) == QQ.poly_ring(x) assert unify(QQ.poly_ring(x), ZZ.poly_ring(x)) == QQ.poly_ring(x) assert unify(QQ.poly_ring(x), QQ.poly_ring(x)) == QQ.poly_ring(x) assert unify(ZZ.poly_ring(x, y), ZZ.poly_ring(x)) == ZZ.poly_ring(x, y) assert unify(ZZ.poly_ring(x, y), QQ.poly_ring(x)) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x, y), ZZ.poly_ring(x)) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x, y), QQ.poly_ring(x)) == QQ.poly_ring(x, y) assert unify(ZZ.poly_ring(x), ZZ.poly_ring(x, y)) == ZZ.poly_ring(x, y) assert unify(ZZ.poly_ring(x), QQ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x), ZZ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x), QQ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(ZZ.poly_ring(x, y), ZZ.poly_ring(x, z)) == ZZ.poly_ring(x, y, z) assert unify(ZZ.poly_ring(x, y), QQ.poly_ring(x, z)) == QQ.poly_ring(x, y, z) assert unify(QQ.poly_ring(x, y), ZZ.poly_ring(x, z)) == QQ.poly_ring(x, y, z) assert unify(QQ.poly_ring(x, y), QQ.poly_ring(x, z)) == QQ.poly_ring(x, y, z) assert unify(ZZ.frac_field(x), ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(ZZ.frac_field(x), QQ.frac_field(x)) == QQ.frac_field(x) assert unify(QQ.frac_field(x), ZZ.frac_field(x)) == QQ.frac_field(x) assert unify(QQ.frac_field(x), QQ.frac_field(x)) == QQ.frac_field(x) assert unify(ZZ.frac_field(x, y), ZZ.frac_field(x)) == ZZ.frac_field(x, y) assert unify(ZZ.frac_field(x, y), QQ.frac_field(x)) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x, y), ZZ.frac_field(x)) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x, y), QQ.frac_field(x)) == QQ.frac_field(x, y) assert unify(ZZ.frac_field(x), ZZ.frac_field(x, y)) == ZZ.frac_field(x, y) assert unify(ZZ.frac_field(x), QQ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x), ZZ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x), QQ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(ZZ.frac_field(x, y), ZZ.frac_field(x, z)) == ZZ.frac_field(x, y, z) assert unify(ZZ.frac_field(x, y), QQ.frac_field(x, z)) == QQ.frac_field(x, y, z) assert unify(QQ.frac_field(x, y), ZZ.frac_field(x, z)) == QQ.frac_field(x, y, z) assert unify(QQ.frac_field(x, y), QQ.frac_field(x, z)) == QQ.frac_field(x, y, z) assert unify(ZZ.poly_ring(x), ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(ZZ.poly_ring(x), QQ.frac_field(x)) == ZZ.frac_field(x) assert unify(QQ.poly_ring(x), ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(QQ.poly_ring(x), QQ.frac_field(x)) == QQ.frac_field(x) assert unify(ZZ.poly_ring(x, y), ZZ.frac_field(x)) == ZZ.frac_field(x, y) assert unify(ZZ.poly_ring(x, y), QQ.frac_field(x)) == ZZ.frac_field(x, y) assert unify(QQ.poly_ring(x, y), ZZ.frac_field(x)) == ZZ.frac_field(x, y) assert unify(QQ.poly_ring(x, y), QQ.frac_field(x)) == QQ.frac_field(x, y) assert unify(ZZ.poly_ring(x), ZZ.frac_field(x, y)) == ZZ.frac_field(x, y) assert unify(ZZ.poly_ring(x), QQ.frac_field(x, y)) == ZZ.frac_field(x, y) assert unify(QQ.poly_ring(x), ZZ.frac_field(x, y)) == ZZ.frac_field(x, y) assert unify(QQ.poly_ring(x), QQ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(ZZ.poly_ring(x, y), ZZ.frac_field(x, z)) == ZZ.frac_field(x, y, z) assert unify(ZZ.poly_ring(x, y), QQ.frac_field(x, z)) == ZZ.frac_field(x, y, z) assert unify(QQ.poly_ring(x, y), ZZ.frac_field(x, z)) == ZZ.frac_field(x, y, z) assert unify(QQ.poly_ring(x, y), QQ.frac_field(x, z)) == QQ.frac_field(x, y, z) assert unify(ZZ.frac_field(x), ZZ.poly_ring(x)) == ZZ.frac_field(x) assert unify(ZZ.frac_field(x), QQ.poly_ring(x)) == ZZ.frac_field(x) assert unify(QQ.frac_field(x), ZZ.poly_ring(x)) == ZZ.frac_field(x) assert unify(QQ.frac_field(x), QQ.poly_ring(x)) == QQ.frac_field(x) assert unify(ZZ.frac_field(x, y), ZZ.poly_ring(x)) == ZZ.frac_field(x, y) assert unify(ZZ.frac_field(x, y), QQ.poly_ring(x)) == ZZ.frac_field(x, y) assert unify(QQ.frac_field(x, y), ZZ.poly_ring(x)) == ZZ.frac_field(x, y) assert unify(QQ.frac_field(x, y), QQ.poly_ring(x)) == QQ.frac_field(x, y) assert unify(ZZ.frac_field(x), ZZ.poly_ring(x, y)) == ZZ.frac_field(x, y) assert unify(ZZ.frac_field(x), QQ.poly_ring(x, y)) == ZZ.frac_field(x, y) assert unify(QQ.frac_field(x), ZZ.poly_ring(x, y)) == ZZ.frac_field(x, y) assert unify(QQ.frac_field(x), QQ.poly_ring(x, y)) == QQ.frac_field(x, y) assert unify(ZZ.frac_field(x, y), ZZ.poly_ring(x, z)) == ZZ.frac_field(x, y, z) assert unify(ZZ.frac_field(x, y), QQ.poly_ring(x, z)) == ZZ.frac_field(x, y, z) assert unify(QQ.frac_field(x, y), ZZ.poly_ring(x, z)) == ZZ.frac_field(x, y, z) assert unify(QQ.frac_field(x, y), QQ.poly_ring(x, z)) == QQ.frac_field(x, y, z)
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.poly_ring('t')) assert R.dup_factor_list(0) == (0, []) assert R.dup_factor_list(7) == (7, []) R, x = ring("x", QQ.poly_ring('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)] # issue sympy/sympy#8037 assert R.dup_factor_list(6 * x**2 - 5 * x - 6) == (1, [(2 * x - 3, 1), (3 * x + 2, 1)]) R, x = ring("x", QQ) assert R.dup_factor_list(x**2 / 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 # issue diofant/diofant#238 f = 0.1 * x**2 + 1.1 * x + 1.0 assert R.dup_factor_list(f) == (10.0, [(0.1 * x + 0.1, 1), (0.1 * x + 1.0, 1)]) f = 0.25 + 1.0 * x + 1.0 * x**2 assert R.dup_factor_list(f) == (4.0, [(0.25 + 0.5 * x, 2)]) 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, [(x, 1), (x + t, 1)]) Rt, t = ring("t", QQ) R, x = ring("x", Rt) f = t * x**2 / 2 + t**2 * x / 2 assert R.dup_factor_list(f) == (t / 2, [(x, 1), (x + t, 1)]) R, x = ring("x", QQ.algebraic_field(I)) f = x**4 + 2 * x**2 assert R.dup_factor_list(f) == (R.domain(1), [(x, 2), (x**2 + 2, 1)]) R, x = ring("x", EX) pytest.raises(DomainError, lambda: R.dup_factor_list(EX(sin(1))))
def test_Domain__contains__(): assert (0 in EX) is True assert (0 in ZZ) is True assert (0 in QQ) is True assert (0 in RR) is True assert (0 in CC) is True assert (0 in ALG) is True assert (0 in ZZ.poly_ring(x, y)) is True assert (0 in QQ.poly_ring(x, y)) is True assert (0 in RR.poly_ring(x, y)) is True assert (-7 in EX) is True assert (-7 in ZZ) is True assert (-7 in QQ) is True assert (-7 in RR) is True assert (-7 in CC) is True assert (-7 in ALG) is True assert (-7 in ZZ.poly_ring(x, y)) is True assert (-7 in QQ.poly_ring(x, y)) is True assert (-7 in RR.poly_ring(x, y)) is True assert (17 in EX) is True assert (17 in ZZ) is True assert (17 in QQ) is True assert (17 in RR) is True assert (17 in CC) is True assert (17 in ALG) is True assert (17 in ZZ.poly_ring(x, y)) is True assert (17 in QQ.poly_ring(x, y)) is True assert (17 in RR.poly_ring(x, y)) is True assert (-Rational(1, 7) in EX) is True assert (-Rational(1, 7) in ZZ) is False assert (-Rational(1, 7) in QQ) is True assert (-Rational(1, 7) in RR) is True assert (-Rational(1, 7) in CC) is True assert (-Rational(1, 7) in ALG) is True assert (-Rational(1, 7) in ZZ.poly_ring(x, y)) is False assert (-Rational(1, 7) in QQ.poly_ring(x, y)) is True assert (-Rational(1, 7) in RR.poly_ring(x, y)) is True assert (Rational(3, 5) in EX) is True assert (Rational(3, 5) in ZZ) is False assert (Rational(3, 5) in QQ) is True assert (Rational(3, 5) in RR) is True assert (Rational(3, 5) in CC) is True assert (Rational(3, 5) in ALG) is True assert (Rational(3, 5) in ZZ.poly_ring(x, y)) is False assert (Rational(3, 5) in QQ.poly_ring(x, y)) is True assert (Rational(3, 5) in RR.poly_ring(x, y)) is True assert (3.0 in EX) is True assert (3.0 in ZZ) is True assert (3.0 in QQ) is True assert (3.0 in RR) is True assert (3.0 in CC) is True assert (3.0 in ALG) is True assert (3.0 in ZZ.poly_ring(x, y)) is True assert (3.0 in QQ.poly_ring(x, y)) is True assert (3.0 in RR.poly_ring(x, y)) is True assert (3.14 in EX) is True assert (3.14 in ZZ) is False assert (3.14 in QQ) is True assert (3.14 in RR) is True assert (3.14 in CC) is True assert (3.14 in ALG) is True assert (3.14 in ZZ.poly_ring(x, y)) is False assert (3.14 in QQ.poly_ring(x, y)) is True assert (3.14 in RR.poly_ring(x, y)) is True assert (oo in EX) is True assert (oo in ZZ) is False assert (oo in QQ) is False assert (oo in RR) is True assert (oo in CC) is True assert (oo in ALG) is False assert (oo in ZZ.poly_ring(x, y)) is False assert (oo in QQ.poly_ring(x, y)) is False assert (oo in RR.poly_ring(x, y)) is True assert (-oo in EX) is True assert (-oo in ZZ) is False assert (-oo in QQ) is False assert (-oo in RR) is True assert (-oo in CC) is True assert (-oo in ALG) is False assert (-oo in ZZ.poly_ring(x, y)) is False assert (-oo in QQ.poly_ring(x, y)) is False assert (-oo in RR.poly_ring(x, y)) is True assert (sqrt(7) in EX) is True assert (sqrt(7) in ZZ) is False assert (sqrt(7) in QQ) is False assert (sqrt(7) in RR) is True assert (sqrt(7) in CC) is True assert (sqrt(7) in ALG) is False assert (sqrt(7) in ZZ.poly_ring(x, y)) is False assert (sqrt(7) in QQ.poly_ring(x, y)) is False assert (sqrt(7) in RR.poly_ring(x, y)) is True assert (2*sqrt(3) + 1 in EX) is True assert (2*sqrt(3) + 1 in ZZ) is False assert (2*sqrt(3) + 1 in QQ) is False assert (2*sqrt(3) + 1 in RR) is True assert (2*sqrt(3) + 1 in CC) is True assert (2*sqrt(3) + 1 in ALG) is True assert (2*sqrt(3) + 1 in ZZ.poly_ring(x, y)) is False assert (2*sqrt(3) + 1 in QQ.poly_ring(x, y)) is False assert (2*sqrt(3) + 1 in RR.poly_ring(x, y)) is True assert (sin(1) in EX) is True assert (sin(1) in ZZ) is False assert (sin(1) in QQ) is False assert (sin(1) in RR) is True assert (sin(1) in CC) is True assert (sin(1) in ALG) is False assert (sin(1) in ZZ.poly_ring(x, y)) is False assert (sin(1) in QQ.poly_ring(x, y)) is False assert (sin(1) in RR.poly_ring(x, y)) is True assert (x**2 + 1 in EX) is True assert (x**2 + 1 in ZZ) is False assert (x**2 + 1 in QQ) is False assert (x**2 + 1 in RR) is False assert (x**2 + 1 in CC) is False assert (x**2 + 1 in ALG) is False assert (x**2 + 1 in ZZ.poly_ring(x)) is True assert (x**2 + 1 in QQ.poly_ring(x)) is True assert (x**2 + 1 in RR.poly_ring(x)) is True assert (x**2 + 1 in ZZ.poly_ring(x, y)) is True assert (x**2 + 1 in QQ.poly_ring(x, y)) is True assert (x**2 + 1 in RR.poly_ring(x, y)) is True assert (x**2 + y**2 in EX) is True assert (x**2 + y**2 in ZZ) is False assert (x**2 + y**2 in QQ) is False assert (x**2 + y**2 in RR) is False assert (x**2 + y**2 in CC) is False assert (x**2 + y**2 in ALG) is False assert (x**2 + y**2 in ZZ.poly_ring(x)) is False assert (x**2 + y**2 in QQ.poly_ring(x)) is False assert (x**2 + y**2 in RR.poly_ring(x)) is False assert (x**2 + y**2 in ZZ.poly_ring(x, y)) is True assert (x**2 + y**2 in QQ.poly_ring(x, y)) is True assert (x**2 + y**2 in RR.poly_ring(x, y)) is True assert (Rational(3, 2)*x/(y + 1) - z in QQ.poly_ring(x, y, z)) is False
def test_poly_frac(): pytest.raises(GeneratorsNeeded, lambda: QQ.poly_ring()) pytest.raises(GeneratorsNeeded, lambda: QQ.frac_field())
def test_Domain_preprocess(): assert Domain.preprocess(ZZ) == ZZ assert Domain.preprocess(QQ) == QQ assert Domain.preprocess(EX) == EX assert Domain.preprocess(FF(2)) == FF(2) assert Domain.preprocess(ZZ.poly_ring(x, y)) == ZZ.poly_ring(x, y) assert Domain.preprocess('Z') == ZZ assert Domain.preprocess('Q') == QQ assert Domain.preprocess('ZZ') == ZZ assert Domain.preprocess('QQ') == QQ assert Domain.preprocess('EX') == EX assert Domain.preprocess('FF(23)') == FF(23) assert Domain.preprocess('GF(23)') == GF(23) pytest.raises(OptionError, lambda: Domain.preprocess('Z[]')) assert Domain.preprocess('Z[x]') == ZZ.poly_ring(x) assert Domain.preprocess('Q[x]') == QQ.poly_ring(x) assert Domain.preprocess('ZZ[x]') == ZZ.poly_ring(x) assert Domain.preprocess('QQ[x]') == QQ.poly_ring(x) assert Domain.preprocess('Z[x,y]') == ZZ.poly_ring(x, y) assert Domain.preprocess('Q[x,y]') == QQ.poly_ring(x, y) assert Domain.preprocess('ZZ[x,y]') == ZZ.poly_ring(x, y) assert Domain.preprocess('QQ[x,y]') == QQ.poly_ring(x, y) pytest.raises(OptionError, lambda: Domain.preprocess('Z()')) assert Domain.preprocess('Z(x)') == ZZ.frac_field(x) assert Domain.preprocess('Q(x)') == QQ.frac_field(x) assert Domain.preprocess('ZZ(x)') == ZZ.frac_field(x) assert Domain.preprocess('QQ(x)') == QQ.frac_field(x) assert Domain.preprocess('Z(x,y)') == ZZ.frac_field(x, y) assert Domain.preprocess('Q(x,y)') == QQ.frac_field(x, y) assert Domain.preprocess('ZZ(x,y)') == ZZ.frac_field(x, y) assert Domain.preprocess('QQ(x,y)') == QQ.frac_field(x, y) assert Domain.preprocess('Q<I>') == QQ.algebraic_field(I) assert Domain.preprocess('QQ<I>') == QQ.algebraic_field(I) assert Domain.preprocess('Q<sqrt(2), I>') == QQ.algebraic_field(sqrt(2), I) assert Domain.preprocess( 'QQ<sqrt(2), I>') == QQ.algebraic_field(sqrt(2), I) pytest.raises(OptionError, lambda: Domain.preprocess('abc')) assert Domain.preprocess('RR') == RR assert Domain.preprocess('RR_5') == RealField(prec=5) assert Domain.preprocess('CC') == CC assert Domain.preprocess('CC_5') == ComplexField(prec=5) pytest.raises(OptionError, lambda: Domain.preprocess(()))
def test_Domain__contains__(): assert (0 in EX) is True assert (0 in ZZ) is True assert (0 in QQ) is True assert (0 in RR) is True assert (0 in CC) is True assert (0 in ALG) is True assert (0 in ZZ.poly_ring(x, y)) is True assert (0 in QQ.poly_ring(x, y)) is True assert (0 in RR.poly_ring(x, y)) is True assert (-7 in EX) is True assert (-7 in ZZ) is True assert (-7 in QQ) is True assert (-7 in RR) is True assert (-7 in CC) is True assert (-7 in ALG) is True assert (-7 in ZZ.poly_ring(x, y)) is True assert (-7 in QQ.poly_ring(x, y)) is True assert (-7 in RR.poly_ring(x, y)) is True assert (17 in EX) is True assert (17 in ZZ) is True assert (17 in QQ) is True assert (17 in RR) is True assert (17 in CC) is True assert (17 in ALG) is True assert (17 in ZZ.poly_ring(x, y)) is True assert (17 in QQ.poly_ring(x, y)) is True assert (17 in RR.poly_ring(x, y)) is True assert (-Rational(1, 7) in EX) is True assert (-Rational(1, 7) in ZZ) is False assert (-Rational(1, 7) in QQ) is True assert (-Rational(1, 7) in RR) is True assert (-Rational(1, 7) in CC) is True assert (-Rational(1, 7) in ALG) is True assert (-Rational(1, 7) in ZZ.poly_ring(x, y)) is False assert (-Rational(1, 7) in QQ.poly_ring(x, y)) is True assert (-Rational(1, 7) in RR.poly_ring(x, y)) is True assert (Rational(3, 5) in EX) is True assert (Rational(3, 5) in ZZ) is False assert (Rational(3, 5) in QQ) is True assert (Rational(3, 5) in RR) is True assert (Rational(3, 5) in CC) is True assert (Rational(3, 5) in ALG) is True assert (Rational(3, 5) in ZZ.poly_ring(x, y)) is False assert (Rational(3, 5) in QQ.poly_ring(x, y)) is True assert (Rational(3, 5) in RR.poly_ring(x, y)) is True assert (3.0 in EX) is True assert (3.0 in ZZ) is True assert (3.0 in QQ) is True assert (3.0 in RR) is True assert (3.0 in CC) is True assert (3.0 in ALG) is True assert (3.0 in ZZ.poly_ring(x, y)) is True assert (3.0 in QQ.poly_ring(x, y)) is True assert (3.0 in RR.poly_ring(x, y)) is True assert (3.14 in EX) is True assert (3.14 in ZZ) is False assert (3.14 in QQ) is True assert (3.14 in RR) is True assert (3.14 in CC) is True assert (3.14 in ALG) is True assert (3.14 in ZZ.poly_ring(x, y)) is False assert (3.14 in QQ.poly_ring(x, y)) is True assert (3.14 in RR.poly_ring(x, y)) is True assert (oo in EX) is True assert (oo in ZZ) is False assert (oo in QQ) is False assert (oo in RR) is True assert (oo in CC) is True assert (oo in ALG) is False assert (oo in ZZ.poly_ring(x, y)) is False assert (oo in QQ.poly_ring(x, y)) is False assert (oo in RR.poly_ring(x, y)) is True assert (-oo in EX) is True assert (-oo in ZZ) is False assert (-oo in QQ) is False assert (-oo in RR) is True assert (-oo in CC) is True assert (-oo in ALG) is False assert (-oo in ZZ.poly_ring(x, y)) is False assert (-oo in QQ.poly_ring(x, y)) is False assert (-oo in RR.poly_ring(x, y)) is True assert (sqrt(7) in EX) is True assert (sqrt(7) in ZZ) is False assert (sqrt(7) in QQ) is False assert (sqrt(7) in RR) is True assert (sqrt(7) in CC) is True assert (sqrt(7) in ALG) is False assert (sqrt(7) in ZZ.poly_ring(x, y)) is False assert (sqrt(7) in QQ.poly_ring(x, y)) is False assert (sqrt(7) in RR.poly_ring(x, y)) is True assert (2 * sqrt(3) + 1 in EX) is True assert (2 * sqrt(3) + 1 in ZZ) is False assert (2 * sqrt(3) + 1 in QQ) is False assert (2 * sqrt(3) + 1 in RR) is True assert (2 * sqrt(3) + 1 in CC) is True assert (2 * sqrt(3) + 1 in ALG) is True assert (2 * sqrt(3) + 1 in ZZ.poly_ring(x, y)) is False assert (2 * sqrt(3) + 1 in QQ.poly_ring(x, y)) is False assert (2 * sqrt(3) + 1 in RR.poly_ring(x, y)) is True assert (sin(1) in EX) is True assert (sin(1) in ZZ) is False assert (sin(1) in QQ) is False assert (sin(1) in RR) is True assert (sin(1) in CC) is True assert (sin(1) in ALG) is False assert (sin(1) in ZZ.poly_ring(x, y)) is False assert (sin(1) in QQ.poly_ring(x, y)) is False assert (sin(1) in RR.poly_ring(x, y)) is True assert (x**2 + 1 in EX) is True assert (x**2 + 1 in ZZ) is False assert (x**2 + 1 in QQ) is False assert (x**2 + 1 in RR) is False assert (x**2 + 1 in CC) is False assert (x**2 + 1 in ALG) is False assert (x**2 + 1 in ZZ.poly_ring(x)) is True assert (x**2 + 1 in QQ.poly_ring(x)) is True assert (x**2 + 1 in RR.poly_ring(x)) is True assert (x**2 + 1 in ZZ.poly_ring(x, y)) is True assert (x**2 + 1 in QQ.poly_ring(x, y)) is True assert (x**2 + 1 in RR.poly_ring(x, y)) is True assert (x**2 + y**2 in EX) is True assert (x**2 + y**2 in ZZ) is False assert (x**2 + y**2 in QQ) is False assert (x**2 + y**2 in RR) is False assert (x**2 + y**2 in CC) is False assert (x**2 + y**2 in ALG) is False assert (x**2 + y**2 in ZZ.poly_ring(x)) is False assert (x**2 + y**2 in QQ.poly_ring(x)) is False assert (x**2 + y**2 in RR.poly_ring(x)) is False assert (x**2 + y**2 in ZZ.poly_ring(x, y)) is True assert (x**2 + y**2 in QQ.poly_ring(x, y)) is True assert (x**2 + y**2 in RR.poly_ring(x, y)) is True assert (Rational(3, 2) * x / (y + 1) - z in QQ.poly_ring(x, y, z)) is False
def test_Domain_unify_composite(): assert unify(ZZ.poly_ring(x), ZZ) == ZZ.poly_ring(x) assert unify(ZZ.poly_ring(x), QQ) == QQ.poly_ring(x) assert unify(QQ.poly_ring(x), ZZ) == QQ.poly_ring(x) assert unify(QQ.poly_ring(x), QQ) == QQ.poly_ring(x) assert unify(ZZ, ZZ.poly_ring(x)) == ZZ.poly_ring(x) assert unify(QQ, ZZ.poly_ring(x)) == QQ.poly_ring(x) assert unify(ZZ, QQ.poly_ring(x)) == QQ.poly_ring(x) assert unify(QQ, QQ.poly_ring(x)) == QQ.poly_ring(x) assert unify(ZZ.poly_ring(x, y), ZZ) == ZZ.poly_ring(x, y) assert unify(ZZ.poly_ring(x, y), QQ) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x, y), ZZ) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x, y), QQ) == QQ.poly_ring(x, y) assert unify(ZZ, ZZ.poly_ring(x, y)) == ZZ.poly_ring(x, y) assert unify(QQ, ZZ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(ZZ, QQ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(QQ, QQ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(ZZ.frac_field(x), ZZ) == ZZ.frac_field(x) assert unify(ZZ.frac_field(x), QQ) == QQ.frac_field(x) assert unify(QQ.frac_field(x), ZZ) == QQ.frac_field(x) assert unify(QQ.frac_field(x), QQ) == QQ.frac_field(x) assert unify(ZZ, ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(QQ, ZZ.frac_field(x)) == QQ.frac_field(x) assert unify(ZZ, QQ.frac_field(x)) == QQ.frac_field(x) assert unify(QQ, QQ.frac_field(x)) == QQ.frac_field(x) assert unify(ZZ.frac_field(x, y), ZZ) == ZZ.frac_field(x, y) assert unify(ZZ.frac_field(x, y), QQ) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x, y), ZZ) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x, y), QQ) == QQ.frac_field(x, y) assert unify(ZZ, ZZ.frac_field(x, y)) == ZZ.frac_field(x, y) assert unify(QQ, ZZ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(ZZ, QQ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(QQ, QQ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(ZZ.poly_ring(x), ZZ.poly_ring(x)) == ZZ.poly_ring(x) assert unify(ZZ.poly_ring(x), QQ.poly_ring(x)) == QQ.poly_ring(x) assert unify(QQ.poly_ring(x), ZZ.poly_ring(x)) == QQ.poly_ring(x) assert unify(QQ.poly_ring(x), QQ.poly_ring(x)) == QQ.poly_ring(x) assert unify(ZZ.poly_ring(x, y), ZZ.poly_ring(x)) == ZZ.poly_ring(x, y) assert unify(ZZ.poly_ring(x, y), QQ.poly_ring(x)) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x, y), ZZ.poly_ring(x)) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x, y), QQ.poly_ring(x)) == QQ.poly_ring(x, y) assert unify(ZZ.poly_ring(x), ZZ.poly_ring(x, y)) == ZZ.poly_ring(x, y) assert unify(ZZ.poly_ring(x), QQ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x), ZZ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(QQ.poly_ring(x), QQ.poly_ring(x, y)) == QQ.poly_ring(x, y) assert unify(ZZ.poly_ring(x, y), ZZ.poly_ring(x, z)) == ZZ.poly_ring(x, y, z) assert unify(ZZ.poly_ring(x, y), QQ.poly_ring(x, z)) == QQ.poly_ring(x, y, z) assert unify(QQ.poly_ring(x, y), ZZ.poly_ring(x, z)) == QQ.poly_ring(x, y, z) assert unify(QQ.poly_ring(x, y), QQ.poly_ring(x, z)) == QQ.poly_ring(x, y, z) assert unify(ZZ.frac_field(x), ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(ZZ.frac_field(x), QQ.frac_field(x)) == QQ.frac_field(x) assert unify(QQ.frac_field(x), ZZ.frac_field(x)) == QQ.frac_field(x) assert unify(QQ.frac_field(x), QQ.frac_field(x)) == QQ.frac_field(x) assert unify(ZZ.frac_field(x, y), ZZ.frac_field(x)) == ZZ.frac_field(x, y) assert unify(ZZ.frac_field(x, y), QQ.frac_field(x)) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x, y), ZZ.frac_field(x)) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x, y), QQ.frac_field(x)) == QQ.frac_field(x, y) assert unify(ZZ.frac_field(x), ZZ.frac_field(x, y)) == ZZ.frac_field(x, y) assert unify(ZZ.frac_field(x), QQ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x), ZZ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(QQ.frac_field(x), QQ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(ZZ.frac_field(x, y), ZZ.frac_field(x, z)) == ZZ.frac_field(x, y, z) assert unify(ZZ.frac_field(x, y), QQ.frac_field(x, z)) == QQ.frac_field(x, y, z) assert unify(QQ.frac_field(x, y), ZZ.frac_field(x, z)) == QQ.frac_field(x, y, z) assert unify(QQ.frac_field(x, y), QQ.frac_field(x, z)) == QQ.frac_field(x, y, z) assert unify(ZZ.poly_ring(x), ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(ZZ.poly_ring(x), QQ.frac_field(x)) == ZZ.frac_field(x) assert unify(QQ.poly_ring(x), ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(QQ.poly_ring(x), QQ.frac_field(x)) == QQ.frac_field(x) assert unify(ZZ.poly_ring(x, y), ZZ.frac_field(x)) == ZZ.frac_field(x, y) assert unify(ZZ.poly_ring(x, y), QQ.frac_field(x)) == ZZ.frac_field(x, y) assert unify(QQ.poly_ring(x, y), ZZ.frac_field(x)) == ZZ.frac_field(x, y) assert unify(QQ.poly_ring(x, y), QQ.frac_field(x)) == QQ.frac_field(x, y) assert unify(ZZ.poly_ring(x), ZZ.frac_field(x, y)) == ZZ.frac_field(x, y) assert unify(ZZ.poly_ring(x), QQ.frac_field(x, y)) == ZZ.frac_field(x, y) assert unify(QQ.poly_ring(x), ZZ.frac_field(x, y)) == ZZ.frac_field(x, y) assert unify(QQ.poly_ring(x), QQ.frac_field(x, y)) == QQ.frac_field(x, y) assert unify(ZZ.poly_ring(x, y), ZZ.frac_field(x, z)) == ZZ.frac_field(x, y, z) assert unify(ZZ.poly_ring(x, y), QQ.frac_field(x, z)) == ZZ.frac_field(x, y, z) assert unify(QQ.poly_ring(x, y), ZZ.frac_field(x, z)) == ZZ.frac_field(x, y, z) assert unify(QQ.poly_ring(x, y), QQ.frac_field(x, z)) == QQ.frac_field(x, y, z) assert unify(ZZ.frac_field(x), ZZ.poly_ring(x)) == ZZ.frac_field(x) assert unify(ZZ.frac_field(x), QQ.poly_ring(x)) == ZZ.frac_field(x) assert unify(QQ.frac_field(x), ZZ.poly_ring(x)) == ZZ.frac_field(x) assert unify(QQ.frac_field(x), QQ.poly_ring(x)) == QQ.frac_field(x) assert unify(ZZ.frac_field(x, y), ZZ.poly_ring(x)) == ZZ.frac_field(x, y) assert unify(ZZ.frac_field(x, y), QQ.poly_ring(x)) == ZZ.frac_field(x, y) assert unify(QQ.frac_field(x, y), ZZ.poly_ring(x)) == ZZ.frac_field(x, y) assert unify(QQ.frac_field(x, y), QQ.poly_ring(x)) == QQ.frac_field(x, y) assert unify(ZZ.frac_field(x), ZZ.poly_ring(x, y)) == ZZ.frac_field(x, y) assert unify(ZZ.frac_field(x), QQ.poly_ring(x, y)) == ZZ.frac_field(x, y) assert unify(QQ.frac_field(x), ZZ.poly_ring(x, y)) == ZZ.frac_field(x, y) assert unify(QQ.frac_field(x), QQ.poly_ring(x, y)) == QQ.frac_field(x, y) assert unify(ZZ.frac_field(x, y), ZZ.poly_ring(x, z)) == ZZ.frac_field(x, y, z) assert unify(ZZ.frac_field(x, y), QQ.poly_ring(x, z)) == ZZ.frac_field(x, y, z) assert unify(QQ.frac_field(x, y), ZZ.poly_ring(x, z)) == ZZ.frac_field(x, y, z) assert unify(QQ.frac_field(x, y), QQ.poly_ring(x, z)) == QQ.frac_field(x, y, z)
def test_Domain_preprocess(): assert Domain.preprocess(ZZ) == ZZ assert Domain.preprocess(QQ) == QQ assert Domain.preprocess(EX) == EX assert Domain.preprocess(FF(2)) == FF(2) assert Domain.preprocess(ZZ.poly_ring(x, y)) == ZZ.poly_ring(x, y) assert Domain.preprocess('Z') == ZZ assert Domain.preprocess('Q') == QQ assert Domain.preprocess('ZZ') == ZZ assert Domain.preprocess('QQ') == QQ assert Domain.preprocess('EX') == EX assert Domain.preprocess('FF(23)') == FF(23) assert Domain.preprocess('GF(23)') == GF(23) pytest.raises(OptionError, lambda: Domain.preprocess('Z[]')) assert Domain.preprocess('Z[x]') == ZZ.poly_ring(x) assert Domain.preprocess('Q[x]') == QQ.poly_ring(x) assert Domain.preprocess('ZZ[x]') == ZZ.poly_ring(x) assert Domain.preprocess('QQ[x]') == QQ.poly_ring(x) assert Domain.preprocess('Z[x,y]') == ZZ.poly_ring(x, y) assert Domain.preprocess('Q[x,y]') == QQ.poly_ring(x, y) assert Domain.preprocess('ZZ[x,y]') == ZZ.poly_ring(x, y) assert Domain.preprocess('QQ[x,y]') == QQ.poly_ring(x, y) pytest.raises(OptionError, lambda: Domain.preprocess('Z()')) assert Domain.preprocess('Z(x)') == ZZ.frac_field(x) assert Domain.preprocess('Q(x)') == QQ.frac_field(x) assert Domain.preprocess('ZZ(x)') == ZZ.frac_field(x) assert Domain.preprocess('QQ(x)') == QQ.frac_field(x) assert Domain.preprocess('Z(x,y)') == ZZ.frac_field(x, y) assert Domain.preprocess('Q(x,y)') == QQ.frac_field(x, y) assert Domain.preprocess('ZZ(x,y)') == ZZ.frac_field(x, y) assert Domain.preprocess('QQ(x,y)') == QQ.frac_field(x, y) assert Domain.preprocess('Q<I>') == QQ.algebraic_field(I) assert Domain.preprocess('QQ<I>') == QQ.algebraic_field(I) assert Domain.preprocess('Q<sqrt(2), I>') == QQ.algebraic_field(sqrt(2), I) assert Domain.preprocess('QQ<sqrt(2), I>') == QQ.algebraic_field( sqrt(2), I) pytest.raises(OptionError, lambda: Domain.preprocess('abc')) assert Domain.preprocess('RR') == RR assert Domain.preprocess('RR_5') == RealField(prec=5) assert Domain.preprocess('CC') == CC assert Domain.preprocess('CC_5') == ComplexField(prec=5) pytest.raises(OptionError, lambda: Domain.preprocess(()))
def test_dmp_factor_list(): R, x = ring("x", ZZ) assert R.dmp_factor_list(0) == (0, []) assert R.dmp_factor_list(7) == (7, []) R, x = ring("x", QQ) assert R.dmp_factor_list(0) == (0, []) assert R.dmp_factor_list(QQ(1, 7)) == (QQ(1, 7), []) R, x = ring("x", ZZ.poly_ring('t')) assert R.dmp_factor_list(0) == (0, []) assert R.dmp_factor_list(7) == (7, []) R, x = ring("x", QQ.poly_ring('t')) assert R.dmp_factor_list(0) == (0, []) assert R.dmp_factor_list(QQ(1, 7)) == (QQ(1, 7), []) R, x = ring("x", ZZ) assert R.dmp_factor_list(x**2 + 2*x + 1) == (1, [(x + 1, 2)]) # issue sympy/sympy#8037 assert R.dmp_factor_list(6*x**2 - 5*x - 6) == (1, [(2*x - 3, 1), (3*x + 2, 1)]) R, x = ring("x", QQ) assert R.dmp_factor_list(x**2/2 + x + QQ(1, 2)) == (QQ(1, 2), [(x + 1, 2)]) R, x = ring("x", FF(2)) assert R.dmp_factor_list(x**2 + 1) == (1, [(x + 1, 2)]) R, x = ring("x", RR) assert R.dmp_factor_list(1.0*x**2 + 2.0*x + 1.0) == (1.0, [(1.0*x + 1.0, 2)]) assert R.dmp_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.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 # issue diofant/diofant#238 f = 0.1*x**2 + 1.1*x + 1.0 assert R.dmp_factor_list(f) == (10.0, [(0.1*x + 0.1, 1), (0.1*x + 1.0, 1)]) f = 0.25 + 1.0*x + 1.0*x**2 assert R.dmp_factor_list(f) == (4.0, [(0.25 + 0.5*x, 2)]) Rt, t = ring("t", ZZ) R, x = ring("x", Rt) f = 4*t*x**2 + 4*t**2*x assert R.dmp_factor_list(f) == (4*t, [(x, 1), (x + t, 1)]) Rt, t = ring("t", QQ) R, x = ring("x", Rt) f = t*x**2/2 + t**2*x/2 assert R.dmp_factor_list(f) == (t/2, [(x, 1), (x + t, 1)]) R, x = ring("x", QQ.algebraic_field(I)) f = x**4 + 2*x**2 assert R.dmp_factor_list(f) == (R.domain(1), [(x, 2), (x**2 + 2, 1)]) R, x = ring("x", EX) pytest.raises(DomainError, lambda: R.dmp_factor_list(EX(sin(1)))) 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 = ring("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(x**2/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(x**2/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)]) R, x, y = ring("x,y", QQ) f = x**2*y/2 + x*y**2/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 # issue diofant/diofant#238 R, x, y, z = ring("x,y,z", RR) f = x*y + x*z + 0.1*y + 0.1*z assert R.dmp_factor_list(f) == (10.0, [(0.1*y + 0.1*z, 1), (x + 0.1, 1)]) f = 0.25*x**2 + 1.0*x*y*z + 1.0*y**2*z**2 assert R.dmp_factor_list(f) == (4.0, [(0.25*x + 0.5*y*z, 2)]) 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, [(x, 1), (x + t, 1)]) Rt, t = ring("t", QQ) R, x, y = ring("x,y", Rt) f = t*x**2/2 + t**2*x/2 assert R.dmp_factor_list(f) == (t/2, [(x, 1), (x + t, 1)]) R, x, y = ring("x,y", FF(2)) pytest.raises(NotImplementedError, lambda: R.dmp_factor_list(x**2 + y**2)) R, x, y = ring("x,y", EX) pytest.raises(DomainError, lambda: R.dmp_factor_list(EX(sin(1))))
def test_Domain_unify(): F3 = GF(3) assert unify(F3, F3) == F3 assert unify(F3, ZZ) == F3 assert unify(F3, QQ) == QQ assert unify(F3, ALG) == ALG assert unify(F3, RR) == RR assert unify(F3, CC) == CC assert unify(F3, ZZ.poly_ring(x)) == F3.poly_ring(x) assert unify(F3, ZZ.frac_field(x)) == F3.frac_field(x) assert unify(F3, EX) == EX assert unify(ZZ, F3) == F3 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.poly_ring(x)) == ZZ.poly_ring(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.poly_ring(x)) == QQ.poly_ring(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.poly_ring(x)) == RR.poly_ring(x) assert unify(RR, ZZ.frac_field(x)) == RR.frac_field(x) assert unify(RR, EX) == EX 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.poly_ring(x)) == CC.poly_ring(x) assert unify(CC, ZZ.frac_field(x)) == CC.frac_field(x) assert unify(CC, EX) == EX CC2 = ComplexField(prec=20) assert unify(CC, CC2) == unify(CC2, CC) == ComplexField(prec=CC.precision, tol=CC2.tolerance) RR2 = RealField(prec=20) assert unify(RR, RR2) == unify(RR2, RR) == RealField(prec=RR.precision, tol=RR2.tolerance) assert unify(ZZ.poly_ring(x), F3) == F3.poly_ring(x) assert unify(ZZ.poly_ring(x), ZZ) == ZZ.poly_ring(x) assert unify(ZZ.poly_ring(x), QQ) == QQ.poly_ring(x) assert unify(ZZ.poly_ring(x), ALG) == ALG.poly_ring(x) assert unify(ZZ.poly_ring(x), RR) == RR.poly_ring(x) assert unify(ZZ.poly_ring(x), CC) == CC.poly_ring(x) assert unify(ZZ.poly_ring(x), ZZ.poly_ring(x)) == ZZ.poly_ring(x) assert unify(ZZ.poly_ring(x), ZZ.frac_field(x)) == ZZ.frac_field(x) assert unify(ZZ.poly_ring(x), EX) == EX assert unify(ZZ.frac_field(x), F3) == F3.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.poly_ring(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.poly_ring(x)) == EX assert unify(EX, ZZ.frac_field(x)) == EX assert unify(EX, EX) == EX
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([Integer(1), Integer(2), Integer(3)]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)]) assert construct_domain( [Integer(1), Integer(2), Integer(3)], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)]) assert construct_domain([Rational(1, 2), Integer(2)]) == (QQ, [QQ(1, 2), QQ(2)]) assert construct_domain([3.14, 1, Rational(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([sqrt(2), 3.14], extension=True) == (EX, [EX(sqrt(2)), EX(3.14)]) 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, Rational(1, 2), sqrt(2)], extension=True) == (alg, [alg(7), alg(Rational(1, 2)), alg(sqrt(2))])) alg = QQ.algebraic_field(sqrt(2) + sqrt(3)) assert (construct_domain([7, sqrt(2), sqrt(3)], extension=True) == (alg, [ alg(7), alg(sqrt(2)), alg(sqrt(3)) ])) dom = ZZ.poly_ring(x) assert construct_domain([2 * x, 3]) == (dom, [dom(2 * x), dom(3)]) dom = ZZ.poly_ring(x, y) assert construct_domain([2 * x, 3 * y]) == (dom, [dom(2 * x), dom(3 * y)]) dom = QQ.poly_ring(x) assert construct_domain([x / 2, 3]) == (dom, [dom(x / 2), dom(3)]) dom = QQ.poly_ring(x, y) assert construct_domain([x / 2, 3 * y]) == (dom, [dom(x / 2), dom(3 * y)]) dom = RR.poly_ring(x) assert construct_domain([x / 2, 3.5]) == (dom, [dom(x / 2), dom(3.5)]) dom = RR.poly_ring(x, y) assert construct_domain([x / 2, 3.5 * y]) == (dom, [dom(x / 2), dom(3.5 * y)]) dom = ZZ.frac_field(x) assert construct_domain([2 / x, 3]) == (dom, [dom(2 / x), dom(3)]) dom = ZZ.frac_field(x, y) assert construct_domain([2 / x, 3 * y]) == (dom, [dom(2 / x), dom(3 * y)]) dom = RR.frac_field(x) assert construct_domain([2 / x, 3.5]) == (dom, [dom(2 / x), dom(3.5)]) dom = RR.frac_field(x, y) assert construct_domain([2 / x, 3.5 * y]) == (dom, [dom(2 / x), dom(3.5 * y)]) assert construct_domain(2) == (ZZ, ZZ(2)) assert construct_domain(Rational(2, 3)) == (QQ, QQ(2, 3)) assert construct_domain({}) == (ZZ, {})
def test_dmp_factor_list(): R, x = ring("x", ZZ) assert R(0).factor_list() == (0, []) assert R(7).factor_list() == (7, []) R, x = ring("x", QQ) assert R(0).factor_list() == (0, []) assert R(QQ(1, 7)).factor_list() == (QQ(1, 7), []) R, x = ring("x", ZZ.poly_ring('t')) assert R(0).factor_list() == (0, []) assert R(7).factor_list() == (7, []) R, x = ring("x", QQ.poly_ring('t')) assert R(0).factor_list() == (0, []) assert R(QQ(1, 7)).factor_list() == (QQ(1, 7), []) R, x = ring("x", ZZ) assert (x**2 + 2 * x + 1).factor_list() == (1, [(x + 1, 2)]) # issue sympy/sympy#8037 assert (6 * x**2 - 5 * x - 6).factor_list() == (1, [(2 * x - 3, 1), (3 * x + 2, 1)]) R, x = ring("x", QQ) assert (x**2 / 2 + x + QQ(1, 2)).factor_list() == (QQ(1, 2), [(x + 1, 2)]) R, x = ring("x", FF(2)) assert (x**2 + 1).factor_list() == (1, [(x + 1, 2)]) R, x = ring("x", RR) assert (1.0 * x**2 + 2.0 * x + 1.0).factor_list() == (1.0, [(1.0 * x + 1.0, 2)]) assert (2.0 * x**2 + 4.0 * x + 2.0).factor_list() == (2.0, [(1.0 * x + 1.0, 2)]) f = 6.7225336055071 * x**2 - 10.6463972754741 * x - 0.33469524022264 coeff, factors = f.factor_list() assert coeff == 1.0 and len(factors) == 1 and factors[0][0].almosteq( f, 1e-10) and factors[0][1] == 1 # issue diofant/diofant#238 f = 0.1 * x**2 + 1.1 * x + 1.0 assert f.factor_list() == (10.0, [(0.1 * x + 0.1, 1), (0.1 * x + 1.0, 1)]) f = 0.25 + 1.0 * x + 1.0 * x**2 assert f.factor_list() == (4.0, [(0.25 + 0.5 * x, 2)]) Rt, t = ring("t", ZZ) R, x = ring("x", Rt) f = 4 * t * x**2 + 4 * t**2 * x assert f.factor_list() == (4 * t, [(x, 1), (x + t, 1)]) Rt, t = ring("t", QQ) R, x = ring("x", Rt) f = t * x**2 / 2 + t**2 * x / 2 assert f.factor_list() == (t / 2, [(x, 1), (x + t, 1)]) R, x = ring("x", QQ.algebraic_field(I)) f = x**4 + 2 * x**2 assert f.factor_list() == (1, [(x, 2), (x**2 + 2, 1)]) R, x = ring("x", EX) pytest.raises(DomainError, lambda: R(EX(sin(1))).factor_list()) R, x, y = ring("x,y", ZZ) assert R(0).factor_list() == (0, []) assert R(7).factor_list() == (7, []) R, x, y = ring("x,y", QQ) assert R(0).factor_list() == (0, []) assert R(QQ(1, 7)).factor_list() == (QQ(1, 7), []) Rt, t = ring("t", ZZ) R, x, y = ring("x,y", Rt) assert R(0).factor_list() == (0, []) assert R(7).factor_list() == (7, []) Rt, t = ring("t", QQ) R, x, y = ring("x,y", Rt) assert R(0).factor_list() == (0, []) assert R(QQ(1, 7)).factor_list() == (QQ(1, 7), []) R, *X = ring("x:200", ZZ) f, g = X[0]**2 + 2 * X[0] + 1, X[0] + 1 assert f.factor_list() == (1, [(g, 2)]) f, g = X[-1]**2 + 2 * X[-1] + 1, X[-1] + 1 assert f.factor_list() == (1, [(g, 2)]) R, x = ring("x", ZZ) assert (x**2 + 2 * x + 1).factor_list() == (1, [(x + 1, 2)]) R, x = ring("x", QQ) assert (x**2 / 2 + x + QQ(1, 2)).factor_list() == (QQ(1, 2), [(x + 1, 2)]) R, x, y = ring("x,y", ZZ) assert (x**2 + 2 * x + 1).factor_list() == (1, [(x + 1, 2)]) R, x, y = ring("x,y", QQ) assert (x**2 / 2 + x + QQ(1, 2)).factor_list() == (QQ(1, 2), [(x + 1, 2)]) R, x, y = ring("x,y", ZZ) f = 4 * x**2 * y + 4 * x * y**2 assert f.factor_list() == (4, [(y, 1), (x, 1), (x + y, 1)]) R, x, y = ring("x,y", QQ) f = x**2 * y / 2 + x * y**2 / 2 assert f.factor_list() == (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 f.factor_list() == (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 = f.factor_list() assert coeff == 1.0 and len(factors) == 1 and factors[0][0].almosteq( f, 1e-10) and factors[0][1] == 1 # issue diofant/diofant#238 R, x, y, z = ring("x,y,z", RR) f = x * y + x * z + 0.1 * y + 0.1 * z assert f.factor_list() == (10.0, [(0.1 * y + 0.1 * z, 1), (x + 0.1, 1)]) f = 0.25 * x**2 + 1.0 * x * y * z + 1.0 * y**2 * z**2 assert f.factor_list() == (4.0, [(0.25 * x + 0.5 * y * z, 2)]) Rt, t = ring("t", ZZ) R, x, y = ring("x,y", Rt) f = 4 * t * x**2 + 4 * t**2 * x assert f.factor_list() == (4 * t, [(x, 1), (x + t, 1)]) Rt, t = ring("t", QQ) R, x, y = ring("x,y", Rt) f = t * x**2 / 2 + t**2 * x / 2 assert f.factor_list() == (t / 2, [(x, 1), (x + t, 1)]) R, x, y = ring("x,y", FF(2)) pytest.raises(NotImplementedError, lambda: (x**2 + y**2).factor_list()) R, x, y = ring("x,y", EX) pytest.raises(DomainError, lambda: R(EX(sin(1))).factor_list()) R, x, y = ring('x, y', QQ.algebraic_field(I)) f, r = x**2 + y**2, (1, [(x - I * y, 1), (x + I * y, 1)]) assert R.dmp_factor_list(f) == r with config.using(aa_factor_method='trager'): assert R.dmp_factor_list(f) == r