练习2.11-练习2.20

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)))



发布了179 篇原创文章 · 获赞 1 · 访问量 13万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览