| hermann on Tue, 15 Sep 2026 23:36:52 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Is my understanding on how my 0-based vector access works correct? |
I implemented "fundsol(d)" in pell.gp below, to determine fundamental solution
of Pell equation x^2-d*y^2=1 per Corollary 6.42 of script.From gemini.google.com I learned the PARI/GP way based on quaduint() to do that in fundpari(d).
With latest commit https://github.com/Hermann-SW/uni-heidelberg/commit/7133265e4c49ebba99cfe98fef912ea17ba4588fI implemented 0-based vector access so that fundsol() matches the Corollary a_i notation that is 0-based for continued fractions (in proof the lecturer used -2 based as well sometimes).
So bottom code works, an "a(i)" is able to access cf vector 0-based. This worked only after quite some time and error. I want to get confirmation or correction on my understanding.When cf variable gets assigned it is allocated as global variable because it is not in "my(...)"?
a(i) then can access that global cf variable? Unrelated, but might be helpful for people working with Graphviz.For above lecture I developed "Latex labels for Graphviz" project as well:
https://gist.github.com/Hermann-SW/12c7644ac0c75b4eb019f76c3f023fe5
Regards,
Hermann.
hermann@8840hs:~/uni-heidelberg/scripts$ gp -q pell.gp
? for(i=2,80,if(!issquare(i),print1(fundsol(i)==fundpari(i))))
111111111111111111111111111111111111111111111111111111111111111111111111
? [x,y]=fundsol(21)
[55, 12]
? x^2-21*y^2==1
1
?
assert(b)={if(!(b),error())}
digmat(a)=[a,1;1,0];
find_first(v, x)={for(i=1, #v, if(v[i]==x, return(i));); return(0); }
a(i)=cf[i+1];
fundsol(d)={
assert(type(d)=="t_INT" && !issquare(d));
cf=contfrac(sqrt(d)); my(h=find_first(cf,2*a(0))-1); if(h%2, h*=2);
my(d=digmat(a(0))); for(i=1, h-1, d*=digmat(a(i))); d[,1]~
};
fundpari(d)={
assert(type(d)=="t_INT" && !issquare(d));
my(u=quadunit(4*d)); if(norm(u)<0, u*=u); [real(u), imag(u)];
}