2 (:use [sicp utils ch2_1_extended ex2_7]
5 ;; let [l1, u2] be lower and upper bound of range x
6 ;; and [l2, u2] that of range y.
8 ;; based on the signs of l1, u1, l2, u2, we have 16 combinations
28 ;; Now, if lower bound is +ve and upper is -ve, then it is invalid. So,
47 (defn new-mul-interval [x y]
48 (let [l1 (lower-bound x)
56 (cond (and sl1? su1? sl2? su2?) (make-interval (* l1 l2) (* u1 u2))
57 (and sl1? su1? (not sl2?) su2?) (make-interval (* u1 l2) (* u1 u2))
58 (and sl1? su1? (not sl2?) (not su2?)) (make-interval (* u1 l2) (* u2 l1))
59 (and (not sl1?) su1? sl2? su2?) (make-interval (* l1 u2) (* u1 u2))
60 (and (not sl1?) su1? (not sl2?) (not su2?)) (make-interval (* u1 l2) (* l1 l2))
61 (and (not sl1?) (not su1?) sl2? su2?) (make-interval (* l1 u2) (* u1 l2))
62 (and (not sl1?) (not su1?) (not sl2?) su2?) (make-interval (* l1 u2) (* l1 l2))
63 (and (not sl1?) (not su1?) (not sl2?) (not su2?)) (make-interval (* u1 u2) (* l1 l2))
64 (and (not sl1?) su1? (not sl2?) su2?) (let [p1 (* l1 l2)
68 (make-interval (min p1 p2 p3 p4)
69 (max p1 p2 p3 p4))))))