Exercise 3.69. Write a procedure triples that takes three infinite streams, S, T, and U, and produces the stream of triples (Si,Tj,Uk) such that i ≤ j ≤ k. Use triples to generate the stream of all Pythagorean triples of positive integers, i.e., the triples (i,j,k) such that i ≤ j and i² + j² = k². ———————————————————————————————————————————————————————————————————————— We can divide the triples into four groups: the first triple (S₀,T₀,U₀), (S₀,T₀,U₁)... for the rest of U, (S₀,T₁,U₁)... for the all pairs from the rest of T and U, (S₁,T₁,U₁)..., i.e. all the rest of the triples. (define (triples s t u) (cons-stream (list (stream-car s) (stream-car t) (stream-car u)) (interleave-3 (stream-map (lambda (x) (list (stream-car s) (stream-car t) x)) (stream-cdr u)) (stream-map (lambda (x) (cons (stream-car s) x)) (pairs (stream-cdr t) (stream-cdr u))) (triples (stream-cdr s) (stream-cdr t) (stream-cdr u))))) (define pythagorean-triples (stream-filter (lambda (triple) (= (+ (square (car triple)) (square (cadr triple))) (square (caddr triple)))) (triples integers integers integers)))