예제 #1
0
def test_find_DN():
    assert find_DN(x**2 - 2*x - y**2) == (1, 1)
    assert find_DN(x**2 - 3*y**2 - 5) == (3, 5)
    assert find_DN(x**2 - 2*x*y - 4*y**2 - 7) == (5, 7)
    assert find_DN(4*x**2 - 8*x*y - y**2 - 9) == (20, 36)
    assert find_DN(7*x**2 - 2*x*y - y**2 - 12) == (8, 84)
    assert find_DN(-3*x**2 + 4*x*y -y**2) == (1, 0)
    assert find_DN(-13*x**2 - 7*x*y + y**2 + 2*x - 2*y -14) == (101, -7825480)
예제 #2
0
def test_find_DN():
    assert find_DN(x**2 - 2*x - y**2) == (1, 1)
    assert find_DN(x**2 - 3*y**2 - 5) == (3, 5)
    assert find_DN(x**2 - 2*x*y - 4*y**2 - 7) == (5, 7)
    assert find_DN(4*x**2 - 8*x*y - y**2 - 9) == (20, 36)
    assert find_DN(7*x**2 - 2*x*y - y**2 - 12) == (8, 84)
    assert find_DN(-3*x**2 + 4*x*y -y**2) == (1, 0)
    assert find_DN(-13*x**2 - 7*x*y + y**2 + 2*x - 2*y -14) == (101, -7825480)
예제 #3
0
def test_find_DN():

    # Note that b**2 - 4*a*c > 0 and should not be a perfect square for this
    # method to work
    assert find_DN(x**2 - 2*x - y**2) == (1, 1)
    assert find_DN(x**2 - 3*y**2 - 5) == (3, 5)
    assert find_DN(x**2 - 2*x*y - 4*y**2 - 7) == (5, 7)
    assert find_DN(4*x**2 - 8*x*y - y**2 - 9) == (20, 36)
    assert find_DN(7*x**2 - 2*x*y - y**2 - 12) == (8, 84)
    assert find_DN(-3*x**2 + 4*x*y -y**2) == (1, 0)
    assert find_DN(-13*x**2 - 7*x*y + y**2 + 2*x - 2*y -14) == (101, -7825480)
예제 #4
0
# via find_DN
# find 2 initial solutions
# via brute force
# transform those two solutions into many solutions
# via brahmagupta
# transform pell solutions back to diophatine
# via A & B from transformation_to_DN
# find first solution pair that red+blue > 10**12

from sympy.solvers.diophantine import transformation_to_DN, diophantine, find_DN
from sympy import *

x, y = symbols("x, y", integer=True)
s = diophantine(x**2 - 2 * x * y - y**2 - x + y)
A, B = transformation_to_DN(s)
D, N = find_DN(s)


def pell(y, D, N):
    return ((D * y**2 + N)**.5)


answers = []
y = 0
while len(answers) < 2:
    y += 1
    if pell(y).is_integer():
        answers.append([pell(y, D, N), y])


def brahmagupta(z):