Chapter 2, Building Abstractions with Data

Section - 2.1 - Introduction to Data Abstraction

Exercise 2.14


Lets first take an example of two intervals, and , and compute and using the procedures par1 and par2 given in exercise.

1
2
3
4
5
6
7
8
> (define I1 (make-center-percent 25 1.5))
> (define I2 (make-center-percent 75 0.75))
> (define rs1 (par1 I1 I2))
> (define rs2 (par2 I1 I2))
> (display-interval rs1)
[18.15998452012384,19.35544164037855]
> (display-interval rs2)
[18.50370662460568,18.995897832817338]

Clearly both results in different answers.

Lets see if the formulas are actually equivalent when applied to intervals.

We have:


By algebra, we can simplify it as:

This will be true for intervals, iff:

  • for any interval and . If we look closely this actually means that .
  • , for any interval .

Lets see using Alyssa’s “interval arithmetic” that above is correct or not:

1
2
3
4
5
6
7
8
9
> (define I1 (make-center-percent 25 1.5))
> (display-interval I1)
[24.625,25.375]
> (display-interval div)
[0.9704433497536946,1.030456852791878]
> (define reverse (div-interval (make-interval 1.0 1.0) I1))
> (define reverse_reverse (div-interval (make-interval 1.0 1.0) reverse))
> (display-interval reverse_reverse)
[24.625000000000004,25.375]

As we can see by interval arithmetic that . Thus the algebraic equivalent is not same as interval equivalent. However , for any interval holds true which means this farmulae alegebraic equivalent is same as arithmetic equivalent.