Scheme: Accelerated Stream

119 views Asked by At

From this example code I found online, which functions are the unaccelerated stream, the singly-accelrated stream, and the super-accelerated stream? Thank you in advance.

Cite: lawfulsamurai.blogspot.com/2009/01/sicp-section-35-streams.html

(define (log2-summands n)  
  (cons-stream (/ 1.0 n)  
           (stream-map - (log2-summands (+ n 1))))) 

(define log2-stream   
 (partial-sums (log2-summands 1))) 

(define log2-stream-euler   
  (euler-transform log2-stream))  

(define log2-stream-accelerated  
  (accelerated-sequence euler-transform log2-stream))  
1

There are 1 answers

0
Joshua Taylor On BEST ANSWER

Well, you didn't tell us what either a "singly-accelrated" or "super-accelerated" are, so it's hard to say where in the code they are. It's like playing "Where's Waldo", but without knowing what a "Waldo" is.

That said, I can see that log2-summands, euler-transform, make-tableau, and accelerated-sequence all return streams, so it seems like they'd be the candidates. Now, if we actually look at the blog post that you linked to, SICP Section 3.5 Streams, we read:

  1. Straightforward summation using partial-sums. The value of log2 oscillates between 0.6687714031754279 and 0.7163904507944756 after 20 iterations.

    (define log2-stream   
      (partial-sums (log2-summands 1)))  
    
  2. Log2 using Euler Transformation. Value converges to 0.6932106782106783 after 10 iterations.

    (define log2-stream-euler   
      (euler-transform log2-stream))  
    
  3. Accelerated summation. Value converges to 0.6931488693329254 in 4 iterations.

    (define log2-stream-accelerated  
      (accelerated-sequence euler-transform log2-stream))
    

It sounds like that the log2-stream, log2-stream-euler, and log2-stream-accelerated are, respectively, the "unaccelerated stream, the singly-accelrated stream, and the super-accelerated stream".