Exercise 1.37

(define golden-ratio (/ (+ 1 (sqrt 5)) 2))

a. Recursive process:

scheme (define (cont-frac n d k) (define (helper i) (if (= i k) 0 (/ (n i) (+ (d i) (helper (+ i 1)))))) (helper 1))

b. Iterative process:

scheme (define (cont-frac n d k) (define (iter i acc) (if (zero? i) acc (iter (- i 1) (/ (n i) (+ (d i) acc))))) (iter k 0))

Approximating the inverse golden ratio using cont-frac:

(define (always-one i) 1.0)
(define (approx-igr k) (cont-frac always-one always-one k))

When \(k = 11\), the value is accurate to 4 decimal places:

(approx-igr 01) ~> 1.0
(approx-igr 02) ~> 0.5
(approx-igr 03) ~> 0.6666666666666666
(approx-igr 04) ~> 0.6000000000000001
(approx-igr 05) ~> 0.625
(approx-igr 06) ~> 0.6153846153846154
(approx-igr 07) ~> 0.6190476190476191
(approx-igr 08) ~> 0.6176470588235294
(approx-igr 09) ~> 0.6181818181818182
(approx-igr 10) ~> 0.6179775280898876
(approx-igr 11) ~> 0.6180555555555556

(define (round4 x) (* 1e-4 (truncate (* 1e4 x))))
(round4 (approx-igr 11)) ~> (round4 (/ golden-ratio))