<< Previous exercise (2.7) | Index | Next exercise (2.9) >>

Specifying subtraction in terms of addition is more accurate.

We also have the example of division specified in terms of multiplication in the text

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

Where add-interval as given in the text is :

```
(define (add-interval x y)
(make-interval (+ (lower-bound x) (lower-bound y))
(+ (upper-bound x) (upper-bound y))))
```

This even works for negative valued interval, whether or not , we want to use values in that range ;-)

Here are some examples:

1 ]=> (sub-interval (make-interval 4 5) (make-interval 1 2)) ;Value 27: (2 . 4) 1 ]=> (sub-interval (make-interval (- 4) (- 5)) (make-interval 1 2)) ;Value 28: (-7 . -5) 1 ]=> (sub-interval (make-interval 4 5) (make-interval (- 1) 2)) ;Value 29: (2 . 6) 1 ]=> (sub-interval (make-interval 4 5) (make-interval 1 (- 2))) ;Value 30: (3 . 7) 1 ]=> (sub-interval (make-interval (- 4) 5) (make-interval 1 2)) ;Value 31: (-6 . 4) 1 ]=> (sub-interval (make-interval 4 (- 5)) (make-interval 1 2)) ;Value 32: (-7 . 3) 1 ]=>

> *This even works for negative valued interval, whether or not , we want to use values in that range ;-)*

The proposed solution works for negative values as well. The minimum of two intervals is *always* (- (lower a) (upper b)), and the maximum is *always* (- (upper a) (lower b)).

Otherwise, though, you are correct; it certainly is more elegant to define subtraction in terms of addition.

jz