summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2018-08-11 03:22:39 +0000
committerrsiddharth <s@ricketyspace.net>2018-08-11 03:22:39 +0000
commit7ed2f6a8664e9c71f8972da58af5b4e3878b0f4b (patch)
treef7a32a4723b98a8dfa061ac399d44b7c20c8ae15 /net
parentab88f8ee42ab2934bed5eac5f4be9edc61be7cf8 (diff)
Add (net ricketyspace sicp two ten).
Diffstat (limited to 'net')
-rw-r--r--net/ricketyspace/sicp/two/ten.scm24
1 files changed, 24 insertions, 0 deletions
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)))))))