(define (product term a next b) (if (> a b) 1 (* (term a) (product term (next a) next b)))) (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 10) ; ;Value: 3.2137849402931895 ; ;1 ]=> (approx-pi 100) ; ;Value: 3.1493784731686008 ; ;1 ]=> (approx-pi 1000) ; ;Value: 3.142377365093878 ; ;1 ]=> (approx-pi 1000000) ; ;Aborting!: maximum recursion depth exceeded ;