理系学生日記

おまえはいつまで学生気分なのか

忍者TOOLS

問題1.8

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

(define (improve-cube y x)
  (/ (+ (/ x (square y))
	(* 2 y))
     3.0))


(define (good-enough? previous guess)
  (< (abs (- (/ previous guess) 1.0)) 0.001))

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

(define (cubic-root x)
  (cubic-root-iter 1.0 x x))