Exercise 5.3. Design a machine to compute square roots using Newton's method, as described in section 1.1.7: (define (sqrt x) (define (good-enough? guess) (< (abs (- (square guess) x)) 0.001)) (define (improve guess) (average guess (/ x guess))) (define (sqrt-iter guess) (if (good-enough? guess) guess (sqrt-iter (improve guess)))) (sqrt-iter 1.0)) Begin by assuming that good-enough? and improve operations are available as primitives. Then show how to expand these in terms of arithmetic operations. Describe each version of the sqrt machine design by drawing a data-path diagram and writing a controller definition in the register-machine language. ———————————————————————————————————————————————————————————————————————— We assume that the input x is in a register x. (controller (assign g (constant 1.0)) loop (test (op good-enough?) (reg g) (reg x) (branch sqrt_done) (assign g (op improve) (reg g) (reg x)) (goto loop) sqrt_done) Now with good-enough written inline: (controller (assign g (constant 1.0)) loop (assign g (op improve) (reg g) (reg x)) ; here we always improve at least once (assign t (op mul) (reg g) (reg g)) ; assign to t the guess squared (assign t (op sub) (reg t) (reg x)) ; subtract actual value from squared guess (test (op >) (reg t) (constant 0.001)) ; if difference > 0.001 (branch loop) ; ...then continue (test (op >) (constant -0.001) (reg t)) ; if difference > -0.001 (and lte 0.001 per above) (branch sqrt_done) ; ...then we are done (goto loop) sqrt_done) And with improve also expanded: (controller (assign g (constant 1.0)) loop (assign t (op mul) (reg g) (reg g)) (assign t (op sub) (reg t) (reg x)) (test (op >) (reg t) (constant 0.001)) (branch improve) (test (op >) (constant -0.001) (reg t)) (branch sqrt_done) improve (assign t (op div) (reg x) (reg g)) (assign t (op add) (reg g) (reg t)) (assign g (op div) (reg t) (constant 2.0)) (goto loop) sqrt_done)