Ejemplo n.º 1
0
def test_pickling_polys_domains():
    for c in (PythonIntegerRing, PythonIntegerRing()):
        check(c)

    for c in (PythonRationalField, PythonRationalField()):
        check(c)

    for c in (PythonFiniteField, PythonFiniteField(7), PythonFiniteField(64)):
        check(c, exclude=[0, 1])

    if HAS_GMPY:
        for c in (GMPYIntegerRing, GMPYIntegerRing()):
            check(c)

        for c in (GMPYRationalField, GMPYRationalField()):
            check(c)

        for c in (GMPYFiniteField, GMPYFiniteField(7), GMPYFiniteField(64)):
            check(c, exclude=[0, 1])

    for c in (RealField, RealField(100)):
        check(c, exclude=[0, 1])

    for c in (ComplexField, ComplexField(100)):
        check(c, exclude=[0, 1])

    for c in (AlgebraicField, AlgebraicField(QQ, sqrt(2))):
        check(c, exclude=[0, 1])

    EX = ExpressionDomain()
    for c in (ExpressionDomain, EX, EX(sin(x))):
        check(c)
Ejemplo n.º 2
0
def test_pickling_polys_elements():
    for c in (PythonRational, PythonRational(1, 7)):
        check(c)

    gf17 = PythonFiniteField(17)
    gf64 = PythonFiniteField(64)

    for c in (gf17(5), gf64(12)):
        check(c, exclude=[0, 1])

    A = AlgebraicField(QQ, sqrt(2))

    for c in (A.one, A.unit, A([2, 1])):
        check(c, exclude=[0, 1])

    R = RealField(100)

    for c in (R.zero, R.one, R(1.2345)):
        check(c, exclude=[0, 1])

    C = ComplexField(100)

    for c in (C.zero, C.one, C(1.2345)):
        check(c, exclude=[0, 1])
Ejemplo n.º 3
0
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(()))