(defclass interval (is-a temporary) (role concrete) (slot a (type NUMBER)) ; low bound (slot b (type NUMBER)) ; high bound (message-handler show) ) ; print interval (defmessage-handler interval show () (printout t "[" ?self:a ";" ?self:b "]") ) ; create interval approximation of the number (defmethod create-interval ((?x NUMBER)) (make-instance of interval (a ?x) (b ?x)) ) ; create interval (defmethod create-interval ((?xl NUMBER) (?xt NUMBER)) (make-instance of interval (a ?xl) (b ?xt)) ) ; $[x_1,x_2]+[y_1,y_2] = [x_1+y_1,x_2+y_2]$ (defmethod + ((?x interval) (?y interval)) (make-instance of interval (a (+ (send ?x get-a) (send ?y get-a))) (b (+ (send ?x get-b) (send ?y get-b))) ) ) ; $[x_1,x_2]-[y_1,y_2] = [x_1-y_2,x_2-y_1]$ (defmethod - ((?x interval) (?y interval)) (make-instance of interval (a (- (send ?x get-a) (send ?y get-b))) (b (- (send ?x get-b) (send ?y get-a))) ) ) ; $[x_1,x_2]\times[y_1,y_2] = [\min(x_1y_1,x_1y_2,x_2y_1,x_2y_2),$ ; \phantom{$[x_1,x_2]\times[y_1,y_2] = [$}$\max(x_1y_1,x_1y_2,x_2y_1,x_2y_2)]$ (defmethod * ((?x interval) (?y interval)) (bind ?x1 (* (send ?x get-a) (send ?y get-a))) (bind ?x2 (* (send ?x get-a) (send ?y get-b))) (bind ?x3 (* (send ?x get-b) (send ?y get-a))) (bind ?x4 (* (send ?x get-b) (send ?y get-b))) (make-instance of interval (a (min ?x1 ?x2 ?x3 ?x4)) (b (max ?x1 ?x2 ?x3 ?x4)) ) ) ; $[x_1,x_2] / [y_1,y_2]=[x_1,x_2]\times\left[\frac1{y_2},\frac1{y_1}\right]$, $0\not\in[y_1,y_2]$ (defmethod / ((?x interval) (?y interval)) (if (and (<= (send ?y get-a) 0) (>= (send ?y get-b) 0)) then (printout t "Division by zero!" crlf) (halt) ) (bind ?inv-y (make-instance of interval (a (/ 1 (send ?y get-b))) (b (/ 1 (send ?y get-a))) )) (* ?x ?inv-y) )