|
14 | 14 | time infinite? abs ref partial =]) |
15 | 15 | (:require [scicloj.kindly.v4.api :as kindly] |
16 | 16 | [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] |
18 | 18 | [civitas.repl :as repl])) |
19 | 19 |
|
20 | 20 | ;; ## 2 Manifolds |
|
24 | 24 | (def prod true) #_"used to check Emmy in Scittle kitchen" |
25 | 25 |
|
26 | 26 | ^: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) |
36 | 28 |
|
37 | 29 | ^:kindly/hide-code |
38 | 30 | (defmacro define [& b] |
|
43 | 35 | ^:kindly/hide-code |
44 | 36 | (define emmy-env |
45 | 37 | '[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]]) |
47 | 39 |
|
48 | 40 | ^:kindly/hide-code |
49 | 41 | (define emmy-lg |
|
66 | 58 | (require emmy-lg) |
67 | 59 | (require emmy-mn))) |
68 | 60 |
|
| 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 | + |
69 | 67 | ^:kindly/hide-code |
70 | 68 | (define string-exp (comp str simplify)) |
71 | 69 |
|
|
148 | 146 |
|
149 | 147 | (define R2->R '(-> (UP Real Real) Real)) |
150 | 148 |
|
| 149 | +;; ### Manifold Functions Are Coordinate Independent |
151 | 150 | (define f |
152 | 151 | (compose (literal-function 'f-rect R2->R) R2-rect-chi)) |
153 | 152 |
|
|
168 | 167 | (print-expression |
169 | 168 | (f corresponding-polar-point)) |
170 | 169 |
|
| 170 | +;; ### Naming Coordinate Functions |
| 171 | + |
171 | 172 | (define-coordinates (up x y) R2-rect) |
172 | 173 |
|
173 | 174 | (define-coordinates (up r theta) R2-polar) |
174 | 175 |
|
175 | | -(x (R2-rect-chi-inverse (up 'x0 'y0))) |
| 176 | +(print-expression |
| 177 | + (x (R2-rect-chi-inverse (up 'x0 'y0)))) |
176 | 178 |
|
177 | | -(x (R2-polar-chi-inverse (up 'r0 'theta0))) |
| 179 | +(print-expression |
| 180 | + (x (R2-polar-chi-inverse (up 'r0 'theta0)))) |
178 | 181 |
|
179 | | -(r (R2-polar-chi-inverse (up 'r0 'theta0))) |
| 182 | +(print-expression |
| 183 | + (r (R2-polar-chi-inverse (up 'r0 'theta0)))) |
180 | 184 |
|
181 | | -(r (R2-rect-chi-inverse (up 'x0 'y0))) |
| 185 | +(print-expression |
| 186 | + (r (R2-rect-chi-inverse (up 'x0 'y0)))) |
182 | 187 |
|
183 | | -(theta (R2-rect-chi-inverse (up 'x0 'y0))) |
| 188 | +(print-expression |
| 189 | + (theta (R2-rect-chi-inverse (up 'x0 'y0)))) |
184 | 190 |
|
185 | 191 | (define h (+ (* x (square r)) (cube y))) |
186 | 192 |
|
187 | | -(h R2-rect-point) |
188 | | - |
189 | | -(h (R2-polar-chi-inverse (up 'r0 'theta0))) |
| 193 | +(print-expression |
| 194 | + (h R2-rect-point)) |
190 | 195 |
|
191 | | -(define-coordinates (up r theta) R2-polar) |
| 196 | +(print-expression |
| 197 | + (h (R2-polar-chi-inverse (up 'r0 'theta0)))) |
192 | 198 |
|
193 | | -((- r (* 2 'a (+ 1 (cos theta)))) ((point R2-rect) (up 'x 'y))) |
| 199 | +;; ### Exercise 2.1: Curves |
194 | 200 |
|
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) |
201 | 202 |
|
| 203 | +(print-expression |
| 204 | + ((- r (* 2 'a (+ 1 (cos theta)))) ((point R2-rect) (up 'x 'y)))) |
202 | 205 |
|
203 | | -;; requires emmy.util.def/careful-def for define-coordinates |
| 206 | +;; ### Exercise 2.2: Stereographic Projection |
204 | 207 |
|
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) |
0 commit comments