Skip to content

Latest commit

 

History

History
84 lines (62 loc) · 3.17 KB

2.14.md

File metadata and controls

84 lines (62 loc) · 3.17 KB

2.14

Question

After considerable work, Alyssa P. Hacker delivers her finished system. Several years later, after she has forgotten all about it, she gets a frenzied call from an irate user, Lem E. Tweakit. It seems that Lem has noticed that the formula for parallel resistors can be written in two algebraically equivalent ways:

$$\frac{R_1 \cdot R_2}{R_1 + R_2}$$

and

$$\frac{1}{1 / R_1 + 1 / R_2}$$

He has written the following two programs, each of which computes the parallel-resistors formula differently:

(define (par1 r1 r2)
  (div-interval (mul-interval r1 r2)
                (add-interval r1 r2)))
(define (par2 r1 r2)
  (let ((one (make-interval 1 1)))
    (div-interval one
                  (add-interval (div-interval one r1)
                                (div-interval one r2)))))

Lem complains that Alyssa's program gives different answers for the two ways of computing. This is a serious complaint.

Demonstrate that Lem is right. Investigate the behavior of the system on a variety of arithmetic expressions. Make some intervals $A$ and $B$, and use them in computing the expressions $A/A$ and $A/B$. You will get the most insight by using intervals whose width is a small percentage of the center value. Examine the results of the computation in center-percent form (see exercise 2.12).

Answer

Recall $\text{percent}(x * y) \approx \text{percent}(x) + \text{percent}(y)$ for small percentage tolerances (Ex 2.13).

$$ \begin{align*} p_x = \text{percent}(x) &= 2 (x_2 - x_1) / (x_1 + x_2) \\ x * y= \text{product}(x, y) &= [x_1 y_1, x_2 y_2] \text{ (assuming positive)} \\ x / y= \text{quotient}(x, y) &= \text{product}(x, [1 / y_2, 1 / y_1]) \text{ (Ex 4.7)} \\ \end{align*} $$

We demonstrate the same holds for $\text{percent}(x / y)$:

$$ \begin{align*} \text{percent}(x / y) &= \text{percent}(\text{quotient}(x, y)) \\ &= \text{percent}(\text{product}(x, [1 / y_2, 1 / y_1])) \\ &\approx p_x + \text{percent}([1 / y_2, 1 / y_1]) \\ &\approx p_x + p_y \\ \end{align*} $$

Where

$$ \begin{align*} \text{percent}([1 / x_2, 1 / x_1]) &= 2 (1 / x_1 - 1 / x_2) / (1 / x_2 + 1 / x_1)\\ &= 2 ((x_1 - x_2) / (x_1 x_2)) / ((x_1 + x_2)(x_1 x_2)) \\ &= 2 (x_1 - x_2) / (x_1 + x_2) \ &= p_x \\ \end{align*} $$

This is confirmed by display-interval below:

(load "2.interval.scm")
;; (define (div-interval x y)
;;   (mul-interval x
;;                 (make-interval (/ 1.0 (upper-bound y))
;;                                (/ 1.0 (lower-bound y)))))

(define a (make-center-percent 1000 0.1))
(define b (make-center-percent 2000 0.05))
(define aa (div-interval a a))
(define ab (div-interval a b))
(display-interval aa) ; center: 1., percent: .2
(display-interval ab) ; center: .5, percent: .15

$\text{percent}(A/B)$ looks right, but $\text{percent}(A/A)$ should be zero, not 0.15!

The issue is that div-interval treats $A$ as a separate variable in the numerator and denominator when it is actually the same. The procedure simulates drawing twice from the same distribution instead of using the same draw twice.

This is why Lem's procedures produce different answers: par1 takes two draws of r1 and r2 while par2 only uses one draw of r1 and r2. The latter is correct.