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

In the resistor example, the resistor is measured at 6.8 ohm with a tolerance of 10%. This means the actual value is , which makes the interval [6.12 , 7.48]. The other resistor is with the interval of [4.465 , 4.935]. Naively subtracting the two intervals would give, [1.655 , 2.545]. Which doesn’t seem wrong but it is. It is wrong because we are biasing the tolerance in one direction for both measurements. We assume that the first value is and second . There is no basis to assume that the following case isn’t just as valid: and .

It’s even clearer with the interval of [2 , 4] and [1 , 3]. Naively subtracting these terms yields an interval of 0 length, [1,1] or which is nonsense.

In order to make sure no tolerance bias exists that makes calculations seem more accurate than is possible, the worst case measurement error must be assumed. The intervals will become as wide as possible to not give a false sense of accuracy.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
(define (sub-interval x y) (make-interval (- (lower-bound x) (upper-bound y)) (- (upper-bound x) (lower-bound y)))) (define (make-interval a b) (cons a b)) (define (lower-bound inter) (car inter)) (define (upper-bound inter) (cdr inter)) (define (add-interval x y) (make-interval (+ (lower-bound x) (lower-bound y)) (+ (upper-bound x) (upper-bound y)))) (define (add-interval x y) (make-interval (+ (lower-bound x) (lower-bound y)) (+ (upper-bound x) (upper-bound y)))) (define (div-interval x y) (mul-interval x (make-interval (/ 1.0 (upper-bound y)) (/ 1.0 (lower-bound y))))) (define (mul-interval x y) (let ((p1 (* (lower-bound x) (lower-bound y))) (p2 (* (lower-bound x) (upper-bound y))) (p3 (* (upper-bound x) (lower-bound y))) (p4 (* (upper-bound x) (upper-bound y)))) (make-interval (min p1 p2 p3 p4) (max p1 p2 p3 p4)))) (define (print int) (newline) (display "[") (display (lower-bound int)) (display ",") (display (upper-bound int)) (display "]") (newline)) |

> (print (sub-interval (make-interval 6.12 7.48) (make-interval 4.465 4.935)))

*[1.1850000000000005,3.0150000000000006]*