Esempio n. 1
0
def test_quadratic_perfect_square():

    # B**2 - 4*A*C > 0
    # B**2 - 4*A*C is a perfect square
    assert diop_solve(48 * x * y) == set([(Integer(0), t), (t, Integer(0))])
    assert diop_solve(4 * x ** 2 - 5 * x * y + y ** 2 + 2) == set(
        [(-Integer(1), -Integer(3)), (-Integer(1), -Integer(2)), (Integer(1), Integer(2)), (Integer(1), Integer(3))]
    )
    assert diop_solve(-2 * x ** 2 - 3 * x * y + 2 * y ** 2 - 2 * x - 17 * y + 25) == set([(Integer(4), Integer(15))])
    assert diop_solve(12 * x ** 2 + 13 * x * y + 3 * y ** 2 - 2 * x + 3 * y - 12) == set(
        [(-Integer(6), Integer(9)), (-Integer(2), Integer(5)), (Integer(4), -Integer(4)), (-Integer(6), Integer(16))]
    )
    assert diop_solve(8 * x ** 2 + 10 * x * y + 2 * y ** 2 - 32 * x - 13 * y - 23) == set(
        [(-Integer(44), Integer(47)), (Integer(22), -Integer(85))]
    )
    assert diop_solve(4 * x ** 2 - 4 * x * y - 3 * y - 8 * x - 3) == set(
        [(-Integer(1), -Integer(9)), (-Integer(6), -Integer(9)), (Integer(0), -Integer(1)), (Integer(1), -Integer(1))]
    )
    assert diop_solve(-4 * x * y - 4 * y ** 2 - 3 * y - 5 * x - 10) == set(
        [(-Integer(2), Integer(0)), (-Integer(11), -Integer(1)), (-Integer(5), Integer(5))]
    )
    assert diop_solve(x ** 2 - y ** 2 - 2 * x - 2 * y) == set([(t, -t), (-t, -t - 2)])
    assert diop_solve(x ** 2 - 9 * y ** 2 - 2 * x - 6 * y) == set([(-3 * t + 2, -t), (3 * t, -t)])
    assert diop_solve(4 * x ** 2 - 9 * y ** 2 - 4 * x - 12 * y - 3) == set(
        [(-3 * t - 3, -2 * t - 3), (3 * t + 1, -2 * t - 1)]
    )
Esempio n. 2
0
def test_quadratic_perfect_square():

    # B**2 - 4*A*C > 0
    # B**2 - 4*A*C is a perfect square
    assert diop_solve(48 * x * y) == set([(Integer(0), t), (t, Integer(0))])
    assert diop_solve(4*x**2 - 5*x*y + y**2 + 2) == \
        set([(-Integer(1), -Integer(3)),(-Integer(1), -Integer(2)),(Integer(1), Integer(2)),(Integer(1), Integer(3))])
    assert diop_solve(-2 * x**2 - 3 * x * y + 2 * y**2 - 2 * x - 17 * y +
                      25) == set([(Integer(4), Integer(15))])
    assert diop_solve(12*x**2 + 13*x*y + 3*y**2 - 2*x + 3*y - 12) == \
        set([(-Integer(6), Integer(9)), (-Integer(2), Integer(5)), (Integer(4), -Integer(4)), (-Integer(6), Integer(16))])
    assert diop_solve(8*x**2 + 10*x*y + 2*y**2 - 32*x - 13*y - 23) == \
        set([(-Integer(44), Integer(47)), (Integer(22), -Integer(85))])
    assert diop_solve(4*x**2 - 4*x*y - 3*y- 8*x - 3) == \
        set([(-Integer(1), -Integer(9)), (-Integer(6), -Integer(9)), (Integer(0), -Integer(1)), (Integer(1), -Integer(1))])
    assert diop_solve(- 4*x*y - 4*y**2 - 3*y- 5*x - 10) == \
        set([(-Integer(2), Integer(0)), (-Integer(11), -Integer(1)), (-Integer(5), Integer(5))])
    assert diop_solve(x**2 - y**2 - 2 * x - 2 * y) == set([(t, -t),
                                                           (-t, -t - 2)])
    assert diop_solve(x**2 - 9 * y**2 - 2 * x - 6 * y) == set([
        (-3 * t + 2, -t), (3 * t, -t)
    ])
    assert diop_solve(4 * x**2 - 9 * y**2 - 4 * x - 12 * y - 3) == set([
        (-3 * t - 3, -2 * t - 3), (3 * t + 1, -2 * t - 1)
    ])
Esempio n. 3
0
def test_quadratic_elliptical_case():
    # Elliptical case: B**2 - 4AC < 0
    assert diop_solve(42*x**2 + 8*x*y + 15*y**2 + 23*x + 17*y - 4915) == set([(-Integer(11), -Integer(1))])
    assert diop_solve(4*x**2 + 3*y**2 + 5*x - 11*y + 12) == set([])
    assert diop_solve(x**2 + y**2 + 2*x + 2*y + 2) == set([(-Integer(1), -Integer(1))])
    assert diop_solve(15*x**2 - 9*x*y + 14*y**2 - 23*x - 14*y - 4950) == set([(-Integer(15), Integer(6))])
    assert diop_solve(10*x**2 + 12*x*y + 12*y**2 - 34) == \
        set([(Integer(1), -Integer(2)), (-Integer(1), -Integer(1)),(Integer(1), Integer(1)), (-Integer(1), Integer(2))])
