1 (define tolerance 0.00001)
2 (define (fixed-point f first-guess)
3 (define (close-enough? v1 v2)
4 (< (abs (- v1 v2)) tolerance))
6 (let ((next (f guess)))
7 (if (close-enough? guess next)
14 (define (average-damp f)
15 (lambda (x) (average x (f x))))
16 (define (fixed-point-of-transform g transform guess)
17 (fixed-point (transform g) guess))
19 (fixed-point-of-transform (lambda (y) (/ x y))
23 (fixed-point-of-transform (lambda (y) (/ x (square y)))
31 (define (test-case actual expected)
34 (format #t "Actual: ~A Expected: ~A" actual expected))
36 (define (square x) (* x x))
37 (define (inc x) (1+ x))
38 ;; (test-case ((compose square inc) 6) 49)
40 (define (repeated f n)
43 (compose f (repeated f (- n 1)))))
45 ;; (test-case ((repeated square 2) 5) 625)
46 (test-case (cube-root 5) 1.70997594668)
49 ;; Exercise 1.44. The idea of smoothing a function is an important concept in signal processing. If f is a function and dx is some small number, then the smoothed version of f is the function whose value at a point x is the average of f(x - dx), f(x), and f(x + dx). Write a procedure smooth that takes as input a procedure that computes f and returns a procedure that computes the smoothed f. It is sometimes valuable to repeatedly smooth a function (that is, smooth the smoothed function, and so on) to obtained the n-fold smoothed function. Show how to generate the n-fold smoothed function of any given function using smooth and repeated from exercise 1.43.
59 (define (n-fold-smooth f n)
60 ((repeated smooth n) f))