def test_dmp_convert():
    K0, K1 = ZZ['x'], ZZ

    f = [[DMP([1], ZZ)], [DMP([2], ZZ)], [], [DMP([3], ZZ)]]

    assert dmp_convert(f, 1, K0, K1) == \
        [[ZZ(1)],[ZZ(2)],[],[ZZ(3)]]
Beispiel #2
0
def test_DUP_to_dict():
    f = DUP([3,0,0,2,0,0,0,0,8], ZZ)

    assert f.to_dict() == \
        {8: 3, 5: 2, 0: 8}
    assert f.to_sympy_dict() == \
        {8: ZZ.to_sympy(3), 5: ZZ.to_sympy(2), 0: ZZ.to_sympy(8)}
Beispiel #3
0
def test_DUP_to_dict():
    f = DMP([[3],[],[2],[],[8]], ZZ)

    assert f.to_dict() == \
        {(4, 0): 3, (2, 0): 2, (0, 0): 8}
    assert f.to_sympy_dict() == \
        {(4, 0): ZZ.to_sympy(3), (2, 0): ZZ.to_sympy(2), (0, 0): ZZ.to_sympy(8)}
Beispiel #4
0
def test_Algebra_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() == ZZ[x]
    assert ZZ[x, y].get_ring() == ZZ[x, y]
    assert QQ[x, y].get_ring() == ZZ[x, y]
    assert ZZ.frac_field(x).get_ring() == ZZ[x]
    assert QQ.frac_field(x).get_ring() == ZZ[x]
    assert ZZ.frac_field(x, y).get_ring() == ZZ[x, y]
    assert QQ.frac_field(x, y).get_ring() == ZZ[x, y]

    raises(DomainError, "EX.get_ring()")
    raises(DomainError, "RR.get_ring()")
    raises(DomainError, "ALG.get_ring()")
Beispiel #5
0
def test_Algebra_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() == ZZ[x]
    assert ZZ[x,y].get_ring() == ZZ[x,y]
    assert QQ[x,y].get_ring() == ZZ[x,y]
    assert ZZ.frac_field(x).get_ring() == ZZ[x]
    assert QQ.frac_field(x).get_ring() == ZZ[x]
    assert ZZ.frac_field(x,y).get_ring() == ZZ[x,y]
    assert QQ.frac_field(x,y).get_ring() == ZZ[x,y]

    raises(DomainError, "EX.get_ring()")
    raises(DomainError, "RR.get_ring()")
    raises(DomainError, "ALG.get_ring()")
def test_dmp_copy():
    f = [[ZZ(1)], [ZZ(2), ZZ(0)]]
    g = dmp_copy(f, 1)

    g[0][0], g[1][1] = ZZ(7), ZZ(1)

    assert f != g
def test_dup_convert():
    K0, K1 = ZZ['x'], ZZ

    f = [DMP([1], ZZ), DMP([2], ZZ), DMP([], ZZ), DMP([3], ZZ)]

    assert dup_convert(f, K0, K1) == \
        [ZZ(1),ZZ(2),ZZ(0),ZZ(3)]
Beispiel #8
0
def test_DUP_to_dict():
    f = DMP([[3],[],[2],[],[8]], ZZ)

    assert f.to_dict() == \
        {(4, 0): 3, (2, 0): 2, (0, 0): 8}
    assert f.to_sympy_dict() == \
        {(4, 0): ZZ.to_sympy(3), (2, 0): ZZ.to_sympy(2), (0, 0): ZZ.to_sympy(8)}
def test_dup_copy():
    f = [ZZ(1), ZZ(0), ZZ(2)]
    g = dup_copy(f)

    g[0], g[2] = ZZ(7), ZZ(0)

    assert f != g
Beispiel #10
0
def test_dmp_exquo_ground():
    f = dmp_normal([[6],[2],[8]], 1, ZZ)

    assert dmp_exquo_ground(f, ZZ(1), 1, ZZ) == f
    assert dmp_exquo_ground(f, ZZ(2), 1, ZZ) == dmp_normal([[3],[1],[4]], 1, ZZ)

    assert dmp_normal(dmp_exquo_ground(f, ZZ(3), 1, ZZ), 1, ZZ) == dmp_normal([[2],[],[2]], 1, ZZ)
Beispiel #11
0
def test_DUP_to_dict():
    f = DUP([3,0,0,2,0,0,0,0,8], ZZ)

    assert f.to_dict() == \
        {8: 3, 5: 2, 0: 8}
    assert f.to_sympy_dict() == \
        {8: ZZ.to_sympy(3), 5: ZZ.to_sympy(2), 0: ZZ.to_sympy(8)}
Beispiel #12
0
def test_dmp_grounds():
    assert dmp_grounds(ZZ(7), 0, 2) == []

    assert dmp_grounds(ZZ(7), 1, 2) == [[[[7]]]]
    assert dmp_grounds(ZZ(7), 2, 2) == [[[[7]]], [[[7]]]]
    assert dmp_grounds(ZZ(7), 3, 2) == [[[[7]]], [[[7]]], [[[7]]]]

    assert dmp_grounds(ZZ(7), 3, -1) == [7, 7, 7]
Beispiel #13
0
def test_dup_mul_ground():
    f = dup_normal([], ZZ)

    assert dup_mul_ground(f, ZZ(2), ZZ) == dup_normal([], ZZ)

    f = dup_normal([1,2,3], ZZ)

    assert dup_mul_ground(f, ZZ(0), ZZ) == dup_normal([], ZZ)
    assert dup_mul_ground(f, ZZ(2), ZZ) == dup_normal([2,4,6], ZZ)
