frames.red 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. module frames;
  2. % Author: Eberhard Schruefer;
  3. global '(basisforml!* basisvectorl!* keepl!* naturalframe2coframe
  4. dbaseform2base2form dimex!* indxl!* naturalvector2framevector
  5. metricd!* metricu!* coord!* cursym!* detm!*
  6. commutator!-of!-framevectors);
  7. fluid '(alglist!* indl kord!* subfg!*); % indl needed by Common Lisp.
  8. symbolic procedure coframestat;
  9. begin scalar framel,metric;
  10. flag('(with),'delim);
  11. framel := cdr rlis();
  12. remflag('(with),'delim);
  13. if cursym!* eq '!*semicol!* then go to a;
  14. if scan() eq 'metric then metric := xread t
  15. else if cursym!* eq 'signature then metric := rlis()
  16. else symerr('coframe,t);
  17. a: cofram(framel,metric)
  18. end;
  19. put('coframe,'stat,'coframestat);
  20. %put('cofram,'formfn,'formcofram);
  21. symbolic procedure cofram(u,v);
  22. begin scalar alglist!*;
  23. rmsubs();
  24. u := for each j in u collect
  25. if car j eq 'equal then cdr j else list j;
  26. putform(caar u,1);
  27. basisforml!* := for each j in u collect !*a2k car j;
  28. indxl!* := for each j in basisforml!* collect cadr j;
  29. dimex!* := length u;
  30. basisvectorl!* := nil;
  31. if null v then
  32. metricd!* := nlist(1,dimex!*)
  33. else if car v eq 'signature
  34. then if dimex!* neq length cdr v
  35. then rerror(excalc,12,
  36. "Dimension of coframe and metric are inconsistent.")
  37. else metricd!* := for each j in cdr v collect aeval j;
  38. if null v or (car v eq 'signature) then
  39. <<detm!* := simp car metricd!*;
  40. for each j in cdr metricd!* do
  41. detm!* := multsq(simp j,detm!*);
  42. detm!* := mk!*sq detm!*;
  43. metricu!* := metricd!*:= pair(indxl!*,for each j in
  44. pair(indxl!*,metricd!*) collect list j)>>
  45. else mkmetric v;
  46. if flagp('partdf,'noxpnd) then remflag('(partdf),'noxpnd);
  47. putform('eps . indxl!*,0);
  48. put('eps,'indxsymmetries,
  49. list list('lambda,'(indl),list('tot!-asym!-indp,
  50. list('evlis,mkquote for j := 1:dimex!* collect
  51. list('nth,'indl,j)))));
  52. put('eps,'indxsymmetrize,
  53. list list('lambda,'(indl),list('asymmetrize!-inds,
  54. mkquote(for j := 1: dimex!* collect j),'indl)));
  55. flag('(eps),'covariant);
  56. setk('eps . for each j in indxl!* collect lowerind j,1);
  57. if null cdar u then return;
  58. keepl!* := append(for each j in u collect
  59. !*a2k car j . cadr j,keepl!*);
  60. coframe1 for each j in u collect cadr j
  61. end;
  62. symbolic procedure coframe1 u;
  63. begin scalar osubfg,scoord,v,y,w;
  64. osubfg := subfg!*;
  65. subfg!* := nil;
  66. v := for each j in u collect
  67. <<y := partitop j;
  68. scoord := pickupcoords(y,scoord);
  69. y>>;
  70. if null atom car scoord
  71. then <<remflag({caar scoord},'covariant);
  72. scoord := for each j in scoord
  73. collect mvar numr lc partitop j;
  74. v := for each j in u collect partitop j>>;
  75. if length scoord neq dimex!*
  76. then rerror(excalc,3,"badly formed basis");
  77. w := !*pf2matwrtcoords(v,scoord);
  78. naturalvector2framevector := v;
  79. subfg!* := nil;
  80. naturalframe2coframe := pair(scoord,
  81. for each j in lnrsolve(w,for each k in basisforml!*
  82. collect list !*k2q k)
  83. collect mk!*sqpf partitsq!* car j);
  84. subfg!* := osubfg;
  85. coord!* := scoord;
  86. dbaseform2base2form := pair(basisforml!*,
  87. for each j in v collect mk!*sqpf repartit exdfpf j)
  88. end;
  89. symbolic procedure pickupcoords(u,v);
  90. %u is a pf, v a list. Picks up vars in exdf and declares them as
  91. %zero forms.
  92. if null u then v
  93. else if null eqcar(ldpf u,'d)
  94. then rerror(excalc,4,"badly formed basis")
  95. else if null v then <<putform(cadr ldpf u,0);
  96. pickupcoords(red u,cadr ldpf u . nil)>>
  97. else if ordop(cadr ldpf u,car v)
  98. then if cadr ldpf u eq car v
  99. then pickupcoords(red u,v)
  100. else <<putform(cadr ldpf u,0);
  101. pickupcoords(red u,cadr ldpf u . v)>>
  102. else pickupcoords(red u,car v . pickupcoords(!*k2pf ldpf u,cdr v));
  103. symbolic procedure !*pf2matwrtcoords(u,v);
  104. if null u then nil
  105. else !*pf2colwrtcoords(car u,v) . !*pf2matwrtcoords(cdr u,v);
  106. symbolic procedure !*pf2colwrtcoords(u,v);
  107. if null v then nil
  108. else if u and (cadr ldpf u eq car v)
  109. then lc u . !*pf2colwrtcoords(red u,cdr v)
  110. else (nil ./ 1) . !*pf2colwrtcoords(u,cdr v);
  111. symbolic procedure coordp u;
  112. u memq coord!*;
  113. symbolic procedure mkmetric u;
  114. begin scalar x,y,z,okord;
  115. putform(list(cadr u,nil,nil),0);
  116. put(cadr u,'indxsymmetries,
  117. '((lambda (indl) (tot!-sym!-indp
  118. (evlis '((nth indl 1)
  119. (nth indl 2)))))));
  120. put(cadr u,'indxsymmetrize,
  121. '((lambda (indl) (symmetrize!-inds '(1 2) indl))));
  122. flag(list cadr u,'covariant);
  123. okord := kord!*;
  124. kord!* := basisforml!*;
  125. x := simp!* caddr u;
  126. y := indxl!*;
  127. metricu!* := t; %to make simpindexvar work;
  128. for each j in indxl!* do
  129. <<for each k in y do
  130. setk(list(cadr u,lowerind j,lowerind k),0);
  131. y := cdr y>>;
  132. for each j on partitsq(x,'basep) do
  133. if ldeg ldpf j = 2 then
  134. setk(list(cadr u,lowerind cadr mvar ldpf j,
  135. lowerind cadr mvar ldpf j),
  136. mk!*sq lc j)
  137. else
  138. setk(list(cadr u,lowerind cadr mvar ldpf j,
  139. lowerind cadr mvar lc ldpf j),
  140. mk!*sq multsq(lc j,1 ./ 2));
  141. kord!* := okord;
  142. x := for each j in indxl!* collect
  143. for each k in indxl!* collect
  144. simpindexvar list(cadr u,lowerind j,lowerind k);
  145. z := subfg!*;
  146. subfg!* := nil;
  147. y := lnrsolve(x,generateident length indxl!*);
  148. subfg!* := z;
  149. metricd!* := mkasmetric x;
  150. metricu!* := mkasmetric y;
  151. detm!* := mk!*sq detq x
  152. end;
  153. symbolic procedure mkasmetric u;
  154. for each j in pair(indxl!*,u) collect
  155. car j . begin scalar w,z;
  156. w := indxl!*;
  157. for each k in cdr j do
  158. <<if numr k then
  159. z := (car w . mk!*sq k) . z;
  160. w := cdr w>>;
  161. return z
  162. end;
  163. symbolic procedure frame u;
  164. begin scalar y;
  165. putform(list(car u,nil),-1);
  166. flag(list car u,'covariant);
  167. basisvectorl!* :=
  168. for each j in indxl!* collect !*a2k list(car u,lowerind j);
  169. if null dbaseform2base2form then return;
  170. commutator!-of!-framevectors :=
  171. for each j in pickupwedges dbaseform2base2form collect
  172. list(cadadr j,cadadr cdr j) . mk!*sqpf mkcommutatorfv(j,
  173. dbaseform2base2form);
  174. y := pair(basisvectorl!*,
  175. naturalvector2framevector);
  176. naturalvector2framevector := for each j in coord!* collect
  177. j . mk!*sqpf mknat2framv(j,y)
  178. end;
  179. symbolic procedure pickupwedges u;
  180. pickupwedges1(u,nil);
  181. Symbolic procedure pickupwedges1(u,v);
  182. if null u then v
  183. else if null cdar u then pickupwedges1(cdr u,v)
  184. else if null v then pickupwedges1((caar u . red cdar u) . cdr u,
  185. ldpf cdar u . nil)
  186. else if ldpf cdar u memq v
  187. then pickupwedges1(if red cdar u
  188. then (caar u . red cdar u) . cdr u
  189. else cdr u,v)
  190. else pickupwedges1(if red cdar u
  191. then (caar u . red cdar u) . cdr u
  192. else cdr u,ldpf cdar u . v);
  193. symbolic procedure mkbasevector u;
  194. !*a2k list(caar basisvectorl!*,lowerind u);
  195. symbolic procedure mkcommutatorfv(u,v);
  196. if null v then nil
  197. else addpf(mkcommutatorfv1(u,mkbasevector cadaar v,cdar v),
  198. mkcommutatorfv(u,cdr v));
  199. symbolic procedure mkcommutatorfv1(u,v,w);
  200. if null w then nil
  201. else if u eq ldpf w
  202. then v .* negsq simp!* lc w .+ nil
  203. else if ordop(u,ldpf w) then nil
  204. else mkcommutatorfv1(u,v,red w);
  205. symbolic procedure mknat2framv(u,v);
  206. if null v then nil
  207. else addpf(mknat2framv1(u,caar v,cdar v),mknat2framv(u,cdr v));
  208. symbolic procedure mknat2framv1(u,v,w);
  209. if null w then nil
  210. else if u eq cadr ldpf w
  211. then v .* lc w .+ nil
  212. else if ordop(u,cadr ldpf w) then nil
  213. else mknat2framv1(u,v,red w);
  214. symbolic procedure dualframe u;
  215. rerror(excalc,5,"Dualframe no longer supported - use frame instead");
  216. symbolic procedure riemannconx u;
  217. riemconnection car u;
  218. put('riemannconx,'stat,'rlis);
  219. smacro procedure mkbasformsq u;
  220. mksq(list(caar basisforml!*,u),1);
  221. symbolic procedure riemconnection u;
  222. %calculates the riemannian connection and stores it in u;
  223. begin
  224. putform(list(u,nil,nil),1);
  225. flag(list u,'covariant);
  226. put(u,'indxsymmetries,
  227. '((lambda (indl) (tot!-asym!-indp (evlis '((nth indl 1)
  228. (nth indl 2)))))));
  229. put(u,'indxsymmetrize,
  230. '((lambda (indl) (asymmetrize!-inds '(1 2) indl))));
  231. for each j in indxl!* do
  232. for each k in indxl!* do if (j neq k) and indordp(j,k) then
  233. setk(list(u,lowerind j,lowerind k),0);
  234. riemconpart1 u;
  235. riemconpart2 u;
  236. riemconpart3 u
  237. end;
  238. symbolic procedure riemconpart1 u;
  239. begin scalar covbaseform,indx1,indx2,indx3,varl,w,z;
  240. for each l in dbaseform2base2form do
  241. <<covbaseform := partitindexvar list(caar l,
  242. lowerind cadar l);
  243. for each j on cdr l do
  244. <<varl := cdr ldpf j;
  245. indx1 := cadar varl;
  246. indx2 := cadadr varl;
  247. for each y on covbaseform do
  248. <<w := list(u,lowerind indx1,lowerind indx2);
  249. z := multsq(-1 ./ 2,!*pf2sq multpfsq(lt y .+ nil,
  250. simp!* lc j));
  251. setk(w,mk!*sq addsq(z,mksq(w,1)));
  252. indx3 := cadr ldpf y;
  253. z := multsq(-1 ./ 2,multsq(lc y,simp!* lc j));
  254. if indx1 neq indx3 then
  255. if indordp(indx1,indx3) then
  256. <<w := list(u,lowerind indx1,lowerind indx3);
  257. setk(w,mk!*sq addsq(multsq(z,mkbasformsq indx2),
  258. mksq(w,1)))>>
  259. else
  260. <<w := list(u,lowerind indx3,lowerind indx1);
  261. setk(w,mk!*sq addsq(multsq(negsq z,
  262. mkbasformsq indx2),mksq(w,1)))>>;
  263. if indx2 neq indx3 then
  264. if indordp(indx2,indx3) then
  265. <<w := list(u,lowerind indx2,lowerind indx3);
  266. setk(w,mk!*sq addsq(multsq(negsq z,
  267. mkbasformsq indx1),mksq(w,1)))>>
  268. else
  269. <<w := list(u,lowerind indx3,lowerind indx2);
  270. setk(w,mk!*sq addsq(multsq(z,
  271. mkbasformsq indx1),mksq(w,1)))>>
  272. >>>>>>
  273. end;
  274. symbolic procedure riemconpart2 u;
  275. begin scalar dgkl,indx1,indx2,varl,w,z;
  276. if null(dgkl := mkmetricconx2 metricd!*)
  277. then return;
  278. for each j in dgkl do
  279. for each y on cdr j do
  280. <<varl := ldpf y;
  281. indx1 := cadar varl;
  282. indx2 := cadadr varl;
  283. w := list(u,lowerind indx1,lowerind indx2);
  284. z := multsq(-1 ./ 2,multsq(!*k2q car j,lc y));
  285. setk(w,mk!*sq addsq(z,mksq(w,1)))>>
  286. end;
  287. symbolic procedure mkmetricconx2 u;
  288. if null u then nil
  289. else (if x then (ldpf mkupf list(caar basisforml!*,caar u) . x)
  290. . mkmetricconx2 cdr u
  291. else mkmetricconx2 cdr u)
  292. where x = mkmetricconx21 cdar u;
  293. symbolic procedure mkmetricconx21 u;
  294. if null u then nil
  295. else addpf(wedgepf2(exdf0 simp!* cdar u,
  296. !*k2pf list ldpf mkupf list(caar basisforml!*,caar u)),
  297. mkmetricconx21 cdr u);
  298. symbolic procedure riemconpart3 u;
  299. begin scalar dg,dgk,dgkl,w,x,z;
  300. if null (dg := mkmetricconx3 metricd!*)
  301. then return;
  302. remprop(u,'indxsymmetries);
  303. remprop(u,'indxsymmetrize);
  304. for each j in indxl!* do
  305. <<if dg and (dgk := atsoc(j,dg))
  306. then dgk := cdr dgk
  307. else dgk := nil;
  308. for each k in indxl!* do
  309. if indordp(j,k) then
  310. <<w := list(u,lowerind j,lowerind k);
  311. x := if j eq k then nil ./ 1 else mksq(w,1);
  312. if dgk and (dgkl := atsoc(k,dgk))
  313. then dgkl := cdr dgkl
  314. else dgkl := nil ./ 1;
  315. z := multsq(1 ./ 2,dgkl);
  316. setk(w,mk!*sq addsq(z,x));
  317. w := list(u,lowerind k,lowerind j);
  318. setk(w,mk!*sq addsq(z,negsq x))>>>>
  319. end;
  320. symbolic procedure mkmetricconx3 u;
  321. if null u then nil
  322. else ((if x then (caar u . x) . mkmetricconx3 cdr u
  323. else mkmetricconx3 cdr u)
  324. where x = mkmetricconx31 cdar u);
  325. symbolic procedure mkmetricconx31 u;
  326. if null u then nil
  327. else ((if x then (caar u . x) . mkmetricconx31 cdr u
  328. else mkmetricconx31 cdr u)
  329. where x = !*pf2sq exdf0 simp!* cdar u);
  330. symbolic procedure basep u;
  331. if domainp u then nil
  332. else or(if sfp mvar u then basep mvar u
  333. else eqcar(mvar u,caar basisforml!*),
  334. basep lc u,basep red u);
  335. symbolic procedure wedgefp u;
  336. if domainp u then nil
  337. else or(if sfp mvar u then wedgefp mvar u
  338. else eqcar(mvar u,'wedge),
  339. wedgefp lc u,wedgefp red u);
  340. endmodule;
  341. end;