SICP ex2-6 2-15 Alyssa

ex2-6 2-12 一连串问题过多,不再赘述,前面几个难度都不是很大
(define (make-interval a b)
	(cons a b))
(define (upper-bound x)
	(cdr x))
(define (lower-bound x)
	(car x))
(define (intadd x y)
	(make-interval (+ (lower-bound x) (lower-bound y))
			(+ (upper-bound x) (upper-bound y))))

;;all negative          it is not necessary (make-interval (* u u) (* l l))
;;one upper positive   	it is not necessary (make-interval (* u l) (* l l))
;;two uppers positive   it is necessary
;;one lower positive    it is not necessary (make-interval (* u (min l l)) (* u u))
;;two lower positive    it is not necessary (make-interval (* l l) (* u u))
;;one upper equals zero it is not necessary (make-interval (* (max u u) l) (* l l))
;;two upper equal zero  it is not necessary (make-interval 0 (* l l))
;;one lower equal zero  it is not necessary (make-interval (* (min l l) u) (* u u))
;;two lower equal zero  it is not necessary (make-interval 0 (* u u))
;;It seems this idea become much more complex.
;;so I use the frist one to take the 
;;if you have a better idea please let me know
(define (intmul x y)
	(let (
		(p1 (* (lower-bound x) (lower-bound y)))
		(p2 (* (lower-bound x) (upper-bound y)))
		(p3 (* (upper-bound x) (lower-bound y)))
		(p4 (* (upper-bound x) (upper-bound y))))
		(make-interval 
				(min p1 p2 p3 p4)
				(max p1 p2 p3 p4))))
(define (intdiv x y)
	(if (or (= (upper-bound y) 0) (= (lower-bound y) 0) ) (error "it could not be zero!")
	(intmul x (make-interval  (/ 1 (upper-bound y)) (/ 1 (lower-bound y))))))
(define (intsub x y)
	(make-interval (- (lower-bound x) (upper-bound y)) (- (upper-bound x) (lower-bound y))))
(define (GetWidth x)
	(- (upper-bound x) (lower-bound x)))
(define (Right? combiner function x y)
	(= (GetWidth (function x y)) (combiner (GetWidth x) (GetWidth y))))
(define (center-width c w)
	(make-interval (- c w) (+ c w)))
(define (center i)
	(/ (+ (lower-bound i) (upper-bound i)) 2))
(define (width i)
	(/ (- (upper-bound i) (lower-bound i)) 2))
(define (make-center-percent c pw)
	(make-interval (- c (* c pw)) (+ c (* c pw))))
(define (percent x)
	(let ((c (center x)))
		(/ (- (upper-bound x) c) c)))
(define (mulpercent x y)
	(/ (- (* (+ 1 x)(+ 1 y)) (* (- 1 x) (- 1 y))) (+ (* (+ 1 x)(+ 1 y)) (* (- 1 x) (- 1 y))))) 
(define (par1 r1 r2)
	(intdiv (intmul r1 r2)
		(intadd r1 r2)))
(define (par2 r1 r2)
	(let ((one (make-interval 1 1)))
		(intdiv one
			(intadd (intdiv one r1)
				(intdiv one r2)))))
ex2-13引出问题 1/(1/r1+1/r2) 同r1r2/(r1+r2)结果不同
能力有限,参考了一些解答
问题在于a/a应为1 但是由于a是某个范围内的一个值
因此,我们可以理解为a b均属于A(A为容错区间)
这样当且仅当a=b时才等于1 我们就可以理解a/a!=1的理由了
之后我们看到2-14中的解释,由于一式只使用了一次r1 一次r2 因此,结果更准确,她的分析应该是正确的
也就是说我们接下来要实现的就是能够使除法 r1/r1=1 减法 r1-r1=0
能力有限,无法给出正确答案,以后如果想到会补充

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值