Solution to Exercise SICP 2.8

Structure and Interpretation of Computer Programs

A solution to Exercise 2.8:

The maximum the difference could be is difference between the upper bound of the first interval and the lower bound of the second. The minimum difference is the difference between the lower bound of the first and the upper bound of the second. This holds true even if the second interval is greater than the first or the intervals overlap.

(define (sub-interval x y)
(make-interval (- (lower-bound x) (upper-bound y))
(- (upper-bound x) (lower-bound y))))

Advertisements