#lang planet neil/sicp
+(#%require (only racket random))
+
(define (stream-car s) (car s))
(define (stream-cdr s) (force (cdr s)))
(stream-cdr stream)))))
(define primes (sieve (integers-starting-from 2)))
+
+(define (interleave s1 s2)
+ (if (stream-null? s1)
+ s2
+ (cons-stream (stream-car s1)
+ (interleave s2 (stream-cdr s1)))))
+
+(define (pairs s t)
+ (cons-stream
+ (list (stream-car s) (stream-car t))
+ (interleave
+ (stream-map (lambda (x) (list (stream-car s) x))
+ (stream-cdr t))
+ (pairs (stream-cdr s) (stream-cdr t)))))
+
+(define (integral integrand initial-value dt)
+ (define int
+ (cons-stream initial-value
+ (add-streams (scale-stream integrand dt)
+ int)))
+ int)