Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

SICP exercise 2.11 : mul-interval

Name: Anonymous 2013-02-22 15:14

Ben Bitdiddler, an expert systems programmer, said that I was supposed to find 9 cases, but instead...

table for x * y, where
x = [a,b]
y = [c,d]

 a b c d    ac    ad    bc    bd    min    max
 + + + +    +    +    +    +    ac    bd
 - - - -    +    +    +    +    ac    bd
 + - - -    -    -    +    +    ad    bd
 - + + +    -    -    +    +    ad    bd
 + - + -    +    -    -    +    ad|bc    bd
 - + - +    +    -    -    +    ad|bc    bd
 - - + -    -    +    -    +    bc    bd
 + + - +    -    +    -    +    bc    bd
 
 + - + +    +    +    -    -    bd    ad
 - + - -    +    +    -    -    bd    ad
 + + + -    +    -    +    -    bd    bc
 - - - +    +    -    +    -    bd    bc
 + + - -    -    -    -    -    bd    ac
 - - + +    -    -    -    -    bd    ac
 + - - +    -    +    +    -    bd    ad|bc
 - + + -    -    +    +    -    bd    ad|bc


(define (sign x) (if (< x 0) -1 +1))
(define (same-sign a b) (= (sign a) (sign b)))

(define (mul-interval x y)
  (let ((a (lower-bound x))
        (b (upper-bound x))
        (c (lower-bound y))
        (d (upper-bound y)))
    (if (same-sign b d)
        (if (same-sign b c)
            (if (same-sign a c)
                (make-interval (* a c) (* b d))
                (make-interval (* a d) (* b d)))
            (if (same-sign a c)
                (make-interval (min (* a d)
                                    (* b c))
                               (* b d))
                (make-interval (* b c) (* b d))))
        (if (same-sign a c)
            (if (same-sign a d)
                (make-interval (* b d) (* a d))
                (make-interval (* b d) (* b c)))
            (if (same-sign a d)
                (make-interval (* b d) (max (* a d)
                                            (* b c)))
                (make-interval (* b d) (* a c)))))))


So... what?

Name: Anonymous 2013-02-22 16:11

Well, it looks like exercises 2.14 and 2.15 can be explained by 2.16's answer (about error progression from repeated operations on intervals). Just this bugs me:

Exercise 2.16: Explain, in general, why equivalent algebraic
expressions may lead to different answers. Can you devise an interval-arithmetic package that does not have this shortcoming, or is this task impossible? (Warning: This problem is very difficult.)

Simplify algebraic expressions, right? Do I really need to try?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List