(define (product term a next b) (define (prod-iter a result) (if (> a b) result (prod-iter (next a) (* result (term a))))) (prod-iter a 1)) (define (id n) n) (define (inc n) (+ n 1)) (define (fact n) (product id 1 inc n)) (define (approx-pi n) (define (term-even a) (* 2 a)) (define (term-odd a) (+ 1 (* 2 a))) (* 4.0 (/ (* (product term-even 1 inc n) (product term-even 2 inc (+ 1 n))) (square (product term-odd 1 inc n))))) ;1 ]=> (approx-pi 1000) ; ;Value: 3.142377365093878 ; ;1 ]=> (approx-pi 10000) ; ;Value: 3.1416711865344635 ; ;1 ]=> (approx-pi 100000) ; ; -- time passes -- ; ;Value: 3.1416005075027056 ;