-
Notifications
You must be signed in to change notification settings - Fork 10
/
2.11.ss
37 lines (35 loc) · 2.11 KB
/
2.11.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(define (make-interval a b) (cons a b))
(define (upper-bound i) (max (car i) (cdr i)))
(define (lower-bound i) (min (car i) (cdr i)))
(define (mul-interval x y)
(cond ((and (> (lower-bound x) 0) (> (lower-bound y) 0))
(make-interval (* (lower-bound x) (lower-bound y))
(* (upper-bound x) (upper-bound y))))
((and (< (lower-bound x) 0) (> (upper-bound x) 0) (> (lower-bound y) 0))
(make-interval (* (lower-bound x) (upper-bound y))
(* (upper-bound x) (upper-bound y))))
((and (< (upper-bound x) 0) (> (lower-bound y) 0))
(make-interval (* (lower-bound x) (upper-bound y))
(* (upper-bound x) (lower-bound y))))
((and (> (lower-bound x) 0) (< (lower-bound y) 0) (> (upper-bound y) 0))
(make-interval (* (upper-bound x) (lower-bound y))
(* (upper-bound x) (upper-bound y))))
((and (> (lower-bound x) 0) (< (upper-bound y) 0))
(make-interval (* (upper-bound x) (lower-bound y))
(* (lower-bound x) (upper-bound y))))
((and (< (lower-bound x) 0) (> (upper-bound x) 0) (< (lower-bound y) 0) (> (upper-bound y) 0))
(make-interval (* (min (lower-bound x) (lower-bound y))
(max (upper-bound x) (upper-bound y)))
(max (* (lower-bound x) (lower-bound y))
(* (upper-bound x) (upper-bound y)))))
((and (< (upper-bound x) 0) (< (lower-bound y) 0) (> (upper-bound y) 0))
(make-interval (* (min (lower-bound x) (lower-bound y))
(upper-bound y))
(* (lower-bound x) (lower-bound y))))
((and (< (lower-bound x) 0) (> (upper-bound x) 0) (< (upper-bound y) 0))
(make-interval (* (min (lower-bound x) (lower-bound y))
(upper-bound x))
(* (lower-bound x) (lower-bound y))))
((and (< (upper-bound x) 0) (< (upper-bound y) 0))
(make-interval (* (upper-bound x) (upper-bound y))
(* (lower-bound x) (lower-bound y))))))