hodge-star.scm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. #| -*-Scheme-*-
  2. Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
  3. 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  4. 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Massachusetts
  5. Institute of Technology
  6. This file is part of MIT/GNU Scheme.
  7. MIT/GNU Scheme is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11. MIT/GNU Scheme is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with MIT/GNU Scheme; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
  18. USA.
  19. |#
  20. ;;;; Hodge-star dual
  21. ;;; spec may be a coordinate system with an orthonormal basis
  22. ;;; an orthonormal basis
  23. ;;; a basis
  24. ;;; if the spec is a basis that needs to be orthonormalized,
  25. ;;; the optional orthonormalize? argument must be a coordinate system
  26. (define* (Hodge-star metric spec #:optional orthonormalize?)
  27. (let* ((basis
  28. (if (basis? spec)
  29. (if (default-object? orthonormalize?)
  30. spec
  31. ;; orthonormalize? must be a coordinate system
  32. (orthonormalize spec metric orthonormalize?))
  33. ;; spec must be a coordinate system.
  34. (if (default-object? orthonormalize?)
  35. (coordinate-system->basis spec)
  36. (orthonormalize (coordinate-system->basis spec)
  37. metric
  38. spec))))
  39. (vector-basis (basis->vector-basis basis))
  40. (on-vector-basis (ultra-flatten vector-basis))
  41. (basis-check
  42. (matrix-by-row-list
  43. (map (lambda (ei) (map (lambda (ej) (metric ei ej))
  44. on-vector-basis))
  45. on-vector-basis)))
  46. (bsigns
  47. (make-initialized-list (basis->dimension basis)
  48. (lambda (i) (matrix-ref basis-check i i))))
  49. (on-1form-basis (ultra-flatten (basis->1form-basis basis))))
  50. (define (the-star pform-field)
  51. (assert (or (function? pform-field) (form-field? pform-field)))
  52. (let ((p (get-rank pform-field)))
  53. (if (= p 0)
  54. (* pform-field (apply wedge on-1form-basis))
  55. (let* ((pvect-basis-lists
  56. (combinations on-vector-basis p))
  57. (coeffs
  58. (map (lambda (pvect)
  59. (apply pform-field pvect))
  60. pvect-basis-lists))
  61. (pform-basis-lists
  62. (combinations on-1form-basis p))
  63. (n-p:form-basis-lists
  64. (map (lambda (1fbl)
  65. (list-difference on-1form-basis 1fbl))
  66. pform-basis-lists))
  67. (n-p:basis
  68. (map (lambda (n-p:basis-list)
  69. (apply wedge n-p:basis-list))
  70. n-p:form-basis-lists))
  71. (signs
  72. (map (lambda (bsign-list p:basis-list n-p:basis-list)
  73. (* (apply * bsign-list)
  74. (permutation-parity
  75. (append p:basis-list n-p:basis-list)
  76. on-1form-basis)))
  77. (combinations bsigns p)
  78. pform-basis-lists
  79. n-p:form-basis-lists))
  80. (val
  81. (apply +
  82. (map (lambda (sign coeff basis-element)
  83. (* sign coeff basis-element))
  84. signs
  85. coeffs
  86. n-p:basis))))
  87. val))))
  88. ;;(assert (orthonormal? basis-check)) ;Currently assumed OK.
  89. the-star))
  90. (define (orthonormalize basis metric coordinate-system)
  91. (let ((ovb (Gram-Schmidt (basis->vector-basis basis) metric)))
  92. (make-basis ovb
  93. (vector-basis->dual ovb coordinate-system))))
  94. #|
  95. (define-coordinates (up x y) R2-rect)
  96. (define (E2-metric v1 v2)
  97. (+ (* (dx v1) (dx v2))
  98. (* (dy v1) (dy v2))))
  99. #| E2-metric |#
  100. (define omega (wedge dx dy))
  101. #| omega |#
  102. (define E2-star
  103. (Hodge-star E2-metric
  104. (coordinate-system->basis R2-rect)))
  105. #| E2-star |#
  106. ((E2-star omega)
  107. ((point R2-rect) (up 'x 'y)))
  108. #| 1 |#
  109. ;;; What is a rank 0 form?
  110. (((E2-star dx)
  111. (literal-vector-field 'V R2-rect))
  112. ((point R2-rect) (up 'x 'y)))
  113. #|
  114. (V^1 (up x y))
  115. |#
  116. (((E2-star dy)
  117. (literal-vector-field 'V R2-rect))
  118. ((point R2-rect) (up 'x 'y)))
  119. #|
  120. (* -1 (V^0 (up x y)))
  121. |#
  122. (((E2-star (lambda (pt) 1))
  123. (literal-vector-field 'V R2-rect)
  124. (literal-vector-field 'W R2-rect))
  125. ((point R2-rect) (up 'x 'y)))
  126. #|
  127. (+ (* (V^0 (up x y)) (W^1 (up x y)))
  128. (* -1 (V^1 (up x y)) (W^0 (up x y))))
  129. |#
  130. |#
  131. #|
  132. ;;; First, some simple tests on 3-dimensional Euclidean space.
  133. (clear-arguments)
  134. (suppress-arguments (list '(up x0 y0 z0)))
  135. (define-coordinates (up x y z) R3-rect)
  136. (define R3-point ((R3-rect '->point) (up 'x0 'y0 'z0)))
  137. (define R3-basis (coordinate-system->basis R3-rect))
  138. (define (E3-metric v1 v2)
  139. (+ (* (dx v1) (dx v2))
  140. (* (dy v1) (dy v2))
  141. (* (dz v1) (dz v2))))
  142. (define E3-star (Hodge-star E3-metric R3-rect))
  143. #|
  144. (define E3-star
  145. (Hodge-star E3-metric
  146. (coordinate-system->basis R3-rect)))
  147. |#
  148. (((- (E3-star (lambda (pt) 1))
  149. (wedge dx dy dz))
  150. (literal-vector-field 'u R3-rect)
  151. (literal-vector-field 'v R3-rect)
  152. (literal-vector-field 'w R3-rect))
  153. R3-point)
  154. #| 0 |#
  155. (((- (E3-star dx)
  156. (wedge dy dz))
  157. (literal-vector-field 'u R3-rect)
  158. (literal-vector-field 'v R3-rect))
  159. R3-point)
  160. #| 0 |#
  161. (((+ (E3-star (wedge dx dz)) dy)
  162. (literal-vector-field 'u R3-rect))
  163. R3-point)
  164. #| 0 |#
  165. ((- (E3-star (wedge dx dy dz)) 1)
  166. R3-point)
  167. #| 0 |#
  168. (pec (((E3-star (literal-scalar-field 'f R3-rect))
  169. (literal-vector-field 'u R3-rect)
  170. (literal-vector-field 'v R3-rect)
  171. (literal-vector-field 'w R3-rect))
  172. R3-point)
  173. (compose arg-suppressor simplify))
  174. #| Result:
  175. (+ (* w^2 u^0 f v^1)
  176. (* -1 w^2 u^1 v^0 f)
  177. (* -1 u^0 v^2 w^1 f)
  178. (* v^2 u^1 w^0 f)
  179. (* u^2 w^1 v^0 f)
  180. (* -1 u^2 w^0 f v^1))
  181. |#
  182. (pec (((E3-star (literal-1form-field 'omega R3-rect))
  183. (literal-vector-field 'u R3-rect)
  184. (literal-vector-field 'v R3-rect))
  185. R3-point)
  186. (compose arg-suppressor simplify))
  187. #| Result:
  188. (+ (* v^1 u^0 omega_2)
  189. (* -1 v^1 u^2 omega_0)
  190. (* -1 v^2 u^0 omega_1)
  191. (* v^2 u^1 omega_0)
  192. (* u^2 v^0 omega_1)
  193. (* -1 u^1 v^0 omega_2))
  194. |#
  195. (pec (((E3-star
  196. (+ (* (literal-scalar-field 'alpha R3-rect) (wedge dx dy))
  197. (* (literal-scalar-field 'beta R3-rect) (wedge dy dz))
  198. (* (literal-scalar-field 'gamma R3-rect) (wedge dz dx))))
  199. (literal-vector-field 'u R3-rect))
  200. R3-point)
  201. (compose arg-suppressor simplify))
  202. #| Result:
  203. (+ (* u^0 beta) (* u^2 alpha) (* u^1 gamma))
  204. |#
  205. (pec ((E3-star
  206. (* (literal-scalar-field 'alpha R3-rect) (wedge dx dy dz)))
  207. R3-point)
  208. (compose arg-suppressor simplify))
  209. #| Result:
  210. alpha
  211. |#
  212. (define omega
  213. (+ (* (literal-scalar-field 'alpha R3-rect) dx)
  214. (* (literal-scalar-field 'beta R3-rect) dy)
  215. (* (literal-scalar-field 'gamma R3-rect) dz)))
  216. ;;; omega = alpha*dx + beta*dy + gamma*dz
  217. (pec (((E3-star omega)
  218. (literal-vector-field 'u R3-rect)
  219. (literal-vector-field 'v R3-rect))
  220. R3-point)
  221. (compose arg-suppressor simplify))
  222. #| Result:
  223. (+ (* v^1 u^0 gamma)
  224. (* -1 v^1 u^2 alpha)
  225. (* -1 v^2 u^0 beta)
  226. (* v^2 u^1 alpha)
  227. (* u^2 v^0 beta)
  228. (* -1 u^1 v^0 gamma))
  229. |#
  230. ;;; *omega = alpha*dy^dz - beta*dx^dz + gamma*dx^dy
  231. (pec (((E3-star (d omega))
  232. (literal-vector-field 'u R3-rect))
  233. R3-point)
  234. (compose arg-suppressor simplify))
  235. #| Result:
  236. (+ (* u^0 ((partial 1) gamma))
  237. (* -1 u^0 ((partial 2) beta))
  238. (* u^2 ((partial 0) beta))
  239. (* -1 u^2 ((partial 1) alpha))
  240. (* -1 u^1 ((partial 0) gamma))
  241. (* u^1 ((partial 2) alpha)))
  242. |#
  243. ;;; Indeed, *d is the curl operator.
  244. (pec (((d (E3-star omega))
  245. (literal-vector-field 'u R3-rect)
  246. (literal-vector-field 'v R3-rect)
  247. (literal-vector-field 'w R3-rect))
  248. R3-point)
  249. (compose arg-suppressor simplify))
  250. #| Result:
  251. (+ (* w^2 v^1 u^0 ((partial 0) alpha))
  252. (* w^2 v^1 u^0 ((partial 1) beta))
  253. (* w^2 v^1 u^0 ((partial 2) gamma))
  254. (* -1 w^2 u^1 v^0 ((partial 0) alpha))
  255. (* -1 w^2 u^1 v^0 ((partial 1) beta))
  256. (* -1 w^2 u^1 v^0 ((partial 2) gamma))
  257. (* -1 v^1 w^0 u^2 ((partial 0) alpha))
  258. (* -1 v^1 w^0 u^2 ((partial 1) beta))
  259. (* -1 v^1 w^0 u^2 ((partial 2) gamma))
  260. (* -1 v^2 w^1 u^0 ((partial 0) alpha))
  261. (* -1 v^2 w^1 u^0 ((partial 1) beta))
  262. (* -1 v^2 w^1 u^0 ((partial 2) gamma))
  263. (* v^2 w^0 u^1 ((partial 0) alpha))
  264. (* v^2 w^0 u^1 ((partial 1) beta))
  265. (* v^2 w^0 u^1 ((partial 2) gamma))
  266. (* w^1 u^2 v^0 ((partial 0) alpha))
  267. (* w^1 u^2 v^0 ((partial 1) beta))
  268. (* w^1 u^2 v^0 ((partial 2) gamma)))
  269. |#
  270. (pec ((E3-star (d (E3-star omega)))
  271. R3-point)
  272. (compose arg-suppressor simplify))
  273. #| Result:
  274. (+ ((partial 0) alpha) ((partial 1) beta) ((partial 2) gamma))
  275. |#
  276. ;;; Indeed, *d* is the divergence operator...
  277. (clear-arguments)
  278. |#
  279. #|
  280. ;;; Now for a 2+1 Minkowski space with c=1.
  281. (define-coordinates (up t x y) R3-rect)
  282. (define R3-point
  283. ((R3-rect '->point) (up 't0 'x0 'y0)))
  284. (define R3-basis
  285. (coordinate-system->basis R3-rect))
  286. (define (L3-metric u v)
  287. (+ (* -1 (dt u) (dt v))
  288. (* (dx u) (dx v))
  289. (* (dy u) (dy v))))
  290. (define L3-star
  291. (Hodge-star L3-metric R3-rect))
  292. ((L3-metric d/dt d/dt) R3-point)
  293. #| -1 |#
  294. (((- (L3-star (lambda (m) 1))
  295. (wedge dx dy dt))
  296. (literal-vector-field 'U R3-rect)
  297. (literal-vector-field 'V R3-rect)
  298. (literal-vector-field 'W R3-rect))
  299. R3-point)
  300. #| 0 |#
  301. (((- (L3-star dx)
  302. (wedge dy dt))
  303. (literal-vector-field 'U R3-rect)
  304. (literal-vector-field 'V R3-rect))
  305. R3-point)
  306. #| 0 |#
  307. (((- (L3-star dy)
  308. (wedge dt dx))
  309. (literal-vector-field 'U R3-rect)
  310. (literal-vector-field 'V R3-rect))
  311. R3-point)
  312. #| 0 |#
  313. (((- (L3-star dt)
  314. (wedge dy dx))
  315. (literal-vector-field 'U R3-rect)
  316. (literal-vector-field 'V R3-rect))
  317. R3-point)
  318. #| 0 |#
  319. (((- (L3-star (wedge dx dy)) dt)
  320. (literal-vector-field 'U R3-rect))
  321. R3-point)
  322. #| 0 |#
  323. (((+ (L3-star (wedge dy dt)) dx)
  324. (literal-vector-field 'U R3-rect))
  325. R3-point)
  326. #| 0 |#
  327. (((+ (L3-star (wedge dt dx)) dy)
  328. (literal-vector-field 'U R3-rect))
  329. R3-point)
  330. #| 0 |#
  331. ((+ (L3-star (wedge dx dy dt)) 1)
  332. R3-point)
  333. #| 0 |#
  334. |#
  335. #|
  336. ;;; Now for a 1-1 Minkowski space with c.
  337. (define-coordinates (up t x) R2-rect)
  338. (define R2-point ((R2-rect '->point) (up 't0 'x0)))
  339. (define R2-basis (coordinate-system->basis R2-rect))
  340. (define c 'c)
  341. (define (L2-metric u v)
  342. (+ (* -1 c c (dt u) (dt v))
  343. (* 1 (dx u) (dx v))))
  344. (define L2-Hodge-star
  345. (Hodge-star L2-metric R2-rect))
  346. (pec (((L2-Hodge-star (lambda (x) 1))
  347. (literal-vector-field 'u R2-rect)
  348. (literal-vector-field 'v R2-rect))
  349. R2-point))
  350. #| Result:
  351. (+ (* (u^0 (up t0 x0)) (v^1 (up t0 x0)))
  352. (* -1 (u^1 (up t0 x0)) (v^0 (up t0 x0))))
  353. |#
  354. ;;; Wrong. Must generally orthonormalize.
  355. (define L2-Hodge-star
  356. (Hodge-star L2-metric R2-rect #t))
  357. (pec (((L2-Hodge-star (lambda (x) 1))
  358. (literal-vector-field 'u R2-rect)
  359. (literal-vector-field 'v R2-rect))
  360. R2-point))
  361. #| Result:
  362. (+ (* c (u^0 (up t0 x0)) (v^1 (up t0 x0)))
  363. (* -1 c (v^0 (up t0 x0)) (u^1 (up t0 x0))))
  364. = cdt^dx(u v)
  365. |#
  366. #|
  367. ;;; Can accelerate by explicitly passing in an explicitly constructed
  368. ;;; orthonormal constant basis.
  369. (define L2-basis (orthonormalize R2-basis L2-metric R2-rect))
  370. (define L2-vector-basis (basis->vector-basis L2-basis))
  371. (s:foreach (lambda (v)
  372. (pe ((v (literal-manifold-function 'f R2-rect))
  373. R2-point)))
  374. L2-vector-basis)
  375. #|
  376. (/ (((partial 0) f) (up t0 x0)) c)
  377. (((partial 1) f) (up t0 x0))
  378. |#
  379. (define L2-1form-basis (vector-basis->dual L2-vector-basis R2-rect))
  380. (s:foreach (lambda (omega)
  381. (pe ((omega (literal-vector-field 'v R2-rect))
  382. R2-point)))
  383. L2-1form-basis)
  384. #|
  385. (* c (v^0 (up t0 x0)))
  386. (v^1 (up t0 x0))
  387. |#
  388. (pec ((L2-1form-basis L2-vector-basis) R2-point))
  389. #| Result:
  390. (up (down 1 0) (down 0 1))
  391. |#
  392. ;;; Now make constant basis...
  393. (define L2-constant-vector-basis
  394. (down (* (/ 1 c) d/dt) d/dx))
  395. (define L2-constant-1form-basis
  396. (up (* c dt) dx))
  397. (define L2-constant-basis
  398. (make-basis L2-constant-vector-basis
  399. L2-constant-1form-basis))
  400. (define L2-Hodge-star
  401. (Hodge-star L2-metric L2-constant-basis))
  402. |#
  403. (pec (((L2-Hodge-star (lambda (x) 1))
  404. (literal-vector-field 'u R2-rect)
  405. (literal-vector-field 'v R2-rect))
  406. R2-point))
  407. #| Result:
  408. (+ (* -1 c (v^0 (up t0 x0)) (u^1 (up t0 x0)))
  409. (* c (v^1 (up t0 x0)) (u^0 (up t0 x0))))
  410. |#
  411. ;;; As desired.
  412. (pec (((L2-Hodge-star
  413. (* (literal-manifold-function 'alpha R2-rect)
  414. (* c dt)))
  415. (literal-vector-field 'u R2-rect))
  416. R2-point))
  417. #| Result:
  418. (* -1 (alpha (up t0 x0)) (u^1 (up t0 x0)))
  419. = -alpha dx(u)
  420. |#
  421. (pec (((L2-Hodge-star
  422. (* (literal-manifold-function 'alpha R2-rect)
  423. dx))
  424. (literal-vector-field 'u R2-rect))
  425. R2-point))
  426. #| Result:
  427. (* -1 c (alpha (up t0 x0)) (u^0 (up t0 x0)))
  428. = -alpha c dt(u)
  429. |#
  430. (pec ((L2-Hodge-star
  431. (* (literal-manifold-function 'alpha R2-rect)
  432. (wedge (* c dt) dx)))
  433. R2-point))
  434. #| Result:
  435. (* -1 (alpha (up t0 x0)))
  436. |#
  437. |#
  438. #|
  439. (install-coordinates R2-rect (up 'x 'y))
  440. (define R2-point ((R2-rect '->point) (up 'x0 'y0)))
  441. (define R2-basis (coordinate-system->basis R2-rect))
  442. (define ((g-R2 g_00 g_01 g_11) u v)
  443. (+ (* g_00 (dx u) (dx v))
  444. (* g_01 (+ (* (dx u) (dy v)) (* (dy u) (dx v))))
  445. (* g_11 (dy u) (dy v))))
  446. (define R2-metric (g-R2 'a 'b 'c))
  447. ;;; Hodge-star must Orthonormalize here
  448. (define R2-star (Hodge-star R2-metric R2-rect #t))
  449. (pec (((R2-star (lambda (x) 1)) d/dx d/dy) R2-point))
  450. #| Result:
  451. (sqrt (+ (* a c) (* -1 (expt b 2))))
  452. |#
  453. (pec (((R2-star dx) d/dx) R2-point))
  454. #| Result:
  455. (/ b (sqrt (+ (* a c) (* -1 (expt b 2)))))
  456. |#
  457. (pec (((R2-star dx) d/dy) R2-point))
  458. #| Result:
  459. (/ c (sqrt (+ (* a c) (* -1 (expt b 2)))))
  460. |#
  461. (pec (((R2-star dy) d/dx) R2-point))
  462. #| Result:
  463. (/ (* -1 a) (sqrt (+ (* a c) (* -1 (expt b 2)))))
  464. |#
  465. (pec (((R2-star dy) d/dy) R2-point))
  466. #| Result:
  467. (/ (* -1 b) (sqrt (+ (* a c) (* -1 (expt b 2)))))
  468. |#
  469. (pec ((R2-star (wedge dx dy)) R2-point))
  470. #| Result:
  471. (/ 1 (sqrt (+ (* a c) (* -1 (expt b 2)))))
  472. |#
  473. |#
  474. #|
  475. ;;; Example: Lorentz metric on R^4
  476. (define SR R4-rect)
  477. (install-coordinates SR (up 't 'x 'y 'z))
  478. (define SR-point ((SR '->point) (up 't0 'x0 'y0 'z0)))
  479. (define c 'c)
  480. (define SR-constant-vector-basis
  481. (down (* (/ 1 c) d/dt) d/dx d/dy d/dz))
  482. (define SR-constant-1form-basis
  483. (up (* c dt) dx dy dz))
  484. (define SR-constant-basis
  485. (make-basis SR-constant-vector-basis
  486. SR-constant-1form-basis))
  487. (define (g-Lorentz u v)
  488. (+ (* (dx u) (dx v))
  489. (* (dy u) (dy v))
  490. (* (dz u) (dz v))
  491. (* -1 (square c) (dt u) (dt v))))
  492. (define SR-star
  493. (Hodge-star g-Lorentz SR-constant-basis))
  494. (define u
  495. (+ (* (literal-manifold-function 'ut SR) (/ 1 c) d/dt)
  496. (* (literal-manifold-function 'ux SR) d/dx)
  497. (* (literal-manifold-function 'uy SR) d/dy)
  498. (* (literal-manifold-function 'uz SR) d/dz)))
  499. (define v
  500. (+ (* (literal-manifold-function 'vt SR) (/ 1 c) d/dt)
  501. (* (literal-manifold-function 'vx SR) d/dx)
  502. (* (literal-manifold-function 'vy SR) d/dy)
  503. (* (literal-manifold-function 'vz SR) d/dz)))
  504. (pec (((- (SR-star (wedge dy dz)) (wedge (* c dt) dx))
  505. u v)
  506. SR-point))
  507. #| Result:
  508. 0
  509. |#
  510. (pec (((- (SR-star (wedge dz dx)) (wedge (* c dt) dy))
  511. u v)
  512. SR-point))
  513. #| Result:
  514. 0
  515. |#
  516. ;;; Other rotations of variables are all similar
  517. |#
  518. #|
  519. ;;; Claim: this is the interior product in a metric space
  520. (define (((ip metric basis) X) alpha)
  521. (let ((k (get-rank alpha))
  522. (n (basis->dimension basis))
  523. (dual (Hodge-star metric basis)))
  524. (let ((sign (if (even? (* k (- n k))) +1 -1)))
  525. (* sign
  526. (dual (wedge (dual alpha)
  527. ((lower metric) X)))))))
  528. (install-coordinates R3-rect (up 'x 'y 'z))
  529. (define R3-basis (coordinate-system->basis R3-rect))
  530. (define R3-point ((R3-rect '->point) (up 'x0 'y0 'z0)))
  531. (define u (literal-vector-field 'u R3-rect))
  532. (define v (literal-vector-field 'v R3-rect))
  533. (define w (literal-vector-field 'w R3-rect))
  534. (define (E3-metric v1 v2)
  535. (+ (* (dx v1) (dx v2))
  536. (* (dy v1) (dy v2))
  537. (* (dz v1) (dz v2))))
  538. (define omega
  539. (+ (* (literal-manifold-function 'alpha R3-rect) (wedge dx dy))
  540. (* (literal-manifold-function 'beta R3-rect) (wedge dy dz))
  541. (* (literal-manifold-function 'gamma R3-rect) (wedge dz dx))))
  542. (pec (- (((((ip E3-metric R3-basis) u) omega) v) R3-point)
  543. ((((interior-product u) omega) v) R3-point)))
  544. #| Result:
  545. 0
  546. |#
  547. (define theta
  548. (* (literal-scalar-field 'delta R3-rect) (wedge dx dy dz)))
  549. (pec (- (((((ip E3-metric R3-basis) u) theta) v w) R3-point)
  550. ((((interior-product u) theta) v w) R3-point)))
  551. #| Result:
  552. 0
  553. |#
  554. |#
  555. ;;; Electrodynamics...
  556. #|
  557. (define SR R4-rect)
  558. (install-coordinates SR (up 't 'x 'y 'z))
  559. (define SR-basis (coordinate-system->basis SR))
  560. (define an-event ((SR '->point) (up 't0 'x0 'y0 'z0)))
  561. (define c 'c)
  562. (define (g-Lorentz u v)
  563. (+ (* (dx u) (dx v))
  564. (* (dy u) (dy v))
  565. (* (dz u) (dz v))
  566. (* -1 (square c) (dt u) (dt v))))
  567. (define L4-constant-vector-basis
  568. (down (* (/ 1 c) d/dt) d/dx d/dy d/dz))
  569. (define L4-constant-1form-basis
  570. (up (* c dt) dx dy dz))
  571. (define L4-constant-basis
  572. (make-basis L4-constant-vector-basis
  573. L4-constant-1form-basis))
  574. (define SR-star
  575. (Hodge-star g-Lorentz L4-constant-basis))
  576. (pec (((SR-star
  577. (* (literal-manifold-function 'Bx SR)
  578. (wedge dy dz)))
  579. (* (/ 1 c) d/dt)
  580. d/dx)
  581. an-event))
  582. #| Result:
  583. (Bx (up t0 x0 y0 z0))
  584. |#
  585. ;;; Fields E, B. From MTW p.108
  586. (define (Faraday Ex Ey Ez Bx By Bz)
  587. (+ (* Ex c (wedge dx dt))
  588. (* Ey c (wedge dy dt))
  589. (* Ez c (wedge dz dt))
  590. (* Bx (wedge dy dz))
  591. (* By (wedge dz dx))
  592. (* Bz (wedge dx dy))))
  593. (define (Maxwell Ex Ey Ez Bx By Bz)
  594. (+ (* -1 Bx c (wedge dx dt))
  595. (* -1 By c (wedge dy dt))
  596. (* -1 Bz c (wedge dz dt))
  597. (* Ex (wedge dy dz))
  598. (* Ey (wedge dz dx))
  599. (* Ez (wedge dx dy))))
  600. (pec (((- (SR-star (Faraday 'Ex 'Ey 'Ez 'Bx 'By 'Bz))
  601. (Maxwell 'Ex 'Ey 'Ez 'Bx 'By 'Bz))
  602. (literal-vector-field 'u SR)
  603. (literal-vector-field 'v SR))
  604. an-event))
  605. #| Result:
  606. 0
  607. |#
  608. ;;; **F + F = 0
  609. (pec (((+ ((compose SR-star SR-star) (Faraday 'Ex 'Ey 'Ez 'Bx 'By 'Bz))
  610. (Faraday 'Ex 'Ey 'Ez 'Bx 'By 'Bz))
  611. (literal-vector-field 'u SR)
  612. (literal-vector-field 'v SR))
  613. an-event))
  614. #| Result:
  615. 0
  616. |#
  617. ;;; Defining the 4-current density J.
  618. ;;; Charge density is a manifold function. Current density is a
  619. ;;; vector field having only spatial components.
  620. (define (J charge-density Jx Jy Jz)
  621. (- (* (/ 1 c) (+ (* Jx dx) (* Jy dy) (* Jz dz)))
  622. (* charge-density c dt)))
  623. (define rho (literal-manifold-function 'rho SR))
  624. (define 4-current
  625. (J rho
  626. (literal-manifold-function 'Ix SR)
  627. (literal-manifold-function 'Iy SR)
  628. (literal-manifold-function 'Iz SR)))
  629. (pec (((d (SR-star 4-current))
  630. (literal-vector-field 'a SR)
  631. (literal-vector-field 'b SR)
  632. (literal-vector-field 'c SR)
  633. (literal-vector-field 'd SR))
  634. an-event))
  635. #| Result:
  636. ;;; The charge conservation equations are too ugly to include.
  637. |#
  638. (pec (((SR-star 4-current) d/dx d/dy d/dz) an-event))
  639. #| Result:
  640. (rho (up t0 x0 y0 z0))
  641. |#
  642. (pec (((SR-star 4-current)
  643. (* (/ 1 c) d/dt) d/dy d/dz)
  644. an-event))
  645. #| Result:
  646. (/ (* -1 (Ix (up t0 x0 y0 z0))) c)
  647. |#
  648. (pec (((SR-star 4-current)
  649. (* (/ 1 c) d/dt) d/dz d/dx)
  650. an-event))
  651. #| Result:
  652. (/ (* -1 (Iy (up t0 x0 y0 z0))) c)
  653. |#
  654. (pec (((SR-star 4-current)
  655. (* (/ 1 c) d/dt) d/dx d/dy)
  656. an-event))
  657. #| Result:
  658. (/ (* -1 (Iz (up t0 x0 y0 z0))) c)
  659. |#
  660. ;;; Maxwell's equations in the form language are:
  661. ;;; dF=0, d(*F)=4pi *J
  662. (define F
  663. (Faraday (literal-manifold-function 'Ex SR)
  664. (literal-manifold-function 'Ey SR)
  665. (literal-manifold-function 'Ez SR)
  666. (literal-manifold-function 'Bx SR)
  667. (literal-manifold-function 'By SR)
  668. (literal-manifold-function 'Bz SR)))
  669. ;;; div B = 0
  670. (pec (((d F) d/dx d/dy d/dz) an-event))
  671. #| Result:
  672. (+ (((partial 1) Bx) (up t0 x0 y0 z0))
  673. (((partial 2) By) (up t0 x0 y0 z0))
  674. (((partial 3) Bz) (up t0 x0 y0 z0)))
  675. |#
  676. ;;; curl E = -1/c dB/dt
  677. (pec (((d F) (* (/ 1 c) d/dt) d/dy d/dz) an-event))
  678. #| Result:
  679. (+ (((partial 2) Ez) (up t0 x0 y0 z0))
  680. (* -1 (((partial 3) Ey) (up t0 x0 y0 z0)))
  681. (/ (((partial 0) Bx) (up t0 x0 y0 z0)) c))
  682. |#
  683. (pec (((d F) (* (/ 1 c) d/dt) d/dz d/dx) an-event))
  684. #| Result:
  685. (+ (((partial 3) Ex) (up t0 x0 y0 z0))
  686. (* -1 (((partial 1) Ez) (up t0 x0 y0 z0)))
  687. (/ (((partial 0) By) (up t0 x0 y0 z0)) c))
  688. |#
  689. (pec (((d F) (* (/ 1 c) d/dt) d/dx d/dy) an-event))
  690. #| Result:
  691. (+ (((partial 1) Ey) (up t0 x0 y0 z0))
  692. (* -1 (((partial 2) Ex) (up t0 x0 y0 z0)))
  693. (/ (((partial 0) Bz) (up t0 x0 y0 z0)) c))
  694. |#
  695. ;;; div E = 4pi rho
  696. (pec (((- (d (SR-star F)) (* '4pi (SR-star 4-current)))
  697. d/dx d/dy d/dz)
  698. an-event))
  699. #| Result:
  700. (+ (* -1 4pi (rho (up t0 x0 y0 z0)))
  701. (((partial 1) Ex) (up t0 x0 y0 z0))
  702. (((partial 2) Ey) (up t0 x0 y0 z0))
  703. (((partial 3) Ez) (up t0 x0 y0 z0)))
  704. |#
  705. ;;; curl B = 1/c dE/dt + 4pi I
  706. (pec (((- (d (SR-star F)) (* '4pi (SR-star 4-current)))
  707. (* (/ 1 'c) d/dt) d/dy d/dz)
  708. an-event))
  709. #| Result:
  710. (+ (/ (* 4pi (Ix (up t0 x0 y0 z0))) c)
  711. (* -1 (((partial 2) Bz) (up t0 x0 y0 z0)))
  712. (((partial 3) By) (up t0 x0 y0 z0))
  713. (/ (((partial 0) Ex) (up t0 x0 y0 z0)) c))
  714. |#
  715. (pec (((- (d (SR-star F)) (* '4pi (SR-star 4-current)))
  716. (* (/ 1 c) d/dt) d/dz d/dx)
  717. an-event))
  718. #| Result:
  719. (+ (/ (* 4pi (Iy (up t0 x0 y0 z0))) c)
  720. (* -1 (((partial 3) Bx) (up t0 x0 y0 z0)))
  721. (((partial 1) Bz) (up t0 x0 y0 z0))
  722. (/ (((partial 0) Ey) (up t0 x0 y0 z0)) c))
  723. |#
  724. (pec (((- (d (SR-star F)) (* '4pi (SR-star 4-current)))
  725. (* (/ 1 c) d/dt) d/dx d/dy)
  726. an-event))
  727. #| Result:
  728. (+ (/ (* 4pi (Iz (up t0 x0 y0 z0))) c)
  729. (* -1 (((partial 1) By) (up t0 x0 y0 z0)))
  730. (((partial 2) Bx) (up t0 x0 y0 z0))
  731. (/ (((partial 0) Ez) (up t0 x0 y0 z0)) c))
  732. |#
  733. |#