$ cd ~

SICP Exercise 1.7

Using absolute difference as a criteria for good-enough? will not work for calculating square roots of smaller numbers. Changing it to be a ratio instead would work for both larger and smaller numbers.

(define (sqrt-iter guess x)
  (if (good-enough? guess)
      (sqrt-iter (improve guess x)

(define (improve guess x)
  (average guess (/ x guess)))

(define (average x y)
  (/ (+ x y) 2))

(define (good-enough? guess old-guess)
  (< (/ old-guess guess) 0.001))

(define (square x) (* x x))

(define (sqrt x)
  (sqrt-iter 1.0 x))