CoCalc Shared Filessympy-diophante.ipynb
Author: Harald Schilly
Views : 45

# Quadratische Diophantische Gleichung in Sympy

Mittels SymPy in Python 3

In [1]:
from sympy import init_printing init_printing()
In [2]:
from sympy import pprint, solve, S, Eq, symbols, simplify x, y = symbols('x, y', integer=True)
In [3]:
from sympy.solvers.diophantine import diophantine

Allgemeine Lösung mittels Diophante Modul:

In [4]:
sol = diophantine(Eq(x**2 - 92 * y**2, 1)) sol
$\left\{\left ( - 120 \sqrt{23} \left(- 240 \sqrt{23} + 1151\right)^{t} + \frac{1151}{2} \left(- 240 \sqrt{23} + 1151\right)^{t} + 120 \sqrt{23} \left(240 \sqrt{23} + 1151\right)^{t} + \frac{1151}{2} \left(240 \sqrt{23} + 1151\right)^{t}, \quad - 60 \left(- 240 \sqrt{23} + 1151\right)^{t} + \frac{1151 \sqrt{23}}{92} \left(- 240 \sqrt{23} + 1151\right)^{t} - \frac{1151 \sqrt{23}}{92} \left(240 \sqrt{23} + 1151\right)^{t} - 60 \left(240 \sqrt{23} + 1151\right)^{t}\right ), \left ( - \frac{1151}{2} \left(- 240 \sqrt{23} + 1151\right)^{t} + 120 \sqrt{23} \left(- 240 \sqrt{23} + 1151\right)^{t} - \frac{1151}{2} \left(240 \sqrt{23} + 1151\right)^{t} - 120 \sqrt{23} \left(240 \sqrt{23} + 1151\right)^{t}, \quad - \frac{1151 \sqrt{23}}{92} \left(- 240 \sqrt{23} + 1151\right)^{t} + 60 \left(- 240 \sqrt{23} + 1151\right)^{t} + 60 \left(240 \sqrt{23} + 1151\right)^{t} + \frac{1151 \sqrt{23}}{92} \left(240 \sqrt{23} + 1151\right)^{t}\right )\right\}$

Herauspicken der ersten Lösung

In [20]:
xsol, ysol = list(sol)[0] xsol
$- 120 \sqrt{23} \left(- 240 \sqrt{23} + 1151\right)^{t} + \frac{1151}{2} \left(- 240 \sqrt{23} + 1151\right)^{t} + 120 \sqrt{23} \left(240 \sqrt{23} + 1151\right)^{t} + \frac{1151}{2} \left(240 \sqrt{23} + 1151\right)^{t}$
In [21]:
ysol
$- 60 \left(- 240 \sqrt{23} + 1151\right)^{t} + \frac{1151 \sqrt{23}}{92} \left(- 240 \sqrt{23} + 1151\right)^{t} - \frac{1151 \sqrt{23}}{92} \left(240 \sqrt{23} + 1151\right)^{t} - 60 \left(240 \sqrt{23} + 1151\right)^{t}$
In [ ]:

Ersetzen des freien Parameters mit 0

In [22]:
t = xsol.free_symbols.pop()
In [23]:
xsol.subs({t : 0})
$1151$
In [24]:
ysol.subs({t : 0})
$-120$

## Probe

In [10]:
(x**2 - 92 * y**2).subs({x : -1151, y : 120})
$1$
In [ ]:

## Weitere Lösung mit t = 1?

In [11]:
x2 = xsol.subs({t : 1}) y2 = ysol.subs({t : 1})
In [12]:
x2
$- 120 \sqrt{23} \left(- 240 \sqrt{23} + 1151\right) + 120 \sqrt{23} \left(240 \sqrt{23} + 1151\right) + 1324801$
In [13]:
y2
$- \frac{1151 \sqrt{23}}{92} \left(240 \sqrt{23} + 1151\right) - 138120 + \frac{1151 \sqrt{23}}{92} \left(- 240 \sqrt{23} + 1151\right)$
In [18]:
lhs2 = (x**2 - 92 * y**2).subs({x : x2, y : y2}) lhs2
$- 92 \left(- \frac{1151 \sqrt{23}}{92} \left(240 \sqrt{23} + 1151\right) - 138120 + \frac{1151 \sqrt{23}}{92} \left(- 240 \sqrt{23} + 1151\right)\right)^{2} + \left(- 120 \sqrt{23} \left(- 240 \sqrt{23} + 1151\right) + 120 \sqrt{23} \left(240 \sqrt{23} + 1151\right) + 1324801\right)^{2}$
In [15]:
x2.simplify()
$2649601$
In [16]:
y2.simplify()
$-276240$

## Probe: Ja, passt auch.

In [17]:
lhs2.simplify()
$1$
In [ ]: