SICP Exercise 2.9
Question
The width of an interval is half of the difference between its upper and lower bounds. The width is a measure of the uncertainty of the number specified by the interval. For some arithmetic operations the width of the result of combining two intervals is a function only of the widths of the argument intervals, whereas for others the width of the combination is not a function of the widths of the argument intervals.
Show that the width of the sum (or difference) of two intervals is a function only of the widths of the intervals being added (or subtracted). Give examples to show that this is not true for multiplication or division.
Answer
Addition and Subtraction
This is easily verified programmatically with an example:
(define (get-width i)
(/ (- (upper-bound i) (lower-bound i)) 2))
(define i1 (make-interval 3 11))
(define i2 (make-interval 7 2))
(display "sum: ") (get-width (add-interval i1 i2))
(display "diff: ")(get-width (sub-interval i1 i2))
(newline)
(display "widths added: ") (+ (get-width i1) (get-width i2))
Results:
sum: 13/2
diff: 13/2
widths added: 13/2
But of course this could just be a coincidence. So let us also verify it mathematically. I’m using the terms \(x\) and \(y\) for the two intervals and the term \(w\) for width.
\(w_x = x_{upper} - x_{lower}\)
\((x+y)_{lower} = x_{lower} + y_{lower}\)
\((x+y)_{upper} = x_{upper} + y_{upper}\)
From these two definitions follows:
\(w_{x+y} =\frac{(x_{upper}+y_{upper})-(x_{lower}+y_{lower})}2\)
\(w_{x+y} =\frac{x_{upper}+y_{upper}-x_{lower}-y_{lower}}2\)
Which is the same as:
\(w_x+w_y =\frac{x_{upper}+y_{upper}}{2}-\frac{x_{lower}+y_{lower}}2\)
Therefore, \(w_{x+y}=w_x+w_y\).
Let us do the same for subtraction as well:
\(w_{x-y} =\frac{(x_{upper}-y_{lower})-(x_{lower}-y_{upper})}2\)
\(w_{x-y} =\frac{x_{upper}-y_{lower}-x_{lower}+y_{upper}}2\)
If you reorder this a little, you receive the same right side as with addition:
\(w_{x-y} =\frac{x_{upper}+y_{upper}-x_{lower}-y_{lower}}2\)
So it is shown that \(w_{x+y}=w_{x-y}=w_x+w_y\).
Multiplication and Division
Just trying this programmatically makes it apparent that there is no such connection for multiplication and division:
(define i1 (make-interval 3 11))
(define i2 (make-interval 7 2))
(display "mul: ") (get-width (mul-interval i1 i2))
(display "div: ") (get-width (div-interval i1 i2))
(newline)
(display "widths added: ") (+ (get-width i1) (get-width i2))
Results:
mul: 71/2
div: 2.5357142857142856
widths added: 13/2
We can also show this mathematically (note that I am assuming some things here, for example that both upper and lower bounds are positive numbers):
\(xy_{upper} = x_{upper}y_{upper}\)
\(xy_{lower} = x_{lower}y_{lower}\)
\(2w_{xy} = xy_{upper}-xy_{lower}\)
\(2w_{xy} = x_{upper}y_{upper}-x_{lower}y_{lower}\)
At this point, we can’t really simplify any further in terms of \(w_x\) and \(w_y\). So there does not seem to be any obvious connection between \(w_{xy}\) and \(w_xw_y\).