Skip to content

Instantly share code, notes, and snippets.

(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)
(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))
(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)
(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))
(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))))))
(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)
(define (sub-interval x y)
(make-interval (- (lower-bound x) (upper-bound y))
(+ (upper-bound x) (lower-bound y))))
(define (make-interval a b) (cons a b))
(define (lower-bound i) (car i))
(define (upper-bound i) (cdr i))
(define zero (lambda (f) (lambda (x) x)))
(define one (lambda (f) (lambda (x) (f x))))
(define two (lambda (f) (lambda (x) (f (f x)))))
;;;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))