Example #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)
    raises(CoercionFailed, lambda: G.convert(L.convert(1/(1 + x)), L))
Example #2
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)
    raises(ExactQuotientFailed, lambda: X/Y)
    raises(ExactQuotientFailed, lambda: x/Y)
    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]
Example #3
0
def test_PolyElement_cancel():
    R, x, y = ring("x,y", ZZ)

    f = 2*x**3 + 4*x**2 + 2*x
    g = 3*x**2 + 3*x
    F = 2*x + 2
    G = 3

    assert f.cancel(g) == (F, G)

    assert (-f).cancel(g) == (-F, G)
    assert f.cancel(-g) == (-F, G)

    R, x, y = ring("x,y", QQ)

    f = QQ(1,2)*x**3 + x**2 + QQ(1,2)*x
    g = QQ(1,3)*x**2 + QQ(1,3)*x
    F = 3*x + 3
    G = 2

    assert f.cancel(g) == (F, G)

    assert (-f).cancel(g) == (-F, G)
    assert f.cancel(-g) == (-F, G)

    Fx, x = field("x", ZZ)
    Rt, t = ring("t", Fx)

    f = (-x**2 - 4)/4*t
    g = t**2 + (x**2 + 2)/2

    assert f.cancel(g) == ((-x**2 - 4)*t, 4*t**2 + 2*x**2 + 4)
Example #4
0
def test_Modules():
    from sympy.polys.domains import QQ
    from sympy.polys.agca import homomorphism

    R = QQ.old_poly_ring(x, y)
    F = R.free_module(2)
    M = F.submodule([x, y], [1, x ** 2])

    assert latex(F) == r"{\mathbb{Q}\left[x, y\right]}^{2}"
    assert latex(M) == r"\left< {\left[ {x},{y} \right]},{\left[ {1},{x^{2}} \right]} \right>"

    I = R.ideal(x ** 2, y)
    assert latex(I) == r"\left< {x^{2}},{y} \right>"

    Q = F / M
    assert (
        latex(Q)
        == r"\frac{{\mathbb{Q}\left[x, y\right]}^{2}}{\left< {\left[ {x},{y} \right]},{\left[ {1},{x^{2}} \right]} \right>}"
    )
    assert (
        latex(Q.submodule([1, x ** 3 / 2], [2, y]))
        == r"\left< {{\left[ {1},{\frac{x^{3}}{2}} \right]} + {\left< {\left[ {x},{y} \right]},{\left[ {1},{x^{2}} \right]} \right>}},{{\left[ {2},{y} \right]} + {\left< {\left[ {x},{y} \right]},{\left[ {1},{x^{2}} \right]} \right>}} \right>"
    )

    h = homomorphism(QQ.old_poly_ring(x).free_module(2), QQ.old_poly_ring(x).free_module(2), [0, 0])

    assert (
        latex(h)
        == r"{\left[\begin{matrix}0 & 0\\0 & 0\end{matrix}\right]} : {{\mathbb{Q}\left[x\right]}^{2}} \to {{\mathbb{Q}\left[x\right]}^{2}}"
    )
Example #5
0
def test_Domain_get_ring():
    assert ZZ.has_assoc_Ring is True
    assert QQ.has_assoc_Ring is True
    assert ZZ[x].has_assoc_Ring is True
    assert QQ[x].has_assoc_Ring is True
    assert ZZ[x, y].has_assoc_Ring is True
    assert QQ[x, y].has_assoc_Ring is True
    assert ZZ.frac_field(x).has_assoc_Ring is True
    assert QQ.frac_field(x).has_assoc_Ring is True
    assert ZZ.frac_field(x, y).has_assoc_Ring is True
    assert QQ.frac_field(x, y).has_assoc_Ring is True

    assert EX.has_assoc_Ring is False
    assert RR.has_assoc_Ring is False
    assert ALG.has_assoc_Ring is False

    assert ZZ.get_ring() == ZZ
    assert QQ.get_ring() == ZZ
    assert ZZ[x].get_ring() == ZZ[x]
    assert QQ[x].get_ring() == QQ[x]
    assert ZZ[x, y].get_ring() == ZZ[x, y]
    assert QQ[x, y].get_ring() == QQ[x, y]
    assert ZZ.frac_field(x).get_ring() == ZZ[x]
    assert QQ.frac_field(x).get_ring() == QQ[x]
    assert ZZ.frac_field(x, y).get_ring() == ZZ[x, y]
    assert QQ.frac_field(x, y).get_ring() == QQ[x, y]

    assert EX.get_ring() == EX

    raises(DomainError, lambda: RR.get_ring())
    raises(DomainError, lambda: ALG.get_ring())
