Exercise 1.11

Posted on Tuesday, September 11th, 2007

; f(n) = n if n < 3
; f(n) = f(n-1) + 2f(n-2) + 3f(n-3) if n >= 3

; recursive
(define(f n)
(if (< n 3)
n
[...]

continue reading

Exercise 1.10

Posted on Tuesday, September 11th, 2007

(A 1 10)(A (0 (A 1 9)))

(A 0 (A 0 (A 1 8)))

(A 0 (A 0 (A 0 (A 1 7))))

(A 0 (A 0 (A 0 (A 0 (A 1 6)))))

(A 0 (A 0 (A [...]

continue reading

Exercise 1.9

Posted on Tuesday, September 11th, 2007

(+ 4 5)
(inc (+ 3 5))
(inc (inc (+ 2 5)))
(inc (inc (inc (+ 1 5))))
(inc (inc (inc (inc (+ 0 5)))))
(inc (inc (inc (inc 5))))
(inc (inc (inc 6)))
(inc (inc 7))
(inc 8)
9

(+ 4 5)
(+ 3 6)
(+ [...]

continue reading

Exercise 1.8

Posted on Thursday, September 6th, 2007

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

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

continue reading

Exercise 1.7

Posted on Thursday, September 6th, 2007

Tests that show the problem:
For small numbers – it’s off, large numbers seem to be stuck in an infinite loop.

> (sqrt (square .00001))
0.03125000106562499
> (sqrt (square 10000000))
– endless loop
The reason the small numbers fail is [...]

continue reading

Exercise 1.6

Posted on Thursday, September 6th, 2007

I cheated but it makes sense now, I think. Since the interpreter uses applicative-order evaluation it will attempt to solve all the parameters before substituting them in to the new-if function. Since the [...]

continue reading

Exercise 1.5

Posted on Thursday, September 6th, 2007

applicative-order evaluation: The interpreter would enter an endless loop because it would try to evaluate (p) before it evaluates test. (p) = (p) = (p) and so on.
normal-order evaluation: The interpreter would return 0 [...]

continue reading

Exercise 1.4

Posted on Thursday, September 6th, 2007

0

continue reading

Exercise 1.3

Posted on Thursday, September 6th, 2007

(define (sos-larger2 a b c)
(cond ((and (< a b) (< a c)) (sos b c))
((and (< b a) (< b c)) (sos a c))
[...]

continue reading

Exercise 1.2

Posted on Thursday, September 6th, 2007

(/ (+ 5 4
(- 2
(- 3
(+ 6 (/ [...]

continue reading
Older Entries Newer Entries