<< Previous exercise (3.64) | Index | Next exercise (3.66) >>
Just wondering why not using recurrence relation to define summands, for instance for ln:
(define ln-summands (cons-stream 1 (stream-map (lambda (x) (* (if (> x 0) -1 1) (/ 1 (+ (denominator x) 1)))) ln-summands))) (define ln-stream (stream-map exact->inexact (partial-sums ln-summands)))
(define (sub-streams stream1 stream2) (stream-map - stream1 stream2)) (define (one-order-difference stream) (sub-streams (stream-cdr stream) stream)) (define (euler-transform s) (sub-streams (stream-cdr (stream-cdr s)) (stream-map / (stream-map square (one-order-difference (stream-cdr s))) (one-order-difference (one-order-difference s))))) (define (ln2-summands n) (cons-stream (/ 1.0 n) (stream-map - (ln2-summands (+ n 1))))) (define ln2-stream (partial-sums (ln2-summands 1))) (define (show-streams n . streams) (if (accumulate (lambda (a b) (or a b)) #f (cons (= n 0) (map stream-null? streams))) (newline) (begin (display-line (map stream-car streams)) (apply show-streams (cons (- n 1) (map stream-cdr streams)))))) (define (make-ln2-one-order-difference-tableau) (let ((ln2-tableau (make-tableau euler-transform ln2-stream))) (lambda (i) (one-order-difference (stream-ref ln2-tableau i))))) (define ln2-oodt (make-ln2-one-order-difference-tableau)) (show-streams 12 (ln2-oodt 4) (ln2-oodt 5) (ln2-oodt 6)) ; It can be seen that the convergence rate of this series increases by 2-3 orders of magnitude every time it passes through Euler transformation
meteorgan