Example #6
0
def test_PolyElement_gcd():
    R, x, y = ring("x,y", QQ)

    f = QQ(1,2)*x**2 + x + QQ(1,2)
    g = QQ(1,2)*x + QQ(1,2)

    assert f.gcd(g) == x + 1
Example #7
0
def test_Domain_get_ring():
    assert ZZ.has_assoc_Ring is True
    assert QQ.has_assoc_Ring is True
    assert ZZ[x].has_assoc_Ring is True
    assert QQ[x].has_assoc_Ring is True
    assert ZZ[x, y].has_assoc_Ring is True
    assert QQ[x, y].has_assoc_Ring is True
    assert ZZ.frac_field(x).has_assoc_Ring is True
    assert QQ.frac_field(x).has_assoc_Ring is True
    assert ZZ.frac_field(x, y).has_assoc_Ring is True
    assert QQ.frac_field(x, y).has_assoc_Ring is True

    assert EX.has_assoc_Ring is False
    assert RR.has_assoc_Ring is False
    assert ALG.has_assoc_Ring is False

    assert ZZ.get_ring() == ZZ
    assert QQ.get_ring() == ZZ
    assert ZZ[x].get_ring() == ZZ[x]
    assert QQ[x].get_ring() == QQ[x]
    assert ZZ[x, y].get_ring() == ZZ[x, y]
    assert QQ[x, y].get_ring() == QQ[x, y]
    assert ZZ.frac_field(x).get_ring() == ZZ[x]
    assert QQ.frac_field(x).get_ring() == QQ[x]
    assert ZZ.frac_field(x, y).get_ring() == ZZ[x, y]
    assert QQ.frac_field(x, y).get_ring() == QQ[x, y]

    assert EX.get_ring() == EX

    assert RR.get_ring() == RR
    # XXX: This should also be like RR
    raises(DomainError, lambda: ALG.get_ring())
Example #8
0
def test_Domain_get_ring():
    assert ZZ.has_assoc_Ring == True
    assert QQ.has_assoc_Ring == True
    assert ZZ[x].has_assoc_Ring == True
    assert QQ[x].has_assoc_Ring == True
    assert ZZ[x,y].has_assoc_Ring == True
    assert QQ[x,y].has_assoc_Ring == True
    assert ZZ.frac_field(x).has_assoc_Ring == True
    assert QQ.frac_field(x).has_assoc_Ring == True
    assert ZZ.frac_field(x,y).has_assoc_Ring == True
    assert QQ.frac_field(x,y).has_assoc_Ring == True

    assert EX.has_assoc_Ring == False
    assert RR.has_assoc_Ring == False
    assert ALG.has_assoc_Ring == False

    assert ZZ.get_ring() == ZZ
    assert QQ.get_ring() == ZZ
    assert ZZ[x].get_ring() == ZZ[x]
    assert QQ[x].get_ring() == QQ[x]
    assert ZZ[x,y].get_ring() == ZZ[x,y]
    assert QQ[x,y].get_ring() == QQ[x,y]
    assert ZZ.frac_field(x).get_ring() == ZZ[x]
    assert QQ.frac_field(x).get_ring() == QQ[x]
    assert ZZ.frac_field(x,y).get_ring() == ZZ[x,y]
    assert QQ.frac_field(x,y).get_ring() == QQ[x,y]

    raises(DomainError, "EX.get_ring()")
    raises(DomainError, "RR.get_ring()")
    raises(DomainError, "ALG.get_ring()")
