From 71b1de4198dad80ffc8755c34aa48a39ef512226 Mon Sep 17 00:00:00 2001
From: rsiddharth <s@ricketyspace.net>
Date: Sat, 14 Oct 2017 03:33:06 +0000
Subject: (net ricketyspace sicp one thirtyone): Simplify pi functions.

* net/ricketyspace/sicp/one/thirtyone.scm
(pi, pi-iter): Update functions.
---
 net/ricketyspace/sicp/one/thirtyone.scm | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

(limited to 'net')

diff --git a/net/ricketyspace/sicp/one/thirtyone.scm b/net/ricketyspace/sicp/one/thirtyone.scm
index f84f637..558361e 100644
--- a/net/ricketyspace/sicp/one/thirtyone.scm
+++ b/net/ricketyspace/sicp/one/thirtyone.scm
@@ -29,18 +29,18 @@
     (product-iter term 1 next n)))
 
 (define (pi precision)
-  (let* ((n (lambda (x) (* (+ (quotient x 2) 1) 2))) ; numerator of term.
-         (d (lambda (x) (+ (* (quotient (1+ x) 2) 2) 1))) ; denominator of term.
-         (term (lambda (x) (/ (* (n x) 1.0) (* (d x) 1.0))))
+  (let* ((n (lambda (x) (if (even? x) (+ x 2) (+ x 1)))) ; numerator of term.
+         (d (lambda (x) (if (even? x) (+ x 1) (+ x 2)))) ; denominator of term.
+         (term (lambda (x) (/ (n x) (d x))))
          (next (lambda (x) (1+ x))))
-    (* (product term 1 next precision) 4)))
+    (* (product term 1.0 next precision) 4)))
 
 (define (pi-iter precision)
-  (let* ((n (lambda (x) (* (+ (quotient x 2) 1) 2))) ; numerator of term.
-         (d (lambda (x) (+ (* (quotient (1+ x) 2) 2) 1))) ; denominator of term.
-         (term (lambda (x) (/ (* (n x) 1.0) (* (d x) 1.0))))
+  (let* ((n (lambda (x) (if (even? x) (+ x 2) (+ x 1)))) ; numerator of term.
+         (d (lambda (x) (if (even? x) (+ x 1) (+ x 2)))) ; denominator of term.
+         (term (lambda (x) (/ (n x) (d x))))
          (next (lambda (x) (1+ x))))
-    (* (product-iter term 1 next precision) 4)))
+    (* (product-iter term 1.0 next precision) 4)))
 
 
 ;;; Guile REPL
-- 
cgit v1.2.3