opertens.red 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. module opertens;
  2. % This module generalizes CANONICAL to make it active
  3. % on expressions which are arguments of OPERATORS. The typical
  4. % case, presently implemented, is when the expression is under
  5. % the derivative df.
  6. % A general operator, to be treated as df must be endowed
  7. % with a specific property which makes it "transparent" to canonical
  8. % so that CANONICAL can see the argument(s) it contains, recognize the
  9. % (eventually explicitly declared) dummy indices these depend on
  10. % and, finally, find their normal form.
  11. switch onespace;
  12. !*onespace:=t; % working inside a unique space is the default.
  13. fluid '(opertensnewids!*);
  14. symbolic procedure restorealldfs u;
  15. begin scalar y,z,w;
  16. z:=fullcopy u;
  17. w:=z;
  18. l: if domainp z then return w
  19. else if (not atom mvar z) and (y:=get(car mvar z, 'Translate2))
  20. then mvar z:=apply1(car y,mvar z);
  21. z:= lc z;
  22. go to l;
  23. end;
  24. %symbolic procedure restorealldfs u;
  25. %begin scalar y,z;
  26. % z:=u;
  27. % l: if domainp z then return u
  28. % else if (not atom mvar z) and (y:=get(car mvar z, 'Translate2))
  29. % then mvar z:=apply1(car y,mvar z);
  30. % z:= lc z;
  31. % go to l;
  32. %end;
  33. symbolic procedure clearallnewids;
  34. % the ephemerous operators created by 'dftypetooper' must
  35. % be eliminated after the normal form is found.
  36. % This is done here.
  37. <<for each x in opertensnewids!* do
  38. <<if flagp(x,'tensor) then
  39. rem_tensor1 x
  40. else clear x;
  41. remprop(x,'Translate2)>>;
  42. opertensnewids!*:=nil>>;
  43. symbolic procedure dftypetooper(u);
  44. % (df (g a) (n b) 2) as arg and gives back (df_g_n_2 a b)
  45. % df_g_n_2 gets property (dfprop df (g 1) (n 1) 2)
  46. % same occurs for dfpart if it is given the prop ('Transtocanonical 'dftypetooper)
  47. % Declares the results as being a tensor if one of the args at least is tensor
  48. begin scalar name,proplist,arglist,varlist,switchid,IsTens,spacel,z;
  49. name:=list(car u);
  50. proplist:= name;
  51. for each y in cdr u do
  52. << if listp y then
  53. << name:=car y . ('!_ . name);
  54. if flagp(car y,'tensor) then
  55. << IsTens:=t;
  56. if null !*onespace and null((z:=get(car y,'belong_to_space)) memq spacel)
  57. then spacel:=z . spacel;
  58. if (listp cadr y) and ((caadr y) eq 'list ) then
  59. << proplist:= list(car y, length cdr y - 1, length cadr y - 1) . proplist;
  60. varlist:=append(varlist, cdadr y);
  61. for each z in cddr y do
  62. arglist:=<<if switchid then id_switch_variance z
  63. else z>> . arglist ;>>
  64. else
  65. << proplist:= list(car y, length cdr y) . proplist ;
  66. for each z in cdr y do
  67. arglist:= <<if switchid then id_switch_variance z
  68. else z>> . arglist ;>>; >>
  69. else
  70. << proplist:= list(car y,length cdr y) . proplist;
  71. varlist:=append(varlist,cdr y); >>;
  72. >>
  73. else
  74. << name:= y . ('!_ . name);
  75. proplist:= y . proplist ; >>;
  76. switchid:=t;
  77. >>;
  78. arglist:=reverse(arglist);
  79. proplist:=reverse(proplist);
  80. name:=list_to_ids!:(reverse name);
  81. if IsTens then
  82. << if flagp(name,'tensor)
  83. then
  84. << if get(name,'translate2) and ((cdr get(name,'translate2)) neq proplist) then
  85. rerror(cantens,13,"problem in number of arg") >>
  86. else
  87. <<make_tensor(name,t);
  88. intern name;
  89. if (null !*onespace) and (length(spacel)=1)
  90. then put(name,'belong_to_space,car spacel);
  91. opertensnewids!*:= name . opertensnewids!* ;
  92. put(name,'translate2,'opertodftype . proplist)>>;
  93. if varlist then arglist := ('list . varlist) . arglist >>
  94. else
  95. << if (get(name,'translate2)) and ( cdr get(name,'translate2) neq proplist) then
  96. rerror(cantens,13,"problem in number of arg")
  97. else
  98. <<if null (gettype name = 'operator)
  99. then << mkop name;
  100. opertensnewids!*:= name . opertensnewids!* ;
  101. intern name>>;
  102. put(name,'Translate2,'opertodftype . proplist);
  103. arglist:=varlist>> >>;
  104. return name . arglist;
  105. end;
  106. symbolic procedure opertodftype(u);
  107. % u is an operator (df_g_n_2 a b) where df_g_n_2 has property
  108. % (dfprop (g 1) (n 1) 2)
  109. % gives back the df : (df (g a) (n b) 2)
  110. begin scalar proplist,idslist,varlist,argres,name,i,switchid,y,idsl,varl;
  111. proplist:=cdr get(car u,'translate2);
  112. name:=car proplist;
  113. proplist:=cdr proplist;
  114. idslist:=cdr u;
  115. % get variables if there are some
  116. if ((listp car idslist) and (caar idslist eq 'list)) then
  117. <<varlist:=cdar idslist; idslist:=cdr idslist>>;
  118. if flagp(car u,'tensor) then
  119. for each y in proplist do
  120. <<if listp y then
  121. if flagp(car y,'tensor) then
  122. << idsl:=nil;
  123. for i:=1:cadr y do
  124. << idsl:=(if switchid then id_switch_variance car idslist
  125. else car idslist) . idsl;
  126. idslist:=cdr idslist; >>;
  127. idsl:=reverse idsl;
  128. if cddr y then
  129. << varl:=nil;
  130. for i:=1:caddr y do
  131. << varl:= car varlist . varl;
  132. varlist:=cdr varlist >>;
  133. varl:=reverse varl;
  134. argres:=((car y . ( ('list . varl) . idsl)) . argres) >>
  135. else argres:=((car y . idsl) . argres); >>
  136. else
  137. << varl:=nil;
  138. for i:=1:cadr y do
  139. << varl:=(car varlist) . varl;
  140. varlist:=cdr varlist >>;
  141. varl:=reverse varl;
  142. argres:=(((car y) . varl) . argres)>>
  143. else argres:=y . argres;
  144. switchid:=t; >>
  145. else
  146. << for each y in proplist do
  147. if listp y then
  148. << varl:=nil;
  149. for i:=1:cadr y do
  150. << varl:=((car idslist) . varl);
  151. idslist:=cdr idslist >>;
  152. varl:=reverse varl;
  153. argres:=(((car y) . varl) . argres)>>
  154. else argres:= y. argres; >>;
  155. return name . (reverse argres)
  156. end;
  157. symbolic procedure makedfperm;
  158. put('df,'Translate1,'dftypetooper);
  159. flag ('(makedfperm), 'opfn);
  160. deflist('((makedfperm endstat)),'stat);
  161. makedfperm;
  162. endmodule;
  163. end;