On Fri, Feb 14, 2025 at 07:30:59AM -0800, Lindsay Lawrence wrote:
> On Thu, Feb 13, 2025 at 9:49 PM Lindsay Lawrence <
> lawrence.lindsayj...@gmail.com> wrote:
> 
> 
> > 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!)
> >
> 
> There was an error in the variable scoping of the function I posted in
> previous email. Here is the corrected version
> 
> (de makePi (N)
>   (let (G 1 R 180 S 60 I 2)
>    (tco (G R S I N)
>       (let
>          (U (* 3 (+ (* 3 I) 1) (+ (* 3 I) 2) )
>           Y (/ (+ (* G (- (* 27 I) 12)) (* 5 R) ) (* 5 S) ) )
>          (prin Y)
>          (if (or (not N) (gt0 N))
>             (tc
>                (* 10 G I (- (* 2 I) 1))
>                (* 10 U (- (+ (* G (- (* 5 I) 2)) R) (* Y S) ) )
>                (* S U)
>                (+ I 1)
>                (dec N) ) ) ) ) ))

Wow, that's cool! I'll measure it now :)


How about a coroutine version?

   (de pi (Flg)
      (if Flg
         (co 'pi
            (yield 3)
            (yield ".")
            (let (G 60  R 13440  S 10080  I 3)
               (tco (G R S I)
                  (let
                     (U (* 3 (inc (* 3 I)) (+ (* 3 I) 2))
                        Y (/ (+ (* G (- (* 27 I) 12)) (* 5 R) ) (* 5 S)) )
                     (yield Y)
                     (tc
                        (* 10 G I (dec (* 2 I)))
                        (* 10 U (- (+ (* G (- (* 5 I) 2)) R) (* Y S )))
                        (* S U)
                        (inc I) ) ) ) ) )
         (co 'pi) ) )

   (de prinPi (N)
      (do N
         (prin (pi T)) )
      (pi)
      (prinl) )

☺/ A!ex

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to