Exemplo n.º 1
0
def test_diop_general_sum_of_squares_quick():
    for i in range(3, 10):
        assert check_solutions(sum(i**2 for i in symbols(':%i' % i)) - i)
    raises(ValueError, lambda: _diop_general_sum_of_squares((x, y), 2))
    assert _diop_general_sum_of_squares((x, y, z), -2) == set()
    eq = x**2 + y**2 + z**2 - (1 + 4 + 9)
    assert diop_general_sum_of_squares(eq) == \
        set([(1, 2, 3)])
    eq = u**2 + v**2 + x**2 + y**2 + z**2 - 1313
    assert len(diop_general_sum_of_squares(eq, 3)) == 3
    # issue 11016
    var = symbols(':5') + (symbols('6', negative=True), )
    eq = Add(*[i**2 for i in var]) - 112

    base_soln = set([(0, 1, 1, 5, 6, -7), (1, 1, 1, 3, 6, -8),
                     (2, 3, 3, 4, 5, -7), (0, 1, 1, 1, 3, -10),
                     (0, 0, 4, 4, 4, -8), (1, 2, 3, 3, 5, -8),
                     (0, 1, 2, 3, 7, -7), (2, 2, 4, 4, 6, -6),
                     (1, 1, 3, 4, 6, -7), (0, 2, 3, 3, 3, -9),
                     (0, 0, 2, 2, 2, -10), (1, 1, 2, 3, 4, -9),
                     (0, 1, 1, 2, 5, -9), (0, 0, 2, 6, 6, -6),
                     (1, 3, 4, 5, 5, -6), (0, 2, 2, 2, 6, -8),
                     (0, 3, 3, 3, 6, -7), (0, 2, 3, 5, 5, -7),
                     (0, 1, 5, 5, 5, -6)])
    assert diophantine(eq) == base_soln
    assert len(diophantine(eq, permute=True)) == 196800

    # handle negated squares with signsimp
    assert diophantine(12 - x**2 - y**2 - z**2) == set([(2, 2, 2)])
    # diophantine handles simplification, so classify_diop should
    # not have to look for additional patterns that are removed
    # by diophantine
    eq = a**2 + b**2 + c**2 + d**2 - 4
    raises(NotImplementedError, lambda: classify_diop(-eq))
Exemplo n.º 2
0
def test_diop_general_sum_of_squares_quick():
    for i in range(3, 10):
        assert check_solutions(sum(i**2 for i in symbols(':%i' % i)) - i)
    raises(ValueError, lambda: _diop_general_sum_of_squares((x, y), 2))
    assert _diop_general_sum_of_squares((x, y, z), -2) == set()
    eq = x**2 + y**2 + z**2 - (1 + 4 + 9)
    assert diop_general_sum_of_squares(eq) == \
        set([(1, 2, 3)])
    eq = u**2 + v**2 + x**2 + y**2 + z**2 - 1313
    assert len(diop_general_sum_of_squares(eq, 3)) == 3
    # issue 11016
    var = symbols(':5') + (symbols('6', negative=True),)
    eq = Add(*[i**2 for i in var]) - 112
    assert diophantine(eq) == set(
        [(0, 1, 1, 5, 6, -7), (1, 1, 1, 3, 6, -8), (2, 3, 3, 4,
        5, -7), (0, 1, 1, 1, 3, -10), (0, 0, 4, 4, 4, -8), (1, 2, 3,
        3, 5, -8), (0, 1, 2, 3, 7, -7), (2, 2, 4, 4, 6, -6), (1, 1,
        3, 4, 6, -7), (0, 2, 3, 3, 3, -9), (0, 0, 2, 2, 2, -10), (1,
        1, 2, 3, 4, -9), (0, 1, 1, 2, 5, -9), (0, 0, 2, 6, 6, -6),
        (1, 3, 4, 5, 5, -6), (0, 2, 2, 2, 6, -8), (0, 3, 3, 3, 6,
        -7), (0, 2, 3, 5, 5, -7), (0, 1, 5, 5, 5, -6)])
    # handle negated squares with signsimp
    assert diophantine(12 - x**2 - y**2 - z**2) == set([(2, 2, 2)])
    # diophantine handles simplification, so classify_diop should
    # not have to look for additional patterns that are removed
    # by diophantine
    eq = a**2 + b**2 + c**2 + d**2 - 4
    raises(NotImplementedError, lambda: classify_diop(-eq))
