(load "2_07.scm")

(define (mul-interval x y)
    (let ((xl (lower-bound x))
          (xu (upper-bound x))
          (yl (lower-bound y))
          (yu (upper-bound y)))

        ; cases are limited by the fact that lower < upper
        ; otherwise there would be more
  case 1
                ; (+, +) * (+, +)
                ; (l * l, u * u)
                (make-interval (* xl yl) (* xu yu)))
  case 2
                ; (-, -) * (-, -)
                ; (u * u, l * l)
                (make-interval (* xu yu) (* xl yl)))
  case 3
                ; (+, +) * (-, -)
                ; (u * l, l * u) 
                (make-interval (* xu yl) (* xl yu)))
  case 4
                ; (-, -) * (+, +)
                ; (l * u, u * l)  
                (make-interval (* xl yu) (* xu yl)))
  case 5
                ; (+, +) * (-, +)
                ; (u * l, l * u)
                (make-interval (* xu yl) (* xl yu)))
  case 6
                ; (+, +) * (-, +)
                ; (u * l, l * u)
                (make-interval (* xu yl) (* xl yu)))
  case 6
                ; (-, +) * (+, +)
                ; (l * u, u * l)
                (make-interval (* xl yu) (* xu yl)))
  case 7
                ; (-, -) * (-, +)
                ; (l * u, u * l)
                (make-interval (* xl yu) (* xu yl)))
  case 8
                ; (-, +) * (-, -)
                ; (u * l, l * u)
                (make-interval (* xu yl) (* xl yu)))
  case 9
                ; (-, +) * (-, +)
                ; ?
                (let ((p1 (* xl yl))
                          (p2 (* xl yu))
                          (p3 (* xu yl))
                          (p4 (* xu yu)))
                        (make-interval (min p1 p2 p3 p4)
                                       (max p1 p2 p3 p4)))
                )
              (else (error "cases should be handles"))
            )))
 

(display-interval (mul-interval (make-interval -4 -2) (make-interval 0 1)))
(newline)

; this should fail since its a bad interval (else case)
(mul-interval (make-interval 5 -5) (make-interval 0 1))


 cases are limited by the fact that lower < upper
 otherwise there would be more
 (+, +) * (+, +)
 (l * l, u * u)
 (-, -) * (-, -)
 (u * u, l * l)
 (+, +) * (-, -)
 (u * l, l * u) 
 (-, -) * (+, +)
 (l * u, u * l)  
 (+, +) * (-, +)
 (u * l, l * u)
 (+, +) * (-, +)
 (u * l, l * u)
 (-, +) * (+, +)
 (l * u, u * l)
 (-, -) * (-, +)
 (l * u, u * l)
 (-, +) * (-, -)
 (u * l, l * u)
 (-, +) * (-, +)
 ?
 this should fail since its a bad interval (else case)
(load "2_07.scm")

(define (mul-interval x y)
    (let ((xl (lower-bound x))
          (xu (upper-bound x))
          (yl (lower-bound y))
          (yu (upper-bound y)))

  case 1
                (make-interval (* xl yl) (* xu yu)))
  case 2
                (make-interval (* xu yu) (* xl yl)))
  case 3
                (make-interval (* xu yl) (* xl yu)))
  case 4
                (make-interval (* xl yu) (* xu yl)))
  case 5
                (make-interval (* xu yl) (* xl yu)))
  case 6
                (make-interval (* xu yl) (* xl yu)))
  case 6
                (make-interval (* xl yu) (* xu yl)))
  case 7
                (make-interval (* xl yu) (* xu yl)))
  case 8
                (make-interval (* xu yl) (* xl yu)))
  case 9
                (let ((p1 (* xl yl))
                          (p2 (* xl yu))
                          (p3 (* xu yl))
                          (p4 (* xu yu)))
                        (make-interval (min p1 p2 p3 p4)
                                       (max p1 p2 p3 p4)))
                )
              (else (error "cases should be handles"))
            )))
 

(display-interval (mul-interval (make-interval -4 -2) (make-interval 0 1)))
(newline)

(mul-interval (make-interval 5 -5) (make-interval 0 1))

