sicp-ex-3.59



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


meteorgan

  
  
 ;; a) 
 (define (integrate-series s) 
   (stream-map * (stream-map / ones integers) s)) 
  
 ;; b) 
 (define sine-series 
   (cons-stream 0 (integrate-series cosine-series))) 
 (define cosine-series 
   (cons-stream 1 (integrate-series 
                   (scale-stream sine-series -1)))) 

shawn

  
  
 ;; a) 
 (define (integrate-series s) 
   (stream-map /  s integers)) 
  
 ;; Here's a simpler version of a). 
  
  
  
 ;; a) 
 (define (integrate-series stream) 
   (stream-map / stream integers)) 
    
 ;; b) 
 (define cosine-series 
   (cons-stream 1 (stream-map - (integrate-series sine-series)))) 
 (define sine-series 
   (cons-stream 0 (integrate-series cosine-series))) 
  
  
 ;; other way to exp 
 (define exp-series 
   (stream-map / ones (cons-stream 1 factorials))) 

  
  
 ; (a 
 (define (integrate-series s) 
   (stream-map / s integers)) 
 (define exp-series 
   (cons-stream 1 (integrate-series exp-series))) 
  
 ; (b 
 (define (filter-odd s) 
   (cons-stream (stream-car s) 
                (filter-odd (stream-cdr (stream-cdr s))))) 
 (define (filter-even s) 
   (cons-stream (stream-car (stream-cdr s)) 
                (filter-even (stream-cdr (stream-cdr s))))) 
 (define s-11 
   (cons-stream 1 (stream-map (lambda (e) 
                                (if (= 1 e) -1 1)) 
                              s-11))) 
 (define cosine-series 
   (stream-map * s-11 (filter-odd exp-series))) 
 (define sine-series 
   (stream-map * s-11 (filter-even exp-series)))