乐正

Actions speak louder than words.

Sicp-ex2-8

问题

通过类似于Alyssa的推理,说明两个区间的差应该怎样计算。请定义出相应的减法过程sub-interval

解答

1
2
3
(define (sub-interval x y)
  (make-interval (- (lower-bound x) (upper-bound y))
     (- (upper-bound x) (lower-bound y))))

测试

1
2
3
4
5
6
7
8
9
10
11
12
13
(define a
  (make-interval 10 20))
;Value: a

(define b
  (make-interval 13 19))
;Value: b

(lower-bound (sub-interval a b))
;Value: -9

(upper-bound (sub-interval a b))
;Value: 7

draft

« sicp-ex2-7 sicp-ex2-9 »

Comments