Skip to content

Commit 7fa3e74

Browse files
authored
FDGCh02 in browser (#313)
1 parent c53bf97 commit 7fa3e74

8 files changed

Lines changed: 69 additions & 94 deletions

File tree

src/mentat_collective/emmy/debroglie.clj

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,14 @@
1313
time infinite? abs ref partial =])
1414
(:require [scicloj.kindly.v4.api :as kindly]
1515
[scicloj.kindly.v4.kind :as kind]
16-
[mentat-collective.emmy.scheme :refer [define-1 let-scheme lambda]]
16+
[mentat-collective.emmy.scheme :refer [define-1 let-scheme lambda] :as scheme]
1717
[civitas.repl :as repl]))
1818

1919
^:kindly/hide-code
2020
(def prod true) #_"used to check Emmy in Scittle kitchen"
2121

2222
^:kindly/hide-code
23-
(kind/hiccup
24-
[:div
25-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.js"}]
26-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.emmy.js"}]
27-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.cljs-ajax.js"}]
28-
[:script {:src "https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js", :crossorigin ""}]
29-
[:script {:src "https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js", :crossorigin ""}]
30-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.reagent.js"}]
31-
[:script {:type "application/x-scittle" :src "scheme.cljc"}]])
23+
(kind/hiccup scheme/scittle-kitchen-hiccup)
3224

3325
^:kindly/hide-code
3426
(defmacro define [& b]

src/mentat_collective/emmy/fdg_ch01.clj

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
time infinite? abs ref partial =])
1414
(:require [scicloj.kindly.v4.api :as kindly]
1515
[scicloj.kindly.v4.kind :as kind]
16-
[mentat-collective.emmy.scheme :refer [define-1 let-scheme]]
16+
[mentat-collective.emmy.scheme :refer [define-1 let-scheme] :as scheme]
1717
[civitas.repl :as repl]))
1818

1919
;; The code snippets are executable, copy-paste them to the sidebar of the page.
@@ -30,15 +30,7 @@
3030
;; while being sure of the gratitude of all readers of the immutable, dense book. So without further ado ...
3131

3232
^:kindly/hide-code
33-
(kind/hiccup
34-
[:div
35-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.js"}]
36-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.emmy.js"}]
37-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.cljs-ajax.js"}]
38-
[:script {:src "https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js", :crossorigin ""}]
39-
[:script {:src "https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js", :crossorigin ""}]
40-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.reagent.js"}]
41-
[:script {:type "application/x-scittle" :src "scheme.cljc"}]])
33+
(kind/hiccup scheme/scittle-kitchen-hiccup)
4234

