From: Ramakrishnan Muthukrishnan Date: Sun, 13 Jun 2010 20:07:31 +0000 (+0530) Subject: solution to 2.11. X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/bcase/install.html?a=commitdiff_plain;h=16bc240d870f856872edb2fa1b595150a4e50619;p=sicp.git solution to 2.11. --- diff --git a/src/sicp/ex2_11.clj b/src/sicp/ex2_11.clj index 03fbfd0..2909020 100644 --- a/src/sicp/ex2_11.clj +++ b/src/sicp/ex2_11.clj @@ -44,5 +44,26 @@ ;; - - - + ;; - - - - - -;; too boring a problem. Skipping the rest of it. +(defn new-mul-interval [x y] + (let [l1 (lower-bound x) + u1 (upper-bound x) + l2 (lower-bound y) + u2 (upper-bound y) + sl1? (pos? l1) + su1? (pos? u1) + sl2? (pos? l2) + su2? (pos? u2)] + (cond (and sl1? su1? sl2? su2?) (make-interval (* l1 l2) (* u1 u2)) + (and sl1? su1? (not sl2?) su2?) (make-interval (* u1 l2) (* u1 u2)) + (and sl1? su1? (not sl2?) (not su2?)) (make-interval (* u1 l2) (* u2 l1)) + (and (not sl1?) su1? sl2? su2?) (make-interval (* l1 u2) (* u1 u2)) + (and (not sl1?) su1? (not sl2?) (not su2?)) (make-interval (* u1 l2) (* l1 l2)) + (and (not sl1?) (not su1?) sl2? su2?) (make-interval (* l1 u2) (* u1 l2)) + (and (not sl1?) (not su1?) (not sl2?) su2?) (make-interval (* l1 u2) (* l1 l2)) + (and (not sl1?) (not su1?) (not sl2?) (not su2?)) (make-interval (* u1 u2) (* l1 l2)) + (and (not sl1?) su1? (not sl2?) su2?) (let [p1 (* l1 l2) + p2 (* l1 u2) + p3 (* u1 l2) + p4 (* u1 u2)] + (make-interval (min p1 p2 p3 p4) + (max p1 p2 p3 p4)))))) \ No newline at end of file