Chapter 3, Modularity, Objects, and State

Exercise 3.65


1
2
3
4
5
6
7
8
9
10
11
12
(define ln2-stream
  (partial-sums (ln2-summands 1)))

(define ln2-stream-euler
  (euler-transform ln2-stream))

(define ln2-accelerated
  (accelerated-sequence euler-transform ln2-stream))

(define (ln2-summands n)
  (cons-stream (/ 1.0 n)
               (stream-map - (ln2-summands (+ n 1)))))

Output:

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
1 ]=> (stream-ref ln2-stream 0)

;Value: memo-proc

1 ]=> 
;Value: 1.

1 ]=> (stream-ref ln2-stream 1)

;Value: .5

1 ]=> (stream-ref ln2-stream 2)

;Value: .8333333333333333

1 ]=> (stream-ref ln2-stream 3)

;Value: .5833333333333333

1 ]=> (stream-ref ln2-stream 4)

;Value: .7833333333333332

1 ]=> (stream-ref ln2-stream 5)

;Value: .6166666666666666

1 ]=> (stream-ref ln2-stream 6)

;Value: .7595238095238095

1 ]=> (stream-ref ln2-stream 7)

;Value: .6345238095238095

1 ]=> (stream-ref ln2-stream 8)

;Value: .7456349206349207

1 ]=> (stream-ref ln2-stream 9)

;Value: .6456349206349207

1 ]=> (stream-ref ln2-stream 10)

;Value: .7365440115440116

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

1 ]=> (stream-ref ln2-stream-euler 0)

;Value: .7

1 ]=> (stream-ref ln2-stream-euler 1)

;Value: .6904761904761905

1 ]=> (stream-ref ln2-stream-euler 2)

;Value: .6944444444444444

1 ]=> (stream-ref ln2-stream-euler 3)

;Value: .6924242424242424

1 ]=> (stream-ref ln2-stream-euler 4)

;Value: .6935897435897436

1 ]=> (stream-ref ln2-stream-euler 5)

;Value: .6928571428571428

1 ]=> (stream-ref ln2-stream-euler 6)

;Value: .6933473389355742

1 ]=> (stream-ref ln2-stream-euler 7)

;Value: .6930033416875522

1 ]=> (stream-ref ln2-stream-euler 8)

;Value: .6932539682539683

1 ]=> (stream-ref ln2-stream-euler 9)

;Value: .6930657506744464

1 ]=> (stream-ref ln2-stream-euler 10)

;Value: .6932106782106783



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



1 ]=> (stream-ref ln2-accelerated 0)

;Value: 1.

1 ]=> (stream-ref ln2-accelerated 1)

;Value: .7

1 ]=> (stream-ref ln2-accelerated 2)

;Value: .6932773109243697

1 ]=> (stream-ref ln2-accelerated 3)

;Value: .6931488693329254

1 ]=> (stream-ref ln2-accelerated 4)

;Value: .6931471960735491

1 ]=> (stream-ref ln2-accelerated 5)

;Value: .6931471806635636

1 ]=> (stream-ref ln2-accelerated 6)

;Value: .6931471805604039

1 ]=> (stream-ref ln2-accelerated 7)

;Value: .6931471805599445

1 ]=> (stream-ref ln2-accelerated 8)

;Value: .6931471805599427

1 ]=> (stream-ref ln2-accelerated 9)

;Value: .6931471805599454

1 ]=> (stream-ref ln2-accelerated 10)

;Value: #[NaN]