Example #1
0
 def factor_list(f):
     """Returns a list of irreducible factors of `f`. """
     coeff, factors = dmp_factor_list(f.rep, f.lev, f.dom)
     return coeff, [ (f.per(g), k) for g, k in factors ]
Example #2
0
 def factor_list(f):
     """Returns a list of irreducible factors of `f`. """
     coeff, factors = dmp_factor_list(f.rep, f.lev, f.dom)
     return coeff, [ (f.per(g), k) for g, k in factors ]
Example #3
0
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)")
Example #4
0
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_include([[]], 1, ZZ) == [([[]], 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_include([[ZZ(7)]], 1, ZZ) == [([[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),ZZ(0)]], 1),
                 ([[ZZ(1)],[]], 1),
                 ([[ZZ(1)],[ZZ(1),ZZ(0)]], 1)])

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

    K = FF(2)

    raises(DomainError, "dmp_factor_list([[K(1)],[],[K(1),K(0),K(0)]], 1, K)")
    raises(DomainError, "dmp_factor_list([[EX(sin(1))]], 1, EX)")