Example #9
0
def test_localring():
    Qxy = QQ.frac_field(x, y)
    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 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
    raises(ExactQuotientFailed, lambda: X/Y)
    raises(ExactQuotientFailed, lambda: x/Y)
    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[x, y].convert(x), ZZ[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: X/Y)
    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)]
Example #10
0
def test_PolyElement_diff():
    R, X = xring("x:11", QQ)

    f = QQ(288,5)*X[0]**8*X[1]**6*X[4]**3*X[10]**2 + 8*X[0]**2*X[2]**3*X[4]**3 +2*X[0]**2 - 2*X[1]**2

    assert f.diff(X[0]) == QQ(2304,5)*X[0]**7*X[1]**6*X[4]**3*X[10]**2 + 16*X[0]*X[2]**3*X[4]**3 + 4*X[0]
    assert f.diff(X[4]) == QQ(864,5)*X[0]**8*X[1]**6*X[4]**2*X[10]**2 + 24*X[0]**2*X[2]**3*X[4]**2
    assert f.diff(X[10]) == QQ(576,5)*X[0]**8*X[1]**6*X[4]**3*X[10]
Example #11
0
def test_dup_euclidean_prs():
    f = QQ.map([1, 0, 1, 0, -3, -3, 8, 2, -5])
    g = QQ.map([3, 0, 5, 0, -4, -9, 21])

    assert dup_euclidean_prs(f, g, QQ) == [f, g,
        [-QQ(5,9), QQ(0,1), QQ(1,9), QQ(0,1), -QQ(1,3)],
        [-QQ(117,25), -QQ(9,1), QQ(441,25)],
        [QQ(233150,19773), -QQ(102500,6591)],
        [-QQ(1288744821,543589225)]]
def test_minpoly_domain():
    assert minimal_polynomial(sqrt(2), x, domain=QQ.algebraic_field(sqrt(2))) == \
        x - sqrt(2)
    assert minimal_polynomial(sqrt(8), x, domain=QQ.algebraic_field(sqrt(2))) == \
        x - 2*sqrt(2)
    assert minimal_polynomial(sqrt(Rational(3,2)), x,
        domain=QQ.algebraic_field(sqrt(2))) == 2*x**2 - 3

    raises(NotAlgebraic, lambda: minimal_polynomial(y, x, domain=QQ))
Example #13
0
def test_PolyElement_sqf_norm():
    R, x = ring("x", QQ.algebraic_field(sqrt(3)))
    X = R.to_ground().x

    assert (x**2 - 2).sqf_norm() == (1, x**2 - 2*sqrt(3)*x + 1, X**4 - 10*X**2 + 1)

    R, x = ring("x", QQ.algebraic_field(sqrt(2)))
    X = R.to_ground().x

    assert (x**2 - 3).sqf_norm() == (1, x**2 - 2*sqrt(2)*x - 1, X**4 - 10*X**2 + 1)
Example #14
0
def test_Domain___eq__():
    assert (ZZ[x,y] == ZZ[x,y]) == True
    assert (QQ[x,y] == QQ[x,y]) == True

    assert (ZZ[x,y] == QQ[x,y]) == False
    assert (QQ[x,y] == ZZ[x,y]) == False

    assert (ZZ.frac_field(x,y) == ZZ.frac_field(x,y)) == True
    assert (QQ.frac_field(x,y) == QQ.frac_field(x,y)) == True

    assert (ZZ.frac_field(x,y) == QQ.frac_field(x,y)) == False
    assert (QQ.frac_field(x,y) == ZZ.frac_field(x,y)) == False
