1.8|

$ cd ~

SICP Exercise 1.8

Simply implementing Newton’s method of calculating cube roots.

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

(define (improve y x)
  (/ (+ (/ x (* y y)) (* 2 y)) 3))

(define (good-enough? guess x)
  (< (abs (- (cube guess) x)) 0.0001))

(define (cube x) (* x x x))

(define (cbrt x)
  (cube-iter 1.0 x))

Although this program suffers from the same issue we faced in SICP Exercise 1.7. That can be easily remedied by changing the good enough program procedure.

(define (good-enough? guess x)
  (< (/ (cube guess) x) 0.0001))