Blob


1 (define (add-interval x y)
2 (make-interval (+ (lower-bound x) (lower-bound y))
3 (+ (upper-bound x) (upper-bound y))))
4 (define (mul-interval x y)
5 (let ((p1 (* (lower-bound x) (lower-bound y)))
6 (p2 (* (lower-bound x) (upper-bound y)))
7 (p3 (* (upper-bound x) (lower-bound y)))
8 (p4 (* (upper-bound x) (upper-bound y))))
9 (make-interval (min p1 p2 p3 p4)
10 (max p1 p2 p3 p4))))
12 (define (div-interval x y)
13 (mul-interval x
14 (make-interval (/ 1.0 (upper-bound y))
15 (/ 1.0 (lower-bound y)))))
17 (define (make-interval lower upper)
18 (cons lower upper))
19 (define (upper-bound interval)
20 (cdr interval))
21 (define (lower-bound interval)
22 (car interval))
24 (define (sub-interval x y)
25 (make-interval (- (lower-bound x) (upper-bound y))
26 (- (upper-bound x) (lower-bound y))))
29 ;; Exercise 2.10. Ben Bitdiddle, an expert systems programmer, looks over Alyssa's shoulder and comments that it is not clear what it means to divide by an interval that spans zero. Modify Alyssa's code to check for this condition and to signal an error if it occurs.