A stream that converges to the square root a number

It is well-known that the square root function can be implemented by use of Newton's method. In case you need some background, you can consult this video.

If we need to find `sqrt(x)` based on an initial quess `g`, we can iteratively improve our guess by this simple function:

(define (improve-sqrt-guess guess x) (/ (+ guess (/ x guess)) 2))

Produce a stream of real numbers, starting with the initial guess *1.0*, that will converge towards `sqrt(x)`.

You may find the following stream variant of `map` useful:

(define (map-stream f stream) (cond ((empty-stream? stream) the-empty-stream) (else (cons-stream (f (head stream)) (map-stream f (tail stream))))))

Here is all you need to get started:

(define (improve-sqrt-guess guess x) (/ (+ guess (/ x guess)) 2)) (define-syntax cons-stream (syntax-rules () ((cons-stream x y) (cons x (delay y))))) (define head car) (define (tail stream) (force (cdr stream))) (define empty-stream? null?) (define the-empty-stream '()) (define (stream-section n stream) (cond ((= n 0) '()) (else (cons (head stream) (stream-section (- n 1) (tail stream)))))) (define (map-stream f stream) (cond ((empty-stream? stream) the-empty-stream) (else (cons-stream (f (head stream)) (map-stream f (tail stream))))))