Answers to Quiz 6
3 points
15 minutes

Trace the evolution of
1: (+ (- 5 (* 2 3)) (/ 10 2))


(+ (- 5 6) 5) (+ -1 5) 4

2: (define (p x y) (if (= x 0) y (p (- x 1) (+ (* x x) y)))) (p 4 0)


(p 4 0) (if (= 4 0) 0 (p (- 4 1) (+ (* 4 4) 0))) (p (- 4 1) (+ (* 4 4) 0)) (p 3 (+ 16 0)) (p 3 16) ...now we skip the if step .... (p 2 (+ (* 3 3) 16)) (p 2 (+ 9 16)) (p 2 25) ... now we skip the if step and the arithmetic evaluation steps (p 1 29) (p 0 30) (if (= 0 0) 30 (p (- 0 1) (+ (* 0 0) 30)))) .... you could skip this too 30 So the shortest correct answer would be: (p 4 0) (if (= 4 0) 0 (p (- 4 1) (+ (* 4 4) 0))) (p 3 16) (p 2 25) (p 1 29) (p 0 30) 30 because I asked you to include 1 example of tracing through the "if"

answers