Пример #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_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
Пример #8
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
Пример #9
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)
Пример #10
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
Пример #11
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
Пример #12
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
Пример #13
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