Exemplo n.º 1
0
def test_PolynomialRing():
    sT(ZZ.inject('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.inject('x', 'y', 'z', 't').eject('t'),
       "PolynomialRing(PolynomialRing(%s, (Symbol('t'),), "
       "LexOrder()), (Symbol('x'), Symbol('y'), Symbol('z')), "
       'LexOrder())' % repr(ZZ))
Exemplo n.º 2
0
def test_PolynomialRing():
    sT(ZZ.inject('x'),
       f"UnivarPolynomialRing({ZZ!r}, (Symbol('x'),), LexOrder())")
    sT(
        QQ.poly_ring('x', 'y', order=grlex),
        f"PolynomialRing({QQ!r}, (Symbol('x'), Symbol('y')), GradedLexOrder())"
    )
    sT(
        ZZ.inject('x', 'y', 'z', 't').eject('t'),
        f"PolynomialRing(UnivarPolynomialRing({ZZ!r}, (Symbol('t'),), "
        "LexOrder()), (Symbol('x'), Symbol('y'), Symbol('z')), LexOrder())")
Exemplo n.º 3
0
def test_units():
    R = QQ.inject(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.inject(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
Exemplo n.º 4
0
def test_conversion():
    L = QQ.poly_ring(x, y, order='ilex')
    G = QQ.inject(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.inject(x, y)
    assert R.convert(ALG(1), ALG) == R(1)
    pytest.raises(CoercionFailed,
                  lambda: R.convert(ALG(1), QQ.algebraic_field(sqrt(2))))

    R = R.drop(y)
    pytest.raises(CoercionFailed, lambda: R.convert(G(y), R))

    pytest.raises(CoercionFailed, lambda: R.convert(FF(8)(2)))
Exemplo n.º 5
0
def test_localring():
    Qxy = QQ.inject(x, y).field
    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.inject(x, y).convert(x), ZZ.inject(x, y)) == X
    assert R.convert(Qxy.convert(x), Qxy) == X
Exemplo n.º 6
0
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, ))
Exemplo n.º 7
0
def test_PolynomialRing():
    assert str(ZZ.inject('x')) == 'ZZ[x]'
    assert str(QQ.poly_ring('x', 'y', order=grlex)) == 'QQ[x,y]'
    assert str(ZZ.inject('x', 'y', 'z', 't').eject('t')) == 'ZZ[t][x,y,z]'