Name: Anonymous 2008-12-04 9:20
Well, have you?
#lang scheme
(define (cuberoot number)
(cuberooter number 1.0))
(define (cuberooter number guess)
(if (good-enough guess number)
guess
(cuberooter number (improve-guess number guess))))
(define (improve-guess x y)
(/ (+ (/ x (square y)) (* y 2)) 3))
(define (square x)
(* x x))
(define (cube x)
(* x (square x)))
(define (good-enough guess x)
(< (abs (- (cube guess) x)) 0.000000000001))
(define (abs x)
(cond ((> x 0) x)
((= x 0) x)
((< x 0) (- x))))
(cuberoot 1000000)
(cube (cuberoot 1000000))
(define (+ a b)
(if (= a 0)
b
(inc (+ (dec a) b))))
(define (inc a)
(+ a 1))
(define (dec a)
(- a 1))
(define (+ a b)
(if (= a 0)
b
(+ (dec a) (inc b))))
(define (inc a)
(+ a 1))
(define (dec a)
(- a 1))
(+ 4 5)(+ 1 1) using your "iterative" definition (which is actually mutually recursive with inc); assuming you haven't fucked up (- a b) yet…
(+ 1 1)
(+ (dec 1) (inc 1))
(+ 0 (+ 1 1))
(+ 0 (+ (dec 1) (inc 1)))
(+ 0 (+ 0 (+ 1 1)))
(+ 0 (+ 0 (+ (dec 1) (inc 1))))
(+ 0 (+ 0 (+ 0 (+ 1 1))))
(+ 0 (+ 0 (+ 0 (+ (dec 1) (inc 1)))))
(+ 0 (+ 0 (+ 0 (+ 0 (+ 1 1)))))
.
.
.(+ 1 1) with your recursive definition.
(+ 1 1)
(inc (+ (dec 1) 1))
(inc (+ 0 1))
(inc 1)
(+ 1 1)
(inc (+ (dec 1) 1))
(inc (+ 0 1))
(inc 1)
(+ 1 1)
(inc (+ (dec 1) 1))
(inc (+ 0 1))
(inc 1)
(+ 1 1)
.
.
.