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 a (make-interval 100 101)) | |
(define b (make-interval 1.001 1.002)) | |
(mul-interval-small a a) ;;; '(10000 . 10200) | |
(mul-interval a a) ;;; '(10000 . 10201) | |
(mul-interval-small b b) ;;; '(1.0020009999999997 . 1.004003) | |
(mul-interval b b) ;;; '(1.0020009999999997 . 1.004004) |
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 (lower-bound i) (car i)) | |
(define (upper-bound i) (cdr i)) | |
(define (mul-interval-small x y) | |
(let ((a (lower-bound x)) | |
(b (upper-bound x)) | |
(c (lower-bound y)) | |
(d (upper-bound y)) | |
(width-x (/ (- (upper-bound x) (lower-bound x)) 2)) |
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 (lower-bound i) (car i)) | |
(define (upper-bound i) (cdr i)) | |
;;; c is the center | |
;;; n is the percentage | |
(define (make-center-percent c n) | |
(let ((w (* c (/ n 100)))) ;;; convert percentage to width | |
(make-center-width c w))) | |
(define (percent i) |
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 (+? x) (>= x 0)) ;;; Is x a positive number? | |
(define (-? x) (< x 0)) ;;; Is x a negative number? | |
(define (make-interval a b) (cons a b)) | |
(define (lower-bound i) (car i)) | |
(define (upper-bound i) (cdr i)) | |
(define (mul-interval x y) | |
(let ((a (lower-bound x)) | |
(b (upper-bound x)) |
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 (div-interval x y) | |
(let ((low (lower-bound y)) | |
(high (upper-bound y))) | |
(if (or (= low 0) (= high 0)) | |
(display "error") | |
(mul-interval x (make-interval (/ 1.0 high) (/ 1.0 low)))))) |
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
(mul-interval (make-interval 1 2) (make-interval 1 2)) ;;;'(1 . 4) | |
(mul-interval (make-interval 2 3) (make-interval 2 3)) ;;;'(4 . 9) | |
(mul-interval (make-interval 3 4) (make-interval 3 4)) ;;;'(9 . 16) |
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 (sub-interval x y) | |
(make-interval (- (lower-bound x) (upper-bound y)) | |
(+ (upper-bound x) (lower-bound y)))) |
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 (lower-bound i) (car i)) | |
(define (upper-bound i) (cdr i)) |
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 zero (lambda (f) (lambda (x) x))) | |
(define one (lambda (f) (lambda (x) (f x)))) | |
(define two (lambda (f) (lambda (x) (f (f x))))) |
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
;;;zero | |
(define zero (lambda (f) (lambda (x) x))) | |
(((lambda (f) (lambda (x) x)) square) 100) | |
((lambda (x) x) 100) | |
100 | |
;;;one | |
(((lambda (f) (lambda (x) (f ((zero f) x)))) square) 100) | |
((lambda (x) (square ((zero square) x))) 100) | |
(square ((zero square) 100)) |