Esempio n. 1
0
def test_conversion():
    L = QQ.old_poly_ring(x, y, order="ilex")
    G = QQ.old_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))
Esempio n. 2
0
def test_localring():
    Qxy = QQ.old_frac_field(x, y)
    R = QQ.old_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 1 / (1 + x) in R
    assert Y in R
    assert X.ring == R
    assert X * (Y**2 + 1) / (1 + X) == R.convert(x * (y**2 + 1) / (1 + x))
    assert X * y == X * Y
    pytest.raises(ExactQuotientFailed, lambda: X / Y)
    pytest.raises(ExactQuotientFailed, lambda: x / Y)
    pytest.raises(ExactQuotientFailed, lambda: X / y)
    assert X + y == X + Y == R.convert(x + y) == x + Y
    assert X - y == X - Y == R.convert(x - y) == x - Y
    assert X + 1 == R.convert(x + 1)
    assert X**2 / X == X

    assert R.from_GlobalPolynomialRing(
        ZZ.old_poly_ring(x, y).convert(x), ZZ.old_poly_ring(x, y)) == X
    assert R.from_FractionField(Qxy.convert(x), Qxy) == X
    pytest.raises(CoercionFailed,
                  lambda: R.from_FractionField(Qxy.convert(x) / y, Qxy))
    pytest.raises(ExactQuotientFailed, lambda: X / Y)
    pytest.raises(NotReversible, lambda: X.invert())

    assert R._sdm_to_vector(
        R._vector_to_sdm([X/(X + 1), Y/(1 + X*Y)], R.order), 2) == \
        [X*(1 + X*Y), Y*(1 + X)]
Esempio n. 3
0
def test_globalring():
    Qxy = QQ.old_frac_field(x, y)
    R = QQ.old_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
    assert X * (Y**2 + 1) == R.convert(x * (y**2 + 1))
    assert X * y == X * Y == R.convert(x * y) == x * Y
    assert X + y == X + Y == R.convert(x + y) == x + Y
    assert X - y == X - Y == R.convert(x - y) == x - Y
    assert X + 1 == R.convert(x + 1)
    pytest.raises(ExactQuotientFailed, lambda: X / Y)
    pytest.raises(ExactQuotientFailed, lambda: x / Y)
    pytest.raises(ExactQuotientFailed, lambda: X / y)
    assert X**2 / X == X

    assert R.from_GlobalPolynomialRing(
        ZZ.old_poly_ring(x, y).convert(x), ZZ.old_poly_ring(x, y)) == X
    assert R.from_FractionField(Qxy.convert(x), Qxy) == X
    assert R.from_FractionField(Qxy.convert(x) / y, Qxy) is None

    assert R._sdm_to_vector(R._vector_to_sdm([X, Y], R.order), 2) == [X, Y]
Esempio n. 4
0
def test_units():
    R = QQ.old_poly_ring(x)
    assert R.is_unit(R.convert(1))
    assert R.is_unit(R.convert(2))
    assert not R.is_unit(R.convert(x))
    assert not R.is_unit(R.convert(1 + x))

    R = QQ.old_poly_ring(x, order='ilex')
    assert R.is_unit(R.convert(1))
    assert R.is_unit(R.convert(2))
    assert not R.is_unit(R.convert(x))
    assert R.is_unit(R.convert(1 + x))

    R = ZZ.old_poly_ring(x)
    assert R.is_unit(R.convert(1))
    assert not R.is_unit(R.convert(2))
    assert not R.is_unit(R.convert(x))
    assert not R.is_unit(R.convert(1 + x))
Esempio n. 5
0
def test_build_order():
    R = QQ.old_poly_ring(x, y, order=(("lex", x), ("ilex", y)))
    assert R.order((1, 5)) == ((1, ), (-5, ))
Esempio n. 6
0
def test_old_poly_frac():
    pytest.raises(GeneratorsNeeded, lambda: QQ.old_poly_ring())
    pytest.raises(GeneratorsNeeded, lambda: QQ.old_frac_field())