hermann on Mon, 18 Dec 2023 19:32:03 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Pell's equations and beyond


I stumbled over
https://math.stackexchange.com/a/3341210

on finding solution for Pell's equation x^2-D*y^2=1 for D=61.

Then I implemented my pell.gq (bottom) that did the job for any D.

Then I found this 2008 posting from Karim:
https://pari.math.u-bordeaux.fr/archives/pari-users-0811/msg00001.html


1) How do these commands from Karim's posting reveal x and y?

? quadunit(61)
%15 = 17 + 5*w
? K = bnfinit(x^2 - 61); K.fu
%16 = [Mod(-5/2*x + 39/2, x^2 - 61)]
?


pell.gp determines x and y given D and verifies result being 1:

pi@raspberrypi5:~ $ D=61 gp -q < pell.gp
period=11
CF=[7, 1, 4, 3, 1, 2, 2, 1, 3, 4, 1, 14, 1, 4, 3, 1, 2, 2, 1, 3, 5]
[x,y]=[1766319049, 226153980]
x^2-D*y^2=1
pi@raspberrypi5:~ $


2) Is there a simpler way to compute continued fraction period than calling "period()" from contfrac.gp in examples directory?


$ cat pell.gp
readvec("pari-2.15.4/examples/contfrac.gp");
D=eval(getenv("D"));
p=period(D);
print("period=",p);
CF=contfrac(sqrt(D),,2*p);
print("CF=",CF);
[x,y]=contfracpnqn(CF,2*p-1)[,2*p-1];
print("[x,y]=",[x,y]);
print("x^2-D*y^2=",x^2-D*y^2);
$


Regards,

Hermann.