Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (product term a next b)
- (cond
- ((> a b) 1)
- (else (* (term a) (product term (next a) next b)))))
- (define (i-product term a next b)
- (cond ((> a b) null)
- (else
- (define (iter a result)
- (cond ((> a b) result)
- (else (iter (next a) (* (term a) result)))))
- (iter a 1))))
- (define (identity x) x)
- (define (inc x) (+ 1 x))
- (define (multiply-integers a b) (i-product identity a inc b))
- (define (square x) (* x x))
- (define (compute-pi steps)
- (define (next n) (+ n 2.0))
- (* 8.0 (* steps 2) (/ (i-product square 4.0 next (* (- steps 1) 2))
- (i-product square 3.0 next (* steps 2)))))
- (define (factorial n)
- (define (next n) (+ n 1))
- (i-product identity 1 next n))
- (define (product term a next b)
- (if (> a b)
- 1
- (* (term a) (product term (next a) next b))))
- (define (i-product term a next b)
- (define (iter a result)
- (if (> a b)
- result
- (iter (next a) (* (term a) result))))
- (iter a 1))
- (define (compute-pi steps)
- (define (next n) (+ n 2))
- (* 8.0 (* steps 2) (/ (i-product square 4 next (* (- steps 1) 2))
- (i-product square 3 next (* steps 2)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement