Skip to content

Instantly share code, notes, and snippets.

@pathsny
Created April 6, 2010 06:38
Show Gist options
  • Save pathsny/357296 to your computer and use it in GitHub Desktop.
Save pathsny/357296 to your computer and use it in GitHub Desktop.
(define (make-interval a b) (cons a b))
(define (lower-bound int) (car int))
(define (upper-bound int) (cdr int))
(define (add-interval x y)
(make-interval (+ (lower-bound x) (lower-bound y))
(+ (upper-bound x) (upper-bound y))))
(define (sub-interval x y)
(make-interval (- (lower-bound x) (upper-bound y))
(- (upper-bound x) (lower-bound y))))
(define r1 (make-interval 4.2 4.5))
(define r2 (make-interval 4.2 4.5))
(add-interval (sub-interval r2 r1) r1) ; (3.9000000000000004 . 4.8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment