/
ex2-13.scm
38 lines (28 loc) · 855 Bytes
/
ex2-13.scm
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
;; ex2-07
(define (make-interval a b) (cons a b))
(define (lower-bound x)
(if (< (car x) (cdr x))
(car x)
(cdr x)))
(define (upper-bound x)
(if (> (car x) (cdr x))
(car x)
(cdr x)))
;; ex2-11
(define (make-center-width c w)
(make-interval (- c w) (+ c w)))
(define (center i)
(/ (+ (lower-bound i) (upper-bound i)) 2))
(define (width i)
(/ (- (upper-bound i) (lower-bound i)) 2))
;; ex2-12
(define (make-center-percent c p)
(make-interval (- c (* c p)) (+ c (* c p))))
;; ex2-13
(define (mul-interval a b)
(let ((this (* (center a) (center b))))
(make-interval
;; NOTE: this is the full expansion, you can drop the outer most term
(+ (* this (- 1 (* 0.5 (+ (width a) (width b))) )) (* 0.25 (width a) (width b)))
(+ (* this (+ 1 (* 0.5 (+ (width a) (width b))) )) (* 0.25 (width a) (width b)))
)))