# 2.9

## 练习 2.9 区间的宽度就是其上界和下界之差的一半，区间宽度是有关区间所描述的相应数值的非确定性的一种度量。对于某些算术运算，两个区间的组合结果的宽度就是参数区间的宽度的函数，而对其他运算，组合区间的宽度则不是参数区间的函数。证明两个区间的和（与差）的宽度就是被加（或减）的区间的宽度的函数。举例说明，对于乘和除而言，情况并非如此。

width = (upper-bound - lower-bound) / 2
width-of-sum = (upper-bound-of-sum - lower-bound-of-sum) / 2
=  ((upper-bound-of-x + upper-bound-of-y)
- (lower-bound-of-x + lower-bound-of-y)) / 2
=   width-of-x + width-of-y


width = (upper-bound - lower-bound) / 2
width-of-sum = (upper-bound-of-sum - lower-bound-of-sum) / 2
=  ((upper-bound-of-x - lower-bound-of-y)
- (lower-bound-of-x - upper-bound-of-y)) / 2
=   width-of-x + width-of-y

(define (make-interval a b) (cons a b))
(define upper-bound cdr)
(define lower-bound car)
(make-interval (+ (lower-bound x) (lower-bound y))
(+ (upper-bound x) (upper-bound y))))
(define (sub-interval x y) (add-interval x (make-interval (- 0 (upper-bound y)) (- 0 (lower-bound y)))))
(define (subtract-interval x y)
(define p1 (- (lower-bound x) (lower-bound y)))
(define p2 (- (lower-bound x) (upper-bound y)))
(define p3 (- (upper-bound x) (lower-bound y)))
(define p4 (- (upper-bound x) (upper-bound y)))

(make-interval (min p1 p2 p3 p4) (max p1 p2 p3 p4)))


(define (mul-interval x y)
(define p1 (* (lower-bound x) (lower-bound y)))
(define p2 (* (lower-bound x) (upper-bound y)))
(define p3 (* (upper-bound x) (lower-bound y)))
(define p4 (* (upper-bound x) (upper-bound y)))

(make-interval (min p1 p2 p3 p4) (max p1 p2 p3 p4))
)

(define (width x) (/ (- (upper-bound x) (lower-bound x)) 2))
(define int1 (make-interval 1 2))
(define int2 (make-interval 1 2))

int1

int2

(define int3 (mul-interval int1 int2))
int3


(define int4 (make-interval 2 3))
(define int5 (make-interval 2 3))

(define int6 (mul-interval int4 int5))
int6