42 lines
963 B
Plaintext
42 lines
963 B
Plaintext
(defn cube [x]
|
|
(* x x x))
|
|
|
|
(defn p [x]
|
|
(-
|
|
(* 3 x)
|
|
(* 4 (cube x))))
|
|
|
|
(defn sine [angle]
|
|
(if (not (> (math/abs angle) 0.1))
|
|
angle
|
|
(p (sine (/ angle 3.0)))))
|
|
|
|
(import ./dot :as dot)
|
|
|
|
(defn add-to [graph counter angle parent]
|
|
(def label (string/format "(sine %f)" angle))
|
|
(def node_name (string/format "node_%d" counter))
|
|
(def clr
|
|
(cond (> angle 0.1) "lightgray"
|
|
"lightgreen"))
|
|
(dot/add-node graph node_name :label label :shape "box" :fillcolor clr :style "filled")
|
|
|
|
(dot/add-relation graph parent node_name)
|
|
node_name)
|
|
|
|
(defn sine2 [angle]
|
|
(def graph (dot/create "angle" :graph_type :digraph))
|
|
(var counter 0)
|
|
(defn sin [angle parent]
|
|
(def name (add-to graph counter angle parent))
|
|
(set counter (+ counter 1))
|
|
(if (not (> (math/abs angle) 0.1))
|
|
angle
|
|
(p (sin (/ angle 3.0) name))))
|
|
|
|
(def result (sin angle "start"))
|
|
(dot/write graph "exercise_1_15.gv")
|
|
result)
|
|
|
|
(print (sine2 12.15))
|