Exemplo n.º 3
0
def test_classify_diop():
    raises(TypeError, lambda: classify_diop(x**2/3 - 1))
    raises(ValueError, lambda: classify_diop(1))
    raises(NotImplementedError, lambda: classify_diop(w*x*y*z - 1))
    assert classify_diop(14*x**2 + 15*x - 42) == (
        [x], {1: -42, x: 15, x**2: 14}, 'univariate')
    assert classify_diop(x*y + z) == (
        [x, y, z], {x*y: 1, z: 1}, 'inhomogeneous_ternary_quadratic')
    assert classify_diop(x*y + z + w + x**2) == (
        [w, x, y, z], {x*y: 1, w: 1, x**2: 1, z: 1}, 'inhomogeneous_general_quadratic')
    assert classify_diop(x*y + x*z + x**2 + 1) == (
        [x, y, z], {x*y: 1, x*z: 1, x**2: 1, 1: 1}, 'inhomogeneous_general_quadratic')
    assert classify_diop(x*y + z + w + 42) == (
        [w, x, y, z], {x*y: 1, w: 1, 1: 42, z: 1}, 'inhomogeneous_general_quadratic')
    assert classify_diop(x*y + z*w) == (
        [w, x, y, z], {x*y: 1, w*z: 1}, 'homogeneous_general_quadratic')
    assert classify_diop(x*y**2 + 1) == (
        [x, y], {x*y**2: 1, 1: 1}, 'cubic_thue')
Exemplo n.º 4
0
def test_classify_diop():
    raises(TypeError, lambda: classify_diop(x**2 / 3 - 1))
    raises(ValueError, lambda: classify_diop(1))
    raises(NotImplementedError, lambda: classify_diop(w * x * y * z - 1))
    assert classify_diop(14 * x**2 + 15 * x - 42) == ([x], {
        1: -42,
        x: 15,
        x**2: 14
    }, 'univariate')
    assert classify_diop(x * y + z) == ([x, y, z], {
        x * y: 1,
        z: 1
    }, 'inhomogeneous_ternary_quadratic')
    assert classify_diop(x * y + z + w + x**2) == ([w, x, y, z], {
        x * y: 1,
        w: 1,
        x**2: 1,
        z: 1
    }, 'inhomogeneous_general_quadratic')
    assert classify_diop(x * y + x * z + x**2 + 1) == ([x, y, z], {
        x * y: 1,
        x * z: 1,
        x**2: 1,
        1: 1
    }, 'inhomogeneous_general_quadratic')
    assert classify_diop(x * y + z + w + 42) == ([w, x, y, z], {
        x * y: 1,
        w: 1,
        1: 42,
        z: 1
    }, 'inhomogeneous_general_quadratic')
    assert classify_diop(x * y + z * w) == ([w, x, y, z], {
        x * y: 1,
        w * z: 1
    }, 'homogeneous_general_quadratic')
    assert classify_diop(x * y**2 + 1) == ([x, y], {
        x * y**2: 1,
        1: 1
    }, 'cubic_thue')
Exemplo n.º 5
0
def test_classify_diop():
    raises(TypeError, lambda: classify_diop(x ** 2 / 3 - 1))
    raises(ValueError, lambda: classify_diop(1))
    raises(NotImplementedError, lambda: classify_diop(w * x * y * z - 1))
    raises(NotImplementedError, lambda: classify_diop(x ** 3 + y ** 3 + z ** 4 - 90))
    assert classify_diop(14 * x ** 2 + 15 * x - 42) == ([x], {1: -42, x: 15, x ** 2: 14}, "univariate")
    assert classify_diop(x * y + z) == ([x, y, z], {x * y: 1, z: 1}, "inhomogeneous_ternary_quadratic")
    assert classify_diop(x * y + z + w + x ** 2) == (
        [w, x, y, z],
        {x * y: 1, w: 1, x ** 2: 1, z: 1},
        "inhomogeneous_general_quadratic",
    )
    assert classify_diop(x * y + x * z + x ** 2 + 1) == (
        [x, y, z],
        {x * y: 1, x * z: 1, x ** 2: 1, 1: 1},
        "inhomogeneous_general_quadratic",
    )
    assert classify_diop(x * y + z + w + 42) == (
        [w, x, y, z],
        {x * y: 1, w: 1, 1: 42, z: 1},
        "inhomogeneous_general_quadratic",
    )
    assert classify_diop(x * y + z * w) == ([w, x, y, z], {x * y: 1, w * z: 1}, "homogeneous_general_quadratic")
    assert classify_diop(x * y ** 2 + 1) == ([x, y], {x * y ** 2: 1, 1: 1}, "cubic_thue")
    assert classify_diop(x ** 4 + y ** 4 + z ** 4 - (1 + 16 + 81)) == (
        [x, y, z],
        {1: -98, x ** 4: 1, z ** 4: 1, y ** 4: 1},
        "general_sum_of_even_powers",
    )