Esempio n. 4
0
def test_quadratic_elliptical_case():
    # Elliptical case: B**2 - 4AC < 0
    # Two test cases highlighted require lot of memory due to quadratic_congruence() method.
    # This above method should be replaced by Pernici's square_mod() method when his PR gets merged.

    # assert diop_solve(42*x**2 + 8*x*y + 15*y**2 + 23*x + 17*y - 4915) == set([(-11, -1)])
    assert diop_solve(4 * x ** 2 + 3 * y ** 2 + 5 * x - 11 * y + 12) == set([])
    assert diop_solve(x ** 2 + y ** 2 + 2 * x + 2 * y + 2) == set([(-1, -1)])
    # assert diop_solve(15*x**2 - 9*x*y + 14*y**2 - 23*x - 14*y - 4950) == set([(-15, 6)])
    assert diop_solve(10 * x ** 2 + 12 * x * y + 12 * y ** 2 - 34) == set([(-1, 2), (1, 1)])
Esempio n. 5
0
def test_quadratic_parabolic_case():
    # Parabolic case: B**2 - 4AC = 0
    assert diop_solve(8*x**2 - 24*x*y + 18*y**2 + 5*x + 7*y + 16) == \
        set([(-174*t**2 + 17*t - 2, -116*t**2 + 21*t - 2), (-174*t**2 + 41*t - 4, -116*t**2 + 37*t - 4)])
    assert diop_solve(8*x**2 - 24*x*y + 18*y**2 + 6*x + 12*y - 6) == \
        set([(-63*t**2 + 12*t, -42*t**2 + 15*t -1), (-63*t**2 + 30*t - 3, -42*t**2 + 27*t - 4)])
    assert diop_solve(8*x**2 + 24*x*y + 18*y**2 + 4*x + 6*y - 7) == set([])
    assert diop_solve(x**2 + 2*x*y + y**2 + 2*x + 2*y + 1) == set([(t,-t - 1)])
    assert diop_solve(x**2 - 2*x*y + y**2 + 2*x + 2*y + 1) == \
        set([(-4*t**2, -4*t**2 + 4*t - 1),(-4*t**2 + 4*t -1, -4*t**2 + 8*t - 4)])
Esempio n. 6
0
def test_quadratic_elliptical_case():
    # Elliptical case: B**2 - 4AC < 0
    # Two test cases highlighted require lot of memory due to quadratic_congruence() method.
    # This above method should be replaced by Pernici's square_mod() method when his PR gets merged.

    #assert diop_solve(42*x**2 + 8*x*y + 15*y**2 + 23*x + 17*y - 4915) == set([(-11, -1)])
    assert diop_solve(4 * x**2 + 3 * y**2 + 5 * x - 11 * y + 12) == set([])
    assert diop_solve(x**2 + y**2 + 2 * x + 2 * y + 2) == set([(-1, -1)])
    #assert diop_solve(15*x**2 - 9*x*y + 14*y**2 - 23*x - 14*y - 4950) == set([(-15, 6)])
    assert diop_solve(10*x**2 + 12*x*y + 12*y**2 - 34) == \
        set([(-1, -1), (-1, 2), (1, -2), (1, 1)])
Esempio n. 7
0
def test_diop_ternary_quadratic():
    assert check_solutions(2*x**2 + z**2 + y**2 - 4*x*y)
    assert check_solutions(x**2 - y**2 - z**2 - x*y - y*z)
    assert check_solutions(3*x**2 - x*y - y*z - x*z)
    assert check_solutions(x**2 - y*z - x*z)
    assert check_solutions(5*x**2 - 3*x*y - x*z)
    assert check_solutions(4*x**2 - 5*y**2 - x*z)
    assert check_solutions(3*x**2 + 2*y**2 - z**2 - 2*x*y + 5*y*z - 7*y*z)
    assert check_solutions(8*x**2 - 12*y*z)
    assert check_solutions(45*x**2 - 7*y**2 - 8*x*y - z**2)
    assert check_solutions(x**2 - 49*y**2 - z**2 + 13*z*y -8*x*y)
    assert check_solutions(90*x**2 + 3*y**2 + 5*x*y + 2*z*y + 5*x*z)
    assert check_solutions(x**2 + 3*y**2 + z**2 - x*y - 17*y*z)
    assert check_solutions(x**2 + 3*y**2 + z**2 - x*y - 16*y*z + 12*x*z)
    assert check_solutions(x**2 + 3*y**2 + z**2 - 13*x*y - 16*y*z + 12*x*z)
    assert check_solutions(x*y - 7*y*z + 13*x*z)

    assert diop_ternary_quadratic_normal(x**2 + y**2 + z**2) == (None, None, None)
    assert diop_ternary_quadratic_normal(x**2 + y**2) is None
    raises(ValueError, lambda:
        _diop_ternary_quadratic_normal((x, y, z),
        {x*y: 1, x**2: 2, y**2: 3, z**2: 0}))
    eq = -2*x*y - 6*x*z + 7*y**2 - 3*y*z + 4*z**2
    assert diop_ternary_quadratic(eq) == (7, 2, 0)
    assert diop_ternary_quadratic_normal(4*x**2 + 5*y**2 - z**2) == \
        (1, 0, 2)
    assert diop_ternary_quadratic(x*y + 2*y*z) == \
        (-2, 0, n1)
    eq = -5*x*y - 8*x*z - 3*y*z + 8*z**2
    assert parametrize_ternary_quadratic(eq) == \
        (8*p**2 - 3*p*q, -8*p*q + 8*q**2, 5*p*q)
    # this cannot be tested with diophantine because it will
    # factor into a product
    assert diop_solve(x*y + 2*y*z) == (-2*p*q, -n1*p**2 + p**2, p*q)
