(load "streams.txt") ; s1 = a1 + s1r*x ; s2 = a2 + s2r*x ; s1 * s2 = a1*a2 + a1*s2r*x + a2*s1r*x + (s1r*x * s2r*x) ; = a1*a2 + x*(a1*s2r + a2*s1r + (s1r * s2r)x) (define (mul-series2 s1 s2) (let ((a1 (stream-car s1)) (a2 (stream-car s2)) (s1r (stream-cdr s1)) (s2r (stream-cdr s2))) (cons-stream (* a1 a2) (add-streams (add-streams (scale-stream s2r a1) (scale-stream s1r a2)) (cons-stream 0 (mul-series2 s1r s2r)))))) ; s1 = a1 + s1r*x ; s2 = a2 + s2r*x ; s1 * s2 = a1*a2 + a1*s2r*x + a2*s1r*x + (s1r*x * s2r*x) ; = a1*a2 + x(a1*s2r + a2*s1r + s1r*s2r*x) ; = a1*a2 + x((a1 + s1r*x)*sr2 + a2*s1r) ; = a1*a2 + x(s1*sr2 + a2*s1r) (define (mul-series s1 s2) (cons-stream (* (stream-car s1) (stream-car s2)) (add-streams (scale-stream (stream-cdr s1) (stream-car s2)) (mul-series s1 (stream-cdr s2))))) ; 1 ]=> (load "3.59.txt") ; ; ;Loading "3.59.txt"... done ; ;Value: sine-series ; ; 1 ]=> (stream-prefix (add-streams (mul-series sine-series sine-series) ; (mul-series cosine-series cosine-series)) 10) ; ; ;Value: (1 0 0 0 0 0 0 0 0 0)