sicp习题试解 (2.10)

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

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


;; SICP No.2.10

(define (div-interval x y)
(let ((y-l (lower-bound y))
(y-u (upper-bound y)))
(if (< (* y-l y-u) 0)
(error "divisor interval expands zero")
(mul-interval x
(make-interval
(/ 1.0 y-u)
(/ 1.0 y-l))))))


;; Test-it:
;; Welcome to MzScheme version 209, Copyright (c) 2004 PLT Scheme, Inc.
;; ;; .............
;; > test1
;; (3 . 5)
;; > test3
;; (-5 . 3)
;; > (div-interval test1 test3)
;; divisor interval expands zero
;; > (div-interval test3 test1)
;; (-1.6666666666666665 . 1.0)

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