SICP Exercise 2.8

Question

Using reasoning analogous to Alyssa’s, describe how the difference of two intervals may be computed. Define a corresponding subtraction procedure, called sub-interval.

Answer

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

Let’s set up a test:

(define i1 (make-interval 1 3))
(define i2 (make-interval 5 2))

(sub-interval i1 i2)

Results:

'(-4 . 1)