Example #15
0
def test_Domain_get_exact():
    assert EX.get_exact() == EX
    assert ZZ.get_exact() == ZZ
    assert QQ.get_exact() == QQ
    assert RR.get_exact() == QQ
    assert ALG.get_exact() == ALG
    assert ZZ[x].get_exact() == ZZ[x]
    assert QQ[x].get_exact() == QQ[x]
    assert ZZ[x,y].get_exact() == ZZ[x,y]
    assert QQ[x,y].get_exact() == QQ[x,y]
    assert ZZ.frac_field(x).get_exact() == ZZ.frac_field(x)
    assert QQ.frac_field(x).get_exact() == QQ.frac_field(x)
    assert ZZ.frac_field(x,y).get_exact() == ZZ.frac_field(x,y)
    assert QQ.frac_field(x,y).get_exact() == QQ.frac_field(x,y)
Example #16
0
def test_Domain___eq__():
    assert (ZZ[x, y] == ZZ[x, y]) is True
    assert (QQ[x, y] == QQ[x, y]) is True

    assert (ZZ[x, y] == QQ[x, y]) is False
    assert (QQ[x, y] == ZZ[x, y]) is False

    assert (ZZ.frac_field(x, y) == ZZ.frac_field(x, y)) is True
    assert (QQ.frac_field(x, y) == QQ.frac_field(x, y)) is True

    assert (ZZ.frac_field(x, y) == QQ.frac_field(x, y)) is False
    assert (QQ.frac_field(x, y) == ZZ.frac_field(x, y)) is False

    assert RealField()[x] == RR[x]
Example #17
0
def test_dmp_lift():
    q = [QQ(1, 1), QQ(0, 1), QQ(1, 1)]

    f = [
        ANP([QQ(1, 1)], q, QQ),
        ANP([], q, QQ),
        ANP([], q, QQ),
        ANP([QQ(1, 1), QQ(0, 1)], q, QQ),
        ANP([QQ(17, 1), QQ(0, 1)], q, QQ),
    ]

    assert dmp_lift(f, 0, QQ.algebraic_field(I)) == [
        QQ(1),
        QQ(0),
        QQ(0),
        QQ(0),
        QQ(0),
        QQ(0),
        QQ(2),
        QQ(0),
        QQ(578),
        QQ(0),
        QQ(0),
        QQ(0),
        QQ(1),
        QQ(0),
        QQ(-578),
        QQ(0),
        QQ(83521),
    ]

    raises(DomainError, "dmp_lift([EX(1), EX(2)], 0, EX)")
Example #18
0
def test_dmp_ext_factor():
    h = [QQ(1),QQ(0),QQ(-2)]
    K = QQ.algebraic_field(sqrt(2))

    assert dmp_ext_factor([], 0, K) == (ANP([], h, QQ), [])
    assert dmp_ext_factor([[]], 1, K) == (ANP([], h, QQ), [])

    f = [[ANP([QQ(1)], h, QQ)], [ANP([QQ(1)], h, QQ)]]

    assert dmp_ext_factor(f, 1, K) == (ANP([QQ(1)], h, QQ), [(f, 1)])

    g = [[ANP([QQ(2)], h, QQ)], [ANP([QQ(2)], h, QQ)]]

    assert dmp_ext_factor(g, 1, K) == (ANP([QQ(2)], h, QQ), [(f, 1)])

    f = [[ANP([QQ(1)], h, QQ)], [], [ANP([QQ(-2)], h, QQ), ANP([], h, QQ), ANP([], h, QQ)]]

    assert dmp_ext_factor(f, 1, K) == \
        (ANP([QQ(1)], h, QQ), [
            ([[ANP([QQ(1)], h, QQ)], [ANP([QQ(-1),QQ(0)], h, QQ), ANP([], h, QQ)]], 1),
            ([[ANP([QQ(1)], h, QQ)], [ANP([QQ( 1),QQ(0)], h, QQ), ANP([], h, QQ)]], 1),
        ])

    f = [[ANP([QQ(2)], h, QQ)], [], [ANP([QQ(-4)], h, QQ), ANP([], h, QQ), ANP([], h, QQ)]]

    assert dmp_ext_factor(f, 1, K) == \
        (ANP([QQ(2)], h, QQ), [
            ([[ANP([QQ(1)], h, QQ)], [ANP([QQ(-1),QQ(0)], h, QQ), ANP([], h, QQ)]], 1),
            ([[ANP([QQ(1)], h, QQ)], [ANP([QQ( 1),QQ(0)], h, QQ), ANP([], h, QQ)]], 1),
        ])