4335
^:kindly/hide-code
4436
(defmacro define [& b]
@@ -433,6 +425,10 @@
433425
(kind/hidden
434426
(define-coordinates t e/R1-rect))
435427

428+
^:kindly/hide-code
429+
(kind/scittle
430+
'(define-coordinates t e/R1-rect))
431+
436432
;; :::{#cartan}
437433
(define Cartan
438434
(Christoffel->Cartan
@@ -441,7 +437,7 @@
441437
(coordinate-system->basis R2-rect))))
442438
;; :::
443439

444-
(def geodesic-equation-residuals
440+
(define geodesic-equation-residuals
445441
(((((covariant-derivative Cartan gamma) d:dt)
446442
((differential gamma) d:dt))
447443
(chart R2-rect))
@@ -450,8 +446,6 @@
450446
;; where =d:dt= is a vector field on the real line[fn:8] and =Cartan= is a way of
451447
;; encapsulating the geometry, as specified by the Christoffel coefficients.
452448

453-
;; [note KLM: I could not get d:dt to work in the sidebar. In [clj-tiles, FDG001 page 19](https://kloimhardt.github.io/cljtiles.html?page=FDG001) and [maria cloud](https://2.maria.cloud/gist/65d96869f9a901b243df06f996c1d707) the code works on-line]
454-
455449
;;The Christoffel coefficients are computed from the metric:
456450

457451
;; {{<contents cartan>}}
@@ -460,12 +454,12 @@
460454
;; If we change the representation of the geodesic equations by "lowering" them
461455
;; using the mass and the metric, we see that the residuals are equal:
462456

463-
(def metric-components
457+
(define metric-components
464458
(metric->components
465459
the-metric
466460
(coordinate-system->basis R2-rect)))
467461

468-
(show-expression :calc-on-server
462+
(show-expression
469463
(- Lagrange-residuals
470464
(* (* 'm (metric-components (gamma ((point R1-rect) 't))))
471465
geodesic-equation-residuals)))

src/mentat_collective/emmy/fdg_ch02.clj

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
time infinite? abs ref partial =])
1515
(:require [scicloj.kindly.v4.api :as kindly]
1616
[scicloj.kindly.v4.kind :as kind]
17-
[mentat-collective.emmy.scheme :refer [define-1 let-scheme lambda]]
17+
[mentat-collective.emmy.scheme :refer [define-1 let-scheme lambda] :as scheme]
1818
[civitas.repl :as repl]))
1919

2020
;; ## 2 Manifolds
@@ -24,15 +24,7 @@
2424
(def prod true) #_"used to check Emmy in Scittle kitchen"
2525

2626
^:kindly/hide-code
27-
(kind/hiccup
28-
[:div
29-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.js"}]
30-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.emmy.js"}]
31-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.cljs-ajax.js"}]
32-
[:script {:src "https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js", :crossorigin ""}]
33-
[:script {:src "https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js", :crossorigin ""}]
34-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.reagent.js"}]
35-
[:script {:type "application/x-scittle" :src "scheme.cljc"}]])
27+
(kind/hiccup scheme/scittle-kitchen-hiccup)
3628

3729
^:kindly/hide-code
3830
(defmacro define [& b]
@@ -43,7 +35,7 @@
4335
^:kindly/hide-code
4436
(define emmy-env
4537
'[emmy.env :refer :all :exclude [print-expression Lagrangian-action find-path Lagrange-equations r->p
46-
R2 R2-rect R2-polar]])
38+
R2 R2-rect R2-polar define-coordinates]])
4739

4840
^:kindly/hide-code
4941
(define emmy-lg
@@ -66,6 +58,12 @@
6658
(require emmy-lg)
6759
(require emmy-mn)))
6860

