wedge.scm 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. ;;; Higher rank forms can be constructed from 1forms by wedging them
  21. ;;; together. This antisymmetric tensor product is computed as a
  22. ;;; determinant. The purpose of this is to allow us to use the
  23. ;;; construction dx^dy to compute the area described by the vectors
  24. ;;; that are given to it.
  25. (define (wedge2 form1 form2)
  26. (let ((n1 (get-rank form1)) (n2 (get-rank form2)))
  27. (if (or (zero? n1) (zero? n2))
  28. (* form1 form2)
  29. (let ((n (fix:+ n1 n2)))
  30. (define (the-wedge . args)
  31. (assert (fix:= (length args) n)
  32. "Wrong number of args to wedge product")
  33. (let ((perms (permutations (iota n))))
  34. (g:* (/ 1 (* (factorial n1) (factorial n2))) ; Error in Singer.
  35. (apply g:+
  36. (map (lambda (p)
  37. (let ((pargs (permute p args)))
  38. (let ((order (permutation-interchanges p))
  39. (a1 (list-head pargs n1))
  40. (a2 (list-tail pargs n1)))
  41. (g:* (if (even? order) 1 -1)
  42. (apply form1 a1)
  43. (apply form2 a2)))))
  44. perms)))))
  45. (procedure->nform-field the-wedge
  46. n
  47. `(wedge ,(diffop-name form1)
  48. ,(diffop-name form2)))))))
  49. (define (wedge . args)
  50. (reduce-right wedge2 (constant 1) args))
  51. ;;; See Spivak p275 v1 "Differential Geometry" to see the correct
  52. ;;; definition. The key is that the wedge of the coordinate basis
  53. ;;; forms had better be the volume element.
  54. (define (get-rank op)
  55. (cond ((operator? op)
  56. (let ((a (arity op)))
  57. (if (not (and (pair? a)
  58. (exact-integer? (car a))
  59. (exact-integer? (cdr a))
  60. (int:= (car a) (cdr a))))
  61. (error "Unknown rank operator " op))
  62. (car a)))
  63. ((function? op) 0)
  64. (else (error "Bad rank " op))))
  65. (define (rank->arity n)
  66. (cons n n))
  67. (define* (procedure->nform-field proc n #:optional name)
  68. (if (default-object? name)
  69. (set! name 'unnamed-nform-field))
  70. (if (= n 0)
  71. (proc)
  72. (let ((the-field (make-operator proc name wedge (rank->arity n))))
  73. (declare-argument-types! the-field (make-list n vector-field?))
  74. the-field)))
  75. #|
  76. (install-coordinates R3-rect (up 'x 'y 'z))
  77. (define R3-point ((R3-rect '->point) (up 'x0 'y0 'z0)))
  78. (define w (literal-1form-field 'w R3-rect))
  79. (define u (literal-1form-field 'u R3-rect))
  80. (define v (literal-1form-field 'v R3-rect))
  81. (define X (literal-vector-field 'X R3-rect))
  82. (define Y (literal-vector-field 'Y R3-rect))
  83. (define Z (literal-vector-field 'Z R3-rect))
  84. (define W (literal-vector-field 'W R3-rect))
  85. ;;; Just checking that everything is working...
  86. (pec ((w X) R3-point))
  87. #| Result:
  88. (+ (* (X^0 (up x0 y0 z0)) (w_0 (up x0 y0 z0)))
  89. (* (X^1 (up x0 y0 z0)) (w_1 (up x0 y0 z0)))
  90. (* (X^2 (up x0 y0 z0)) (w_2 (up x0 y0 z0))))
  91. |#
  92. ;;; A few theorems
  93. (pec (((- (wedge (wedge w u) v) (wedge w (wedge u v))) X Y Z)
  94. R3-point))
  95. #| Result:
  96. 0
  97. |#
  98. (pec (((- (wedge (+ w u) v) (+ (wedge w v) (wedge u v))) X Y)
  99. R3-point))
  100. #| Result:
  101. 0
  102. |#
  103. ;;; Note, a product of forms is their wedge!
  104. (pec (((- (wedge u v) (* u v)) X Y)
  105. R3-point))
  106. #| Result:
  107. 0
  108. |#
  109. |#
  110. #|
  111. (define dx^dy (wedge dx dy))
  112. ((dx^dy d/dx d/dy) R3-point)
  113. ;Value 1
  114. ((dx^dy d/dx d/dx) R3-point)
  115. ;Value: 0
  116. ((dx^dy d/dy d/dx) R3-point)
  117. ;Value: -1
  118. |#
  119. ;;; Alternative definition in terms of alternation.
  120. (define (Alt form)
  121. (let ((n (get-rank form)))
  122. (if (zero? n)
  123. form
  124. (let ()
  125. (define (the-alternation . args)
  126. (assert (fix:= (length args) n)
  127. "Wrong number of args to alternation")
  128. (let ((perms (permutations (iota n))))
  129. (g:* (/ 1 (factorial n))
  130. (apply g:+
  131. (map (lambda (p)
  132. (let ((pargs (permute p args)))
  133. (let ((order (permutation-interchanges p)))
  134. (g:* (if (even? order) 1 -1)
  135. (apply form pargs)))))
  136. perms)))))
  137. (procedure->nform-field the-alternation
  138. n
  139. `(Alt ,(diffop-name form)))))))
  140. ;;; FBE start: buggy? missing definition of form1 ...
  141. ;; (define (tensor-product2 t1 t2)
  142. ;; (let ((n1 (get-rank t1)) (n2 (get-rank t2)))
  143. ;; (if (or (zero? n1) (zero? n2))
  144. ;; (* form1 form2)
  145. ;; (let ((n (fix:+ n1 n2)))
  146. ;; (define (the-product . args)
  147. ;; (assert (fix:= (length args) n)
  148. ;; "Wrong number of args to tensor product")
  149. ;; (* (apply t1 (list-head args n1))
  150. ;; (apply t2 (list-tail args n1))))
  151. ;; (procedure->nform-field the-product
  152. ;; n
  153. ;; `(tensor-product ,(diffop-name t1)
  154. ;; ,(diffop-name t2)))))))
  155. ;; (define (w2 form1 form2)
  156. ;; (let ((n1 (get-rank form1)) (n2 (get-rank form2)))
  157. ;; (* (/ (factorial (+ n1 n2))
  158. ;; (* (factorial n1) (factorial n2)))
  159. ;; (Alt (tensor-product2 form1 form2)))))
  160. ;;; FBE end
  161. ;;;(define (wedge . args)
  162. ;;; (reduce w2 (constant 1) args))