def test_minimal_basis():
    fac = DictPolyFactory(("y", "x"), monomial_orders.lex)
    p1 = fac.from_string("y**2 + y*x + x**2")
    p2 = fac.from_string("y + x")
    p3 = fac.from_string("y")
    p4 = fac.from_string("x**2")
    p5 = fac.from_string("x")
    G = [p1, p2, p3, p4, p5]

    result = minimal_basis.minimise_basis(G)
    expected = [p5, p2]

    assert expected == result
Beispiel #2
0
def test_poly_from_string():
    string = "2*x**2 + 3*y**3 + z"
    variables = ("x", "y", "z")
    fac = DictPolyFactory(variables, monomial_orders.degree_lex)
    p = fac.from_string(string)
    expected = fac.from_universal_rep({
        (2, 0, 0): 2,
        (0, 3, 0): 3,
        (0, 0, 1): 1
    })
    assert p == expected
Beispiel #3
0

def test_div():

    fac = DictPolyFactory(("x", "y", "z"), term_key=None)
    p1 = fac.from_universal_rep({(1, 2, 3): 4})
    p2 = fac.from_universal_rep({(1, 2, 3): 2, (1, 1, 1): 4})

    expected = [fac.from_universal_rep({(0, 0, 0): 0.5, (0, -1, -2): 1}), 1]
    assert [p2 / p1, p1 / p1] == expected


fac_xyz = DictPolyFactory(("x", "y", "z"), term_key=lambda x: x)
fac_yx = DictPolyFactory(("y", "x"), term_key=lambda x: x)
L = [
    (fac_xyz.from_string("2*x**2*y**2*z**3"),
     fac_xyz.from_string("4*x*y**2*z**3")),
    (fac_yx.from_string("y**2 + y*x + x**2"), fac_yx.from_string("y + x")),
    (fac_yx.from_string("y**2 + y*x + x**2"), fac_yx.from_string("y + x")),
]


@pytest.mark.parametrize("p1,p2", L)
def test_divisibility_yes(p1, p2):
    assert p1.lead_term() | p2.lead_term()


fac_xyz = DictPolyFactory(("x", "y", "z"), term_key=lambda x: x)
fac_yx = DictPolyFactory(("y", "x"), term_key=lambda x: x)
L = [
    (fac_yx.from_string("y + x"), fac_yx.from_string("y**2 + y*x + x**2")),