exterior-derivative.scm 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. ;;;; Exterior derivative
  21. #|
  22. A form field is a function of a place and a number of vector fields.
  23. The exterior derivative of this form field is a derivative of the form
  24. with respect to the place, removing any dependence on place of the
  25. vector fields.
  26. Consider w(v)(x), where b is the coefficient function for w in coordinates X:
  27. v1(w(v2))(x) - v2(w(v1))(x)
  28. = v1(b v2(X))(x) - v2(b v1(X))(x)
  29. = v1(b)(x) v2(X)(x) + b(x) v1(v2(X))(x)
  30. - v2(b)(x) v1(X)(x) - b(x) v2(v1(X))(x)
  31. = v1(b)(x) v2(X)(x) - v2(b)(x) v1(X)(x) + b(x)[v1, v2](X)(x)
  32. = v1(b)(x) v2(X)(x) - v2(b)(x) v1(X)(x) + w([v1, v2])(x)
  33. We define exterior derivative as follows
  34. dw(v1, v2)(x)
  35. = v1(b)(x) v2(X)(x) - v2(b)(x) v1(X)(x)
  36. = v1(w(v2))(x) - v2(w(v1))(x) - w([v1, v2])(x)
  37. It is not obvious that this is equivalent to the standard definition.
  38. See page 91 in Spivak.
  39. Another way to think about this is that if we were able to define
  40. constant vector fields (v1_bar, v2_bar) that have constant
  41. coefficient functions equal to the value of the coefficient function
  42. at the point, then dw(v1, v2)(x) would be just
  43. v1_bar(w(v2_bar))(x) - v2_bar(w(v1_bar))(x)
  44. |#
  45. ;;; This definition is a generalization to k-forms, by recursion on
  46. ;;; the vector argument list.
  47. ;;; The test for k<n is best if the n is the dimension of the manifold
  48. ;;; under study. However, if the manifold is embedded in a higher
  49. ;;; dimensional manifold n will be the dimension of the bigger
  50. ;;; manifold, making this test less effective (cutting off fewer
  51. ;;; branches).
  52. ;;; Formula is from Spivak Vol. 1 p289.
  53. (define (exterior-derivative-procedure kform)
  54. (let ((k (get-rank kform)))
  55. (if (fix:= k 0)
  56. (differential-of-function kform)
  57. (let ((the-k+1form
  58. (lambda vectors
  59. (assert (fix:= (length vectors) (fix:+ k 1)))
  60. (lambda (point)
  61. (let ((n ((point->manifold point) 'dimension)))
  62. ;;(s:dimension (manifold-point-representation point))
  63. (if (fix:< k n)
  64. (sigma
  65. (lambda (i)
  66. (let ((rest (delete-nth i vectors)))
  67. (+ (* (if (even? i) +1 -1)
  68. (((ref vectors i) (apply kform rest))
  69. point))
  70. (sigma
  71. (lambda (j)
  72. (* (if (even? (fix:+ i j)) +1 -1)
  73. ((apply kform
  74. (cons
  75. (commutator (ref vectors i)
  76. (ref vectors j))
  77. ;; j-1 because already deleted i.
  78. (delete-nth (fix:- j 1)
  79. rest)))
  80. point)))
  81. (fix:+ i 1) k))))
  82. 0 k)
  83. 0))))))
  84. (procedure->nform-field the-k+1form
  85. (fix:+ (get-rank kform) 1)
  86. `(d ,(diffop-name kform)))))))
  87. (define exterior-derivative
  88. (make-operator exterior-derivative-procedure
  89. 'd
  90. 'exterior-derivative))
  91. (define d exterior-derivative)
  92. ;;; This is an excessively complicated program. Another, more
  93. ;;; elementary program would, for a k-form, extract the cofficient
  94. ;;; functions relative to a literal basis, by applying it to the basis
  95. ;;; vectors, do the derivatives of the coefficients, to make one
  96. ;;; forms, and form the sum of the weges of the new 1-forms with the
  97. ;;; wedges of the corresponding dual basis elements.
  98. #|
  99. (install-coordinates R3-rect (up 'x 'y 'z))
  100. (define R3-rect-point ((R3-rect '->point) (up 'x0 'y0 'z0)))
  101. (install-coordinates R3-cyl (up 'r 'theta 'zeta))
  102. (define R3-cyl-point ((R3-cyl '->point) (up 'r0 'theta0 'zeta0)))
  103. (define w (literal-1form-field 'w R3-rect))
  104. (define u (literal-1form-field 'u R3-rect))
  105. (define v (literal-1form-field 'v R3-rect))
  106. (define X (literal-vector-field 'X R3-rect))
  107. (define Y (literal-vector-field 'Y R3-rect))
  108. (define Z (literal-vector-field 'Z R3-rect))
  109. (define W (literal-vector-field 'W R3-rect))
  110. (pec (((d (literal-scalar-field 'f R3-rect)) X)
  111. R3-rect-point))
  112. #| Result:
  113. (+ (* (((partial 0) f) (up x0 y0 z0)) (X^0 (up x0 y0 z0)))
  114. (* (((partial 1) f) (up x0 y0 z0)) (X^1 (up x0 y0 z0)))
  115. (* (((partial 2) f) (up x0 y0 z0)) (X^2 (up x0 y0 z0))))
  116. |#
  117. (pec ((((square d) (literal-scalar-field 'f R3-rect)) X Y)
  118. R3-cyl-point))
  119. #| Result:
  120. 0
  121. |#
  122. ;;; To aid reading of expressions...
  123. (clear-arguments)
  124. (suppress-arguments (list '(up x0 y0 z0)))
  125. (pec (((d w) X Y) R3-rect-point)
  126. (compose arg-suppressor simplify))
  127. #| Result:
  128. (+ (* Y^2 ((partial 0) w_2) X^0)
  129. (* Y^2 ((partial 1) w_2) X^1)
  130. (* -1 Y^2 ((partial 2) w_0) X^0)
  131. (* -1 Y^2 ((partial 2) w_1) X^1)
  132. (* -1 Y^0 ((partial 0) w_2) X^2)
  133. (* Y^0 ((partial 2) w_0) X^2)
  134. (* Y^0 ((partial 1) w_0) X^1)
  135. (* -1 Y^0 ((partial 0) w_1) X^1)
  136. (* -1 ((partial 1) w_2) Y^1 X^2)
  137. (* ((partial 2) w_1) Y^1 X^2)
  138. (* -1 Y^1 ((partial 1) w_0) X^0)
  139. (* Y^1 ((partial 0) w_1) X^0))
  140. |#
  141. (define omega
  142. (+ (* (literal-scalar-field 'omega_0 R3-rect)
  143. (wedge dx dy))
  144. (* (literal-scalar-field 'omega_1 R3-rect)
  145. (wedge dy dz))
  146. (* (literal-scalar-field 'omega_2 R3-rect)
  147. (wedge dz dx))))
  148. (pec (((d omega) X Y Z) R3-rect-point)
  149. (compose arg-suppressor simplify))
  150. #| Result:
  151. (+ (* X^0 Z^2 ((partial 0) omega_1) Y^1)
  152. (* X^0 Z^2 ((partial 1) omega_2) Y^1)
  153. (* X^0 Z^2 ((partial 2) omega_0) Y^1)
  154. (* -1 X^0 Y^2 Z^1 ((partial 0) omega_1))
  155. (* -1 X^0 Y^2 Z^1 ((partial 1) omega_2))
  156. (* -1 X^0 Y^2 Z^1 ((partial 2) omega_0))
  157. (* -1 Z^2 X^1 Y^0 ((partial 0) omega_1))
  158. (* -1 Z^2 X^1 Y^0 ((partial 1) omega_2))
  159. (* -1 Z^2 X^1 Y^0 ((partial 2) omega_0))
  160. (* X^1 Y^2 Z^0 ((partial 0) omega_1))
  161. (* X^1 Y^2 Z^0 ((partial 1) omega_2))
  162. (* X^1 Y^2 Z^0 ((partial 2) omega_0))
  163. (* X^2 Y^0 Z^1 ((partial 0) omega_1))
  164. (* X^2 Y^0 Z^1 ((partial 1) omega_2))
  165. (* X^2 Y^0 Z^1 ((partial 2) omega_0))
  166. (* -1 X^2 Z^0 ((partial 0) omega_1) Y^1)
  167. (* -1 X^2 Z^0 ((partial 1) omega_2) Y^1)
  168. (* -1 X^2 Z^0 ((partial 2) omega_0) Y^1))
  169. |#
  170. (pec (((d (d omega)) X Y Z W) R3-rect-point))
  171. #| Result:
  172. 0
  173. |#
  174. |#
  175. #|
  176. ;;; Jack's neat method of computing the exterior derivative of a form.
  177. ;;; One problem is that this needs the coordinate system to make the
  178. ;;; constant vector field.
  179. ;;; Broken because coordinate systems must be associated with patches.
  180. (define (make-constant-vector-field m0 v)
  181. (let ((coordinate-system (rectangular (s:dimension m0))))
  182. (components->vector-field (lambda (coords)
  183. ((v (coordinate-system '->coords)) m0))
  184. coordinate-system
  185. `(constant-vector-field ,m0 ,v))))
  186. (define (((exterior-derivative-helper kform) #!rest vectors) point)
  187. (let ((k (get-rank kform)))
  188. (assert (fix:= (length vectors) (fix:+ k 1)))
  189. (let ((n ((point->manifold point) 'dimension)))
  190. ;;(s:dimension (manifold-point-representation point))
  191. (cond ((fix:= k 0)
  192. (((ref vectors 0) kform) point))
  193. ((fix:< k n)
  194. (let ((constant-vector-fields
  195. (map (lambda (v)
  196. (make-constant-vector-field point v))
  197. vectors)))
  198. (let lp ((i 0) (sum 0))
  199. (if (fix:= i (fix:+ k 1))
  200. sum
  201. (lp (fix:+ i 1)
  202. (let ((h (ref constant-vector-fields i)))
  203. (+ sum
  204. (* (if (even? i) 1 -1)
  205. ((h
  206. (apply kform
  207. (delete-nth i
  208. constant-vector-fields)))
  209. point)))))))))
  210. (else 0)))))
  211. |#