Esempio n. 8
0
def laundry_basic(bal, P):
    eqn = diop_solve(1000 * A + int(bal * 100) - int(100 * P) * L)
    print('L, A')
    for intiger in [-1, -2, -3, -4]:
        a = sympify(str(eqn[0]).replace('t_0', str(intiger)))
        l = sympify(str(eqn[1]).replace('t_0', str(intiger)))
        print(l, a)
Esempio n. 9
0
def test_diop_ternary_quadratic():
    assert check_solutions(2*x**2 + z**2 + y**2 - 4*x*y)
    assert check_solutions(x**2 - y**2 - z**2 - x*y - y*z)
    assert check_solutions(3*x**2 - x*y - y*z - x*z)
    assert check_solutions(x**2 - y*z - x*z)
    assert check_solutions(5*x**2 - 3*x*y - x*z)
    assert check_solutions(4*x**2 - 5*y**2 - x*z)
    assert check_solutions(3*x**2 + 2*y**2 - z**2 - 2*x*y + 5*y*z - 7*y*z)
    assert check_solutions(8*x**2 - 12*y*z)
    assert check_solutions(45*x**2 - 7*y**2 - 8*x*y - z**2)
    assert check_solutions(x**2 - 49*y**2 - z**2 + 13*z*y -8*x*y)
    assert check_solutions(90*x**2 + 3*y**2 + 5*x*y + 2*z*y + 5*x*z)
    assert check_solutions(x**2 + 3*y**2 + z**2 - x*y - 17*y*z)
    assert check_solutions(x**2 + 3*y**2 + z**2 - x*y - 16*y*z + 12*x*z)
    assert check_solutions(x**2 + 3*y**2 + z**2 - 13*x*y - 16*y*z + 12*x*z)
    assert check_solutions(x*y - 7*y*z + 13*x*z)

    assert diop_ternary_quadratic_normal(x**2 + y**2 + z**2) == (None, None, None)
    assert diop_ternary_quadratic_normal(x**2 + y**2) is None
    raises(ValueError, lambda:
        _diop_ternary_quadratic_normal((x, y, z),
        {x*y: 1, x**2: 2, y**2: 3, z**2: 0}))
    eq = -2*x*y - 6*x*z + 7*y**2 - 3*y*z + 4*z**2
    assert diop_ternary_quadratic(eq) == (7, 2, 0)
    assert diop_ternary_quadratic_normal(4*x**2 + 5*y**2 - z**2) == \
        (1, 0, 2)
    assert diop_ternary_quadratic(x*y + 2*y*z) == \
        (-2, 0, n1)
    eq = -5*x*y - 8*x*z - 3*y*z + 8*z**2
    assert parametrize_ternary_quadratic(eq) == \
        (64*p**2 - 24*p*q, -64*p*q + 64*q**2, 40*p*q)
    # this cannot be tested with diophantine because it will
    # factor into a product
    assert diop_solve(x*y + 2*y*z) == (-4*p*q, -2*n1*p**2 + 2*p**2, 2*p*q)
Esempio n. 10
0
def test_diopcoverage():
    eq = (2 * x + y + 1)**2
    assert diop_solve(eq) == set([(t_0, -2 * t_0 - 1)])
    eq = 2 * x**2 + 6 * x * y + 12 * x + 4 * y**2 + 18 * y + 18
    assert diop_solve(eq) == set([(t_0, -t_0 - 3), (2 * t_0 - 3, -t_0)])
    assert diop_quadratic(x + y**2 - 3) == set([(-t**2 + 3, -t)])

    assert diop_linear(x + y - 3) == (t_0, 3 - t_0)

    assert base_solution_linear(0, 1, 2, t=None) == (0, 0)
    ans = (3 * t - 1, -2 * t + 1)
    assert base_solution_linear(4, 8, 12, t) == ans
    assert base_solution_linear(4, 8, 12,
                                t=None) == tuple(_.subs(t, 0) for _ in ans)

    assert cornacchia(1, 1, 20) is None
    assert cornacchia(1, 1, 5) == set([(2, 1)])
    assert cornacchia(1, 2, 17) == set([(3, 2)])

    raises(ValueError, lambda: reconstruct(4, 20, 1))

    assert gaussian_reduce(4, 1, 3) == (1, 1)
    eq = -w**2 - x**2 - y**2 + z**2

    assert diop_general_pythagorean(eq) == \
        diop_general_pythagorean(-eq) == \
            (m1**2 + m2**2 - m3**2, 2*m1*m3,
            2*m2*m3, m1**2 + m2**2 + m3**2)

    assert check_param(S(3) + x / 3, S(4) + x / 2, S(2), x) == (None, None)
    assert check_param(S(3) / 2, S(4) + x, S(2), x) == (None, None)
    assert check_param(S(4) + x, S(3) / 2, S(2), x) == (None, None)

    assert _nint_or_floor(16, 10) == 2
    assert _odd(1) == (not _even(1)) == True
    assert _odd(0) == (not _even(0)) == False
    assert _remove_gcd(2, 4, 6) == (1, 2, 3)
    raises(TypeError, lambda: _remove_gcd((2, 4, 6)))
    assert sqf_normal(2 * 3**2 * 5, 2 * 5 * 11, 2 * 7**2 * 11)  == \
        (11, 1, 5)

    # it's ok if these pass some day when the solvers are implemented
    raises(NotImplementedError,
           lambda: diophantine(x**2 + y**2 + x * y + 2 * y * z - 12))
    raises(NotImplementedError, lambda: diophantine(x**3 + y**2))
    assert diop_quadratic(x**2 + y**2 - 1**2 - 3**4) == \
        set([(-9, -1), (-9, 1), (-1, -9), (-1, 9), (1, -9), (1, 9), (9, -1), (9, 1)])
Esempio n. 11
0
def test_diopcoverage():
    eq = (2*x + y + 1)**2
    assert diop_solve(eq) == set([(t_0, -2*t_0 - 1)])
    eq = 2*x**2 + 6*x*y + 12*x + 4*y**2 + 18*y + 18
    assert diop_solve(eq) == set([(t_0, -t_0 - 3), (2*t_0 - 3, -t_0)])
    assert diop_quadratic(x + y**2 - 3) == set([(-t**2 + 3, -t)])

    assert diop_linear(x + y - 3) == (t_0, 3 - t_0)

    assert base_solution_linear(0, 1, 2, t=None) == (0, 0)
    ans = (3*t - 1, -2*t + 1)
    assert base_solution_linear(4, 8, 12, t) == ans
    assert base_solution_linear(4, 8, 12, t=None) == tuple(_.subs(t, 0) for _ in ans)

    assert cornacchia(1, 1, 20) is None
    assert cornacchia(1, 1, 5) == set([(2, 1)])
    assert cornacchia(1, 2, 17) == set([(3, 2)])

    raises(ValueError, lambda: reconstruct(4, 20, 1))

    assert gaussian_reduce(4, 1, 3) == (1, 1)
    eq = -w**2 - x**2 - y**2 + z**2

    assert diop_general_pythagorean(eq) == \
        diop_general_pythagorean(-eq) == \
            (m1**2 + m2**2 - m3**2, 2*m1*m3,
            2*m2*m3, m1**2 + m2**2 + m3**2)

    assert check_param(S(3) + x/3, S(4) + x/2, S(2), x) == (None, None)
    assert check_param(S(3)/2, S(4) + x, S(2), x) == (None, None)
    assert check_param(S(4) + x, S(3)/2, S(2), x) == (None, None)

    assert _nint_or_floor(16, 10) == 2
    assert _odd(1) == (not _even(1)) == True
    assert _odd(0) == (not _even(0)) == False
    assert _remove_gcd(2, 4, 6) == (1, 2, 3)
    raises(TypeError, lambda: _remove_gcd((2, 4, 6)))
    assert sqf_normal(2 * 3**2 * 5, 2 * 5 * 11, 2 * 7**2 * 11)  == \
        (11, 1, 5)

    # it's ok if these pass some day when the solvers are implemented
    raises(NotImplementedError, lambda: diophantine(x**2 + y**2 + x*y + 2*y*z - 12))
    raises(NotImplementedError, lambda: diophantine(x**3 + y**2))
    assert diop_quadratic(x**2 + y**2 - 1**2 - 3**4) == \
        set([(-9, -1), (-9, 1), (-1, -9), (-1, 9), (1, -9), (1, 9), (9, -1), (9, 1)])
Esempio n. 12
0
def test_diop_sum_of_even_powers():
    eq = x ** 4 + y ** 4 + z ** 4 - 2673
    assert diop_solve(eq) == set([(3, 6, 6), (2, 4, 7)])
    assert diop_general_sum_of_even_powers(eq, 2) == set([(3, 6, 6), (2, 4, 7)])
    raises(NotImplementedError, lambda: diop_general_sum_of_even_powers(-eq, 2))
    neg = symbols("neg", negative=True)
    eq = x ** 4 + y ** 4 + neg ** 4 - 2673
    assert diop_general_sum_of_even_powers(eq) == set([(-3, 6, 6)])
    assert diophantine(x ** 4 + y ** 4 + 2) == set()
    assert diop_general_sum_of_even_powers(x ** 4 + y ** 4 - 2, limit=0) == set()
