2.6
2.7
2.8
2.9
2.10
(define zero (lambda (f) (lambda (x) x)))
(define (add-1 n)
(lambda (f) (lambda (x) (f ((n f) x)))))
((zero 4) 3)
(add-1 5 1)
2.7
(define (add-interval x y)
(make-interval (+ (lower-bound x) (lower-bound y))
(+ (upper-bound x) (upper-bound y))))
(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 (div-interval x y)
(mul-interval x
(make-interval (/ 1.0 (upper-bound y))
(/ 1.0 (lower-bound y)))))
(define (make-interval a b) (cons a b))
(define (lower-bound x) (car x))
(define (upper-bound x) (cdr x))
(define interval-1 (make-interval 1.1 2.1))
(define interval-2 (make-interval 1.2 2.2))
(define new-interval (add-interval one-interval two-interval))
(lower-bound new-interval)
(upper-bound new-interval)
2.8
(define (add-interval x y)
(make-interval (+ (lower-bound x) (lower-bound y))
(+ (upper-bound x) (upper-bound y))))
(define (sub-interval x y)
(add-interval x (make-interval (- 0 (lower-bound y)) (- 0 (upper-bound y)))))
(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 (div-interval x y)
(mul-interval x
(make-interval (/ 1.0 (upper-bound y))
(/ 1.0 (lower-bound y)))))
(define (make-interval a b) (cons a b))
(define (lower-bound x) (car x))
(define (upper-bound x) (cdr x))
(define interval-1 (make-interval 1.1 2.1))
(define interval-2 (make-interval 1.2 2.2))
(define new-add-interval (add-interval interval-1 interval-2))
(define new-mul-interval (mul-interval interval-1 interval-2))
(define new-div-interval (div-interval interval-1 interval-2))
(define new-sub-interval (sub-interval interval-1 interval-2))
(lower-bound new-sub-interval)
(upper-bound new-sub-interval)
2.9
(define (add-interval x y)
(make-interval (+ (lower-bound x) (lower-bound y))
(+ (upper-bound x) (upper-bound y))))
(define (sub-interval x y)
(add-interval x (make-interval (- 0 (lower-bound y)) (- 0 (upper-bound y)))))
(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 (div-interval x y)
(mul-interval x
(make-interval (/ 1.0 (upper-bound y))
(/ 1.0 (lower-bound y)))))
(define (make-interval a b) (cons a b))
(define (lower-bound x) (car x))
(define (upper-bound x) (cdr x))
(define (interval-width interval)
(/ (- (upper-bound interval) (lower-bound interval)) 2))
(define (oper-interval-width v1 v2)
(let ((w1 (interval-width v1))
(w2 (interval-width v2)))
(lambda(x) (x w1 w2))))
(define interval-1 (make-interval 1.1 2.1))
(define interval-2 (make-interval 1.2 2.2))
(interval-width (add-interval interval-1 interval-2))
((oper-interval-width interval-1 interval-2) +)
(interval-width (sub-interval interval-1 interval-2))
((oper-interval-width interval-1 interval-2) -)
(interval-width (mul-interval interval-1 interval-2))
((oper-interval-width interval-1 interval-2) *)
(interval-width (div-interval interval-1 interval-2))
((oper-interval-width interval-1 interval-2) /)
2.10
(define (add-interval x y)
(make-interval (+ (lower-bound x) (lower-bound y))
(+ (upper-bound x) (upper-bound y))))
(define (sub-interval x y)
(add-interval x (make-interval (- 0 (lower-bound y)) (- 0 (upper-bound y)))))
(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 (div-interval x y)
(let ((product-y (* (lower-bound y) (upper-bound y))))
(if (< product-y 0)
(display "illegal number")
(mul-interval x
(make-interval (/ 1.0 (upper-bound y)) (/ 1.0 (lower-bound y)))))))
(define (make-interval a b) (cons a b))
(define (lower-bound x) (car x))
(define (upper-bound x) (cdr x))
(define (interval-width interval)
(/ (- (upper-bound interval) (lower-bound interval)) 2))
(define (oper-interval-width v1 v2)
(let ((w1 (interval-width v1))
(w2 (interval-width v2)))
(lambda(x) (x w1 w2))))
(define interval-1 (make-interval 1.1 2.1))
(define interval-2 (make-interval -1.2 2.2))
(div-interval interval-1 interval-2)