From 9bbad1be5874ab0be0f6e9ef1c2125ecd4247c7b Mon Sep 17 00:00:00 2001 From: Folkert Kevelam Date: Tue, 3 Jun 2025 20:47:33 +0200 Subject: [PATCH] Initial commit --- SICP/exercise_1_44.janet | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 SICP/exercise_1_44.janet diff --git a/SICP/exercise_1_44.janet b/SICP/exercise_1_44.janet new file mode 100644 index 0000000..5425bbe --- /dev/null +++ b/SICP/exercise_1_44.janet @@ -0,0 +1,34 @@ +(defn compose [f g] + (fn [x] (f (g x)))) + +(defn repeated [f n] + (defn iter [inner_f k] + (cond + (= k 1) inner_f + (iter (compose f inner_f) (- k 1)))) + (iter f n)) + +(def dx 0.01) +(defn smooth [f] + (fn [x] (let [c (f x) + p (f (- x dx)) + n (f (+ x dx))] + (/ (+ c p n) 3)))) + +(defn n-smooth [f n] + ((repeated smooth n) f)) + +(defn cubic [a b c] (fn [x] (+ (* x x x) (* a x x) (* b x) c))) +(def abs-cube (compose math/abs math/sin)) +(def smooth-abs (smooth abs-cube)) + +(def n-smooth-abs (n-smooth abs-cube 5)) + +(var i 0) +(while (< i 400000) + (printf "%f,%f,%f,%f" + (* i 0.00001) + (abs-cube (* i 0.00001)) + (smooth-abs (* i 0.00001)) + (n-smooth-abs (* i 0.00001))) + (set i (+ i 1)))