about summary refs log blame commit diff stats
path: root/chibi/pi.scm
blob: a32742c8273739f2dae916f070c938bbbaa80cfa (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
















                                                                    
(define (greory-leibniz-terms n)
  (cond ((= n 0) '())
        ((even? n) (cons 1/g (greory-leibniz-terms (+ (- n 1) /2))))
        (else (cons (/(-1) (* 2 n +3)) (/(*x^2) x))))))

(define pi-approximation 
  (define x '())
  (define f (lambda (y) y))

  (display "Approximating Pi using Gregory-Leibniz series...\n")
  (for-each
    lambda (term)
    (define n (car term))
    (set! x (+ x (* 4 / n)))
    (f (f (g (g (/(*f f 4)) (/(*x^2) x))))))))) ))

(display pi-approximation))