SICP exercise 2.14

From Drewiki

Jump to: navigation, search

Problem

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. He has written the following two programs, each of which computes the parallel-resistors formula differently:

 

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).

Solution

Here are the relevant routines from exercise 2.12 and from the text:

 

Here are a few tests that demonstrate Lem's findings:

 

Output:

26666.6666666667


 

Output:

5.41666667231765e-06


 

Output:

26666.6666666667


 

Output:

2.08333332238908e-06


Note that the percent tolerances are different.

Personal tools