thanks. Very subtle difference... definitely not a good idea to try
to double an existing variable as an accumulator too...
I reworked it to:
(define (pi4 accuracy)
(let helper ((k 0) (r 0))
(let ((this (* (/ (expt -1 k) (expt 4 k))
(+ (/ 2 (+ (* 4 k) 1))
If you systematically apply cps and then accumulator transformations, you get
this:
(define (pi3 accuracy)
(let helper ((k 0))
(let ((this (formula k)))
(if (< (abs this) accuracy)
this
(+ this (helper (+ k 1)))
(pi3 .1)
(define (pi3-cps accuracy)
(let he
2 matches
Mail list logo