One solution to Exercise 2.13:

In exercise 2.12, we found a way to express a range as a tolerance.

`(define (make-center-percent c p)`

#1

(make-center-width c (* c (/ p 100))))

Where,

`(define (make-center-width c w)`

#2

(make-interval (- c w) (+ c w)))

Expanding #2 in #1 give us:

`(define (make-center-percent c p)`

#3

(make-interval (- c (* c (/ p 100)))

(+ c (* c (/ p 100)))))

Now, imagine a range, `x`

with a center `cx`

and a percentage tolerance `px`

.

`(define x (make-center-percent cx px))`

#4

Expanding #4 out, from #3, we get:

`(define x`

#5

(make-interval (- cx (* cx (/ px 100)))

(+ cx (* cx (/ px 100)))))

That’s a bit messy with all those divisions by 100. Let’s introduce

an absolute tolerance, `tx`

, that is one hundreth the

size of the percentage tolerance.

`(define px (* tx 100))`

#6

Substituting #6 into #5, we get:

`(define x`

#7

(make-interval (- cx (* cx tx))

(+ cx (* cx tx))))

We’ll need another range if we are to do any multiplication. Let’s

likewise define `y`

:

`(define y`

#8

(make-interval (- cy (* cy ty))

(+ cy (* cy ty))))

Another lesson we learned from exercise 2.12 is how to find the

width of a range:

`(define (width i)`

#9

(/ (- (upper-bound i) (lower-bound i)) 2))

A couple of relations that we are almost certain to find useful

(and I hope you’ll find obvious):

`(equal u (upper-bound (make-interval l u)))`

#10

`(equal l (lower-bound (make-interval l u)))`

#11

In exercise 2.11, we found that when all the numbers are positive,

we can define `mul-interval`

as follows:

`(define (mul-interval x y)`

#12

(make-interval (* (lower-bound x) (lower-bound y))

(* (upper-bound x) (upper-bound y))))

We are interested in the percentage tolerance of the product of two

intervals in terms of their percentage tolerances. In other words,

`(percent (mul-interval x y))`

#13

You’ll recall the definition of `percent`

from exercise

2.12:

`(define (percent i)`

#14

(* (/ (width i) (center i)) 100))

Expanding #13 with #14, we get:

`(* (/ (width (mul-interval x y))`

#15

(center (mul-interval x y)))

100)

To keep things from getting too messy, let’s just focus on the

`width`

part for now:

`(width (mul-interval x y))`

#16

Substituting in #12

`(width (make-interval`

#17

(* (lower-bound x)

(lower-bound y))

(* (upper-bound x)

(upper-bound y))))

And the definitions of `x`

and `y`

from #7

and #8:

`(width (make-interval`

#18

(* (lower-bound (make-interval (- cx (* cx tx))

(+ cx (* cx tx))))

(lower-bound (make-interval (- cy (* cy ty))

(+ cy (* cy ty)))))

(* (upper-bound (make-interval (- cx (* cx tx))

(+ cx (* cx tx))))

(upper-bound (make-interval (- cy (* cy ty))

(+ cy (* cy ty)))))))

Boy, this is getting messy. We can rely on relations #10 and #11 to

tidy things up a bit.

`(width (make-interval`

#19

(* (- cx (* cx tx))

(- cy (* cy ty)))

(* (+ cx (* cx tx))

(+ cy (* cy ty)))))

Expanding out the products:

`(width (make-interval`

#20

(- (+ (* cx cy) (* cx tx cy ty))

(+ (* cx cy ty) (* cy cx tx)))

(+ (* cx cy) (*cx tx cy ty)

(* cx cy ty) (* cy cx tx))))

Substituting into #9

`(/ (- (upper-bound`

#21

(make-interval

(- (+ (* cx cy) (* cx tx cy ty))

(+ (* cx cy ty) (* cy cx tx)))

(+ (* cx cy) (*cx tx cy ty)

(* cx cy ty) (* cy cx tx))))