Example #19
0
def test_sring():
    x, y, z, t = symbols("x,y,z,t")

    R = PolyRing("x,y,z", ZZ, lex)
    assert sring(x + 2*y + 3*z) == (R, R.x + 2*R.y + 3*R.z)

    R = PolyRing("x,y,z", QQ, lex)
    assert sring(x + 2*y + z/3) == (R, R.x + 2*R.y + R.z/3)
    assert sring([x, 2*y, z/3]) == (R, [R.x, 2*R.y, R.z/3])

    Rt = PolyRing("t", ZZ, lex)
    R = PolyRing("x,y,z", Rt, lex)
    assert sring(x + 2*t*y + 3*t**2*z, x, y, z) == (R, R.x + 2*Rt.t*R.y + 3*Rt.t**2*R.z)

    Rt = PolyRing("t", QQ, lex)
    R = PolyRing("x,y,z", Rt, lex)
    assert sring(x + t*y/2 + t**2*z/3, x, y, z) == (R, R.x + Rt.t*R.y/2 + Rt.t**2*R.z/3)

    Rt = FracField("t", ZZ, lex)
    R = PolyRing("x,y,z", Rt, lex)
    assert sring(x + 2*y/t + t**2*z/3, x, y, z) == (R, R.x + 2*R.y/Rt.t + Rt.t**2*R.z/3)

    r = sqrt(2) - sqrt(3)
    R, a = sring(r, extension=True)
    assert R.domain == QQ.algebraic_field(r)
    assert R.gens == ()
    assert a == R.domain.from_sympy(r)
Example #20
0
def test_QuotientRing():
    from sympy.polys.domains import QQ
    R = QQ.old_poly_ring(x)/[x**2 + 1]

    assert latex(
        R) == r"\frac{\mathbb{Q}\left[x\right]}{\left< {x^{2} + 1} \right>}"
    assert latex(R.one) == r"{1} + {\left< {x^{2} + 1} \right>}"
Example #21
0
def test_dmp_ext_factor():
    R, x,y = ring("x,y", QQ.algebraic_field(sqrt(2)))
    def anp(x):
        return ANP(x, [QQ(1), QQ(0), QQ(-2)], QQ)

    assert R.dmp_ext_factor(0) == (anp([]), [])

    f = anp([QQ(1)])*x + anp([QQ(1)])

    assert R.dmp_ext_factor(f) == (anp([QQ(1)]), [(f, 1)])

    g = anp([QQ(2)])*x + anp([QQ(2)])

    assert R.dmp_ext_factor(g) == (anp([QQ(2)]), [(f, 1)])

    f = anp([QQ(1)])*x**2 + anp([QQ(-2)])*y**2

    assert R.dmp_ext_factor(f) == \
        (anp([QQ(1)]), [(anp([QQ(1)])*x + anp([QQ(-1), QQ(0)])*y, 1),
                        (anp([QQ(1)])*x + anp([QQ( 1), QQ(0)])*y, 1)])

    f = anp([QQ(2)])*x**2 + anp([QQ(-4)])*y**2

    assert R.dmp_ext_factor(f) == \
        (anp([QQ(2)]), [(anp([QQ(1)])*x + anp([QQ(-1), QQ(0)])*y, 1),
                        (anp([QQ(1)])*x + anp([QQ( 1), QQ(0)])*y, 1)])
Example #22
0
def test_conversion():
    L = QQ.poly_ring(x, y, order="ilex")
    G = QQ[x, y]

    assert L.convert(x) == L.convert(G.convert(x), G)
    assert G.convert(x) == G.convert(L.convert(x), L)
    raises(CoercionFailed, 'G.convert(L.convert(1/(1+x)), L)')
Example #23
0
def test_PrettyPoly():
    from sympy.polys.domains import QQ
    F = QQ.frac_field(x, y)
    R = QQ[x, y]

    assert latex(F.convert(x/(x + y))) == latex(x/(x + y))
    assert latex(R.convert(x + y)) == latex(x + y)
Example #24
0
def test_dup_factor_list():
    assert dup_factor_list([], ZZ) == (ZZ(0), [])
    assert dup_factor_list([], QQ) == (QQ(0), [])
    assert dup_factor_list([], ZZ['y']) == (DMP([],ZZ), [])
    assert dup_factor_list([], QQ['y']) == (DMP([],QQ), [])

    assert dup_factor_list_include([], ZZ) == [([], 1)]

    assert dup_factor_list([ZZ(7)], ZZ) == (ZZ(7), [])
    assert dup_factor_list([QQ(1,7)], QQ) == (QQ(1,7), [])
    assert dup_factor_list([DMP([ZZ(7)],ZZ)], ZZ['y']) == (DMP([ZZ(7)],ZZ), [])
    assert dup_factor_list([DMP([QQ(1,7)],QQ)], QQ['y']) == (DMP([QQ(1,7)],QQ), [])

    assert dup_factor_list_include([ZZ(7)], ZZ) == [([ZZ(7)], 1)]

    assert dup_factor_list([ZZ(1),ZZ(2),ZZ(1)], ZZ) == \
        (ZZ(1), [([ZZ(1), ZZ(1)], 2)])
    assert dup_factor_list([QQ(1,2),QQ(1),QQ(1,2)], QQ) == \
        (QQ(1,2), [([QQ(1),QQ(1)], 2)])

    assert dup_factor_list_include([ZZ(1),ZZ(2),ZZ(1)], ZZ) == \
        [([ZZ(1), ZZ(1)], 2)]

    K = FF(2)

    assert dup_factor_list([K(1),K(0),K(1)], K) == \
        (K(1), [([K(1), K(1)], 2)])

    assert dup_factor_list([RR(1.0),RR(2.0),RR(1.0)], RR) == \
        (RR(1.0), [([RR(1.0),RR(1.0)], 2)])
    assert dup_factor_list([RR(2.0),RR(4.0),RR(2.0)], RR) == \
        (RR(2.0), [([RR(1.0),RR(1.0)], 2)])


    f = [DMP([ZZ(4),ZZ(0)],ZZ),DMP([ZZ(4),ZZ(0),ZZ(0)],ZZ),DMP([],ZZ)]

    assert dup_factor_list(f, ZZ['y']) == \
        (DMP([ZZ(4)],ZZ), [([DMP([ZZ(1),ZZ(0)],ZZ)], 1),
                           ([DMP([ZZ(1)],ZZ),DMP([],ZZ)], 1),
                           ([DMP([ZZ(1)],ZZ),DMP([ZZ(1),ZZ(0)],ZZ)], 1)])


    f = [DMP([QQ(1,2),QQ(0)],ZZ),DMP([QQ(1,2),QQ(0),QQ(0)],ZZ),DMP([],ZZ)]

    assert dup_factor_list(f, QQ['y']) == \
        (DMP([QQ(1,2)],QQ), [([DMP([QQ(1),QQ(0)],QQ)], 1),
                             ([DMP([QQ(1)],QQ),DMP([],QQ)], 1),
                             ([DMP([QQ(1)],QQ),DMP([QQ(1),QQ(0)],QQ)], 1)])

    K = QQ.algebraic_field(I)
    h = [QQ(1,1), QQ(0,1), QQ(1,1)]

    f = [ANP([QQ(1,1)], h, QQ), ANP([], h, QQ), ANP([QQ(2,1)], h, QQ), ANP([], h, QQ), ANP([], h, QQ)]

    assert dup_factor_list(f, K) == \
        (ANP([QQ(1,1)], h, QQ), [([ANP([QQ(1,1)], h, QQ), ANP([], h, QQ)], 2),
                                 ([ANP([QQ(1,1)], h, QQ), ANP([], h, QQ), ANP([QQ(2,1)], h, QQ)], 1)])

    raises(DomainError, "dup_factor_list([EX(sin(1))], EX)")
