1 (define (search f neg-point pos-point)
2 (let ((midpoint (average neg-point pos-point)))
3 (if (close-enough? neg-point pos-point)
5 (let ((test-value (f midpoint)))
6 (cond ((positive? test-value)
7 (search f neg-point midpoint))
8 ((negative? test-value)
9 (search f midpoint pos-point))
11 (define (close-enough? x y)
12 (< (abs (- x y)) 0.001))
14 (define (half-interval-method f a b)
17 (cond ((and (negative? a-value) (positive? b-value))
19 ((and (negative? b-value) (positive? a-value))
22 (error "Values are not of opposite sign" a b)))))
23 (define tolerance 0.00001)
24 (define (fixed-point f first-guess)
25 (define (close-enough? v1 v2)
26 (< (abs (- v1 v2)) tolerance))
28 (let ((next (f guess)))
29 (if (close-enough? guess next)
34 (fixed-point (lambda (y) (+ (sin y) (cos y)))
38 (fixed-point (lambda (y) (average y (/ x y)))
44 (define golden-ratio (fixed-point (lambda (x) (+ 1 (/ 1 x)))
47 (define (test-case actual expected)
50 (format #t "Actual: ~A Expected: ~A" actual expected))
52 (test-case golden-ratio (/ (+ 1.0 (sqrt 5.0)) 2.0))