On Thu, Feb 13, 2025 at 9:37 AM Alexander Burger <picolisp@software-lab.de> wrote:
> On Thu, Feb 13, 2025 at 08:50:16AM -0800, Lindsay Lawrence wrote: > > I think it is also a good a test/example of picolisp's support for > bignums. > > Indeed. The numbers in the 'E' environment get quite big. After ten > thousand digits of PI, 'S' and 'Q' have 145746 digits and 'R' has 145748 > digits. > > I verified that the first hundred thousand ouput digits are correct. > A bit of searching came up with the paper with the haskell version https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf Interestingly enough there is another version of PI in there, recursive, based on the Gosper series, that a faster... although it is based on a conjecture they haven't proven in that paper. The picolisp version of that one is below ('tco' is a nice fit for it as well!) (de piDigits (N) (default Q 1 R 180 S 60 I 2) (tco (Q R S I N) (let (U (* 3 (+ (* 3 I) 1) (+ (* 3 I) 2) ) Y (/ (+ (* Q (- (* 27 I) 12)) (* 5 R) ) (* 5 S) ) ) (prin Y) (if (or (not N) (gt0 N)) (tc (* 10 Q I (- (* 2 I) 1)) (* 10 U (- (+ (* Q (- (* 5 I) 2)) R) (* Y S) ) ) (* S U) (+ I 1) (dec N) ) ) ) ) ) On my machine that outputs digits of PI like below : (bench (out "pi-digits.1.txt" (piDigits 10000))) 8.751 sec -> NIL : (bench (out "pi-digits.1.txt" (piDigits 50000))) 117.745 sec -> NIL : (bench (out "pi-digits.1.txt" (piDigits 100000))) 613.212 sec -> NIL /Lindsay