showrule.red 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. module showrule; % Display rules for an operator.
  2. % Author: Herbert Melenk, ZIB, Berlin. E-mail: melenk@zib.de.
  3. % Copyright (c) 1992 ZIB Berlin. All rights reserved.
  4. % Modified by: Francis J. Wright <F.J.Wright@Maths.QMW.ac.uk>
  5. % Time-stamp: <10 November 1998>
  6. % $Id: showrule.red 1.2 1998-11-10 08:33:09+00 fjw Exp $
  7. global '(!*match);
  8. fluid '(asymplis!* powlis!*);
  9. % All let-rules for an operator are collected as rule set.
  10. % Usage in algebraic mode:
  11. % e.g. SHOWRULES SIN;
  12. % The rules for exponentiation can be listed by
  13. % SHOWRULES EXPT;
  14. symbolic procedure showrules opr;
  15. begin scalar r;
  16. r := showruleskvalue opr;
  17. r:=append(r,showrulesopmtch opr);
  18. r:=append(r,showrules!*match opr);
  19. r:=append(r,showrulesdfn opr);
  20. if opr eq 'expt then
  21. <<r:=append(r,showrulespowlis!*());
  22. r:=append(r,showrulespowlis1!*());
  23. r:=append(r,showrulesasymplis!*())>>
  24. else
  25. %% FJW: Show rules for powers of opr:
  26. <<r:=append(r,showrulespowlis!*opr opr);
  27. r:=append(r,showrulespowlis1!*opr opr);
  28. r:=append(r,showrulesasymplis!*opr opr)>>;
  29. return 'list.r;
  30. end;
  31. symbolic procedure showruleskvalue opr;
  32. for each rule in get(opr,'kvalue) collect
  33. begin scalar pattern, vars, target;
  34. pattern := car rule;
  35. vars := selectletvars pattern;
  36. vars := arbvars vars;
  37. pattern := subla(vars,pattern);
  38. target := cadr rule;
  39. target := subla(vars,target);
  40. return mkrule(nil,pattern,target)
  41. end;
  42. symbolic procedure showonerule(test,pattern,target);
  43. % central routine produces one rule.
  44. begin scalar vars;
  45. vars := selectletvars pattern;
  46. vars := arbvars vars;
  47. pattern := subla(vars,pattern);
  48. test := subla(vars,test);
  49. target := subla(vars,target);
  50. test := simpletsymbolic test;
  51. if test=t then test:=nil;
  52. %% target := simpletsymbolic target;
  53. %% FJW: mangles lists in target, e.g. for hypergeometric, but
  54. %% not applying simpletsymbolic might not be the right fix!
  55. return mkrule(test,pattern,target)
  56. end;
  57. symbolic procedure showrulesopmtch opr;
  58. for each rule in get(opr,'opmtch) collect
  59. showonerule(cdadr rule,opr . car rule,caddr rule);
  60. symbolic procedure showrulesdfn opr;
  61. append(showrulesdfn1 opr, showrulesdfn2 opr);
  62. symbolic procedure showrulesdfn1 opr;
  63. for i:=1:5 join showrulesdfn1!*(opr,i);
  64. symbolic procedure showrulesdfn1!*(opr,n);
  65. % simple derivatives
  66. begin scalar dfn,pl,rule,pattern,target;
  67. dfn:=dfn_prop(for j:=0:n collect j);
  68. if(pl:=get(opr,dfn)) then return
  69. for j:=1:n join
  70. if (rule:=nth(pl,j)) then
  71. << pattern := car rule;
  72. pattern := {'df,opr . pattern,nth(pattern,j)};
  73. target := cdr rule;
  74. {showonerule(nil,pattern,target)}
  75. >>;
  76. end;
  77. symbolic procedure mkrule(c,a,b);
  78. <<b:=strip!~ b; c:=strip!~ c;
  79. {'replaceby,separate!~ a,if c then {'when,b,c} else b}>>;
  80. symbolic procedure strip!~ u;
  81. if null u then u else
  82. if idp u then
  83. (if eqcar(w,'!~) then intern compress cdr w else u)
  84. where w=explode2 u
  85. else if atom u then u
  86. else if car u = '!~ then strip!~ cadr u
  87. else strip!~ car u . strip!~ cdr u;
  88. symbolic procedure separate!~ u;
  89. if null u or u='!~ then u else
  90. if idp u then
  91. (if eqcar(w,'!~) then {'!~,intern compress cdr w} else u)
  92. where w=explode2 u
  93. else if atom u then u
  94. else separate!~ car u . separate!~ cdr u;
  95. symbolic procedure showrulesdfn2 opr;
  96. % collect possible rules from df
  97. for each rule in get('df,'opmtch) join
  98. if eqcar(caar rule,opr) then
  99. {showonerule(cdadr rule,'df . car rule,caddr rule)};
  100. symbolic procedure showrules!*match opr;
  101. for each rule in !*match join if smember(opr,rule) then
  102. begin scalar pattern,target,test,p1,p2;
  103. pattern := car rule;
  104. p1 := car pattern;
  105. p2 := cadr pattern;
  106. pattern := list('times,prepsq !*p2q p1,
  107. prepsq !*p2q p2);
  108. test := cdadr rule;
  109. target := caddr rule;
  110. return {showonerule(test,pattern,target)}
  111. end;
  112. symbolic procedure showrulespowlis!*();
  113. for each rule in powlis!* collect
  114. begin scalar pattern,target;
  115. pattern := list ('expt,car rule,cadr rule);
  116. target := cadddr rule;
  117. return mkrule(nil,pattern,target);
  118. end;
  119. symbolic procedure showrulespowlis1!*();
  120. for each rule in powlis1!* collect
  121. begin scalar pattern,target,test,p1,p2;
  122. pattern := car rule;
  123. p1 := car pattern;
  124. p2 := cdr pattern;
  125. pattern := list ('expt, p1, p2);
  126. test := cdadr rule;
  127. target := caddr rule;
  128. return showonerule(test,pattern,target);
  129. end;
  130. symbolic procedure showrulesasymplis!*();
  131. for each rule in asymplis!* collect
  132. mkrule(nil,{'expt,car rule,cdr rule},0);
  133. symbolic procedure showrulespowlis!*opr opr;
  134. %% FJW: Pick rules in powlis!* for operator opr:
  135. for each rule in powlis!* join
  136. if eqcar(car rule, opr) then
  137. begin scalar pattern,target;
  138. pattern := list ('expt,car rule,cadr rule);
  139. target := cadddr rule;
  140. return mkrule(nil,pattern,target) . nil
  141. end;
  142. symbolic procedure showrulespowlis1!*opr opr;
  143. %% FJW: Pick rules in powlis1!* for operator opr:
  144. for each rule in powlis1!* join
  145. if eqcar(caar rule, opr) then
  146. begin scalar pattern,target,test,p1,p2;
  147. pattern := car rule;
  148. p1 := car pattern;
  149. p2 := cdr pattern;
  150. pattern := list ('expt, p1, p2);
  151. test := cdadr rule;
  152. target := caddr rule;
  153. return showonerule(test,pattern,target) . nil
  154. end;
  155. symbolic procedure showrulesasymplis!*opr opr;
  156. %% FJW: Pick rules in asymplis!* for operator opr:
  157. for each rule in asymplis!* join
  158. if eqcar(car rule, opr) then
  159. mkrule(nil,{'expt,car rule,cdr rule},0) . nil;
  160. symbolic procedure selectletvars u;
  161. if null u then nil else
  162. if memq(u,frlis!*) then {u} else
  163. if atom u then nil else
  164. union (selectletvars car u, selectletvars cdr u);
  165. symbolic procedure simpletsymbolic u;
  166. if atom u then u else
  167. if car u eq 'quote then simpletsymbolic cadr u else
  168. if car u memq '(aeval reval revalx boolvalue!*) then
  169. if needs!-lisp!-tag cadr u
  170. then {'symbolic,simpletsymbolic cadr u}
  171. else simpletsymbolic cadr u
  172. else
  173. if car u eq 'list then simpletsymbolic cdr u else
  174. if isboolfn car u then simpletsymbolic (isboolfn car u . cdr u)
  175. else simpletsymbolic car u . simpletsymbolic cdr u;
  176. symbolic procedure needs!-lisp!-tag u;
  177. if numberp u then nil else
  178. if atom u then t else
  179. if car u memq '(aeval reval revalx boolvalue!* quote) then nil else
  180. if car u eq 'list then needs!-lisp!-tag1 cdr u
  181. else if car u eq 'cons then
  182. needs!-lisp!-tag cadr u or needs!-lisp!-tag caddr u
  183. else t;
  184. symbolic procedure needs!-lisp!-tag1 u;
  185. if null u then nil else
  186. needs!-lisp!-tag car u or needs!-lisp!-tag1 cdr u;
  187. fluid '(bool!-functions!*);
  188. bool!-functions!* :=
  189. for each x in {'equal,'greaterp,'lessp,'geq,'leq,'neq,'numberp}
  190. collect get(x,'boolfn).x;
  191. symbolic procedure isboolfn u;
  192. if idp u and (u:=assoc(u,bool!-functions!*)) then cdr u;
  193. symbolic procedure arbvars vars;
  194. for each var in vars collect
  195. var . {'!~, intern compress cddr explode var};
  196. symbolic operator showrules;
  197. endmodule;
  198. end;