3.60 Exercise 3.60
In order to multiply two series together, we need to distribute the multiplication over addition. In other words, when multiplying the coefficients a0, a1, ... and b0, b1, ..., we need to multiply a0 by every bi.
The first element of this stream will naturally be a0 * b0. The rest of the coefficients can be found by summing two other series: One being the rest of the coefficients bi multiplied by a0, and the other being the multiplication of the streams of coefficients a1, ... and every bi. This can be defined as follows:
(define (mul-series s1 s2) (cons-stream (* (stream-car s1) (stream-car s2)) (add-streams (scale-stream (stream-cdr s2) (stream-car s1)) (mul-series (stream-cdr s1) s2))))
We can use this to verify the identity sin2x + cos2x = 1:
(define (take-stream s n) (if (<= n 0) the-empty-stream (cons-stream (stream-car s) (take-stream (stream-cdr s) (- n 1)))))
(define sine-cosine-identity (add-streams (mul-series sine-series sine-series) (mul-series cosine-series cosine-series)))
The expected coefficients should all be zero, with a leading constant 1. And indeed, this is the case:
> (display-stream (take-stream sine-cosine-identity 5))
1
0
0
0
0
'done