Exercise 1.8

If \(y\) is an approximmation to the cube root of \(x\), then a better approximation is given by the following expression:

\[{x/y^2 + 2y\over3}.\]

This formula can be used to implement a cbrt procedure analogous to the sqrt procedure implemented in the previous two exercises. The helper function good-enough? remains the same, but the improve function is now the above formula rewritten into prefix notation:

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

The other procedures are the same with the exception of some name changes:

(define (cbrt-iter current-guess last-guess x)
  (if (good-enough? current-guess last-guess)
      current-guess
      (cbrt-iter (improve current-guess x)
                 current-guess
                 x)))

(define (good-enough? current-guess last-guess)
  (<
   (/
    (abs (- current-guess last-guess))
    current-guess)
   0.001))

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

Back to exercises