Chapter 1, Building Abstractions with Procedures
Section - The Elements of Programming
Exercise 1.8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#lang sicp
(define (cubert-iter oldguess newguess x)
(if (good-enough? oldguess newguess)
newguess
(cubert-iter newguess (improve newguess x)
x)))
(define (improve guess x)
(/ (+ (/ x (* guess guess)) (* 2 guess)) 3))
(define (average x y)
(/ (+ x y) 2))
(define (good-enough? oldguess newguess)
(< (/ (abs (- oldguess newguess)) oldguess) 0.001))
(define (cubert x)
(cubert-iter 1.0 x x))