练习2.11-练习2.20

15 篇文章 0 订阅

1.练习2.11

(define (mul-interval x y)
  (let ((x1 (lower-bound x))
	(x2 (upper-bound x))
	(y1 (lower-bound y))
	(y2 (upper-bound y)))
    (let
	((zzx (and (>= x1 0) (>= x2 0)))
	 (zzy (and (>= y1 0) (>= y2 0)))
	 (fzx (and (< x1 0) (>= x2 0)))
	 (fzy (and (< y1 0) (>= y2 0)))
	 (ffx (and (< x1 0) (< x2 0)))
	 (ffy (and (< y1 0) (< y2 0))))
      (cond (zzy (cond (zzx (make-interval (* x1 y1) (* x2 y2)))
		       (fzx (make-interval (* x1 y2) (* x2 y2)))
		       (ffx (make-interval (* x1 y2) (* x2 y1)))))
	    (fzy (cond (zzx (make-interval (* x2 y1) (* x2 y2)))
		       (fzx (make-interval (min (* x1 y2) (* x2 y1))
					   (max (* x1 y1) (* x2 y2))))
		       (ffx (make-interval (* x1 y2) (* x1 y1)))))
	    (ffy (cond (zzx (make-interval (* x2 y1) (* x1 y2)))
		       (fzx (make-interval (* x2 y1) (* x1 y1)))
		       (ffx (make-interval (* x2 y2) (* x1 y1)))))))))
2.练习2.12

(define (mul-interval x y)
  (let ((x1 (lower-bound x))
	(x2 (upper-bound x))
	(y1 (lower-bound y))
	(y2 (upper-bound y)))
    (let
	((zzx (and (>= x1 0) (>= x2 0)))
	 (zzy (and (>= y1 0) (>= y2 0)))
	 (fzx (and (< x1 0) (>= x2 0)))
	 (fzy (and (< y1 0) (>= y2 0)))
	 (ffx (and (< x1 0) (< x2 0)))
	 (ffy (and (< y1 0) (< y2 0))))
      (cond (zzy (cond (zzx (make-interval (* x1 y1) (* x2 y2)))
		       (fzx (make-interval (* x1 y2) (* x2 y2)))
		       (ffx (make-interval (* x1 y2) (* x2 y1)))))
	    (fzy (cond (zzx (make-interval (* x2 y1) (* x2 y2)))
		       (fzx (make-interval (min (* x1 y2) (* x2 y1))
					   (max (* x1 y1) (* x2 y2))))
		       (ffx (make-interval (* x1 y2) (* x1 y1)))))
	    (ffy (cond (zzx (make-interval (* x2 y1) (* x1 y2)))
		       (fzx (make-interval (* x2 y1) (* x1 y1)))
		       (ffx (make-interval (* x2 y2) (* x1 y1)))))))))
3.练习2.13

中文的翻译太差了,句中的“两个被乘区间的误差”应该是“被乘区间的百分比误差”吧,很生气。。。

4.练习2.14

5.练习2.15

因为引入的误差少,所以更精确

6.练习2.16

设计一种好难啊

7.练习2.17

(define (last-pair items)
  (let ((len (length items)))
    (define (last-pair-iter item tmplen)
      (if (= tmplen 1)
	  item
	  (last-pair-iter (cdr item) (- tmplen 1))))
    (last-pair-iter items len)))
8.练习2.18

(define (reverse items)
  (define (reverse-iter tmpitems result)
    (if (null? tmpitems)
	result
	(reverse-iter (cdr tmpitems)
		      (cons (car tmpitems) result))))
  (reverse-iter items '()))
9.练习2.19

(define (first-denomination list1)
  (car list1))

(define (except-first-denomination list1)
  (cdr list1))

(define (no-more? list1)
  (null? list1))
10.练习2.20

(define (same-parity . other)
  (define (even-number? number)
    (= (remainder number 2) 0))
  (define (same-parity-recur even items)
    (if (null? items)
	'()
	(let ((now-even (even-number? (car items)))
	      (next (same-parity-recur even (cdr items))))
	  (if (or (and even now-even)
		  (and (not even) (not now-even)))
	      (cons (car items) next)
	      next))))
  (let ((evenodds (even-number? (car other))))
    (same-parity-recur evenodds other)))



  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

_海阔天空

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值