sicp习题试解 (2.8)

类别:编程语言 点击:0 评论:0 推荐:

; ======================================================================
;
; Structure and Interpretation of Computer Programs
; (trial answer to excercises)
;
; 计算机程序的构造和解释(习题试解)
;
; created: code17 04/25/05
; modified:
; (保持内容完整不变前提下,可以任意转载)
; ======================================================================


;; SICP No.2.8

;; 两个interval的差依然是interval。根据不等式原理,此interval的最小值可以达到
;; 减数的lower-bound减去被减数的upper-bound,其最大值最大可至减数的upper-bound
;; 减去被减数的lower-bound
(define (sub-interval x y)
(make-interval (- (lower-bound x) (upper-bound y))
(- (upper-bound x) (lower-bound y))))


;; Test-it:
;; Welcome to MzScheme version 209, Copyright (c) 2004 PLT Scheme, Inc.
;; > (define test1 (make-interval 3 5))
;; > (define test2 (make-interval 8 1))
;; > (add-interval test1 test2)
;; (4 . 13)
;; > (sub-interval test1 test2)
;; (-5 . 4)

本文地址:http://com.8s8s.com/it/it22094.htm