Exercise 2.11. In passing, Ben also cryptically comments: ``By testing the signs of the endpoints of the intervals, it is possible to break mul-interval into nine cases, only one of which requires more than two multiplications.'' Rewrite this procedure using Ben's suggestion. ———————————————————————————————————————————————————————————————————————— There are three relevant classes of intervals: entirely positive (i.e. having a positive lower bound), entirely negative (having a negative upper bound), and mixed (all others). There are then 9 possible combinations of positive, negative, or mixed values of x and y: x | y ————— P | P P | N P | M N | P N | N N | M M | P M | N M | M Of these, only M M (both x and y mixed) requires more than two multiplications. In all other cases, the signs and relative magnitudes of the terms are sufficient to determine which multiplication will yield the upper and lower bounds of the result. Knowing this, We can calculate the result with at most four sign checks and as few multiplications as possible: (define (mul-interval x y) (let ((xl (lower-bound x)) (xu (upper-bound x)) (yl (lower-bound y)) (yu (upper-bound y))) (cond ((positive? xl) (cond ((positive? yl) (make-interval (* xl yl) (* xu yu))) ((negative? yu) (make-interval (* xu yl) (* xl yu))) (else (make-interval (* xu yl) (* xu yu))))) ((negative? xu) (cond ((positive? yl) (make-interval (* xl yu) (* xu yl))) ((negative? yu) (make-interval (* xu yu) (* xl yl))) (else (make-interval (* xl yu) (* xl yl))))) (else (cond ((positive? yl) (make-interval (* xl yu) (* xu yu))) ((negative? yu) (make-interval (* xu yl) (* xl yl))) (else (make-interval (min (* xl yu) (* xu yl)) (max (* xl yl) (* xu yu)))))))))