(lower-bound

(make-interval

(- (+ (* cx cy) (* cx tx cy ty))

(+ (* cx cy ty) (* cy cx tx)))

(+ (* cx cy) (*cx tx cy ty)

(* cx cy ty) (* cy cx tx)))))

2)

Another mess. But we can call on #10 and #11 again to clean things

up.

`(/ (- (+ (* cx cy) (*cx tx cy ty)`

#22

(* cx cy ty) (* cy cx tx))

(- (+ (* cx cy) (* cx tx cy ty))

(+ (* cx cy ty) (* cy cx tx))))

2)

Let’s rearrange the terms to see what, if anything, cancels out.

`(/ (+ (- (* cx cy) (* cx cy))`

#23

(- (*cx tx cy ty) (*cx tx cy ty))

(* cx cy ty) (* cx cy ty)

(* cy cx tx) (* cy cx tx))

2)

Now we’re getting somewhere:

`(/ (+ (* 2 cx cy ty)`

#24

(* 2 cy cx tx))

2)

Simplifying.

`(+ (* cx cy ty) (* cy cx tx)))`

#25

And again.

`(* cx cy (+ tx ty))`

#26

So now we know what the `width`

of a product is in terms

of the tolerances and centers. Now let’s take a look at the

`center`

of a product.

`(center (mul-interval x y))`

#27

From exercise 2.12, we know the definiton of `center`

`(define (center i)`

#28

(/ (+ (lower-bound i) (upper-bound i)) 2))

Expanding #27.

`(/ (+ (lower-bound (mul-interval x y))`

#29

(upper-bound (mul-interval x y)))

2)

Substituting #12.

`(/ (+ (lower-bound (make-interval`

#30

(* (lower-bound x) (lower-bound y))

(* (upper-bound x) (upper-bound y))))

(upper-bound (make-interval

(* (lower-bound x) (lower-bound y))

(* (upper-bound x) (upper-bound y)))))

2)

Using #10 and #11, again.

`(/ (+ (* (lower-bound x) (lower-bound y))`

#31

(* (upper-bound x) (upper-bound y)))

2)

Subsituting in #7 and #8:

`(/ (+ (* (lower-bound (make-interval (- cx (* cx tx))`

#32

(+ cx (* cx tx))))

(lower-bound (make-interval (- cy (* cy ty))

(+ cy (* cy ty)))))

(* (upper-bound (make-interval (- cx (* cx tx))

(+ cx (* cx tx))))

(upper-bound (make-interval (- cy (* cy ty))

(+ cy (* cy ty))))))

2)

Can’t get enough of #10 and #11:

`(/ (+ (* (- cx (* cx tx))`

#33

(- cy (* cy ty)))

(* (+ cx (* cx tx))

(+ cy (* cy ty))))

2)

Expanding it all out:

`(/ (+ (- (* cx cy) (* cx cy ty))`

#34

(- (* cx tx cy ty) (* cy cx tx))

(* cx cy) (* cx cy ty)

(* cx tx cy ty) (* cy cx tx))

2)

Several terms cancel out again, leaving:

`(/ (+ (* 2 cx cy)`

#35

(* 2 cx tx cy ty))

2)

Since we are assuming small tolerances, the second term

`(* 2 cx tx cy ty)`

is effectively zero, leaving us

with:

`(/ (* 2 cx cy)`

#36

2)

Or,

`(* cx cy)`

#37

Now we can return to #15, substituting #26 and #37 in:

`(* (/ (* cx cy (+ tx ty)))`

#38

(* cx cy))

100)

This simplifies quite nicely to:

`(* (+ tx ty) 100)`

#39

Recall from #6 that we defined `tx`

and `ty`

to eliminate the division by 100. If we switch back to percentage

notation, now, we get rid of that pesky 100 for good:

`(+ px py)`

#40

There you have it. Assuming small tolerances, we can conclude that

the percentage tolerance of the product of two intervals is equal

to the sum of the tolerances of the multiplicands.