61+
^:kindly/hide-code
62+
(defmacro define-coordinates [& b]
63+
(list 'do
64+
(cons 'emmy.env/define-coordinates b)
65+
(list 'kind/scittle (list 'quote (cons 'emmy.env/define-coordinates b)))))
66+
6967
^:kindly/hide-code
7068
(define string-exp (comp str simplify))
7169

@@ -148,6 +146,7 @@
148146

149147
(define R2->R '(-> (UP Real Real) Real))
150148

149+
;; ### Manifold Functions Are Coordinate Independent
151150
(define f
152151
(compose (literal-function 'f-rect R2->R) R2-rect-chi))
153152

@@ -168,38 +167,50 @@
168167
(print-expression
169168
(f corresponding-polar-point))
170169

170+
;; ### Naming Coordinate Functions
171+
171172
(define-coordinates (up x y) R2-rect)
172173

173174
(define-coordinates (up r theta) R2-polar)
174175

175-
(x (R2-rect-chi-inverse (up 'x0 'y0)))
176+
(print-expression
177+
(x (R2-rect-chi-inverse (up 'x0 'y0))))
176178

177-
(x (R2-polar-chi-inverse (up 'r0 'theta0)))
179+
(print-expression
180+
(x (R2-polar-chi-inverse (up 'r0 'theta0))))
178181

179-
(r (R2-polar-chi-inverse (up 'r0 'theta0)))
182+
(print-expression
183+
(r (R2-polar-chi-inverse (up 'r0 'theta0))))
180184

181-
(r (R2-rect-chi-inverse (up 'x0 'y0)))
185+
(print-expression
186+
(r (R2-rect-chi-inverse (up 'x0 'y0))))
182187

183-
(theta (R2-rect-chi-inverse (up 'x0 'y0)))
188+
(print-expression
189+
(theta (R2-rect-chi-inverse (up 'x0 'y0))))
184190

185191
(define h (+ (* x (square r)) (cube y)))
186192

187-
(h R2-rect-point)
188-
189-
(h (R2-polar-chi-inverse (up 'r0 'theta0)))
193+
(print-expression
194+
(h R2-rect-point))
190195

191-
(define-coordinates (up r theta) R2-polar)
196+
(print-expression
197+
(h (R2-polar-chi-inverse (up 'r0 'theta0))))
192198

193-
((- r (* 2 'a (+ 1 (cos theta)))) ((point R2-rect) (up 'x 'y)))
199+
;; ### Exercise 2.1: Curves
194200

195-
((compose
196-
(chart S2-spherical)
197-
(point S2-Riemann)
198-
(chart R2-rect)
199-
(point R2-polar))
200-
(up 'rho 'theta))
201+
(define-coordinates (up r theta) R2-polar)
201202

203+
(print-expression
204+
((- r (* 2 'a (+ 1 (cos theta)))) ((point R2-rect) (up 'x 'y))))
202205

203-
;; requires emmy.util.def/careful-def for define-coordinates
206+
;; ### Exercise 2.2: Stereographic Projection
204207

205-
;; (repl/scittle-sidebar)
208+
(print-expression
209+
((compose
210+
(chart S2-spherical)
211+
(point S2-Riemann)
212+
(chart R2-rect)
213+
(point R2-polar))
214+
(up 'rho 'theta)))
215+
216+
(repl/scittle-sidebar)

src/mentat_collective/emmy/fdg_prologue.clj

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
time infinite? abs ref partial =])
1313
(:require [scicloj.kindly.v4.api :as kindly]
1414
[scicloj.kindly.v4.kind :as kind]
15-
[mentat-collective.emmy.scheme :refer [define-1 let-scheme]]
15+
[mentat-collective.emmy.scheme :refer [define-1 let-scheme] :as scheme]
1616
[civitas.repl :as repl]))
1717

1818
;; Elementary introduction to Emmy, taken from the first pages of the MIT open-access book
@@ -26,15 +26,7 @@
2626
;; while being sure of the gratitude of all readers of the immutable, dense book. So without further ado ...
2727

2828
^:kindly/hide-code
29-
(kind/hiccup
30-
[:div
31-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen/dist/scittle.js"}]
32-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen/dist/scittle.emmy.js"}]
33-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen/dist/scittle.cljs-ajax.js"}]
34-
[:script {:src "https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js", :crossorigin ""}]
35-
[:script {:src "https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js", :crossorigin ""}]
36-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen/dist/scittle.reagent.js"}]
37-
[:script {:type "application/x-scittle" :src "scheme.cljc"}]])
29+
(kind/hiccup scheme/scittle-kitchen-hiccup)
3830

3931
^:kindly/hide-code
4032
(defmacro define [& b]

src/mentat_collective/emmy/scheme.cljc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,13 @@
3535

3636
(defmacro lambda [h b]
3737
(list 'fn (into [] h) b))
38+
39+
(def scittle-kitchen-hiccup
40+
[:div
41+
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.30-64/dist/scittle.js"}]
42+
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.30-64/dist/scittle.emmy.js"}]
43+
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.30-64/dist/scittle.cljs-ajax.js"}]
44+
[:script {:src "https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js", :crossorigin ""}]
45+
[:script {:src "https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js", :crossorigin ""}]
46+
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.30-64/dist/scittle.reagent.js"}]
47+
[:script {:type "application/x-scittle" :src "scheme.cljc"}]])

src/mentat_collective/emmy/sicm_ch01.clj

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
time infinite? abs ref partial =])
1414
(:require [scicloj.kindly.v4.api :as kindly]
1515
[scicloj.kindly.v4.kind :as kind]
16-
[mentat-collective.emmy.scheme :refer [define-1 let-scheme lambda]]
16+
[mentat-collective.emmy.scheme :refer [define-1 let-scheme lambda] :as scheme]
1717
[civitas.repl :as repl]))
1818

1919
;; The following examples are taken from the MIT open-access book [Structure and Interpretation of Classical Mechanics (SICM)](https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/9579/sicm_edition_2.zip/chapter001.html).
@@ -34,15 +34,7 @@
3434
;; while being sure of the gratitude of all readers of the immutable, dense book.
3535

3636
^:kindly/hide-code
37-
(kind/hiccup
38-
[:div
39-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.js"}]
40-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.emmy.js"}]
41-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.cljs-ajax.js"}]
42-
[:script {:src "https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js", :crossorigin ""}]
43-
[:script {:src "https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js", :crossorigin ""}]
44-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.reagent.js"}]
45-
[:script {:type "application/x-scittle" :src "scheme.cljc"}]])
37+
(kind/hiccup scheme/scittle-kitchen-hiccup)
4638

4739
^:kindly/hide-code
4840
(defmacro define [& b]

src/mentat_collective/emmy/sicm_original_ch01.clj

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
time infinite? abs ref partial =])
1414
(:require [scicloj.kindly.v4.api :as kindly]
1515
[scicloj.kindly.v4.kind :as kind]
16-
[mentat-collective.emmy.scheme :refer [define-1 let-scheme lambda]]
16+
[mentat-collective.emmy.scheme :refer [define-1 let-scheme lambda] :as scheme]
1717
[civitas.repl :as repl]))
1818

1919
;; ## 1 Lagrangian Mechanics
@@ -30,15 +30,7 @@
3030
(def prod true) #_"used to check Emmy in Scittle kitchen"
3131

3232
^:kindly/hide-code
33-
(kind/hiccup
34-
[:div
35-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.js"}]
36-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.emmy.js"}]
37-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.cljs-ajax.js"}]
38-
[:script {:src "https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js", :crossorigin ""}]
39-
[:script {:src "https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js", :crossorigin ""}]
40-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.reagent.js"}]
41-
[:script {:type "application/x-scittle" :src "scheme.cljc"}]])
33+
(kind/hiccup scheme/scittle-kitchen-hiccup)
4234

4335
^:kindly/hide-code
4436
(defmacro define [& b]

src/mentat_collective/emmy/silcm_ch01.clj

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
time infinite? abs ref partial =])
1414
(:require [scicloj.kindly.v4.api :as kindly]
1515
[scicloj.kindly.v4.kind :as kind]
16-
[mentat-collective.emmy.scheme :refer [define-1 let-scheme lambda]]
16+
[mentat-collective.emmy.scheme :refer [define-1 let-scheme lambda] :as scheme]
1717
[civitas.repl :as repl]))
1818

1919
;; ##!!Draft Version!!
@@ -28,15 +28,7 @@
2828
(def prod true) #_"used to check Emmy in Scittle kitchen"
2929

3030
^:kindly/hide-code
31-
(kind/hiccup
32-
[:div
33-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.js"}]
34-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.emmy.js"}]
35-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.cljs-ajax.js"}]
36-
[:script {:src "https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js", :crossorigin ""}]
37-
[:script {:src "https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js", :crossorigin ""}]
38-
[:script {:src "https://cdn.jsdelivr.net/npm/scittle-kitchen@0.7.28-59/dist/scittle.reagent.js"}]
39-
[:script {:type "application/x-scittle" :src "scheme.cljc"}]])
31+
(kind/hiccup scheme/scittle-kitchen-hiccup)
4032

4133
^:kindly/hide-code
4234
(defmacro define [& b]

0 commit comments

Comments
 (0)