Created
August 13, 2013 23:20
-
-
Save yakreved/6226669 to your computer and use it in GitHub Desktop.
sicp 2.12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (make-interval a b) (cons a b)) | |
| (define (upper-bound x) (car x)) | |
| (define (lower-bound x) (cdr x)) | |
| (define (width x) (- (cdr x) (car x))) | |
| (define (mul-interval x y) | |
| (let ((p1 (* (lower-bound x) (lower-bound y))) | |
| (p2 (* (lower-bound x) (upper-bound y))) | |
| (p3 (* (upper-bound x) (lower-bound y))) | |
| (p4 (* (upper-bound x) (upper-bound y)))) | |
| (make-interval (min p1 p2 p3 p4) | |
| (max p1 p2 p3 p4)))) | |
| (define (make-center-percent c p) | |
| (let ((w (* c (/ p 100)))) | |
| (make-interval (- c w) (+ c w)))) | |
| (define (percent x) | |
| (abs (* 100 (/ (- (upper-bound x) (lower-bound x)) (+ (upper-bound x) (lower-bound x))))) | |
| ) | |
| (make-center-percent 100 5) | |
| (percent (make-interval 95 105)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment