]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex2_15.clj
Lazy version of evaluator and tests.
[sicp.git] / src / sicp / ex2_15.clj
1 (ns sicp.ex2_15
2   (:use [sicp utils ch2_1_extended ex2_7 ex2_8 ex2_12]
3         [clojure.test]))
4
5 (def r1 (make-center-percent 1000 1))
6 (def r2 (make-center-percent 100  5))
7
8 (def r3 (sub-interval (add-interval r1 r2) r2))
9 ;;=> (999.8799999999999 1000.1200000000001)
10
11 (percentage r3)
12 ;;=> 0.012000000000011824
13
14 (center r3)
15 ;;=> 1000.0
16
17 (comment
18 "This shows that even if you add and subtract an interval (r2) from
19 another interval, we get back an interval which is not the same as
20 the original one r1. Let us look at the range as (center, percentage)
21 pair.
22  r1 = c1 +/- w1
23  r2 = c2 +/- w2
24
25 Now r1+r2-r2 = c1 + c2 - c1 +/- (2*w1+w2)
26              = c1 +/- (2*w1 + w2)
27
28 i.e. we have a new percentage width as the errors add up. The inference
29 from this is that, we reduce the number of ranges in a calculation to
30 get a more accurate range. So, yes, Eva Lu Ator is right."
31 )