読者です 読者をやめる 読者になる 読者になる

SICPゼミ第27回

練習問題3.53

1,2,4,8,16....

練習問題3.54
(define (mul-streams s1 s2) (stream-map * s1 s2))

(define factorials
  (cons-stream 1 (mul-streams (stream-cdr integers) factorials)))
練習問題3.55
(define (partial-sums s)
  (cons-stream (stream-car s) (add-streams (partial-sums s) (stream-cdr s))))
練習問題3.56
(define S (cons-stream 1 
                       (merge (scale-stream integers 2) 
                              (merge (scale-stream integers 3) 
                                     (scale-stream integers 5)))))

by pine

練習問題3.57

add-streams って結局は先頭要素以外計算しないので加算の呼び出し回数は昔やった普通に末尾再帰を n 回まわすやつと同じ。

by tube

練習問題3.58

radix 進数において、num / den の無限小数列。

by tube

練習問題3.59

a.

(define q-integers (stream-map / ones integers))

(define (integrate-series s) 
	(mul-streams s q-integers))

b.

(define cosine-series (cons-stream 1 (stream-map (lambda (x) (- x)) (integrate-series sine-series))))
(define sine-series (cons-stream 0 (integrate-series cosine-series)))

by dolicas

練習問題3.60
(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))))

by dolicas

練習問題3.61
(define (invert-unit-series s) 
	(stream-cons 1 (scale-stream (mul-series (stream-cdr s) (invert-unit-series s)) (- 1))))

by dolicas

練習問題3.62
(define (div-series s1 s2) 
	(let ((inv (/ 1 (stream-car s2))))
	(scale-stream (mul-series s1 (invert-unit-series (scale-stream s2 inv))) inv)))