(define (integrate-series series) (define (aux series i) (cons-stream (/ (stream-car series) i) (aux (stream-cdr series) (+ i 1)))) (aux series 1)) ; a) ; 1 ]=> (load "streams.txt") ; ; ;Loading "streams.txt"... done ; ;Value: stream-prefix ; ; 1 ]=> (stream-prefix (integrate-series integers) 10) ; ; ;Value: (1 1 1 1 1 1 1 1 1 1) ; ; 1 ]=> (stream-prefix (integrate-series ones) 10) ; ; ;Value: (1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9 1/10) (define exp-series (cons-stream 1 (integrate-series exp-series))) ; d(sin(x))/dx = cos(x) ; d(cos(x))/dx = -sin(x) ; => sin(x) = integrate cos(x) ; => cos(x) = integrate -sin(x) (define cosine-series (cons-stream 1 (integrate-series (scale-stream sine-series -1)))) (define sine-series (cons-stream 0 (integrate-series cosine-series))) ; b) ; 1 ]=> (load "streams.txt") ; ; ;Loading "streams.txt"... done ; ;Value: stream-prefix ; ; 1 ]=> (stream-prefix exp-series 10) ; ; ;Value: (1 1 1/2 1/6 1/24 1/120 1/720 1/5040 1/40320 1/362880) ; ; 1 ]=> (stream-prefix cosine-series 10) ; ; ;Value: (1 0 -1/2 0 1/24 0 -1/720 0 1/40320 0) ; ; 1 ]=> (stream-prefix sine-series 10) ; ; ;Value: (0 1 0 -1/6 0 1/120 0 -1/5040 0 1/362880)