makevars.red 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. module makevars; % Make dummy variables for integration process.
  2. % Authors: Mary Ann Moore and Arthur C. Norman.
  3. fluid '(!*gensymlist!* !*purerisch);
  4. % exports getvariables,varsinlist,varsinsf,findzvars, % varsinsq
  5. % createindices,mergein;
  6. % imports dependsp,union;
  7. % Note that 'i' is already maybe committed for sqrt(-1),
  8. % also 'l' and 'o' are not used as they print badly on certain
  9. % terminals etc and may lead to confusion.
  10. !*gensymlist!* := '(! j ! k ! m ! n ! p ! q ! r ! s ! t ! u ! v ! w ! x
  11. ! y ! z);
  12. %mapc(!*gensymlist!*,function remob); %REMOB protection;
  13. symbolic procedure varsinlist(l,vl);
  14. % L is a list of s.q. - find all variables mentioned,
  15. % given thal vl is a list already known about.
  16. begin while not null l do <<
  17. vl:=varsinsf(numr car l,varsinsf(denr car l,vl));
  18. l:=cdr l >>;
  19. return vl
  20. end;
  21. symbolic procedure getvariables sq;
  22. varsinsf(numr sq,varsinsf(denr sq,nil));
  23. symbolic procedure varsinsf(form,l);
  24. if domainp form then l
  25. else begin
  26. while not domainp form do <<
  27. l:=varsinsf(lc form,union(l,list mvar form));
  28. form:=red form >>;
  29. return l
  30. end;
  31. symbolic procedure findzvars(vl,zl,var,flg);
  32. begin scalar v;
  33. % VL is the crude list of variables found in the original integrand.
  34. % ZL must have merged into it all EXP, LOG etc terms from this.
  35. % If FLG is true then ignore DF as a function.
  36. scan: if null vl then return zl;
  37. v:=car vl; % next variable.
  38. vl:=cdr vl;
  39. % At present items get put onto ZL if they are non-atomic
  40. % and they depend on the main variable. The arguments of
  41. % functions are decomposed by recursive calls to findzvar.
  42. % Give up if V has been declared dependent on other things.
  43. if atom v and v neq var and depends(v,var) then
  44. % rerror(int,7,
  45. % "Can't integrate in the presence of side-relations")
  46. zl := union(list v, zl)
  47. else if not atom v and not(v member zl) and dependsp(v,var)
  48. then if car v='!*sq then zl:=findzvarssq(cadr v,zl,var)
  49. else if car v memq '(times quotient plus minus difference)
  50. or (((car v) eq 'expt) and fixp caddr v)
  51. then
  52. zl:=findzvars(cdr v,zl,var,flg)
  53. else if flg and car v eq 'df
  54. then <<!*purerisch := t; % printc "Pure set";
  55. return zl>> % try and stop it
  56. else zl:=v . findzvars(cdr v,zl,var,flg);
  57. % scan arguments of fn.
  58. %ACH: old code used to look only at CADR if a DF involved.
  59. go to scan
  60. end;
  61. symbolic procedure findzvarssq(sq,zl,var);
  62. findzvarsf(numr sq,findzvarsf(denr sq,zl,var),var);
  63. symbolic procedure findzvarsf(sf,zl,var);
  64. if domainp sf then zl
  65. else findzvarsf(lc sf,
  66. findzvarsf(red sf,
  67. findzvars(list mvar sf,zl,var,nil),
  68. var),
  69. var);
  70. symbolic procedure createindices zl;
  71. % Produces a list of unique indices, each associated with a ;
  72. % different Z-variable;
  73. reversip crindex1(zl,!*gensymlist!*);
  74. symbolic procedure crindex1(zl,gl);
  75. begin if null zl then return nil;
  76. if null gl then << gl:=list int!-gensym1 'i; %new symbol needed;
  77. nconc(!*gensymlist!*,gl) >>;
  78. return (car gl) . crindex1(cdr zl,cdr gl) end;
  79. symbolic procedure cdrmember(a,b);
  80. if null b then nil
  81. else if a=cdar b then car b
  82. else cdrmember(a,cdr b);
  83. symbolic procedure mergein(dl,ll);
  84. % Adjoin logs of things in dl to existing list ll.
  85. if null dl then ll
  86. else if cdrmember(car dl,ll) then mergein(cdr dl,ll)
  87. else mergein(cdr dl,('log . car dl) . ll);
  88. endmodule;
  89. end;