summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2017-09-24 02:29:51 +0000
committerrsiddharth <s@ricketyspace.net>2017-09-24 02:29:51 +0000
commit39c264bbafc10ad9997c21ae36995ab179d8d2b9 (patch)
tree1849407a65041054bbd22848626958eac4187242 /net
parent57257f4909bf43d03f0f1af91327092fc4626925 (diff)
net: Add (net ricketyspace sicp one twenty nine)
Diffstat (limited to 'net')
-rw-r--r--net/ricketyspace/sicp/one/twentynine.scm25
1 files changed, 25 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/one/twentynine.scm b/net/ricketyspace/sicp/one/twentynine.scm
new file mode 100644
index 0000000..1dfdc45
--- /dev/null
+++ b/net/ricketyspace/sicp/one/twentynine.scm
@@ -0,0 +1,25 @@
+;;;; Under Creative Commons Attribution-ShareAlike 4.0
+;;;; International. See
+;;;; <https://creativecommons.org/licenses/by-sa/4.0/>.
+
+(define-module (net ricketyspace sicp one twentynine)
+ #:export (simpsons))
+
+(define (sum term a next b)
+ (if (> a b)
+ 0
+ (+ (term a)
+ (sum term (next a) next b))))
+
+(define (simpsons f a b n)
+ (let* ((h (/ (- b a) (* 1.0 n)))
+ (y (lambda (k) (+ a (* k h))))
+ (ce (lambda (k) ;coefficient
+ (cond ((or (= k 0) (= k n)) 1)
+ ((even? k) 2)
+ (else 4))))
+ (term (lambda (k)
+ (* (ce k) (f (y k)))))
+ (next (lambda (k) (1+ k))))
+ (* (/ h 3.0)
+ (sum term 0 next n))))