2.9 Exercise 2.9
First, a definition of the width procedure:
(define (width x) (/ (- (upper-bound x) (lower-bound x)) 2))
We can use algebra to define the widths of the sum and difference of intervals in terms of the widths of the operands:
Let x and y be intervals (ax, bx) and (ay, by) |
width(x) = (ax + bx) / 2 |
width(y) = (ay + by) / 2 |
|
width(x+y) = ((ax + ay) + (bx + by)) / 2 |
= ((ax + bx) + (ay + by)) / 2 |
= width(x) + width(y) |
|
Similarly, |
width(x - y) = ((ax - ay) + (bx - by)) / 2 |
= ((ax + bx) - (ay + by)) / 2 |
= width(x) - width(y) |
To show that the width of a multiplied (or divided) pair of intervals is not a function of the widths of these intervals, we can construct two intervals with the same width and compare the widths of these intervals multiplied (or divided) by a third interval.
I could demonstrate this algebraically, but instead I will operate on the intervals using our procedures:
> (define i1 (make-interval 0 5)) > (define i2 (make-interval 5 10)) > (= (width i1) (width i2)) #t
> (define i3 (make-interval 1 10)) > (= (width (mul-interval i1 i3)) (width (mul-interval i2 i3))) #f
> (= (width (div-interval i1 i3)) (width (div-interval i2 i3))) #f