tensorio.red 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. %======================================================
  2. % Name: tio.red - tensor user interface
  3. % Author: A.Kryukov (kryukov@npi.msu.su)
  4. % Copyright: (C), 1993i-1995, A.Kryukov
  5. % Version: 1.35
  6. % Release: Apr., 17, 1995
  7. %------------------------------------------------------
  8. % Modified: Apr., 17, 1995 tsym2
  9. % Apr., 24, 1996 tclear0
  10. %======================================================
  11. module tensorio$
  12. %=====================================================
  13. % blist::=((th . pv_list) ...)
  14. % pv_list::= (pv1 pv2 ...)
  15. %=====================================================
  16. smacro procedure tname th$ car th$
  17. smacro procedure ilist th$ cadr th$
  18. smacro procedure dlist th$ cddr th$
  19. smacro procedure mkth(tn,il,dl)$ list tn . il . id$
  20. smacro procedure mkth0(tn,il,dl)$ tn . il . dl$
  21. smacro procedure thead ten$ car ten$
  22. smacro procedure pvect ten$ cdr ten$
  23. smacro procedure mkten0(th,pv)$ th . pv$
  24. smacro procedure mkten(th,pv)$ '!:tensor . list(th . pv)$
  25. symbolic procedure bassoc(th,bl)$
  26. if null bl then nil
  27. else if th_match(th,caar bl) then bl
  28. else bassoc(th,cdr bl)$
  29. global '(!*basis,tensors!*)$
  30. remprop('tensor,'stat)$
  31. remprop('tsym,'stat)$
  32. remprop('tclear,'stat)$
  33. symbolic procedure tensor u$
  34. for each x in u do
  35. if null(x memq tensors!*) then <<
  36. put(x,'!:tensor,99)$ % undefine rank
  37. put(x,'simpfn,'t_simp)$
  38. flag(list x,'full)$
  39. tensors!* := x . tensors!*$
  40. >>
  41. else write "+++ ",x," is already declared as tensor."$
  42. symbolic procedure tclear u$
  43. tclear0(if car u eq 'all then tensors!* else u)$
  44. symbolic procedure tclear0 u$
  45. for each x in u do
  46. if x memq tensors!* then
  47. begin scalar bs,bs1$
  48. tensors!* := delete(x,tensors!*)$
  49. remprop(x,'!:tensor)$
  50. remflag(x,'full)$
  51. bs:=!*basis$
  52. while bs do <<
  53. if null(x memq caaar bs) then bs1:=car bs . bs1$
  54. bs:=cdr bs$
  55. >>$
  56. !*basis:=reversip bs1$
  57. end
  58. else << write "+++ ",x," is not a tensor."$ terpri() >>$
  59. symbolic procedure tsym u$
  60. % u is a list of symmetry identities.
  61. % return nil.
  62. % Out side eff.: add identities to basis list in !*basis.
  63. begin scalar b$
  64. b:=!*basis$
  65. !*basis:=nil$
  66. !*basis:=tsym1(u,b)$
  67. end$
  68. symbolic procedure tsym1(u,b)$
  69. % u is a list of symmetry identities.
  70. % b is a basis list (returned value).
  71. % return new basis list.
  72. if null u then b
  73. else tsym1(cdr u,tsym2(cdr numr simp!* car u,b,nil))$
  74. symbolic procedure tsym2(tt,b,b1)$
  75. % tt is a tensor identity
  76. % b is old basis
  77. % b1 is new basis (returned value)
  78. if cdr tt then rederr list('tsym2,"*** Invalid identity:",tt)
  79. else if null b
  80. then (caar tt . tsym4(gperm length cadaar tt,car tt,nil))
  81. . reversip b1
  82. else if th_match0(caar tt,caar b)
  83. then (caar b . tsym4(gperm length cadaar tt,car tt,cdar b))
  84. . append(cdr b,b1)
  85. else tsym2(tt,cdr b,car b . b1)$
  86. symbolic procedure tsym4(ps,x,b0)$
  87. if null ps then b0
  88. else tsym4(cdr ps,x
  89. ,insert_pv(pv_renorm sieve_pv(pv_applp(cdr x,car ps),b0),b0)
  90. )$
  91. put('tensor,'stat,'rlis)$
  92. put('tsym,'stat,'rlis)$
  93. put('tclear,'stat,'rlis)$
  94. symbolic procedure kbasis x$
  95. for each z in x do basis1 z$
  96. global '(!*dummypri)$
  97. switch dummypri$
  98. symbolic procedure basis1 x$
  99. begin scalar b$
  100. if idp x then x:=list x;
  101. if atom x or null get(car x,'!:tensor)
  102. then rederr list('basis1,"*** Invalid as tensor:",x);
  103. b:=!*basis$
  104. while b do <<
  105. if tnequal(x,caaar b)
  106. then << for each z in cdar b do
  107. t_pri1('!:tensor . list(caar b . z),t)$
  108. write length cdar b$ terpri()$
  109. >>$
  110. b:=cdr b$
  111. >>$
  112. end$
  113. symbolic procedure tnequal(tn1,tn2)$
  114. if atom tn1 then tn1 eq tn2
  115. else (lambda x$ if x neq tn2 then tnequal(cdr tn1,x)
  116. else nil) delete(car tn1,tn2)$
  117. put('kbasis,'stat,'rlis)$
  118. endmodule;
  119. end;