tensor1.red 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. %======================================================
  2. % Name: tensor1.red - tensor continuation
  3. % Author: A.Kryukov (kryukov@theory.npi.msu.su)
  4. % Copyright: (C), 1993-1996, A.Kryukov
  5. % Version: 2.22 Apr. 02, 1996
  6. %------------------------------------------------------
  7. % Release: Dec. 15, 1993
  8. % Mar. 25, 1996 sieve_t2
  9. % Apr. 02, 1996 t_add2
  10. %======================================================
  11. module tensor1$
  12. global '(!*basis)$
  13. global '(pv_den)$
  14. symbolic procedure th2pe(th,v)$
  15. % th - tensor header
  16. % th::=(tname ...) . (i ...) . (d ...)
  17. % v - vector
  18. % return prefix expression
  19. begin scalar pe,r,i,il,tt,tt1$
  20. % tt,tt1 - tensor term
  21. while v do <<
  22. il:=pappl(cdar v,di_restore cadr th)$
  23. tt1:=nil$
  24. for each x in car th do <<
  25. r:=get(x,'!:tensor)$
  26. tt:=list x$
  27. for i:=1:r do << tt:=car il . tt$ il:=cdr il >>$
  28. tt1:=reversip tt . tt1$
  29. >>$ % for each
  30. tt1:=reversip tt1$
  31. if null(caar v = 1) then tt1:=caar v . tt1$
  32. if tt1 and cdr tt1 then tt1:='times . tt1$
  33. if tt1 and null cdr tt1 then tt1:=car tt1$
  34. pe:=tt1 . pe$
  35. v:=cdr v$
  36. >>$ % while v
  37. pe:=reversip pe$
  38. if pe and cdr pe then pe:='plus . pe
  39. else if pe then pe:=car pe$
  40. return pe$
  41. end$
  42. symbolic procedure t_pri1(tt,sw)$
  43. % tt - tensor expression
  44. % tt::=!:tensor . ((th . v) ...)
  45. begin scalar pe,den$ %mod AK 28/03/96
  46. tt:=cdr tt$
  47. den:=cddr caar tt$ %+ AK 28/03/96
  48. while tt do <<
  49. pe:=th2pe(caar tt,cdar tt) . pe$
  50. tt:=cdr tt$
  51. >>$
  52. if pe and cdr pe then pe:='plus . reversip pe
  53. else if pe then pe:=car pe$
  54. if not(den = 1) then pe:='quotient . pe . list den$%+ AK 28/03/96
  55. % terpri()$ print list(">>>>>> t_pri1: pe=",pe)$ terpri()$
  56. assgnpri(pe,nil,sw)$ % WN 10.4.96
  57. end$
  58. symbolic procedure pappl_t(p,tt)$
  59. for each x in tt collect
  60. (caar x . pappl(p,cadar x) . cddar x) . pappl_pv(p,cdr x)$
  61. symbolic procedure t_add(t1,t2)$
  62. if null cdr t1 then t2
  63. else if null cdr t2 then t1
  64. else if th_match(cadr t1,cadr t2)
  65. then sieve_t(t_add2(t1,t2),!*basis)
  66. else t_addf(t1,t2)$
  67. symbolic procedure sieve_t(tt,bs)$
  68. % tt:=(!:tensor . (ten1 ten2 ...))
  69. car tt . sieve_t0(cdr tt,nil,bs)$ % -AK 250396
  70. % ((car tt . car x) . cdr x) % +AK 250396
  71. % where x=sieve_t0(cdr tt,nil,bs)$ % +AK 250396
  72. symbolic procedure sieve_t0(u,v,bs)$ % July 13, 1994
  73. % u::=(ten1 ten2 ...)
  74. % v - sieved tensor (r.v.)
  75. if null u then reversip v
  76. else sieve_t0(cdr u
  77. ,((if cdr x then x . v else v) % -AK 250396
  78. % ,((if cdr x then (x.pv_den) . v else v) % +AK 250396
  79. where x=sieve_t2(car u,bs)
  80. )
  81. ,bs
  82. )$
  83. symbolic procedure sieve_t1(tt,bs)$
  84. % tt::=(th . pv)
  85. begin scalar bs$
  86. bs:=!*basis$
  87. while bs and null th_match(car tt,caar bs) do bs:=cdr bs$
  88. if bs then return car tt . sieve_pv(cdr tt,cdar bs)$
  89. if dl_get(cadar tt) then <<
  90. !*basis:=append(adddummy('!:tensor . list tt),!*basis)$
  91. bs:=!*basis$
  92. while bs and null th_match(car tt,caar bs) do bs:=cdr bs$
  93. if bs then return car tt . sieve_pv(cdr tt,cdar bs)$
  94. >>$
  95. return tt$
  96. end$
  97. %symbolic procedure sieve_t2(tt,bs1)$ % Jul 13, 1994
  98. % % tt::=(th . pv)
  99. % begin scalar bs$
  100. % bs:=bs1$
  101. % if dl_get(cadar tt) then bs:=append(adddummy0(list tt,bs),bs)$
  102. % while bs and null th_match(car tt,caar bs) do bs:=cdr bs$
  103. % if bs then tt := car tt . sieve_pv(cdr tt,cdar bs)$
  104. % return tt$
  105. % end$
  106. symbolic procedure sieve_t2(tt,bs1)$ % Mar. 25, 1996
  107. % tt::=(th . pv)
  108. begin scalar bs,tt1$
  109. bs:=bs1$
  110. if dl_get(cadar tt) then bs:=append(adddummy0(list tt,bs),bs)$
  111. while bs and null th_match(car tt,caar bs) do bs:=cdr bs$
  112. tt1:=tt$
  113. pv_den:=1$
  114. if bs then tt := car tt . sieve_pv0(cdr tt,cdar bs,nil)$
  115. rplacd(cdar tt,cddar tt * pv_den)$ % + AK 28/03/96
  116. if !*debug then
  117. << terpri()$
  118. write " DEBUG: sieve_t2"$
  119. terpri()$
  120. t_pri1('!:tensor.list tt1,t);
  121. if bs then
  122. for each z in cdar bs
  123. do t_pri1('!:tensor.list(caar bs.z),t);
  124. terpri()$
  125. t_pri1('!:tensor.list tt,t);
  126. terpri()$
  127. >>$
  128. return tt$
  129. end$
  130. symbolic procedure t_addf(t1,t2)$
  131. if ordp(cadr t1,cadr t2)
  132. % then ( t1 .+ (t2 .+ nil) )
  133. then ( ((t1 .** 1) .* 1) .+ ( ((t2 .** 1 ) .* 1) .+ nil) )
  134. else t_addf(t2,t1)$
  135. symbolic procedure t_add2(tx1,tx2)$
  136. begin scalar w$
  137. w:=il_update(cadar tx2,dl_get cadar tx1)$
  138. w:=pfind(w,cadar tx1)$
  139. % w:=for each x in cdr tx2 collect car x . pappl0(w,cdr x)$
  140. % - AK 02/04/96
  141. w:=for each x in cdr tx2 collect car x . pappl0(cdr x,w)$
  142. % + AK 02/04/96
  143. return car tx1 . pv_add(cdr tx1,w)$
  144. end$
  145. symbolic procedure t_match(t1,t2)$ th_match(car t1,car t2)$
  146. symbolic procedure th_match(th1,th2)$
  147. th_match0(th1,th2) and
  148. (length dl_get cadr th1 = length dl_get cadr th2)$
  149. symbolic procedure th_match0(th1,th2)$
  150. (car th1 = car th2) and (length cadr th1 = length cadr th2)$
  151. symbolic procedure th_match_(th1,th2)$
  152. if car th1 = car th2 and th_match1(cadr th1,cadr th2)
  153. then pfind(cadr th1,cadr th2)
  154. else nil$
  155. symbolic procedure th_match1(il1,il2)$
  156. if null il1 then null il2
  157. else if null(il2 = (il2:=delete(car il1,il2)))
  158. then th_match1(cdr il1,il2)
  159. else nil$
  160. symbolic procedure t_neg te$
  161. if numberp car te then list(-car te)
  162. else for each x in te collect car x . pv_neg cdr x$
  163. symbolic procedure t_mult(te1,te2)$
  164. if null te1 then te2
  165. else if numberp car te1 then c_mult(car te1,te2)
  166. else if numberp car te2 then c_mult(car te2,te1)
  167. else t_mult(cdr te1,t_mult1(car te1,te2))$
  168. symbolic procedure t_mult1(te1,te)$
  169. for each x in te collect t_mult2(te1,x)$
  170. symbolic procedure t_mult2(tt1,tt2)$
  171. begin scalar tt$
  172. if cddr tt1 or cddr tt2
  173. then rederr list('t_mult2," *** Must be tterms: ",tt1,tt2)$
  174. tt:=tt1$
  175. tt1:=t_upright(tt1,car tt2)$
  176. tt2:=t_upleft(tt2,car tt)$
  177. return (car tt1 . pv_multc(caadr tt1,cdr tt2))$
  178. end$
  179. symbolic procedure c_mult(c,te)$
  180. if null te then nil
  181. else if numberp car te then list(c*car te)
  182. else for each x in te collect car x . pv_multc(c,cdr x)$
  183. symbolic procedure t_upright(tt,th)$
  184. begin scalar th1,tt1$
  185. th1:=car tt$
  186. th1:=append(car th1,car th) . append(cadr th1,cadr th)
  187. . append(cddr th1,cddr th)$
  188. return (th1 . pv_upright(cdr tt,length cadr th))$
  189. end$
  190. symbolic procedure t_upleft(tt,th)$
  191. begin scalar th1,tt1$
  192. th1:=car tt$
  193. th1:=append(car th,car th1) . append(cadr th,cadr th1)
  194. . append(cddr th,cddr th1)$
  195. return (th1 . pv_upleft(cdr tt,length cadr th))$
  196. end$
  197. global '(!*debug_times)$
  198. switch debug_times$
  199. symbolic procedure b_expand(u,v)$
  200. (if !*debug_times then !*basis else !*basis := x
  201. ) where x = b_expand1(cadr u,cadr v,!*basis,!*basis)$
  202. symbolic procedure b_expand1(t1,t2,bs,bs1)$ % Jul 13, 1994
  203. % t1,t2 - (th . pv)
  204. % bs,bs1(r.v.) - (b1 b2 ...) where b::=(th . (pv1 pv2 ...))
  205. if null bs then reversip bs1
  206. else if th_match0(car t1,caar bs)
  207. then b_expand1(t1,t2,cdr bs,b_expand2(car bs,t2,bs1))
  208. else if th_match0(car t2,caar bs)
  209. then b_expand1(t1,t2,cdr bs,b_expand2(car bs,t1,bs1))
  210. else b_expand1(t1,t2,cdr bs,bs1)$
  211. symbolic procedure b_expand2(b,t1,bs)$
  212. % t1 - (th . pv)
  213. % b - (th . (pv1 pv2 ...))
  214. % bs(r.v.) - (b1 b2 ...)
  215. % b_expand2a(car b,cdr b,t1,nil,bs)$
  216. b_expand2b(car b,cdr b,t1,bs)$
  217. symbolic procedure b_expand2b(th,b,t1,bs)$
  218. % t1 - (th . pv)
  219. % b - (th . (pv1 pv2 ...))
  220. % bs(r.v.) - (b1 b2 ...)
  221. if null b then bs
  222. else b_expand2b(th
  223. ,cdr b
  224. ,t1
  225. ,tsym2(list t_prod(th . car b,t1),bs,nil)
  226. )$
  227. symbolic procedure b_expand2a(th,b,t1,b1,bs)$
  228. % t1 - (th . pv)
  229. % b - (th . (pv1 pv2 ...))
  230. % bs(r.v.) - (b1 b2 ...)
  231. if null b then b_join(caar b1 . b_expand3(b1,nil),bs)
  232. else b_expand2a(th,cdr b,t1,t_prod(th . car b,t1) . b1,bs)$
  233. symbolic procedure b_expand3(b,b1)$
  234. if null b then b1
  235. else b_expand3(cdr b,cdar b . b1)$
  236. symbolic procedure b_join(b,bs)$ b_join1(b,bs,nil)$
  237. symbolic procedure b_join1(b,bs,bs1)$
  238. if null bs then reversip(if b then b . bs1 else bs1)
  239. else if b and th_match(car b,caar bs)
  240. then b_join1(nil,cdr bs,(car b . b_join2(cdr b,cdar bs)) . bs1)
  241. else b_join1(b,cdr bs,car bs . bs1)$
  242. symbolic procedure b_join2(b1,b2)$
  243. if null b1 then b2
  244. else b_join2(cdr b1,insert_pv(car b1,b2))$
  245. symbolic procedure t_prod(t1,t2)$
  246. % t1,t2 - tensors::=(th . pv)
  247. % r.v. - direct product of t1 and t2
  248. if null ordp(caar t1,caar t2) then t_prod(t2,t1)
  249. else (append(caar t1,caar t2)
  250. . il_join(cadar t1,cadar t2)
  251. . append(cddar t1,cddar t2)
  252. ) . cdr pv_times('!:pv . cdr t1,'!:pv . cdr t2)$
  253. symbolic procedure il_join(l1,l2)$
  254. if null l1 then l2
  255. else if memq(car l1,l2) then wi_new(car l1) . il_join(cdr l1,l2)
  256. else car l1 . il_join(cdr l1,l2)$
  257. global '(wi_number)$
  258. wi_number:=0$
  259. symbolic procedure wi_new(x)$
  260. begin scalar z$
  261. wi_number := wi_number + 1$
  262. z := intern mkid('!:,wi_number)$ %++++++ intern ?!
  263. put(z,'windex,list x)$
  264. return z$
  265. end$
  266. endmodule;
  267. end;