sicp-ex-3.61



<< Previous exercise (3.60) | Index | Next exercise (3.62) >>


meteorgan

  
  
 (define (reciprocal-series s) 
   (cons-stream 1 
                (scale-stream 
                 (mul-series (stream-cdr s) 
                             (reciprocal-series s)) 
                 -1))) 

This is wrong as leafac says. This problem also holds for the meteorgan's comment in http://community.schemewiki.org/?sicp-ex-3.55 (also see the special case in http://community.schemewiki.org/?sicp-ex-3.60).



leafac

I'm not sure the above solution works, because calling (reciprocal-series s) on the body creates a new stream, which results are not memoized.

Here's my version:

 (define (invert-unit-series series) 
   (define inverted-unit-series 
     (cons-stream 
      1 
      (scale-stream (mul-streams (stream-cdr series) 
                                 inverted-unit-series) 
                    -1))) 
   inverted-unit-series) 
  

Why is it mul-streams, not mul-series?

Should use mul-series since mul-streams is term by term using stream-map.



The point that leafac makes is exactly the topic of exercise 3.63; the very next exercise.