dummy2.red 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. %======================================================
  2. % Name: dummy2.red - dummy indices package
  3. % Author: A.Kryukov (kryukov@npi.msu.su)
  4. % Copyright: (C), 1993, A.Kryukov
  5. %------------------------------------------------------
  6. % Version: 2.34
  7. % Release: Dec. 15, 1993
  8. % Mar. 24, 1996 mk_ddsym1
  9. %======================================================
  10. module dummy2$
  11. global '(!*basis); fluid '(!*debug)$
  12. symbolic procedure adddummy(tt)$
  13. % tt - tensor::=(!:tensor . ((th1 . pv1) ...)))
  14. % (r.v.) - basis::=((th1 . (pv1 pv2 ...)) ...)
  15. adddummy0(cdr tt,!*basis)$
  16. symbolic procedure adddummy0(tt,b)$
  17. % tt - ((th1 . pv1) ...)
  18. % b(r.v.) - basis::=((th1 . (pv1 pv2 ...)) ...)
  19. if null tt then reversip b
  20. else adddummy0(cdr tt,adddummy0b(mk_dsym0 car tt,b))$
  21. symbolic procedure adddummy0b(u,b)$
  22. % u - (th . (pv1 pv2 ...))
  23. %b,b1(r.v.) - basis
  24. if null cdr u then b
  25. else adddummy0b(car u . cddr u,adddummy0a(car u . cadr u,b,nil))$
  26. symbolic procedure adddummy0a(t1,b,b1)$
  27. % t1 - (th . pv)
  28. % b,b1(r.v.) - basis::=((th1 . (pv1 pv2 ...)) ...)
  29. if null b then if null t1 then reversip b1
  30. else reversip(adddummy1(t1
  31. ,gperm length cadar t1
  32. ,nil
  33. ) . b1
  34. )
  35. else if null t1 then adddummy0a(nil,cdr b,car b . b1)
  36. % else if th_match(car t1,caar b) then adddummy0a(nil,b,b1)
  37. else if th_match0(car t1,caar b)
  38. then adddummy0a(nil,cdr b,adddummy1(t1
  39. ,gperm length cadar t1
  40. ,car t1 . cdar b
  41. ) . b1
  42. )
  43. else adddummy0a(t1,cdr b,car b . b1)$
  44. symbolic procedure adddummy1(t1,plist,b)$
  45. << if !*debug
  46. then << terpri()$
  47. write " DEBUG: adddummy1"$
  48. terpri()$
  49. t_pri1('!:tensor . list(t1),t)$
  50. terpri()$
  51. for each z in cdr x
  52. do t_pri1('!:tensor . list(car x . z),t)$
  53. write " DEBUG=",length cdr x$ terpri()$
  54. >>$
  55. x
  56. >> where x=adddummy1a(t1,plist,b)$
  57. symbolic procedure adddummy1a(t1,plist,b)$
  58. % t1 - (th . pv)
  59. % plist - (p1 p2 ...)
  60. % b,w(r.v.) - (th1 . (pv1 pv2 ...))
  61. if null plist then b
  62. else adddummy1a(t1
  63. ,cdr plist
  64. ,(if null b then car t1 else car b)
  65. . insert_pv(pappl_pv(car plist,cdr t1)
  66. ,if null b then b else cdr b
  67. )
  68. )$
  69. symbolic procedure mk_dsym0 t1$
  70. car t1 . append(cdr mk_dsym t1,cdr mk_ddsym t1)$
  71. symbolic procedure mk_dsym(t1)$
  72. % t1 - (th . pv)
  73. car t1 . mk_dsym1(cdr t1
  74. ,nil
  75. ,mk_flips(cadar t1,dl_get cadar t1,nil)
  76. )$
  77. symbolic procedure mk_dsym1(pv1,pv2,fs)$
  78. % pv1,pv2(r.v.) - pvector
  79. % fs - permutation list
  80. if null fs then pv2
  81. else mk_dsym1(pv1
  82. ,pv_add(pv1,pv_neg pv_applp(pv1,car fs)) . pv2
  83. % ,pv_add(pv1,pv_neg pappl_pv(car fs,pv1)) . pv2
  84. ,cdr fs
  85. )$
  86. symbolic procedure dl_get(il)$ dl_get2(il,nil)$
  87. symbolic procedure dl_get2(il,d_alst)$
  88. if null il then d_alst
  89. else if get(car il,'dummy)
  90. then dl_get2(cdr il,di_insert(car il,d_alst,nil))
  91. else dl_get2(cdr il,d_alst)$
  92. symbolic procedure eqdummy(x,y)$
  93. x and car get(x,'dummy) eq car get(y,'dummy)$
  94. symbolic procedure di_insert(di,d_alst1,d_alst2)$
  95. if null d_alst1 then if di then ((di . nil) . d_alst2)
  96. else d_alst2
  97. else if eqdummy(di,caar d_alst1)
  98. then di_insert(nil,cdr d_alst1,(caar d_alst1 . di) . d_alst2)
  99. else di_insert(di,cdr d_alst1,car d_alst1 . d_alst2)$
  100. symbolic procedure il_update(il,d_alst)$
  101. il_update1(il,d_alst,nil)$
  102. symbolic procedure il_update1(il,d_alst,il1)$
  103. if null il then reversip il1
  104. else ((if null y then il_update1(cdr il,d_alst,car il . il1)
  105. else ((if x
  106. then il_update1(cdr il,delete(x,d_alst),cdr x . il1)
  107. else begin scalar z,u$
  108. z:=di_next(d_alst)$
  109. u:=car z$
  110. rplaca(z,y)$
  111. return il_update1(cdr il,d_alst,u . il1
  112. )$
  113. end
  114. ) where x=assoc(y,d_alst)
  115. )
  116. ) where y=get(car il,'dummy)
  117. )$
  118. symbolic procedure di_next(dl)$
  119. if null dl then rederr list('di_next,"+++ Can't find next dummy")
  120. else if get(caar dl,'dummy) then car dl
  121. else di_next(cdr dl)$
  122. symbolic procedure mk_flips(il,dl,fs)$
  123. if null dl then reversip fs
  124. else mk_flips(il,cdr dl,mk_flip(il,car dl) . fs)$
  125. symbolic procedure mk_flip(il,x)$
  126. pfind(il,mk_flip1(il,x,nil))$
  127. symbolic procedure mk_flip1(il,x,w)$
  128. if null il then reverse w
  129. else if car x eq car il
  130. then mk_flip1(cdr il,(cdr x . car x),cdr x . w)
  131. else mk_flip1(cdr il,x,car il . w)$
  132. symbolic procedure mk_flip_(il,di)$
  133. begin scalar il1,il2,w,w1,ok,x$
  134. w:=il$
  135. while w and null ok do if null car w eq caar di
  136. then << il1:=car w . il1$ w:=cdr w >>
  137. else ok:=t$
  138. if null w then rederr 1;
  139. il1:=car w . il1$
  140. il2:=il1$
  141. w:=cdr w$
  142. ok:=nil$
  143. while w do if null car w eq cdar di
  144. then << il2:=car w . il2$ w:=cdr w >>
  145. else ok:=t$
  146. if null w then rederr 2;
  147. il2:=car w . il2$
  148. w:=cdr w$
  149. w1:=il2$
  150. while w do << w1:=car w . w1$ w:=cdr w >>$
  151. x:=car il1$
  152. rplaca(il1,car il2)$
  153. rplaca(il2,x)$
  154. return pfind(il,reversip w)$
  155. end$
  156. %++++++++++++++++++++++++++++++++++
  157. symbolic procedure mk_ddsym(t1)$
  158. % t1 - (th . pv)
  159. % r.v. - (th . (pv1 pv2 ...))
  160. car t1 . mk_ddsym1(cdr t1
  161. ,nil
  162. ,mk_fflips(cadar t1,dl_get cadar t1,nil)
  163. )$
  164. symbolic procedure mk_ddsym1(pv,pvs,fs)$
  165. if null fs then pvs
  166. else mk_ddsym1(pv
  167. % ,pv_add(pv,pv_neg pappl_pv(car fs,pv)) . pvs % -A.K. 24.03.96
  168. ,pv_add(pv,pv_neg pv_applp(pv,car fs)) . pvs % +A.K. 24.03.96
  169. ,cdr fs
  170. )$
  171. symbolic procedure mk_fflips(il,dl,fs)$
  172. if null dl then fs
  173. else mk_fflips(il,cdr dl,mk_fflips1(il,car dl,cdr dl,fs))$
  174. symbolic procedure mk_fflips1(il,dp,dl,fs)$
  175. if null dl then fs
  176. else mk_fflips1(il,dp,cdr dl,mk_fflip1(il,dp,car dl) . fs)$
  177. symbolic procedure mk_fflip1(il,dp1,dp2)$
  178. pfind(il,mk_fflip2(il,dp1,dp2,nil))$
  179. symbolic procedure mk_fflip2(il,dp1,dp2,il1)$
  180. % dp1,dp2 - (di1 . di2) - contracted indecies
  181. if null il then reverse il1
  182. else ((if null(x=get(car dp1,'dummy)) and null(x=get(car dp2,'dummy))
  183. then mk_fflip2(cdr il,dp1,dp2,car il . il1)
  184. else if x=get(car dp2,'dummy)
  185. then mk_fflip2(il,dp2,dp1,il1)
  186. else mk_fflip2(cdr il,dp1,cdr dp2 . car dp2,car dp2 . il1)
  187. ) where x=get(car il,'dummy)
  188. )$
  189. endmodule;
  190. end;