hermann on Wed, 16 Sep 2026 19:36:13 +0200


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

Re: Is my understanding on how my 0-based vector access works correct?


On 2026-09-16 12:07, Bill Allombert wrote:
Yes, but you could also do
  my(cf=contfrac(sqrt(d)), a=i->cf[i+1]);
(this way cf is part of the context of the closure a)

Thanks, that is definitely better and I changed to it. Also the find
function now is named ..._m1() and returns 0-based positions for use with a(i):
https://github.com/Hermann-SW/uni-heidelberg/blob/main/scripts/pell.gp

In you code, you are computing contfrac(sqrt(d)) using floating point.
? contfrac(sqrt(23))
%5 = [4,1,3,1,8,1,3,1,8,1,3,1,8,1,3,1,8,1,3,1,8,1,3,1,8,1,3,1,8,1,3,1,8,1,3,1,8,1,3,1,8,1,3,1,9]
With 2.18.1, you can compute it exactly:
? contfrac(quadgen(4*23))
%8 = [[4],[1,3,1,8]]
which means it is 4 followed by 1,3,1,8 repeating infinitely.

That is great, not for code for oeis.org or a repo because
it will not work for backlevel versions of gp for others.

But really impressive for my work, succeeds where previous approach just fails!

hermann@8840hs:~/pari-2.18.1.alpha$ ./gp -q
? contfrac(sqrt(nextprime(10^5)))
[316, 4, 3, 3, 10, 1, 3, 1, 5, 2, 2, 9, 30, 90, 3, 7, 2, 1, 1, 1, 2, 32, 1, 9, 1, 2, 1, 210]
? contfrac(quadgen(4*nextprime(10^5)))
[[316], [4, 3, 3, 10, 1, 3, 1, 5, 2, 2, 9, 30, 90, 3, 7, 2, 1, 1, 1, 2, 32, 1, 9, 1, 2, 1, 210, 12, 1, 9, 3, 1, 1, 2, 18, 4, 1, 2, 2, 1, 9, 2, 1, 29, 2, 3, 1, 1, 1, 3, 1, 5, 2, 10, 1, 1, 1, 2, 1, 10, 1, 69, 2, 1, 3, 1, 1, 1, 2, 1, 3, 6, 2, 5, 1, 2, 1, 4, 3, 1, 1, 2, 1, 3, 1, 1, 9, 2, 11, 1, 12, 1, 1, 6, 3, 1, 1, 5, 34, 1, 22, 2, 4, 1, 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