Esempio n. 13
0
def test_diop_sum_of_even_powers():
    eq = x**4 + y**4 + z**4 - 2673
    assert diop_solve(eq) == set([(3, 6, 6), (2, 4, 7)])
    assert diop_general_sum_of_even_powers(eq, 2) == set(
        [(3, 6, 6), (2, 4, 7)])
    raises(NotImplementedError, lambda: diop_general_sum_of_even_powers(-eq, 2))
    neg = symbols('neg', negative=True)
    eq = x**4 + y**4 + neg**4 - 2673
    assert diop_general_sum_of_even_powers(eq) == set([(-3, 6, 6)])
    assert diophantine(x**4 + y**4 + 2) == set()
    assert diop_general_sum_of_even_powers(x**4 + y**4 - 2, limit=0) == set()
Esempio n. 14
0
def diOp(bal, A, n_2):
    eqn = diop_solve(1000 * A + int(bal * 100) - 185 * D - 235 * B - 420 * L)
    expr = sympify((str(eqn[3])).replace("t_1", "n"))
    print(expr)
    ineq = list(solve(sympify(expr))[0].items())
    print(ineq)
    print(ineq.replace('t_0', 'A'))
    # x = eval(str(ineq.replace("t_0","1")))
    # print(floor(x)+2)
    # print(floor(x) - 2)
    print([eqn], ineq)
    sig, num = checkGL(ineq, eqn[-1], A, n_2)
    return eqn, ineq, sig, num
Esempio n. 15
0
def test_quadratic_simple_hyperbolic_case():
    # Simple Hyperbolic case: A = C = 0 and B != 0
    assert diop_solve(3 * x * y + 34 * x - 12 * y + 1) == set([(-133, -11), (5, -57)])
    assert diop_solve(6 * x * y + 2 * x + 3 * y + 1) == set([])
    assert diop_solve(-13 * x * y + 2 * x - 4 * y - 54) == set([(27, 0)])
    assert diop_solve(-27 * x * y - 30 * x - 12 * y - 54) == set([(-14, -1)])
    assert diop_solve(2 * x * y + 5 * x + 56 * y + 7) == set(
        [(-161, -3), (-47, -6), (-35, -12), (-29, -69), (-27, 64), (-21, 7), (-9, 1), (105, -2)]
    )
    assert diop_solve(6 * x * y + 9 * x + 2 * y + 3) == set([])
    assert diop_solve(x * y + x + y + 1) == set([(-1, t), (t, -1)])
    assert diophantine(48 * x * y)
Esempio n. 16
0
def test_quadratic_simple_hyperbolic_case():
    # Simple Hyperbolic case: A = C = 0 and B != 0
    assert diop_solve(3*x*y + 34*x - 12*y + 1) == \
        set([(-Integer(133), -Integer(11)), (Integer(5), -Integer(57))])
    assert diop_solve(6*x*y + 2*x + 3*y + 1) == set([])
    assert diop_solve(-13*x*y + 2*x - 4*y - 54) == set([(Integer(27), Integer(0))])
    assert diop_solve(-27*x*y - 30*x - 12*y - 54) == set([(-Integer(14), -Integer(1))])
    assert diop_solve(2*x*y + 5*x + 56*y + 7) == set([(-Integer(161), -Integer(3)),\
        (-Integer(47),-Integer(6)), (-Integer(35), -Integer(12)), (-Integer(29), -Integer(69)),\
        (-Integer(27), Integer(64)), (-Integer(21), Integer(7)),(-Integer(9), Integer(1)),\
        (Integer(105), -Integer(2))])
    assert diop_solve(6*x*y + 9*x + 2*y + 3) == set([])
    assert diop_solve(x*y + x + y + 1) == set([(-Integer(1), t), (t, -Integer(1))])
Esempio n. 17
0
def solutions_ok_quadratic(eq):
    """
    Determines whether solutions returned by diop_solve() satisfy the original
    equation.
    """
    s = diop_solve(eq)
    x, y = symbols("x, y", Integer=True)
    ok = True

    while len(s) and ok:
        u, v = s.pop()

        if simplify(simplify(Subs(eq, (x, y), (u, v)).doit())) != 0:
            ok = False
    return ok
Esempio n. 18
0
def test_quadratic_simple_hyperbolic_case():
    # Simple Hyperbolic case: A = C = 0 and B != 0
    assert diop_solve(3*x*y + 34*x - 12*y + 1) == \
        set([(-133, -11), (5, -57)])
    assert diop_solve(6 * x * y + 2 * x + 3 * y + 1) == set([])
    assert diop_solve(-13 * x * y + 2 * x - 4 * y - 54) == set([(27, 0)])
    assert diop_solve(-27 * x * y - 30 * x - 12 * y - 54) == set([(-14, -1)])
    assert diop_solve(2*x*y + 5*x + 56*y + 7) == set([(-161, -3),\
        (-47,-6), (-35, -12), (-29, -69),\
        (-27, 64), (-21, 7),(-9, 1),\
        (105, -2)])
    assert diop_solve(6 * x * y + 9 * x + 2 * y + 3) == set([])
    assert diop_solve(x * y + x + y + 1) == set([(-1, t), (t, -1)])
    assert diophantine(48 * x * y)
