This article was migrated from http://rails.office.drecom.jp/takiuchi/archive/62

素人くさいSICP読書会に参加してきました。

ここのところ数回続けて参加できていなかったので、参加できて良かったです。

参加者数は、だいたい15名前後でした。今までと同様、演習問題を黙々と解いていくという形式で進められました。今回の範囲は、演習問題 2.9〜2.11でした。 間が空いていたので、前回までに進んだところを追いかけながら進めました。

途中、IntervalのWidthが減る事があるかどうか、という議論がありましたが、Widthは誤差のようなものなので、演算の結果として減る事は無いですね。

ということで、今回使ったコードを置いておきます(ちゃんと検証してないから書き間違いがあるかも)

;;7/5
(define (make-interval a b) (cons a b))
(define (lower-bound x) (car x))
(define (upper-bound x) (cdr x))

(define (add-interval x y)
  (make-interval (+ (lower-bound x) (lower-bound y))
                 (+ (upper-bound x) (upper-bound y))))

(define (mul-interval x y)
  (let ((p1 *1 (lower-bound y)))
        (p2 *2 (upper-bound y)))
        (p3 *3 (lower-bound y)))
        (p4 *4 (upper-bound y))))
    (make-interval (min p1 p2 p3 p4)
                   (max p1 p2 p3 p4))))

(define (div-interval x y)
  (mul-interval x
                (make-interval (/ 1.0 (upper-bound y))
                               (/ 1.0 (lower-bound y)))))

;; ex 2.8
(define (sub-interval x y)
  (make-interval (- (lower-bound x) (upper-bound y))
                 (- (upper-bound x) (lower-bound y))))

;; ex 2.10
(define (div-interval-2 x y)
  (if (and (>= (upper-bound y) 0) (<= (lower-bound y) 0))
      (display "error: divider is spanning zero.")
      (div-interval x y)))

;; ex 2.11
(define (mul-interval-2 x y)
  (define (pp-pp-mul s t)
    (make-interval *5 (lower-bound t))
                   *6 (upper-bound t))))
  (define (pp-mm-mul s t)
    (make-interval *7 (lower-bound t))
                   *8 (upper-bound t))))
  (define (pp-pm-mul s t)
    (make-interval *9 (lower-bound t))
                   *10 (upper-bound t))))
  (define (mm-mm-mul s t)
    (make-interval *11 (upper-bound t))
                   *12 (lower-bound t))))
  (define (mm-pm-mul s t)
    (make-interval *13 (upper-bound t))
                   *14 (lower-bound t))))
  (define (mm-pp-mul s t) (pp-mm-mul t s))
  (define (pm-pp-mul s t) (pp-pm-mul t s))
  (define (pm-mm-mul s t) (mm-pm-mul t s))
  (define (pm-pm-mul s t)
    (make-interval (min *15 (lower-bound t))
                        *16 (upper-bound t)))
                   (max *17 (lower-bound t))
                        *18 (upper-bound t)))))
  (define (pp s) (> (lower-bound s) 0))
  (define (mm s) (< (upper-bound s) 0))
  (define (pm s) (not (or (pp s) (mm s))))
  (cond ((and (pp x) (pp y)) (pp-pp-mul x y))
        ((and (pp x) (mm y)) (pp-mm-mul x y))
        ((and (pp x) (pm y)) (pp-pm-mul x y))
        ((and (mm x) (pp y)) (mm-pp-mul x y))
        ((and (mm x) (mm y)) (mm-mm-mul x y))
        ((and (mm x) (pm y)) (mm-pm-mul x y))
        ((and (pm x) (pp y)) (pm-pp-mul x y))
        ((and (pm x) (mm y)) (pm-mm-mul x y))
        ((and (pm x) (pm y)) (pm-pm-mul x y))))

This article was migrated from http://rails.office.drecom.jp/takiuchi/archive/62

  1. 1 (lower-bound x

  2. 2 (lower-bound x

  3. 3 (upper-bound x

  4. 4 (upper-bound x

  5. 5 (lower-bound s

  6. 6 (upper-bound s

  7. 7 (upper-bound s

  8. 8 (lower-bound s

  9. 9 (upper-bound s

  10. 10 (upper-bound s

  11. 11 (upper-bound s

  12. 12 (lower-bound s

  13. 13 (lower-bound s

  14. 14 (lower-bound s

  15. 15 (upper-bound s

  16. 16 (lower-bound s

  17. 17 (lower-bound s

  18. 18 (upper-bound s

posted by Png genki on Thu 6 Jul 2006 at 16:12
Contents
素人くさいSICP勉強会#20レポート
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
瀧内元気: おお、チェックしてみます。thx! '11-12
overisland: Reeder for iPhone もこの UI を実装していますね。 '11-12
瀧内元気: その情報は見たのですが、以下のサイトによると、現在はまた必要になってるっぽいんですよね。 ... '11-12
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