From 04fcdb04e2983f9b0ad0cfdb5e36ba04511bc121 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 7 Jan 2017 04:31:02 +0000 Subject: Add one/fifteen.scm --- one/fifteen.scm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 one/fifteen.scm diff --git a/one/fifteen.scm b/one/fifteen.scm new file mode 100644 index 0000000..1b2ac24 --- /dev/null +++ b/one/fifteen.scm @@ -0,0 +1,31 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; . + +(define-module (one fifteen) + #:use-module (ice-9 regex) + #:export (sine)) + +(define (sine angle) + (let ((out "")) + (define (log angle) + (set! out (string-append out " (p (sine " + (number->string angle)))) + (define (close-parens s) + (string-trim (string-append + s (fold-matches "\\([p,s]" s "" + (lambda (match prev) + (string-append prev ")")))))) + (define (cube x) (* x x x)) + (define (p x) (- (* 3 x) (* 4 (cube x)))) + (define (s angle) + (if (not (> (abs angle) 0.1)) + angle + (begin + (log angle) + (p (s (/ angle 3.0)))))) + (s angle) + (close-parens out))) +;; +;; (sine 12.15) +;; $24 = "(p (sine 12.15 (p (sine 4.05 (p (sine 1.3499999999999999 (p (sine 0.44999999999999996 (p (sine 0.15))))))))))" -- cgit v1.2.3