# hw2 - ; #1. ; Exercise 1.31(a) (define (product term a next...

This preview shows pages 1–2. Sign up to view the full content.

; #1. ; ;;; Exercise 1.31(a) (define (product term a next b) (if (> a b) 1 (* (term a) (product term (next a) next b)))) ( (define (factorial b) (product * 1 inc b) (define (inc n) (+ n 1)) ( (define (pi-product a b) (define (pi-term x) (/ (* (+ a 1) (+ a 3)) (* (+ a 2) (+ a 2))) (define (pi-next x) (+ x 2)) (product pi-term a pi-next b)) ;;; Exercise 1.32(a) (define (accumulate combiner null-value term a next b) (if (> a b) null-value (combiner (term a) (accumulate combiner null-value term (next a) next b)))) ;;; Exercise 1.33 (define (filtered-accumulate combiner filter null-value term a next b) (if (> a b) null-value (if (filter a) (combiner (term a) (filtered-accumulate combiner filter null-value term (next a) next b)) (filtered-accumulate combiner filter null-value term (next a) next b)))) (define (square x) (* x x)) ( ; a.) ;(filtered-accumulate + prime? 0 square a inc b) ; ; b.) ;(filtered-accumulate * (lambda (i) (equal? (gcd i n) 1)) 1 (lambda (j) j) 1 inc n) ; ;;; Exercise 1.40

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/30/2010 for the course EECS 21281 taught by Professor Harvey during the Spring '10 term at University of California, Berkeley.

### Page1 / 2

hw2 - ; #1. ; Exercise 1.31(a) (define (product term a next...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online