Beispiel #14
0
def test_dup_neg():
    assert dup_neg([], ZZ) == []
    assert dup_neg([ZZ(1)], ZZ) == [ZZ(-1)]
    assert dup_neg([ZZ(-7)], ZZ) == [ZZ(7)]
    assert dup_neg([ZZ(-1),ZZ(2),ZZ(3)], ZZ) == [ZZ(1),ZZ(-2),ZZ(-3)]

    assert dup_neg([], QQ) == []
    assert dup_neg([QQ(1,2)], QQ) == [QQ(-1,2)]
    assert dup_neg([QQ(-7,9)], QQ) == [QQ(7,9)]
    assert dup_neg([QQ(-1,7),QQ(2,7),QQ(3,7)], QQ) == [QQ(1,7),QQ(-2,7),QQ(-3,7)]
Beispiel #15
0
def test_dup_abs():
    assert dup_abs([], ZZ) == []
    assert dup_abs([ZZ( 1)], ZZ) == [ZZ(1)]
    assert dup_abs([ZZ(-7)], ZZ) == [ZZ(7)]
    assert dup_abs([ZZ(-1),ZZ(2),ZZ(3)], ZZ) == [ZZ(1),ZZ(2),ZZ(3)]

    assert dup_abs([], QQ) == []
    assert dup_abs([QQ( 1,2)], QQ) == [QQ(1,2)]
    assert dup_abs([QQ(-7,3)], QQ) == [QQ(7,3)]
    assert dup_abs([QQ(-1,7),QQ(2,7),QQ(3,7)], QQ) == [QQ(1,7),QQ(2,7),QQ(3,7)]
Beispiel #16
0
def test_Algebra_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)
Beispiel #17
0
def test_Algebra_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)
Beispiel #18
0
def test_dup_quo_ground():
    raises(ZeroDivisionError, 'dup_quo_ground(dup_normal([1,2,3], ZZ), ZZ(0), ZZ)')
    raises(ExactQuotientFailed, 'dup_quo_ground(dup_normal([1,2,3], ZZ), ZZ(3), ZZ)')

    f = dup_normal([], ZZ)

    assert dup_quo_ground(f, ZZ(3), ZZ) == dup_normal([], ZZ)

    f = dup_normal([6,2,8], ZZ)

    assert dup_quo_ground(f, ZZ(1), ZZ) == f
    assert dup_quo_ground(f, ZZ(2), ZZ) == dup_normal([3,1,4], ZZ)

    f = dup_normal([6,2,8], QQ)

    assert dup_quo_ground(f, QQ(1), QQ) == f
    assert dup_quo_ground(f, QQ(2), QQ) == [QQ(3),QQ(1),QQ(4)]
    assert dup_quo_ground(f, QQ(7), QQ) == [QQ(6,7),QQ(2,7),QQ(8,7)]
Beispiel #19
0
def test_Algebra_get_field():
    assert EX.has_assoc_Field == True
    assert ZZ.has_assoc_Field == True
    assert QQ.has_assoc_Field == True
    assert ALG.has_assoc_Field == True
    assert ZZ[x].has_assoc_Field == True
    assert QQ[x].has_assoc_Field == True
    assert ZZ[x, y].has_assoc_Field == True
    assert QQ[x, y].has_assoc_Field == True

    assert RR.has_assoc_Field == False

    assert EX.get_field() == EX
    assert ZZ.get_field() == QQ
    assert QQ.get_field() == QQ
    assert ALG.get_field() == ALG
    assert ZZ[x].get_field() == ZZ.frac_field(x)
    assert QQ[x].get_field() == ZZ.frac_field(x)
    assert ZZ[x, y].get_field() == ZZ.frac_field(x, y)
    assert QQ[x, y].get_field() == ZZ.frac_field(x, y)

    raises(DomainError, "RR.get_field()")
Beispiel #20
0
def test_Algebra_get_field():
    assert EX.has_assoc_Field == True
    assert ZZ.has_assoc_Field == True
    assert QQ.has_assoc_Field == True
    assert ALG.has_assoc_Field == True
    assert ZZ[x].has_assoc_Field == True
    assert QQ[x].has_assoc_Field == True
    assert ZZ[x,y].has_assoc_Field == True
    assert QQ[x,y].has_assoc_Field == True

    assert RR.has_assoc_Field == False

    assert EX.get_field() == EX
    assert ZZ.get_field() == QQ
    assert QQ.get_field() == QQ
    assert ALG.get_field() == ALG
    assert ZZ[x].get_field() == ZZ.frac_field(x)
    assert QQ[x].get_field() == ZZ.frac_field(x)
    assert ZZ[x,y].get_field() == ZZ.frac_field(x,y)
    assert QQ[x,y].get_field() == ZZ.frac_field(x,y)

    raises(DomainError, "RR.get_field()")
Beispiel #21
0
def test_dup_sqr():
    assert dup_sqr([], ZZ) == []
    assert dup_sqr([ZZ(2)], ZZ) == [ZZ(4)]
    assert dup_sqr([ZZ(1),ZZ(2)], ZZ) == [ZZ(1),ZZ(4),ZZ(4)]

    assert dup_sqr([], QQ) == []
    assert dup_sqr([QQ(2,3)], QQ) == [QQ(4,9)]
    assert dup_sqr([QQ(1,3),QQ(2,3)], QQ) == [QQ(1,9),QQ(4,9),QQ(4,9)]

    f = dup_normal([2,0,0,1,7], ZZ)

    assert dup_sqr(f, ZZ) == dup_normal([4,0,0,4,28,0,1,14,49], ZZ)
Beispiel #22
0
def test_dmp_sqr():
    assert dmp_sqr([ZZ(1),ZZ(2)], 0, ZZ) == \
           dup_sqr([ZZ(1),ZZ(2)], ZZ)

    assert dmp_sqr([[[]]], 2, ZZ) == [[[]]]
    assert dmp_sqr([[[ZZ(2)]]], 2, ZZ) == [[[ZZ(4)]]]

    assert dmp_sqr([[[]]], 2, QQ) == [[[]]]
    assert dmp_sqr([[[QQ(2,3)]]], 2, QQ) == [[[QQ(4,9)]]]
Beispiel #23
0
def test_dmp_neg():
    assert dmp_neg([ZZ(-1)], 0, ZZ) == [ZZ(1)]
    assert dmp_neg([QQ(-1,2)], 0, QQ) == [QQ(1,2)]

    assert dmp_neg([[[]]], 2, ZZ) == [[[]]]
    assert dmp_neg([[[ZZ(1)]]], 2, ZZ) == [[[ZZ(-1)]]]
    assert dmp_neg([[[ZZ(-7)]]], 2, ZZ) == [[[ZZ(7)]]]

    assert dmp_neg([[[]]], 2, QQ) == [[[]]]
    assert dmp_neg([[[QQ(1,9)]]], 2, QQ) == [[[QQ(-1,9)]]]
    assert dmp_neg([[[QQ(-7,9)]]], 2, QQ) == [[[QQ(7,9)]]]
Beispiel #24
0
def test_dmp_pow():
    assert dmp_pow([[]], 0, 1, ZZ) == [[ZZ(1)]]
    assert dmp_pow([[]], 0, 1, QQ) == [[QQ(1)]]

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

    assert dmp_pow([[ZZ(1)]], 0, 1, ZZ) == [[ZZ(1)]]
    assert dmp_pow([[ZZ(1)]], 1, 1, ZZ) == [[ZZ(1)]]
    assert dmp_pow([[ZZ(1)]], 7, 1, ZZ) == [[ZZ(1)]]

    assert dmp_pow([[QQ(3,7)]], 0, 1, QQ) == [[QQ(1,1)]]
    assert dmp_pow([[QQ(3,7)]], 1, 1, QQ) == [[QQ(3,7)]]
    assert dmp_pow([[QQ(3,7)]], 7, 1, QQ) == [[QQ(2187,823543)]]

    f = dup_normal([2,0,0,1,7], ZZ)

    assert dmp_pow(f, 2, 0, ZZ) == dup_pow(f, 2, ZZ)
Beispiel #25
0
def test_dmp_ground_p():
    assert dmp_ground_p([], 0, 0) == True
    assert dmp_ground_p([[]], 0, 1) == True
    assert dmp_ground_p([[]], 1, 1) == False

    assert dmp_ground_p([[ZZ(1)]], 1, 1) == True
    assert dmp_ground_p([[[ZZ(2)]]], 2, 2) == True

    assert dmp_ground_p([[[ZZ(2)]]], 3, 2) == False
    assert dmp_ground_p([[[ZZ(3)], []]], 3, 2) == False

    assert dmp_ground_p([], None, 0) == True
    assert dmp_ground_p([[]], None, 1) == True

    assert dmp_ground_p([ZZ(1)], None, 0) == True
    assert dmp_ground_p([[[ZZ(1)]]], None, 2) == True

    assert dmp_ground_p([[[ZZ(3)], []]], None, 2) == False
Beispiel #26
0
def test_dup_mul_term():
    f = dup_normal([], ZZ)

    assert dup_mul_term(f, ZZ(2), 3, ZZ) == dup_normal([], ZZ)

    f = dup_normal([1,1], ZZ)

    assert dup_mul_term(f, ZZ(0), 3, ZZ) == dup_normal([], ZZ)

    f = dup_normal([1,2,3], ZZ)

    assert dup_mul_term(f, ZZ(2), 0, ZZ) == dup_normal([2,4,6], ZZ)
    assert dup_mul_term(f, ZZ(2), 1, ZZ) == dup_normal([2,4,6,0], ZZ)
    assert dup_mul_term(f, ZZ(2), 2, ZZ) == dup_normal([2,4,6,0,0], ZZ)
    assert dup_mul_term(f, ZZ(2), 3, ZZ) == dup_normal([2,4,6,0,0,0], ZZ)
