From 7ed2f6a8664e9c71f8972da58af5b4e3878b0f4b Mon Sep 17 00:00:00 2001
From: rsiddharth <s@ricketyspace.net>
Date: Sat, 11 Aug 2018 03:22:39 +0000
Subject: Add (net ricketyspace sicp two ten).

---
 net/ricketyspace/sicp/two/ten.scm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 net/ricketyspace/sicp/two/ten.scm

(limited to 'net/ricketyspace')

diff --git a/net/ricketyspace/sicp/two/ten.scm b/net/ricketyspace/sicp/two/ten.scm
new file mode 100644
index 0000000..d8e92df
--- /dev/null
+++ 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)))))))
-- 
cgit v1.2.3