auxitens.red 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. module auxitens;
  2. % this module introduces basic manipulation functions
  3. % for handling indices and tensor structure
  4. lisp remflag(list 'minus,'intfn);
  5. global '(dimex!* sgn!* signat!* spaces!* numindxl!* pair_id_num!*) ;
  6. lisp (pair_id_num!*:= '((!0 . 0) (!1 . 1) (!2 . 2) (!3 . 3) (!4 . 4)
  7. (!5 . 5) (!6 . 6) (!7 . 7) (!8 . 8) (!9 . 9)
  8. (!10 . 10) (!11 . 11) (!12 . 12) (!13 . 13)));
  9. fluid('(dummy_id!* g_dvnames epsilon!*));
  10. % g_dvnames is a vector.
  11. switch onespace;
  12. !*onespace:=t; % working inside a unique space is the default.
  13. symbolic procedure raiseind!: u;
  14. if atom u then u else raiseind u;
  15. symbolic procedure lowerind_lst u;
  16. % u is a list of indices.
  17. % transforms into a list of covariant indices
  18. for each j in u collect lowerind j;
  19. symbolic procedure raiseind_lst u;
  20. % u is a list of indices.
  21. % transforms into a list of contravariant indices
  22. for each j in u collect raiseind!: j;
  23. symbolic procedure flatindxl u;
  24. % This is taken from EXCALC
  25. for each j in u collect
  26. if atom j
  27. then j
  28. else if careq_minus(j)
  29. then cadr j
  30. else cdr j;
  31. symbolic procedure cov_lst_idsp u;
  32. % True if all indices in list u are covariant
  33. if null u then t
  34. else
  35. if careq_minus car u then cov_lst_idsp cdr u;
  36. symbolic procedure cont_lst_idsp u;
  37. % True if all indices in list u are contravariant
  38. if null u then t
  39. else
  40. if atom car u then cont_lst_idsp cdr u;
  41. symbolic procedure identify_pos_cov_lst(u,i);
  42. % allows to get the position of a fully covariant list
  43. % u is a list of lists
  44. % returns i which is the position of the FIRST relevant list in u.
  45. % starting value of i is zero.
  46. if null u then
  47. if i=0 then nil
  48. else i-1
  49. else
  50. if cov_lst_idsp car u then i:=i+1
  51. else
  52. identify_pos_cov_lst(cdr u,i+1);
  53. symbolic procedure identify_pos_cont_lst(u,i);
  54. % allows to get the position of a fully contravariant list
  55. % u is a list of lists
  56. % returns i which is the position of the FIRST relevant list in u.
  57. % starting value of i is zero.
  58. if null u then
  59. if i=0 then nil
  60. else i-1
  61. else
  62. if cont_lst_idsp car u then i:=i+1
  63. else
  64. identify_pos_cont_lst(cdr u,i+1);
  65. symbolic procedure splitlist!: (u,idp);
  66. % EXTRACTS THE SUBLIST OF ELEMENTS WHOSE CAR ARE EQUAL THE IDP.
  67. % TAG.
  68. % taken from my old tensor package.
  69. if null u then nil
  70. else
  71. if eqcar(car u,idp) then car u . splitlist!:(cdr u,idp)
  72. else splitlist!:(cdr u,idp);
  73. symbolic procedure list_to_ids!: l;
  74. if atom l then rederr "argument for list_to_ids must be a list"
  75. else
  76. intern compress for each i in l join explode i;
  77. symbolic procedure split!:(u,v);
  78. % split!:(list(a,b,c),list(1,1,1)); ==> {{A},{B},{C}}
  79. % No longer used below but ...
  80. if listp u and listp v then
  81. begin scalar x;
  82. return for each n in v collect
  83. for i := 1:n collect
  84. <<x := car u; u := rest u; x>>
  85. end;
  86. symbolic procedure symtree_splitlst(idtens,lsy,bool);
  87. % idtens is the tensor indices argument list and lsy
  88. % is cdr of symtree.
  89. % output is the splitted indices list which mirrors lsy
  90. % and make partial reordering whenever possible .
  91. for each i in lsy collect
  92. if bool and car i memq {'!+,'!-} then
  93. ordn for each j in cdr i collect nth(idtens,j)
  94. else for each j in cdr i collect nth(idtens,j);
  95. symbolic procedure symtree_zerop (idtens,lsym);
  96. % idtens is the list of indices of a given tensor.
  97. % lsym is the symmetry tree list as generated by the
  98. % 'symtree' operator of DUMMY.RED.
  99. % pseudo-boolean: returns the set of indices which is repeated or
  100. % nil.
  101. % It DOES detect MOST but NOT ALL possibilities leaving the rest for
  102. % canonical.
  103. if null cdr lsym then nil
  104. else
  105. if numlis cdr lsym then
  106. if car lsym eq '!- and repeats idtens then repeats idtens
  107. else nil
  108. else
  109. % here we start considering proper partial symmetries
  110. begin scalar lsy, idt,y;
  111. if car lsym eq '!- then
  112. if (y := repeats symtree_splitlst(idtens,cdr lsym,nil))
  113. then return y;
  114. idt:= symtree_splitlst(idtens,cdr lsym,t);
  115. if car lsym eq '!- then
  116. if (y:=repeats idt) then return y;
  117. lsy:=for each j in cdr lsym collect car j;
  118. return partsym_zerop(idt,lsy)
  119. end;
  120. symbolic procedure partsym_zerop(idt,lsy);
  121. % idt: splitted list of indices
  122. % lsy list of tags for partial symmetries.
  123. % they should have the same lengths
  124. if null idt then nil
  125. else
  126. (if car lsy eq '!- and y then y
  127. else partsym_zerop(cdr idt,cdr lsy))where y=repeats car idt;
  128. symbolic procedure cont_before_cov u;
  129. % is a list of indices some are covariant
  130. % others are contravariant
  131. % returns a list with contravariant indices placed
  132. % in front of the covariant indices.
  133. begin scalar x;
  134. x:=splitlist!:(u,'minus);
  135. return append(setdiff(u,x) ,x)
  136. end;
  137. endmodule;
  138. end;