def test_gf_ddf():
    f = gf_from_dict({15: 1, 0: -1}, 11, ZZ)
    g = [([1, 0, 0, 0, 0, 10], 1),
         ([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2)]

    assert gf_ddf_zassenhaus(f, 11, ZZ) == g
    assert gf_ddf_shoup(f, 11, ZZ) == g

    f = gf_from_dict({63: 1, 0: 1}, 2, ZZ)
    g = [([1, 1], 1),
         ([1, 1, 1], 2),
         ([1, 1, 1, 1, 1, 1, 1], 3),
         ([1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0,
           0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0,
           0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1], 6)]

    assert gf_ddf_zassenhaus(f, 2, ZZ) == g
    assert gf_ddf_shoup(f, 2, ZZ) == g

    f = gf_from_dict({6: 1, 5: -1, 4: 1, 3: 1, 1: -1}, 3, ZZ)
    g = [([1, 1, 0], 1),
         ([1, 1, 0, 1, 2], 2)]

    assert gf_ddf_zassenhaus(f, 3, ZZ) == g
    assert gf_ddf_shoup(f, 3, ZZ) == g

    f = [1, 2, 5, 26, 677, 436, 791, 325, 456, 24, 577]
    g = [([1, 701], 1),
         ([1, 110, 559, 532, 694, 151, 110, 70, 735, 122], 9)]

    assert gf_ddf_zassenhaus(f, 809, ZZ) == g
    assert gf_ddf_shoup(f, 809, ZZ) == g

    p = ZZ(nextprime(int((2**15 * pi).evalf())))
    f = gf_from_dict({15: 1, 1: 1, 0: 1}, p, ZZ)
    g = [([1, 22730, 68144], 2),
         ([1, 64876, 83977, 10787, 12561, 68608, 52650, 88001, 84356], 4),
         ([1, 15347, 95022, 84569, 94508, 92335], 5)]

    assert gf_ddf_zassenhaus(f, p, ZZ) == g
    assert gf_ddf_shoup(f, p, ZZ) == g
Beispiel #28
0
def test_dup_mul():
    assert dup_mul([], [], ZZ) == []
    assert dup_mul([], [ZZ(1)], ZZ) == []
    assert dup_mul([ZZ(1)], [], ZZ) == []
    assert dup_mul([ZZ(1)], [ZZ(1)], ZZ) == [ZZ(1)]
    assert dup_mul([ZZ(5)], [ZZ(7)], ZZ) == [ZZ(35)]

    assert dup_mul([], [], QQ) == []
    assert dup_mul([], [QQ(1,2)], QQ) == []
    assert dup_mul([QQ(1,2)], [], QQ) == []
    assert dup_mul([QQ(1,2)], [QQ(4,7)], QQ) == [QQ(2,7)]
    assert dup_mul([QQ(5,7)], [QQ(3,7)], QQ) == [QQ(15,49)]

    f = dup_normal([3,0,0,6,1,2], ZZ)
    g = dup_normal([4,0,1,0], ZZ)
    h = dup_normal([12,0,3,24,4,14,1,2,0], ZZ)

    assert dup_mul(f, g, ZZ) == h
    assert dup_mul(g, f, ZZ) == h

    f = dup_normal([2,0,0,1,7], ZZ)
    h = dup_normal([4,0,0,4,28,0,1,14,49], ZZ)

    assert dup_mul(f, f, ZZ) == h
Beispiel #29
0
def test_Algebra__unify():
    assert ZZ.unify(ZZ) == ZZ
    assert QQ.unify(QQ) == QQ

    assert ZZ.unify(QQ) == QQ
    assert QQ.unify(ZZ) == QQ

    assert EX.unify(EX) == EX

    assert ZZ.unify(EX) == EX
    assert QQ.unify(EX) == EX
    assert EX.unify(ZZ) == EX
    assert EX.unify(QQ) == EX

    assert ZZ.poly_ring('x').unify(EX) == EX
    assert ZZ.frac_field('x').unify(EX) == EX
    assert EX.unify(ZZ.poly_ring('x')) == EX
    assert EX.unify(ZZ.frac_field('x')) == EX

    assert ZZ.poly_ring('x','y').unify(EX) == EX
    assert ZZ.frac_field('x','y').unify(EX) == EX
    assert EX.unify(ZZ.poly_ring('x','y')) == EX
    assert EX.unify(ZZ.frac_field('x','y')) == EX

    assert QQ.poly_ring('x').unify(EX) == EX
    assert QQ.frac_field('x').unify(EX) == EX
    assert EX.unify(QQ.poly_ring('x')) == EX
    assert EX.unify(QQ.frac_field('x')) == EX

    assert QQ.poly_ring('x','y').unify(EX) == EX
    assert QQ.frac_field('x','y').unify(EX) == EX
    assert EX.unify(QQ.poly_ring('x','y')) == EX
    assert EX.unify(QQ.frac_field('x','y')) == EX

    assert ZZ.poly_ring('x').unify(ZZ) == ZZ.poly_ring('x')
    assert ZZ.poly_ring('x').unify(QQ) == QQ.poly_ring('x')
    assert QQ.poly_ring('x').unify(ZZ) == QQ.poly_ring('x')
    assert QQ.poly_ring('x').unify(QQ) == QQ.poly_ring('x')

    assert ZZ.unify(ZZ.poly_ring('x')) == ZZ.poly_ring('x')
    assert QQ.unify(ZZ.poly_ring('x')) == QQ.poly_ring('x')
    assert ZZ.unify(QQ.poly_ring('x')) == QQ.poly_ring('x')
    assert QQ.unify(QQ.poly_ring('x')) == QQ.poly_ring('x')

    assert ZZ.poly_ring('x','y').unify(ZZ) == ZZ.poly_ring('x','y')
    assert ZZ.poly_ring('x','y').unify(QQ) == QQ.poly_ring('x','y')
    assert QQ.poly_ring('x','y').unify(ZZ) == QQ.poly_ring('x','y')
    assert QQ.poly_ring('x','y').unify(QQ) == QQ.poly_ring('x','y')

    assert ZZ.unify(ZZ.poly_ring('x','y')) == ZZ.poly_ring('x','y')
    assert QQ.unify(ZZ.poly_ring('x','y')) == QQ.poly_ring('x','y')
    assert ZZ.unify(QQ.poly_ring('x','y')) == QQ.poly_ring('x','y')
    assert QQ.unify(QQ.poly_ring('x','y')) == QQ.poly_ring('x','y')

    assert ZZ.frac_field('x').unify(ZZ) == ZZ.frac_field('x')
    assert ZZ.frac_field('x').unify(QQ) == EX # QQ.frac_field('x')
    assert QQ.frac_field('x').unify(ZZ) == EX # QQ.frac_field('x')
    assert QQ.frac_field('x').unify(QQ) == QQ.frac_field('x')

    assert ZZ.unify(ZZ.frac_field('x')) == ZZ.frac_field('x')
    assert QQ.unify(ZZ.frac_field('x')) == EX # QQ.frac_field('x')
    assert ZZ.unify(QQ.frac_field('x')) == EX # QQ.frac_field('x')
    assert QQ.unify(QQ.frac_field('x')) == QQ.frac_field('x')

    assert ZZ.frac_field('x','y').unify(ZZ) == ZZ.frac_field('x','y')
    assert ZZ.frac_field('x','y').unify(QQ) == EX # QQ.frac_field('x','y')
    assert QQ.frac_field('x','y').unify(ZZ) == EX # QQ.frac_field('x','y')
    assert QQ.frac_field('x','y').unify(QQ) == QQ.frac_field('x','y')

    assert ZZ.unify(ZZ.frac_field('x','y')) == ZZ.frac_field('x','y')
    assert QQ.unify(ZZ.frac_field('x','y')) == EX # QQ.frac_field('x','y')
    assert ZZ.unify(QQ.frac_field('x','y')) == EX # QQ.frac_field('x','y')
    assert QQ.unify(QQ.frac_field('x','y')) == QQ.frac_field('x','y')

    assert ZZ.poly_ring('x').unify(ZZ.poly_ring('x')) == ZZ.poly_ring('x')
    assert ZZ.poly_ring('x').unify(QQ.poly_ring('x')) == QQ.poly_ring('x')
    assert QQ.poly_ring('x').unify(ZZ.poly_ring('x')) == QQ.poly_ring('x')
    assert QQ.poly_ring('x').unify(QQ.poly_ring('x')) == QQ.poly_ring('x')

    assert ZZ.poly_ring('x','y').unify(ZZ.poly_ring('x')) == ZZ.poly_ring('x','y')
    assert ZZ.poly_ring('x','y').unify(QQ.poly_ring('x')) == QQ.poly_ring('x','y')
    assert QQ.poly_ring('x','y').unify(ZZ.poly_ring('x')) == QQ.poly_ring('x','y')
    assert QQ.poly_ring('x','y').unify(QQ.poly_ring('x')) == QQ.poly_ring('x','y')

    assert ZZ.poly_ring('x').unify(ZZ.poly_ring('x','y')) == ZZ.poly_ring('x','y')
    assert ZZ.poly_ring('x').unify(QQ.poly_ring('x','y')) == QQ.poly_ring('x','y')
    assert QQ.poly_ring('x').unify(ZZ.poly_ring('x','y')) == QQ.poly_ring('x','y')
    assert QQ.poly_ring('x').unify(QQ.poly_ring('x','y')) == QQ.poly_ring('x','y')

    assert ZZ.poly_ring('x','y').unify(ZZ.poly_ring('x','z')) == ZZ.poly_ring('x','y','z')
    assert ZZ.poly_ring('x','y').unify(QQ.poly_ring('x','z')) == QQ.poly_ring('x','y','z')
    assert QQ.poly_ring('x','y').unify(ZZ.poly_ring('x','z')) == QQ.poly_ring('x','y','z')
    assert QQ.poly_ring('x','y').unify(QQ.poly_ring('x','z')) == QQ.poly_ring('x','y','z')

    assert ZZ.frac_field('x').unify(ZZ.frac_field('x')) == ZZ.frac_field('x')
    assert ZZ.frac_field('x').unify(QQ.frac_field('x')) == QQ.frac_field('x')
    assert QQ.frac_field('x').unify(ZZ.frac_field('x')) == QQ.frac_field('x')
    assert QQ.frac_field('x').unify(QQ.frac_field('x')) == QQ.frac_field('x')

    assert ZZ.frac_field('x','y').unify(ZZ.frac_field('x')) == ZZ.frac_field('x','y')
    assert ZZ.frac_field('x','y').unify(QQ.frac_field('x')) == QQ.frac_field('x','y')
    assert QQ.frac_field('x','y').unify(ZZ.frac_field('x')) == QQ.frac_field('x','y')
    assert QQ.frac_field('x','y').unify(QQ.frac_field('x')) == QQ.frac_field('x','y')

    assert ZZ.frac_field('x').unify(ZZ.frac_field('x','y')) == ZZ.frac_field('x','y')
    assert ZZ.frac_field('x').unify(QQ.frac_field('x','y')) == QQ.frac_field('x','y')
    assert QQ.frac_field('x').unify(ZZ.frac_field('x','y')) == QQ.frac_field('x','y')
    assert QQ.frac_field('x').unify(QQ.frac_field('x','y')) == QQ.frac_field('x','y')

    assert ZZ.frac_field('x','y').unify(ZZ.frac_field('x','z')) == ZZ.frac_field('x','y','z')
    assert ZZ.frac_field('x','y').unify(QQ.frac_field('x','z')) == QQ.frac_field('x','y','z')
    assert QQ.frac_field('x','y').unify(ZZ.frac_field('x','z')) == QQ.frac_field('x','y','z')
    assert QQ.frac_field('x','y').unify(QQ.frac_field('x','z')) == QQ.frac_field('x','y','z')

    assert ZZ.poly_ring('x').unify(ZZ.frac_field('x')) == ZZ.frac_field('x')
    assert ZZ.poly_ring('x').unify(QQ.frac_field('x')) == EX # QQ.frac_field('x')
    assert QQ.poly_ring('x').unify(ZZ.frac_field('x')) == EX # QQ.frac_field('x')
    assert QQ.poly_ring('x').unify(QQ.frac_field('x')) == QQ.frac_field('x')

    assert ZZ.poly_ring('x','y').unify(ZZ.frac_field('x')) == ZZ.frac_field('x','y')
    assert ZZ.poly_ring('x','y').unify(QQ.frac_field('x')) == EX # QQ.frac_field('x','y')
    assert QQ.poly_ring('x','y').unify(ZZ.frac_field('x')) == EX # QQ.frac_field('x','y')
    assert QQ.poly_ring('x','y').unify(QQ.frac_field('x')) == QQ.frac_field('x','y')

    assert ZZ.poly_ring('x').unify(ZZ.frac_field('x','y')) == ZZ.frac_field('x','y')
    assert ZZ.poly_ring('x').unify(QQ.frac_field('x','y')) == EX # QQ.frac_field('x','y')
    assert QQ.poly_ring('x').unify(ZZ.frac_field('x','y')) == EX # QQ.frac_field('x','y')
    assert QQ.poly_ring('x').unify(QQ.frac_field('x','y')) == QQ.frac_field('x','y')

    assert ZZ.poly_ring('x','y').unify(ZZ.frac_field('x','z')) == ZZ.frac_field('x','y','z')
    assert ZZ.poly_ring('x','y').unify(QQ.frac_field('x','z')) == EX # QQ.frac_field('x','y','z')
    assert QQ.poly_ring('x','y').unify(ZZ.frac_field('x','z')) == EX # QQ.frac_field('x','y','z')
    assert QQ.poly_ring('x','y').unify(QQ.frac_field('x','z')) == QQ.frac_field('x','y','z')

    assert ZZ.frac_field('x').unify(ZZ.poly_ring('x')) == ZZ.frac_field('x')
    assert ZZ.frac_field('x').unify(QQ.poly_ring('x')) == EX # QQ.frac_field('x')
    assert QQ.frac_field('x').unify(ZZ.poly_ring('x')) == EX # QQ.frac_field('x')
    assert QQ.frac_field('x').unify(QQ.poly_ring('x')) == QQ.frac_field('x')

    assert ZZ.frac_field('x','y').unify(ZZ.poly_ring('x')) == ZZ.frac_field('x','y')
    assert ZZ.frac_field('x','y').unify(QQ.poly_ring('x')) == EX # QQ.frac_field('x','y')
    assert QQ.frac_field('x','y').unify(ZZ.poly_ring('x')) == EX # QQ.frac_field('x','y')
    assert QQ.frac_field('x','y').unify(QQ.poly_ring('x')) == QQ.frac_field('x','y')

    assert ZZ.frac_field('x').unify(ZZ.poly_ring('x','y')) == ZZ.frac_field('x','y')
    assert ZZ.frac_field('x').unify(QQ.poly_ring('x','y')) == EX # QQ.frac_field('x','y')
    assert QQ.frac_field('x').unify(ZZ.poly_ring('x','y')) == EX # QQ.frac_field('x','y')
    assert QQ.frac_field('x').unify(QQ.poly_ring('x','y')) == QQ.frac_field('x','y')

    assert ZZ.frac_field('x','y').unify(ZZ.poly_ring('x','z')) == ZZ.frac_field('x','y','z')
    assert ZZ.frac_field('x','y').unify(QQ.poly_ring('x','z')) == EX # QQ.frac_field('x','y','z')
    assert QQ.frac_field('x','y').unify(ZZ.poly_ring('x','z')) == EX # QQ.frac_field('x','y','z')
    assert QQ.frac_field('x','y').unify(QQ.poly_ring('x','z')) == QQ.frac_field('x','y','z')

    raises(UnificationFailed, "ZZ.poly_ring('x','y').unify(ZZ, gens=('y', 'z'))")
    raises(UnificationFailed, "ZZ.unify(ZZ.poly_ring('x','y'), gens=('y', 'z'))")
Beispiel #30
0
def test_DMP_functionality():
    f = DMP([[1],[2,0],[1,0,0]], ZZ)
    g = DMP([[1],[1,0]], ZZ)
    h = DMP([[1]], ZZ)

    assert f.degree() == 2
    assert f.degree_list() == (2, 2)
    assert f.total_degree() == 4

    assert f.LC() == ZZ(1)
    assert f.TC() == ZZ(0)
    assert f.nth(1, 1) == ZZ(2)

    raises(TypeError, "f.nth(0, 'x')")

    assert f.max_norm() == 2
    assert f.l1_norm() == 4

    u = DMP([[2],[2,0]], ZZ)

    assert f.diff(m=1, j=0) == u
    assert f.diff(m=1, j=1) == u

    raises(TypeError, "f.diff(m='x', j=0)")

    u = DMP([1,2,1], ZZ)
    v = DMP([1,2,1], ZZ)

    assert f.eval(a=1, j=0) == u
    assert f.eval(a=1, j=1) == v

    assert f.eval(1).eval(1) == ZZ(4)

    assert f.cofactors(g) == (g, g, h)
    assert f.gcd(g) == g
    assert f.lcm(g) == f

    u = DMP([[QQ(45),QQ(30),QQ(5)]], QQ)
    v = DMP([[QQ(1),QQ(2,3),QQ(1,9)]], QQ)

    assert u.monic() == v

    assert (4*f).content() == ZZ(4)
    assert (4*f).primitive() == (ZZ(4), f)

    f = DMP([[1],[2],[3],[4],[5],[6]], ZZ)

    assert f.trunc(3) == DMP([[1],[-1],[],[1],[-1],[]], ZZ)

    f = DMP(f_4, ZZ)

    assert f.sqf_part() == -f
    assert f.sqf_list() == (ZZ(-1), [(-f, 1)])

    f = DMP([[-1],[],[],[5]], ZZ)
    g = DMP([[3,1],[],[]], ZZ)
    h = DMP([[45,30,5]], ZZ)

    r = DMP([675,675,225,25], ZZ)

    assert f.subresultants(g) == [f, g, h]
    assert f.resultant(g) == r

    f = DMP([1,3,9,-13], ZZ)

    assert f.discriminant() == -11664

    f = DMP([QQ(2),QQ(0)], QQ)
    g = DMP([QQ(1),QQ(0),QQ(-16)], QQ)

    s = DMP([QQ(1,32),QQ(0)], QQ)
    t = DMP([QQ(-1,16)], QQ)
    h = DMP([QQ(1)], QQ)

    assert f.half_gcdex(g) == (s, h)
    assert f.gcdex(g) == (s, t, h)

    assert f.invert(g) == s

    f = DMP([[1],[2],[3]], QQ)

    raises(ValueError, "f.half_gcdex(f)")
    raises(ValueError, "f.gcdex(f)")

    raises(ValueError, "f.invert(f)")

    f = DMP([1,0,20,0,150,0,500,0,625,-2,0,-10,9], ZZ)
    g = DMP([1,0,0,-2,9], ZZ)
    h = DMP([1,0,5,0], ZZ)

    assert g.compose(h) == f
    assert f.decompose() == [g, h]

    f = DMP([[1],[2],[3]], QQ)

    raises(ValueError, "f.decompose()")
    raises(ValueError, "f.sturm()")
Beispiel #31
0
def test_DUP___eq__():
    assert DUP([ZZ(1),ZZ(2),ZZ(3)], ZZ) == \
           DUP([ZZ(1),ZZ(2),ZZ(3)], ZZ)
    assert DUP([QQ(1),QQ(2),QQ(3)], QQ) == \
           DUP([ZZ(1),ZZ(2),ZZ(3)], ZZ)
    assert DUP([ZZ(1),ZZ(2),ZZ(3)], ZZ) == \
           DUP([QQ(1),QQ(2),QQ(3)], QQ)

    assert DUP([ZZ(1),ZZ(2),ZZ(4)], ZZ) != \
           DUP([ZZ(1),ZZ(2),ZZ(3)], ZZ)

    assert DUP([QQ(1),QQ(2),QQ(4)], QQ) != \
           DUP([ZZ(1),ZZ(2),ZZ(3)], ZZ)
Beispiel #32
0
def test_DMP___eq__():
    assert DMP([[ZZ(1),ZZ(2)],[ZZ(3)]], ZZ) == \
           DMP([[ZZ(1),ZZ(2)],[ZZ(3)]], ZZ)

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

    assert DMP([[[ZZ(1)]]], ZZ) != DMP([[ZZ(1)]], ZZ)
    assert DMP([[ZZ(1)]], ZZ) != DMP([[[ZZ(1)]]], ZZ)
Beispiel #33
0
def test_DUP_functionality():
    f = DUP([1,2,3,4], ZZ)
    g = DUP([3,4,3], ZZ)

    assert f.degree() == 3

    assert f.LC() == ZZ(1)
    assert f.TC() == ZZ(4)
    assert f.nth(1) == ZZ(3)

    raises(TypeError, "f.nth('x')")

    assert f.max_norm() == ZZ(4)
    assert f.l1_norm() == ZZ(10)

    assert f.diff(1) == g
    assert f.eval(1) == ZZ(10)

    raises(TypeError, "f.diff('x')")

    f = DUP([QQ(2),QQ(0)], QQ)
    g = DUP([QQ(1),QQ(0),QQ(-16)], QQ)

    s = DUP([QQ(1,32),QQ(0)], QQ)
    t = DUP([QQ(-1,16)], QQ)
    h = DUP([QQ(1)], QQ)

    assert f.half_gcdex(g) == (s, h)
    assert f.gcdex(g) == (s, t, h)

    assert f.invert(g) == s

    f = DUP([1,-2,1], ZZ)
    g = DUP([1,0,-1], ZZ)

    a = DUP([2,-2], ZZ)

    assert f.subresultants(g) == [f, g, a]
    assert f.resultant(g) == 0

    f = DUP([1,3,9,-13], ZZ)

    assert f.discriminant() == -11664

    f = DUP([1,2,1], ZZ)
    g = DUP([1,1], ZZ)
    h = DUP([1], ZZ)

    assert f.cofactors(g) == (g, g, h)
    assert f.gcd(g) == g
    assert f.lcm(g) == f

    assert f.sqf_part() == g
    assert f.sqf_list() == (ZZ(1), [(g, 2)])

    f = DUP([1,2,3,4,5,6], ZZ)

    assert f.trunc(3) == DUP([1,-1,0,1,-1,0], ZZ)

    f = DUP([QQ(3),QQ(-6)], QQ)
    g = DUP([QQ(1),QQ(-2)], QQ)

    assert f.monic() == g

    f = DUP([3,-6], ZZ)
    g = DUP([1,-2], ZZ)

    assert f.content() == ZZ(3)
    assert f.primitive() == (ZZ(3), g)

    f = DUP([1,0,20,0,150,0,500,0,625,-2,0,-10,9], ZZ)
    g = DUP([1,0,0,-2,9], ZZ)
    h = DUP([1,0,5,0], ZZ)

    assert g.compose(h) == f
    assert f.decompose() == [g, h]

    f = DUP([QQ(1),QQ(0)], QQ)

    assert f.sturm() == [f, DUP([QQ(1)], QQ)]
def test_dmp_factor_list():
    assert dmp_factor_list([[]], 1, ZZ) == (ZZ(0), [])
    assert dmp_factor_list([[]], 1, QQ) == (QQ(0), [])
    assert dmp_factor_list([[]], 1, ZZ['y']) == (DMP([], ZZ), [])
    assert dmp_factor_list([[]], 1, QQ['y']) == (DMP([], QQ), [])

    assert dmp_factor_list([[]], 1, ZZ, include=True) == [([[]], 1)]

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

    assert dmp_factor_list([[ZZ(7)]], 1, ZZ, include=True) == [([[ZZ(7)]], 1)]

    f, g = [ZZ(1), ZZ(2), ZZ(1)], [ZZ(1), ZZ(1)]

    assert dmp_factor_list(dmp_nest(f, 200, ZZ), 200, ZZ) == \
        (ZZ(1), [(dmp_nest(g, 200, ZZ), 2)])

    assert dmp_factor_list(dmp_raise(f, 200, 0, ZZ), 200, ZZ) == \
        (ZZ(1), [(dmp_raise(g, 200, 0, ZZ), 2)])

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

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

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

    assert dmp_factor_list(f, 1, ZZ) == \
        (ZZ(4), [([[ZZ(1)],[]], 1),
                 ([[ZZ(1),ZZ(0)]], 1),
                 ([[ZZ(1)],[ZZ(1),ZZ(0)]], 1)])

    assert dmp_factor_list(f, 1, ZZ, include=True) == \
        [([[ZZ(4)],[]], 1),
         ([[ZZ(1),ZZ(0)]], 1),
         ([[ZZ(1)],[ZZ(1),ZZ(0)]], 1)]

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

    assert dmp_factor_list(f, 1, QQ) == \
        (QQ(1,2), [([[QQ(1)],[]], 1),
                   ([[QQ(1),QQ(0)]], 1),
                   ([[QQ(1)],[QQ(1),QQ(0)]], 1)])

    f = [[RR(2.0)], [], [-RR(8.0), RR(0.0), RR(0.0)]]

    assert dmp_factor_list(f, 1, RR) == \
        (RR(2.0), [([[RR(1.0)],[-RR(2.0),RR(0.0)]], 1),
                   ([[RR(1.0)],[ RR(2.0),RR(0.0)]], 1)])

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

    assert dmp_factor_list(f, 1, ZZ['y']) == \
        (DMP([ZZ(4)],ZZ), [([[DMP([ZZ(1)],ZZ)],[]], 1),
                           ([[DMP([ZZ(1),ZZ(0)],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 dmp_factor_list(f, 1, QQ['y']) == \
        (DMP([QQ(1,2)],QQ), [([[DMP([QQ(1)],QQ)],[]], 1),
                             ([[DMP([QQ(1),QQ(0)],QQ)]], 1),
                             ([[DMP([QQ(1)],QQ)],[DMP([QQ(1),QQ(0)],QQ)]], 1)])

    raises(DomainError, "dmp_factor_list([[EX(sin(1))]], 1, EX)")
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([], ZZ, include=True) == [([], 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([ZZ(7)], ZZ, include=True) == [([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([ZZ(1),ZZ(2),ZZ(1)], ZZ, include=True) == \
        [([ZZ(1), ZZ(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),DMP([],ZZ)], 1),
                           ([DMP([ZZ(1),ZZ(0)],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),DMP([],QQ)], 1),
                             ([DMP([QQ(1),QQ(0)],QQ)], 1),
                             ([DMP([QQ(1)],QQ),DMP([QQ(1),QQ(0)],QQ)], 1)])

    raises(DomainError, "dup_factor_list([EX(sin(1))], EX)")
def test_dmp_zz_wang():
    p = ZZ(nextprime(dmp_zz_mignotte_bound(w_1, 2, ZZ)))

    assert p == ZZ(6291469)

    t_1, k_1, e_1 = dmp_normal([[1], []], 1, ZZ), 1, ZZ(-14)
    t_2, k_2, e_2 = dmp_normal([[1, 0]], 1, ZZ), 2, ZZ(3)
    t_3, k_3, e_3 = dmp_normal([[1], [1, 0]], 1, ZZ), 2, ZZ(-11)
    t_4, k_4, e_4 = dmp_normal([[1], [-1, 0]], 1, ZZ), 1, ZZ(-17)

    T = [t_1, t_2, t_3, t_4]
    K = [k_1, k_2, k_3, k_4]
    E = [e_1, e_2, e_3, e_4]

    T = zip(T, K)

    A = [ZZ(-14), ZZ(3)]

    S = dmp_eval_tail(w_1, A, 2, ZZ)
    cs, s = dup_primitive(S, ZZ)

    assert cs == 1 and s == S == \
        dup_normal([1036728, 915552, 55748, 105621, -17304, -26841, -644], ZZ)

    assert dmp_zz_wang_non_divisors(E, cs, 4, ZZ) == [7, 3, 11, 17]
    assert dup_sqf_p(s, ZZ) and dup_degree(s) == dmp_degree(w_1, 2)

    _, H = dup_zz_factor_sqf(s, ZZ)

    h_1 = dup_normal([44, 42, 1], ZZ)
    h_2 = dup_normal([126, -9, 28], ZZ)
    h_3 = dup_normal([187, 0, -23], ZZ)

    assert H == [h_1, h_2, h_3]

    lc_1 = dmp_normal([[-4], [-4, 0]], 1, ZZ)
    lc_2 = dmp_normal([[-1, 0, 0], []], 1, ZZ)
    lc_3 = dmp_normal([[1], [], [-1, 0, 0]], 1, ZZ)

    LC = [lc_1, lc_2, lc_3]

    assert dmp_zz_wang_lead_coeffs(w_1, T, cs, E, H, A, 2, ZZ) == (w_1, H, LC)

    H_1 = [
        dmp_normal(t, 0, ZZ)
        for t in [[44L, 42L, 1L], [126L, -9L, 28L], [187L, 0L, -23L]]
    ]
    H_2 = [
        dmp_normal(t, 1, ZZ)
        for t in [[[-4, -12], [-3, 0], [1]], [[-9, 0], [-9], [-2, 0]],
                  [[1, 0, -9], [], [1, -9]]]
    ]
    H_3 = [
        dmp_normal(t, 1, ZZ)
        for t in [[[-4, -12], [-3, 0], [1]], [[-9, 0], [-9], [-2, 0]],
                  [[1, 0, -9], [], [1, -9]]]
    ]

    c_1 = dmp_normal([-70686, -5863, -17826, 2009, 5031, 74], 0, ZZ)
    c_2 = dmp_normal(
        [[9, 12, -45, -108, -324], [18, -216, -810, 0],
         [2, 9, -252, -288, -945], [-30, -414, 0], [2, -54, -3, 81], [12, 0]],
        1, ZZ)
    c_3 = dmp_normal(
        [[-36, -108, 0], [-27, -36, -108], [-8, -42, 0], [-6, 0, 9], [2, 0]],
        1, ZZ)

    T_1 = [dmp_normal(t, 0, ZZ) for t in [[-3, 0], [-2], [1]]]
    T_2 = [dmp_normal(t, 1, ZZ) for t in [[[-1, 0], []], [[-3], []], [[-6]]]]
    T_3 = [dmp_normal(t, 1, ZZ) for t in [[[]], [[]], [[-1]]]]

    assert dmp_zz_diophantine(H_1, c_1, [], 5, p, 0, ZZ) == T_1
    assert dmp_zz_diophantine(H_2, c_2, [ZZ(-14)], 5, p, 1, ZZ) == T_2
    assert dmp_zz_diophantine(H_3, c_3, [ZZ(-14)], 5, p, 1, ZZ) == T_3

    factors = dmp_zz_wang_hensel_lifting(w_1, H, LC, A, p, 2, ZZ)

    assert dmp_expand(factors, 2, ZZ) == w_1