1.3.1

> 
(define (cube x) (* x x x))

cube

> 
(define (sum-integers a b)
  (if (> a b)
      0
      (+ a (sum-integers (+ a 1) b))))

sum-integers

> 
(define (sum-cubes a b)
  (if (> a b)
      0
      (+ (cube a) (sum-cubes (+ a 1) b))))

sum-cubes

> 
(define (pi-sum a b)
  (if (> a b)
      0
      (+ (/ 1.0 (* a (+ a 2))) (pi-sum (+ a 4) b))))

pi-sum

> 
(sum-integers 1 3)

6

> 
(sum-cubes 1 3)

36

> 
(pi-sum 1 3)

0.3333333333333333

> 
(define (sum term a next b)
  (if (> a b)
      0
      (+ (term a)
         (sum term (next a) next b))))

sum

> 
(define (inc n) (+ n 1))

inc

> 
(define (sum-cubes-2 a b)
  (sum cube a inc b))

sum-cubes-2

> 
(sum-cubes-2 1 3)

36

> 
(define (identity x) x)

identity

> 
(define (sum-integers-2 a b)
  (sum identity a inc b))

sum-integers-2

> 
(sum-integers-2 1 10)

55

> 
(define (pi-sum-2 a b)
  (define (pi-term x)
    (/ 1.0 (* x (+ x 2))))
  (define (pi-next x)
    (+ x 4))
  (sum pi-term a pi-next b))

pi-sum-2

> 
(* 8 (pi-sum-2 1 1000))

3.139592655589783

> 

1.3.2

> 
(define (square x) (* x x))

square

> 
((lambda (x y z) (+ x y (square z))) 1 2 3)

12

> 

1.3.3

> 
(define (average x y) (/ (+ x y) 2))

average

> 
(define (search f neg-point pos-point)
  (let ((midpoint (average neg-point pos-point)))
    (if (close-enough? neg-point pos-point)
        midpoint
        (let ((test-value (f midpoint)))
          (cond ((positive? test-value)
                 (search f neg-point midpoint))
                ((negative? test-value)
                 (search f midpoint pos-point))
                (else midpoint))))))

search

> 
(define (close-enough? x y)
  (< (abs (- x y)) 0.001))

close-enough?

> 
(define (half-interval-method f a b)
  (let ((a-value (f a))
        (b-value (f b)))
    (cond ((and (negative? a-value) (positive? b-value))
           (search f a b))
          ((and (negative? b-value) (positive? a-value))
           (search f b a))
          (else
           (error "Values are not of opposite sign" a b)))))

half-interval-method

> 
(half-interval-method sin 2.0 4.0)

3.14111328125

> 
(half-interval-method (lambda (x) (- (* x x x) (* 2 x) 3))
                      1.0
                      2.0)

1.89306640625

> 
(define tolerance 0.00001)

0.00001

> 
(define (fixed-point f first-guess)
  (define (close-enough? v1 v2)
    (< (abs (- v1 v2)) tolerance))
  (define (try guess)
    (let ((next (f guess)))
      (if (close-enough? guess next)
          next
          (try next))))
  (try first-guess))

fixed-point

> 
(fixed-point cos 1.0)

0.7390822985224024

> 
(fixed-point (lambda (y) (+ (sin y) (cos y)))
             1.0)

1.2587315962971173

>