Example #25
0
def test_Domain_convert():
    assert QQ.convert(10e-52) == QQ(
        1684996666696915, 1684996666696914987166688442938726917102321526408785780068975640576
    )

    R, x = ring("x", ZZ)
    assert ZZ.convert(x - x) == 0
    assert ZZ.convert(x - x, R.to_domain()) == 0
Example #26
0
def test_dup_sturm():
    assert dup_sturm([QQ(5)], QQ) == [[QQ(1)]]
    assert dup_sturm([QQ(1),QQ(0)], QQ) == [[QQ(1),QQ(0)], [QQ(1)]]

    f = QQ.map([1,-2,3,-5])

    assert dup_sturm(f, QQ) == \
        [f, [QQ(3),QQ(-4),QQ(3)], [QQ(-10,9),QQ(13,3)], [QQ(-3303,100)]]
Example #27
0
def test_Domain_unify_algebraic():
    sqrt5 = QQ.algebraic_field(sqrt(5))
    sqrt7 = QQ.algebraic_field(sqrt(7))
    sqrt57 = QQ.algebraic_field(sqrt(5), sqrt(7))

    assert sqrt5.unify(sqrt7) == sqrt57

    assert sqrt5.unify(sqrt5[x, y]) == sqrt5[x, y]
    assert sqrt5[x, y].unify(sqrt5) == sqrt5[x, y]

    assert sqrt5.unify(sqrt5.frac_field(x, y)) == sqrt5.frac_field(x, y)
    assert sqrt5.frac_field(x, y).unify(sqrt5) == sqrt5.frac_field(x, y)

    assert sqrt5.unify(sqrt7[x, y]) == sqrt57[x, y]
    assert sqrt5[x, y].unify(sqrt7) == sqrt57[x, y]

    assert sqrt5.unify(sqrt7.frac_field(x, y)) == sqrt57.frac_field(x, y)
    assert sqrt5.frac_field(x, y).unify(sqrt7) == sqrt57.frac_field(x, y)
def test_Gaussian_postprocess():
    opt = {'gaussian': True}
    Gaussian.postprocess(opt)

    assert opt == {
        'gaussian': True,
        'extension': set([I]),
        'domain': QQ.algebraic_field(I),
    }
Example #29
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))
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[x, y]) == ZZ[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)

    raises(OptionError, lambda: Domain.preprocess('Z[]'))

    assert Domain.preprocess('Z[x]') == ZZ[x]
    assert Domain.preprocess('Q[x]') == QQ[x]

    assert Domain.preprocess('ZZ[x]') == ZZ[x]
    assert Domain.preprocess('QQ[x]') == QQ[x]

    assert Domain.preprocess('Z[x,y]') == ZZ[x, y]
    assert Domain.preprocess('Q[x,y]') == QQ[x, y]

    assert Domain.preprocess('ZZ[x,y]') == ZZ[x, y]
    assert Domain.preprocess('QQ[x,y]') == QQ[x, y]

    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)

    raises(OptionError, lambda: Domain.preprocess('abc'))