Exercise 3.66. Examine the stream (pairs integers integers). Can you make any general comments about the order in which the pairs are placed into the stream? For example, about how many pairs precede the pair (1,100)? the pair (99,100)? the pair (100,100)? (If you can make precise mathematical statements here, all the better. But feel free to give more qualitative answers if you find yourself getting bogged down.) ———————————————————————————————————————————————————————————————————————— (1,100) is preceded by about 200 pairs. Specifically, (pairs integers integers) returns a stream beginning with (1,1), followed by interleaved (1,j) and (i,j) for i,j > 1. This means that (1,100) will be preceded by the 99 pairs (1,1) .. (1,99), and also by the 98 other pairs which will be interleaved between (1,2) .. (1,98), for a total of 197 pairs preceding (1,100). So any pair (1,n) for n > 1 is preceded by n-1 + n-2 pairs. In the general case, the offset of a pair in the stream (i.e. the number of pairs which precede it) is given by: offset(i,j) = 2^i - 2 if i = j. 1 if i = 1, j = 2. 3 * 2^(i-1) - 2 if j = i+1, i > 1. offset(i,i+1) + (j-i-1) * 2^i otherwise. This gives an offset of 2^100 - 2 for (100,100). For (99,100), this gives 3 * 2^98 - 2. These are large numbers, but we can test smaller values: (11,11) should appear at 2^11 - 2: 1 ]=> (stream-ref (pairs integers integers) 2046) ;Value 17: (11 11) (11,12) should appear at 3 * 2^10 - 2: 1 ]=> (stream-ref (pairs integers integers) 3070) ;Value 18: (11 12) (11,173) should appear at offset(11,12) + (173-11-1) * 2^11. This is 3070 + 161 * 2048 = 332798 1 ]=> (stream-ref (pairs integers integers) 332798) ;Value 19: (11 173)