CoCalc Public Filessympy-diophante.ipynbOpen with one click!
Author: Harald Schilly
Views : 118
Compute Environment: Ubuntu 18.04 (Deprecated)

Quadratische Diophantische Gleichung in Sympy

Frage: https://twitter.com/neuwirthe/status/990882407661391872

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
{(12023(24023+1151)t+11512(24023+1151)t+12023(24023+1151)t+11512(24023+1151)t,60(24023+1151)t+11512392(24023+1151)t11512392(24023+1151)t60(24023+1151)t),(11512(24023+1151)t+12023(24023+1151)t11512(24023+1151)t12023(24023+1151)t,11512392(24023+1151)t+60(24023+1151)t+60(24023+1151)t+11512392(24023+1151)t)}\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
12023(24023+1151)t+11512(24023+1151)t+12023(24023+1151)t+11512(24023+1151)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} + \frac{1151}{2} \left(240 \sqrt{23} + 1151\right)^{t}
In [21]:
ysol
60(24023+1151)t+11512392(24023+1151)t11512392(24023+1151)t60(24023+1151)t- 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})
11511151
In [24]:
ysol.subs({t : 0})
120-120

Probe

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

Weitere Lösung mit t = 1?

In [11]:
x2 = xsol.subs({t : 1}) y2 = ysol.subs({t : 1})
In [12]:
x2
12023(24023+1151)+12023(24023+1151)+1324801- 120 \sqrt{23} \left(- 240 \sqrt{23} + 1151\right) + 120 \sqrt{23} \left(240 \sqrt{23} + 1151\right) + 1324801
In [13]:
y2
11512392(24023+1151)138120+11512392(24023+1151)- \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(11512392(24023+1151)138120+11512392(24023+1151))2+(12023(24023+1151)+12023(24023+1151)+1324801)2- 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()
26496012649601
In [16]:
y2.simplify()
276240-276240

Probe: Ja, passt auch.

In [17]:
lhs2.simplify()
11
In [ ]: