sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit 7ed2f6a8664e9c71f8972da58af5b4e3878b0f4b
parent ab88f8ee42ab2934bed5eac5f4be9edc61be7cf8
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 11 Aug 2018 03:22:39 +0000

Add (net ricketyspace sicp two ten).

Diffstat:
net/ricketyspace/sicp/two/ten.scm | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/net/ricketyspace/sicp/two/ten.scm b/net/ricketyspace/sicp/two/ten.scm @@ -0,0 +1,24 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; <https://creativecommons.org/licenses/by-sa/4.0/>. + +(define-module (net ricketyspace sicp two ten) + #:use-module (net ricketyspace sicp two seven) + #:export (div-interval)) + +(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) + (define (spans-zero y) + (and (<= (lower-bound y) 0) + (>= (upper-bound y) 0))) + (cond ((spans-zero y) (error "Second argument cannot span zero!")) + (else (mul-interval x + (make-interval (/ 1.0 (upper-bound y)) + (/ 1.0 (lower-bound y)))))))