예제 #1
0
def test_is_groebner_basis():
    fac = DictPolyFactory(("x", "y"), monomial_orders.lex)
    p1 = fac.from_universal_rep({(1, 1): 1, (0, 1): -1})
    p2 = fac.from_universal_rep({(1, 0): -1, (0, 2): 1})
    p3 = fac.from_universal_rep({(0, 3): 1, (0, 1): -1})
    G = [p1, p2, p3]
    assert is_groebner_basis(G)
예제 #2
0
def test_reduce_wrt():
    fac = DictPolyFactory(("x","y"),degree_lex)
    p1 = fac.from_universal_rep({(2,1):1,(1,1):4,(0,2):-3})
    p2 = fac.from_universal_rep({(1,0):2,(0,1):1,(0,0):1})
    expected = fac.from_universal_rep({(0,3):f.Fraction(1,4),(0,2):f.Fraction(-9,2),(0,1):f.Fraction(-7,4)})
    answer = reduction_alg.reduce_wrt(p1,[p2])
    assert answer == expected
예제 #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
예제 #4
0
def test_buchberger():
    fac = DictPolyFactory(("x", "y"), monomial_orders.lex)
    p1 = fac.from_universal_rep({(1, 1): 1, (0, 1): -1})
    p2 = fac.from_universal_rep({(1, 0): -1, (0, 2): 1})
    f = [p1, p2]
    p3 = fac.from_universal_rep({(0, 3): 1, (0, 1): -1})
    expected = [p1, p2, p3]
    output = buchberger(f)
    assert expected == output
예제 #5
0
def test_mul():

    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})

    result = [p1 * p2, p1 * 0]
    expected = [fac.from_universal_rep({(2, 4, 6): 8, (2, 3, 4): 16}), 0]

    assert result == expected
예제 #6
0
def test_sub():

    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})

    result = [p1 - p2, p1 - p1]
    expected = [fac.from_universal_rep({(1, 2, 3): 2, (1, 1, 1): -4}), 0]

    assert result == expected
예제 #7
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
예제 #8
0
def test_lcm():
    fac = DictPolyFactory(("w", "x", "y", "z"), monomial_orders.degree_lex)
    p1 = fac.from_universal_rep({(4, 1, 3, 5): 1})
    p2 = fac.from_universal_rep({(2, 2, 2, 4): 1})
    p3 = fac.from_universal_rep({(1, 1, 1): 1, (1, 2, 3): 1})
    expected = fac.from_universal_rep({(4, 2, 3, 5): 1})
    try:
        p1.lcm(p3)
    except:
        "Task failed successfully"
    assert p1.lcm(p2) == expected
예제 #9
0
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
예제 #10
0
def test_exponents_of_lead_term():
    fac = DictPolyFactory(("x", "y"), monomial_orders.degree_lex)
    p = fac.from_universal_rep({(1, 4): 1, (2, 2): 1})
    exp = p.exponents_of_lead_term
    assert exp == (1, 4)
예제 #11
0
def test_radd():
    fac = DictPolyFactory(("x", "y"), term_key=None)
    p = fac.from_universal_rep({(1, 1): 1, (0, 0): 2})
    expected = fac.from_universal_rep({(1, 1): 1, (0, 0): 4})
    assert 2 + p == expected
예제 #12
0
def test_coeff_lt():
    fac = DictPolyFactory(("x", "y"), monomial_orders.degree_lex)
    p = fac.from_universal_rep({(2, 2): 1, (1, 3): 1, (1, 4): 3})
    assert p.coeff_of_lead_term == 3
예제 #13
0
def test_lead_term():
    fac = DictPolyFactory(("x", "y"), monomial_orders.degree_lex)
    p = fac.from_universal_rep({(2, 2): 1, (1, 3): 1, (1, 4): 1})
    lt_deglex = p.lead_term()
    expected = fac.from_universal_rep({(1, 4): 1})
    assert lt_deglex == expected
예제 #14
0
def test_eq():
    fac = DictPolyFactory(("x", "y"), term_key=None)
    p1 = fac.from_universal_rep({})
    p2 = fac.from_universal_rep({(1, 1): 0.25})
    p3 = fac.from_universal_rep({(1, 1): fractions.Fraction(1, 4)})
    assert p1 == 0 and p2 == p3
예제 #15
0
    expected = [fac.from_universal_rep({(2, 4, 6): 8, (2, 3, 4): 16}), 0]

    assert result == expected


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)