SICP Exercise 2.14
Question
Demonstrate that Lem is right. Investigate the behaviour of the
system on a variety of arithmetic expressions. Make some
intervals
Answer
First, let’s see whether par1
and par2
do, in fact, return
different results:
(define x (make-centre-percent 1000 1))
(define y (make-centre-percent 2500 5))
(define xy (div-interval x y))
(define yx (div-interval y x))
(define xx (div-interval x x))
(define yy (div-interval y y))
(par1 x y)
(par2 x y)
Results:
'(646.8363136176066 . 787.890044576523)
'(698.7369985141158 . 729.3672627235213)
So, the results are actually different, even though arithmetically, it should be the same operation. Why this happens will be explored in more detail within the following exercises, 2.15 and 2.16.
For now, let us look at some
(centre xy)
(centre yx)
(centre xx) ; expected: 1
(centre yy) ; expected: 1
Results:
0.401203007518797
2.5015001500150014
1.000200020002
1.005012531328321
So the centre of the division is very close to the division of the centres, but not exactly the same value. Interestingly, the centre of an interval divided by itself is not exactly 1, which we would have expected. How about percentage tolerances?
(percent xy)
(percent yx)
(percent xx)
(percent yy)
Results:
5.997001499250372
5.997001499250374
1.9998000199979968
9.975062344139655
The tolerance of the result is generally close to the sum of the component tolerances, but again not exactly the same value. This matches what we determined in exercise 2.13.