Beispiel #1
0
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, {})
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
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