Chapter 3, Modularity, Objects, and State
Exercise 3.61
1
2
3
4
5
6
(define (invert-unit-series s)
(cons-stream 1
(scale-stream
(mul-series (stream-cdr s)
(invert-unit-series s))
-1)))
Test:
The product of a series by itself should return 1.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
1 ]=> (define rexp (invert-unit-series exp-series))
;Value: memo-proc
1 ]=>
;Value: rexp
1 ]=> (stream-ref rexp 0)
;Value: 1
1 ]=> (stream-ref rexp 1)
;Value: -1
1 ]=> (stream-ref rexp 2)
;Value: 1/2
1 ]=> (define prod (mul-series exp-series rexp))
;Value: prod
1 ]=> (stream-ref prod 0)
;Value: 1
1 ]=> (stream-ref prod 1)
;Value: 0
1 ]=> (stream-ref prod 2)
;Value: 0
1 ]=> (stream-ref prod 3)
;Value: 0