I am done

This commit is contained in:
2024-10-30 22:14:35 +01:00
parent 720dc28c09
commit 40e2a747cf
36901 changed files with 5011519 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,93 @@
"""Tests for the PolynomialRing classes. """
from sympy.polys.domains import QQ, ZZ
from sympy.polys.polyerrors import ExactQuotientFailed, CoercionFailed, NotReversible
from sympy.abc import x, y
from sympy.testing.pytest import raises
def test_build_order():
R = QQ.old_poly_ring(x, y, order=(("lex", x), ("ilex", y)))
assert R.order((1, 5)) == ((1,), (-5,))
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 * (Y**2 + 1) == R.convert(x * (y**2 + 1))
assert X + 1 == R.convert(x + 1)
raises(ExactQuotientFailed, lambda: X/Y)
raises(TypeError, lambda: x/Y)
raises(TypeError, 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]
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*(Y**2 + 1)/(1 + X) == R.convert(x*(y**2 + 1)/(1 + x))
raises(TypeError, lambda: x/Y)
raises(TypeError, lambda: 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
raises(CoercionFailed, lambda: R.from_FractionField(Qxy.convert(x/y), Qxy))
raises(ExactQuotientFailed, lambda: R.exquo(X, Y))
raises(NotReversible, lambda: R.revert(X))
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)]
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)
raises(CoercionFailed, lambda: G.convert(L.convert(1/(1 + x)), L))
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))

View File

@ -0,0 +1,52 @@
"""Tests for quotient rings."""
from sympy.polys.domains.integerring import ZZ
from sympy.polys.domains.rationalfield import QQ
from sympy.abc import x, y
from sympy.polys.polyerrors import NotReversible
from sympy.testing.pytest import raises
def test_QuotientRingElement():
R = QQ.old_poly_ring(x)/[x**10]
X = R.convert(x)
assert X*(X + 1) == R.convert(x**2 + x)
assert X*x == R.convert(x**2)
assert x*X == R.convert(x**2)
assert X + x == R.convert(2*x)
assert x + X == 2*X
assert X**2 == R.convert(x**2)
assert 1/(1 - X) == R.convert(sum(x**i for i in range(10)))
assert X**10 == R.zero
assert X != x
raises(NotReversible, lambda: 1/X)
def test_QuotientRing():
I = QQ.old_poly_ring(x).ideal(x**2 + 1)
R = QQ.old_poly_ring(x)/I
assert R == QQ.old_poly_ring(x)/[x**2 + 1]
assert R == QQ.old_poly_ring(x)/QQ.old_poly_ring(x).ideal(x**2 + 1)
assert R != QQ.old_poly_ring(x)
assert R.convert(1)/x == -x + I
assert -1 + I == x**2 + I
assert R.convert(ZZ(1), ZZ) == 1 + I
assert R.convert(R.convert(x), R) == R.convert(x)
X = R.convert(x)
Y = QQ.old_poly_ring(x).convert(x)
assert -1 + I == X**2 + I
assert -1 + I == Y**2 + I
assert R.to_sympy(X) == x
raises(ValueError, lambda: QQ.old_poly_ring(x)/QQ.old_poly_ring(x, y).ideal(x))
R = QQ.old_poly_ring(x, order="ilex")
I = R.ideal(x)
assert R.convert(1) + I == (R/I).convert(1)