|
11 | 11 | [scicloj.kindly.v4.kind :as kind] |
12 | 12 | [emmy.env :as e :refer [->infix simplify Lagrange-equations literal-function]] |
13 | 13 | [emmy.mechanics.lagrange :as lg] |
14 | | - [emmy.expression.render :as r :refer [->infix]] |
15 | 14 | [civitas.repl :as repl])) |
16 | 15 |
|
17 | 16 | ;; Elemetary introduction to Emmy, taken from the first pages of the open-access book |
|
21 | 20 | ;; The [Emmy]((https://emmy.mentat.org)) maintainer, [Sam Ritchie](https://roadtoreality.substack.com/), wrote the source for this page, namely the |
22 | 21 | ;; [LaTex version of FDG](https://github.com/mentat-collective/fdg-book/blob/main/scheme/org/prologue.org). |
23 | 22 |
|
| 23 | +;; In adopting MIT-Scheme's `(define ...)`, I trust that Clojure people will bridge that gap quickly |
| 24 | +;; and am sure of the eventual gratitude of all readers of that immutable, dense book. So without further ado ... |
| 25 | + |
24 | 26 | ^:kindly/hide-code |
25 | 27 | (kind/hiccup |
26 | 28 | [:div |
|
29 | 31 | [:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen/dist/scittle.cljs-ajax.js"}] |
30 | 32 | [:script {:src "https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js", :crossorigin ""}] |
31 | 33 | [:script {:src "https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js", :crossorigin ""}] |
32 | | - [:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen/dist/scittle.reagent.js"}]]) |
33 | | - |
34 | | -^:kindly/hide-code |
35 | | -(def md |
36 | | - (comp kindly/hide-code kind/md)) |
37 | | - |
38 | | - |
39 | | -^:kindly/hide-code |
40 | | -(kind/scittle |
41 | | - '(defn walk [inner outer form] |
42 | | - (cond |
43 | | - (list? form) (outer (apply list (map inner form))) |
44 | | - (seq? form) (outer (doall (map inner form))) |
45 | | - (coll? form) (outer (into (empty form) (map inner form))) |
46 | | - :else (outer form)))) |
47 | | - |
48 | | -^:kindly/hide-code |
49 | | -(kind/scittle |
50 | | - '(defn postwalk [f form] |
51 | | - (walk (partial postwalk f) f form))) |
52 | | - |
53 | | -^:kindly/hide-code |
54 | | -(kind/scittle |
55 | | - '(defn postwalk-replace [smap form] |
56 | | - (postwalk (fn [x] (if (contains? smap x) (smap x) x)) form))) |
57 | | - |
58 | | -^:kindly/hide-code |
59 | | -(kind/scittle |
60 | | - '(defmacro let-scheme [b & e] |
61 | | - (concat (list 'let (into [] (apply concat b))) e))) |
62 | | - |
63 | | -^:kindly/hide-code |
64 | | -(kind/scittle |
65 | | - '(defmacro define-1 [h & b] |
66 | | - (let [body (postwalk-replace {'let 'let-scheme} b)] |
67 | | - (if (coll? h) |
68 | | - (if (coll? (first h)) |
69 | | - (list 'defn (ffirst h) (into [] (rest (first h))) |
70 | | - (concat (list 'fn (into [] (rest h))) body)) |
71 | | - (concat (list 'defn (first h) (into [] (rest h))) |
72 | | - body)) |
73 | | - (concat (list 'def h) body))))) |
74 | | - |
75 | | -^:kindly/hide-code |
76 | | -(kind/scittle |
77 | | - '(defmacro define [h & b] |
78 | | - (if (and (coll? h) (= (first h) 'tex-inspect)) |
79 | | - (list 'do |
80 | | - (concat ['define-1 (second h)] b) |
81 | | - h) |
82 | | - (concat ['define-1 h] b)))) |
83 | | - |
84 | | -^:kindly/hide-code |
85 | | -(kind/scittle |
86 | | - '(defmacro lambda [h b] |
87 | | - (list 'fn (into [] h) b))) |
| 34 | + [:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen/dist/scittle.reagent.js"}] |
| 35 | + [:script {:type "application/x-scittle" :src "scheme.cljc"}]]) |
88 | 36 |
|
89 | 37 | ^:kindly/hide-code |
90 | 38 | (kind/scittle |
|
119 | 67 | (list 'kind/reagent [:h3 (list 'quote (cons 'show-expression b))])) |
120 | 68 |
|
121 | 69 | ^:kindly/hide-code |
122 | | -(kind/scittle '(declare Gamma)) |
| 70 | +(def md |
| 71 | + (comp kindly/hide-code kind/md)) |
123 | 72 |
|
| 73 | +;; |
124 | 74 | ;; ## Programming and Understanding |
125 | 75 |
|
126 | 76 | ;; One way to become aware of the precision required to unambiguously communicate a |
|
260 | 210 |
|
261 | 211 | ;; This expression is equivalent to a computer program:[fn:6] |
262 | 212 |
|
| 213 | +^:kindly/hide-code |
| 214 | +(kind/scittle '(declare Gamma)) |
| 215 | + |
263 | 216 | (define ((Lagrange-equations Lagrangian) w) |
264 | 217 | (- (D (compose ((partial 2) Lagrangian) (Gamma w))) |
265 | 218 | (compose ((partial 1) Lagrangian) (Gamma w)))) |
|
310 | 263 | proposed-solution) |
311 | 264 | 't)) |
312 | 265 |
|
313 | | -;; [note by MAK: copy-paste the code into the sidebar and verify the above result.] |
| 266 | +;; [note by MAK: copy-paste the `(show-expression ...)` code-snippet into the sidebar, press Ctrl+Enter and verify the above result.] |
314 | 267 |
|
315 | 268 | ;; The residual here shows that for nonzero amplitude, the only solutions allowed |
316 | 269 | ;; are ones where $(k - m\omega^2) = 0$ or $\omega = \sqrt{k/m}$. |
|
0 commit comments