Chapter 1, Building Abstractions with Procedures

Section - Formulating Abstractions with Higher-Order Procedures

Exercise 1.38


We need to generate denominators in the following way: 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1…

If we look closely, ignoring the first two terms of the series, then:

for all the terms which are not equal to .

Similarly note that the values can also be derived for this position:

if and its value is not equal to , than it is: .

Now we can easily write the procedure for computing using cont-frac from previous exercise:

1
2
3
4
5
6
7
8
9
(define (e n)
  (define (den k)
      (cond ((< k 3) k)
            ((= (remainder (- k 2) 3) 0) (* 2 (+ (quotient (- k 2) 3) 1)))
            (else 1)
      )
  )
  (+ 2 (cont-frac (lambda (x) 1.0) den n))
)

Note that we are also adding 2 as call to cont-frac returns .

Sample invocation using :

1
2
3
 
> (e 20)
2.718281828459045