Exercise2-7 <---> Exercise2-9

Exercise 2.8.

Using reasoning analogous to Alyssa's, describe how the difference of two intervals may be computed. Define a corresponding subtraction procedure, called sub-interval.


Ru: Рассуждая в духе Лизы, опишите, как можно вычислить разность двух интервалов. Напишите соответствующую процедуру вычитания, называемую sub-interval.


Scheme solution:

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

Exercise2-7 <---> Exercise2-9


Comments

;;Answer above is incorrect, it should be:

(define (sub-interval x y)

  • (make-interval (- (upper-bound y) (lower-bound y))
    • (- (upper-bound x) (lower-bound y))))

;; since y is > x (from the make-interval procedure in the previous exercise.

Posted by 195 at 2009-02-18 08:13:34 X

The comment above is wrong, and the answer provided is correct.

We are subtracting one interval from another here, not the bounds, so there is no indication which of x and y is larger.

Even if y>x your comment still makes no sense! You would be making an interval with the lower bound equal to the size of the interval y.

Posted by 204 at 2009-06-24 12:34:48 X

I think both are "incorrect", not semanticly speaking (didn't check), but because the exercise says "Using reasoning analogous to Alyssa's". I solved it this way:

(define (sub-interval x y)

  • (add-interval x
    • (make-interval (- (lower-bound y))
      • (- (upper-bound y)))))

analogously to the div-interval procedure.

Posted by Blackout at 2009-08-24 18:37:06 X

:) :)) :( ;) :\ |) X-( B) Markup

Exercise2-8 (last edited 2008-05-11 11:36:08 by localhost)