Esempio n. 19
0
def test_linear():
    assert diop_solve(x) == (0,)
    assert diop_solve(1*x) == (0,)
    assert diop_solve(3*x) == (0,)
    assert diop_solve(x + 1) == (-1,)
    assert diop_solve(2*x + 1) == (None,)
    assert diop_solve(2*x + 4) == (-2,)
    assert diop_solve(y + x) == (t_0, -t_0)
    assert diop_solve(y + x + 0) == (t_0, -t_0)
    assert diop_solve(y + x - 0) == (t_0, -t_0)
    assert diop_solve(0*x - y - 5) == (-5,)
    assert diop_solve(3*y + 2*x - 5) == (3*t_0 - 5, -2*t_0 + 5)
    assert diop_solve(2*x - 3*y - 5) == (-3*t_0 - 5, -2*t_0 - 5)
    assert diop_solve(-2*x - 3*y - 5) == (-3*t_0 + 5, 2*t_0 - 5)
    assert diop_solve(7*x + 5*y) == (5*t_0, -7*t_0)
    assert diop_solve(2*x + 4*y) == (2*t_0, -t_0)
    assert diop_solve(4*x + 6*y - 4) == (3*t_0 - 2, -2*t_0 + 2)
    assert diop_solve(4*x + 6*y - 3) == (None, None)
    assert diop_solve(0*x + 3*y - 4*z + 5) == (-4*t_0 + 5, -3*t_0 + 5)
    assert diop_solve(4*x + 3*y - 4*z + 5) == (t_0, -4*t_1 + 5, t_0 - 3*t_1 + 5)
    assert diop_solve(4*x + 2*y + 8*z - 5) == (None, None, None)
    assert diop_solve(5*x + 7*y - 2*z - 6) == (t_0, -7*t_0 - 2*t_1 + 6, -22*t_0 - 7*t_1 + 18)
    assert diop_solve(3*x - 6*y + 12*z - 9) == (2*t_0 + 3, t_0 + 2*t_1, t_1)
    assert diop_solve(6*w + 9*x + 20*y - z) == (t_0, t_1, -t_1 - t_2, 6*t_0 - 11*t_1 - 20*t_2)
Esempio n. 20
0
def test_univariate():
    assert diop_solve((x - 1)*(x - 2)**2) == set([(Integer(1),), (Integer(2),)])
    assert diop_solve((x - 1)*(x - 2)) == set([(Integer(1),), (Integer(2),)])
Esempio n. 21
0
def test_univariate():
    assert diop_solve((x - 1)*(x - 2)**2) == set([(1,), (2,)])
    assert diop_solve((x - 1)*(x - 2)) == set([(1,), (2,)])
Esempio n. 22
0
def test_linear():
    assert diop_solve(x) == (0,)
    assert diop_solve(1*x) == (0,)
    assert diop_solve(3*x) == (0,)
    assert diop_solve(x + 1) == (-1,)
    assert diop_solve(2*x + 1) == (None,)
    assert diop_solve(2*x + 4) == (-2,)
    assert diop_solve(y + x) == (t_0, -t_0)
    assert diop_solve(y + x + 0) == (t_0, -t_0)
    assert diop_solve(y + x - 0) == (t_0, -t_0)
    assert diop_solve(0*x - y - 5) == (-5,)
    assert diop_solve(3*y + 2*x - 5) == (3*t_0 - 5, -2*t_0 + 5)
    assert diop_solve(2*x - 3*y - 5) == (3*t_0 - 5, 2*t_0 - 5)
    assert diop_solve(-2*x - 3*y - 5) == (3*t_0 + 5, -2*t_0 - 5)
    assert diop_solve(7*x + 5*y) == (5*t_0, -7*t_0)
    assert diop_solve(2*x + 4*y) == (2*t_0, -t_0)
    assert diop_solve(4*x + 6*y - 4) == (3*t_0 - 2, -2*t_0 + 2)
    assert diop_solve(4*x + 6*y - 3) == (None, None)
    assert diop_solve(0*x + 3*y - 4*z + 5) == (4*t_0 + 5, 3*t_0 + 5)
    assert diop_solve(4*x + 3*y - 4*z + 5) == (t_0, 8*t_0 + 4*t_1 + 5, 7*t_0 + 3*t_1 + 5)
    assert diop_solve(4*x + 3*y - 4*z + 5, None) == (0, 5, 5)
    assert diop_solve(4*x + 2*y + 8*z - 5) == (None, None, None)
    assert diop_solve(5*x + 7*y - 2*z - 6) == (t_0, -3*t_0 + 2*t_1 + 6, -8*t_0 + 7*t_1 + 18)
    assert diop_solve(3*x - 6*y + 12*z - 9) == (2*t_0 + 3, t_0 + 2*t_1, t_1)
    assert diop_solve(6*w + 9*x + 20*y - z) == (t_0, t_1, t_1 + t_2, 6*t_0 + 29*t_1 + 20*t_2)

    # to ignore constant factors, use diophantine
    raises(TypeError, lambda: diop_solve(x/2))
Esempio n. 23
0
def test_linear():
    assert diop_solve(x) == (0, )
    assert diop_solve(1 * x) == (0, )
    assert diop_solve(3 * x) == (0, )
    assert diop_solve(x + 1) == (-1, )
    assert diop_solve(2 * x + 1) == (None, )
    assert diop_solve(2 * x + 4) == (-2, )
    assert diop_solve(y + x) == (t_0, -t_0)
    assert diop_solve(y + x + 0) == (t_0, -t_0)
    assert diop_solve(y + x - 0) == (t_0, -t_0)
    assert diop_solve(0 * x - y - 5) == (-5, )
    assert diop_solve(3 * y + 2 * x - 5) == (3 * t_0 - 5, -2 * t_0 + 5)
    assert diop_solve(2 * x - 3 * y - 5) == (-3 * t_0 - 5, -2 * t_0 - 5)
    assert diop_solve(-2 * x - 3 * y - 5) == (-3 * t_0 + 5, 2 * t_0 - 5)
    assert diop_solve(7 * x + 5 * y) == (5 * t_0, -7 * t_0)
    assert diop_solve(2 * x + 4 * y) == (2 * t_0, -t_0)
    assert diop_solve(4 * x + 6 * y - 4) == (3 * t_0 - 2, -2 * t_0 + 2)
    assert diop_solve(4 * x + 6 * y - 3) == (None, None)
    assert diop_solve(0 * x + 3 * y - 4 * z + 5) == (-4 * t_0 + 5,
                                                     -3 * t_0 + 5)
    assert diop_solve(4 * x + 3 * y - 4 * z + 5) == (t_0, -4 * t_1 + 5,
                                                     t_0 - 3 * t_1 + 5)
    assert diop_solve(4 * x + 2 * y + 8 * z - 5) == (None, None, None)
    assert diop_solve(5 * x + 7 * y - 2 * z - 6) == (t_0,
                                                     -7 * t_0 - 2 * t_1 + 6,
                                                     -22 * t_0 - 7 * t_1 + 18)
    assert diop_solve(3 * x - 6 * y + 12 * z - 9) == (2 * t_0 + 3,
                                                      t_0 + 2 * t_1, t_1)
    assert diop_solve(6 * w + 9 * x + 20 * y -
                      z) == (t_0, t_1, -t_1 - t_2,
                             6 * t_0 - 11 * t_1 - 20 * t_2)
Esempio n. 24
0
def test_quadratic_bugs():
    assert diop_solve(x**2 - y**2 - 2*x - 2*y) == set([(t, -t), (-t, -t - 2)])
    assert diop_solve(x**2 - 9*y**2 - 2*x - 6*y) == set([(-3*t + 2, -t), (3*t, -t)])
    assert diop_solve(4*x**2 - 9*y**2 - 4*x - 12*y - 3) == set([(-3*t - 3, -2*t - 3), (3*t + 1, -2*t - 1)])
Esempio n. 25
0
def test_linear():

    assert diop_solve(2 * x + 3 * y - 5) == (3 * t - 5, -2 * t + 5)
    assert diop_solve(3 * y + 2 * x - 5) == (3 * t - 5, -2 * t + 5)
    assert diop_solve(2 * x - 3 * y - 5) == (-3 * t - 5, -2 * t - 5)
    assert diop_solve(-2 * x - 3 * y - 5) == (-3 * t + 5, 2 * t - 5)
    assert diop_solve(7 * x + 5 * y) == (5 * t, -7 * t)
    assert diop_solve(2 * x + 4 * y) == (2 * t, -t)
    assert diop_solve(4 * x + 6 * y - 4) == (3 * t - 2, -2 * t + 2)
    assert diop_solve(4 * x + 6 * y - 3) == (None, None)
    assert diop_solve(4*x + 3*y -4*z + 5) == \
           (3*t + 4*z - 5, -4*t - 4*z + 5, z)
    assert diop_solve(4 * x + 2 * y + 8 * z - 5) == (None, None, None)
    assert diop_solve(5*x + 7*y - 2*z - 6) == \
           (7*t + 6*z + 18, -5*t - 4*z - 12, z)
    assert diop_solve(3*x - 6*y + 12*z - 9) == \
           (-2*t - 4*z + 3, -t, z)
    assert diop_solve(x + 3*y - 4*z + w - 6) == \
           (t, -t - 3*y + 4*z + 6, y, z)
Esempio n. 26
0
def test_univariate():

    assert diop_solve((x - 1) * (x - 2)**2) == set([(Integer(1), ),
                                                    (Integer(2), )])
    assert diop_solve((x - 1) * (x - 2)) == set([(Integer(1), ),
                                                 (Integer(2), )])
Esempio n. 27
0
def test_univariate():
    assert diop_solve((x - 1) * (x - 2)**2) == set([(1, ), (2, )])
    assert diop_solve((x - 1) * (x - 2)) == set([(1, ), (2, )])
Esempio n. 28
0
def test_linear():
    assert diop_solve(2*x + 3*y - 5) == {x: 3*t - 5, y: -2*t + 5}
    assert diop_solve(3*y + 2*x - 5) == {x: 3*t - 5, y: -2*t + 5}
    assert diop_solve(2*x - 3*y - 5) == {x: -3*t - 5, y: -2*t - 5}
    assert diop_solve(-2*x - 3*y - 5) == {x: -3*t + 5, y: 2*t - 5}
    assert diop_solve(7*x + 5*y) == {x: 5*t, y: -7*t}
    assert diop_solve(2*x + 4*y) == {x: 2*t, y: -t}
    assert diop_solve(4*x + 6*y - 4) == {x: 3*t - 2, y: -2*t + 2}
    assert diop_solve(4*x + 6*y - 3) == {x: None, y: None}
    assert diop_solve(4*x + 3*y -4*z + 5) == \
           {x: 3*t + 4*z - 5, y: -4*t - 4*z + 5, z: z}
    assert diop_solve(4*x + 2*y + 8*z - 5) == {x: None, y: None, z: None}
    assert diop_solve(5*x + 7*y - 2*z - 6) == \
           {x: 7*t + 6*z + 18, y: -5*t - 4*z - 12, z: z}
    assert diop_solve(3*x - 6*y + 12*z - 9) == \
           {x: -2*t - 4*z + 3, y: -t, z: z}
    assert diop_solve(x + 3*y - 4*z + w - 6) == \
           {w: t, x: -t - 3*y + 4*z + 6, y: y, z: z}
Esempio n. 29
0
def test_linear():
    assert diop_solve(x) == (0, )
    assert diop_solve(1 * x) == (0, )
    assert diop_solve(3 * x) == (0, )
    assert diop_solve(x + 1) == (-1, )
    assert diop_solve(2 * x + 1) == (None, )
    assert diop_solve(2 * x + 4) == (-2, )
    assert diop_solve(y + x) == (t_0, -t_0)
    assert diop_solve(y + x + 0) == (t_0, -t_0)
    assert diop_solve(y + x - 0) == (t_0, -t_0)
    assert diop_solve(0 * x - y - 5) == (-5, )
    assert diop_solve(3 * y + 2 * x - 5) == (3 * t_0 - 5, -2 * t_0 + 5)
    assert diop_solve(2 * x - 3 * y - 5) == (3 * t_0 - 5, 2 * t_0 - 5)
    assert diop_solve(-2 * x - 3 * y - 5) == (3 * t_0 + 5, -2 * t_0 - 5)
    assert diop_solve(7 * x + 5 * y) == (5 * t_0, -7 * t_0)
    assert diop_solve(2 * x + 4 * y) == (2 * t_0, -t_0)
    assert diop_solve(4 * x + 6 * y - 4) == (3 * t_0 - 2, -2 * t_0 + 2)
    assert diop_solve(4 * x + 6 * y - 3) == (None, None)
    assert diop_solve(0 * x + 3 * y - 4 * z + 5) == (4 * t_0 + 5, 3 * t_0 + 5)
    assert diop_solve(4 * x + 3 * y - 4 * z + 5) == (t_0,
                                                     8 * t_0 + 4 * t_1 + 5,
                                                     7 * t_0 + 3 * t_1 + 5)
    assert diop_solve(4 * x + 3 * y - 4 * z + 5, None) == (0, 5, 5)
    assert diop_solve(4 * x + 2 * y + 8 * z - 5) == (None, None, None)
    assert diop_solve(5 * x + 7 * y - 2 * z - 6) == (t_0,
                                                     -3 * t_0 + 2 * t_1 + 6,
                                                     -8 * t_0 + 7 * t_1 + 18)
    assert diop_solve(3 * x - 6 * y + 12 * z - 9) == (2 * t_0 + 3,
                                                      t_0 + 2 * t_1, t_1)
    assert diop_solve(6 * w + 9 * x + 20 * y -
                      z) == (t_0, t_1, t_1 + t_2,
                             6 * t_0 + 29 * t_1 + 20 * t_2)

    # to ignore constant factors, use diophantine
    raises(TypeError, lambda: diop_solve(x / 2))
Esempio n. 30
0
def test_linear():

    assert diop_solve(2*x + 3*y - 5) == (3*t - 5, -2*t + 5)
    assert diop_solve(3*y + 2*x - 5) == (3*t - 5, -2*t + 5)
    assert diop_solve(2*x - 3*y - 5) == (-3*t - 5, -2*t - 5)
    assert diop_solve(-2*x - 3*y - 5) == (-3*t + 5, 2*t - 5)
    assert diop_solve(7*x + 5*y) == (5*t, -7*t)
    assert diop_solve(2*x + 4*y) == (2*t, -t)
    assert diop_solve(4*x + 6*y - 4) == (3*t - 2, -2*t + 2)
    assert diop_solve(4*x + 6*y - 3) == (None, None)
    assert diop_solve(4*x + 3*y -4*z + 5) == \
           (3*t + 4*z - 5, -4*t - 4*z + 5, z)
    assert diop_solve(4*x + 2*y + 8*z - 5) == (None, None, None)
    assert diop_solve(5*x + 7*y - 2*z - 6) == \
           (7*t + 6*z + 18, -5*t - 4*z - 12, z)
    assert diop_solve(3*x - 6*y + 12*z - 9) == \
           (-2*t - 4*z + 3, -t, z)
    assert diop_solve(x + 3*y - 4*z + w - 6) == \
           (t, -t - 3*y + 4*z + 6, y, z)