Procedure for multiplying series

With power series represented as streams of coefficients as in exercise 3.59 , adding series is implemented by add-streams . Complete the definition of the following procedure for multiplying series:

(define (mul-series s1 s2)
  (cons-stream <??> (add-streams <??> <??>)))

You can test your procedure by verifying that sin²x + cos²x = 1 , using the series from exercise 3.59

There are no comments yet.

Authentication required

You must log in to post a comment.

(define (stream-car stream) (car stream))

(define (stream-cdr stream) (force (cdr stream)))

(define (stream-map proc . list-of-stream)
    (if (null? (car list-of-stream))
            (apply proc 
                   (map (lambda (s)
                            (stream-car s))
            (apply stream-map 
                   (cons proc (map (lambda (s)
                                       (stream-cdr s))

(define (scale-stream stream factor)
  (stream-map (lambda (x) (* x factor)) stream))

(define (add-streams s1 s2)
  (stream-map + s1 s2))

(define (mul-streams s1 s2)
    (stream-map * s1 s2))

(define (div-streams s1 s2)
    (stream-map / s1 s2))

(define ones (cons-stream 1 ones))

(define integers (cons-stream 1 (add-streams ones integers)))

(define s (add-streams (mul-series sine-series sine-series)
                       (mul-series cosine-series cosine-series)))

(check-equal? (stream-car s) 1)