solutions to 3.58 and 3.59
authorRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Sat, 9 Jul 2011 16:26:12 +0000 (21:56 +0530)
committerRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Sat, 9 Jul 2011 16:26:12 +0000 (21:56 +0530)
src/sicp/ex3_58.rkt [new file with mode: 0644]
src/sicp/ex3_59.rkt [new file with mode: 0644]

diff --git a/src/sicp/ex3_58.rkt b/src/sicp/ex3_58.rkt
new file mode 100644 (file)
index 0000000..d0258fb
--- /dev/null
@@ -0,0 +1,13 @@
+#lang racket
+
+(define (expand num den radix)
+  (cons-stream
+   (quotient (* num radix) den)
+   (expand (remainder (* num radix) den) den radix)))
+
+#|
+
+The function gives the digits in the fractional part of the division as a
+stream.
+
+|#
\ No newline at end of file
diff --git a/src/sicp/ex3_59.rkt b/src/sicp/ex3_59.rkt
new file mode 100644 (file)
index 0000000..2f80ee8
--- /dev/null
@@ -0,0 +1,21 @@
+#lang racket
+
+;; part a
+(define (integrate-series stream)
+  (define (integrate-iter S I)
+    (stream-map (lambda (s i)
+                  (* s (/ 1 i)))
+                S
+                I))
+  (integrate-iter stream
+                  (integers-starting-from 1)))
+
+;; part b
+(define sine-series
+  (cons-stream 0 (integrate-series cosine-series)))
+
+(define cosine-series
+    (cons-stream 1 (scale-stream (integrate-series sine-series) -1)))
+
+
+