pmpatch.red 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. module pmpatch; % Patches to make pattern matcher run in REDUCE 3.4.
  2. % Author: Kevin McIsaac.
  3. % Changes by Rainer M .Schoepf
  4. % remflag('(evenp),'opfn);
  5. % remprop('list,'evfn);
  6. % remprop('list,'rtypefn);
  7. % Redefine LISTEVAL so that the arguments are always returned in prefix
  8. % form.
  9. global '(simpcount!* simplimit!*);
  10. symbolic procedure listeval(u,v);
  11. <<if (simpcount!* := simpcount!*+1)>simplimit!*
  12. then <<simpcount!* := 0;
  13. rederr "Simplification recursion too deep">>;
  14. u := if atom u
  15. then listeval(if flagp(u,'share) then eval u
  16. else cadr get(u,'avalue),v)
  17. else car u . for each x in cdr u collect reval1(x,t);
  18. simpcount!* := simpcount!*-1;
  19. u>>;
  20. % Allow EXPR as a keyword in patterns.
  21. % remprop('expr,'stat);
  22. % Make REVAL of an equation return a simplified value.
  23. fluid '(substitution);
  24. symbolic procedure equalreval u;
  25. if null substitution then 'equal . car u . list reval cadr u
  26. else if evalequal(car u,cadr u) then t
  27. else 0;
  28. % Define function to prevent simplification of arguments of symbolic
  29. % operators.
  30. % If the i'th element of `list' is `nil' then the i'th argument of `fn'
  31. % is left unsimplified by simp. If `list' is longer that the argument
  32. % list of `fn' then the extra indicators are ignored. If `list' is
  33. % shorter than the argument list of `fn' then the remaining arguments
  34. % are simplified, eq nosimp(cat,'(nil T nil)) will cause the 1 and third
  35. % arguments of the functions `cat' to be left un simplified.
  36. symbolic procedure nosimp(fn,list);
  37. <<put(fn, 'nosimp, list);>>;
  38. symbolic operator nosimp;
  39. flag('(nosimp), 'noval);
  40. symbolic procedure fnreval(u,v,mode);
  41. % Simplify list u according to list v. If mode is NIL use AEVAL
  42. % else use REVAL.
  43. if null u then nil
  44. else if v eq t then u
  45. else if null v then for each j in u collect reval1(j ,mode)
  46. else ((if car v then car u
  47. else reval1(car u, mode)) . fnreval(cdr u,cdr v,mode));
  48. % Next two routines are changes to module SIMP to add NOSIMP code.
  49. symbolic procedure opfneval u;
  50. lispeval(car u . for each j in
  51. (if flagp(car u,'noval) then cdr u
  52. else fnreval(cdr u,get(car u,'nosimp),t))
  53. collect mkquote j);
  54. fluid '(ncmp!* subfg!*);
  55. symbolic procedure simpiden u;
  56. % Convert the operator expression U to a standard quotient.
  57. % Note: we must use PREPSQXX and not PREPSQ* here, since the REVOP1
  58. % in SUBS3T uses PREPSQXX, and terms must be consistent to prevent a
  59. % loop in the pattern matcher.
  60. begin scalar bool,fn,x,y,z,n;
  61. fn := car u; u := cdr u;
  62. if x := valuechk(fn,u) then return x;
  63. if not null u and eqcar(car u,'list)
  64. then return mksq(list(fn,aeval car u),1);
  65. % *** Following line added to add nosimp code.
  66. x := fnreval(u, get(fn, 'nosimp),nil);
  67. % x := for each j in cdr u collect aeval j;
  68. u := for each j in x collect
  69. if eqcar(j,'!*sq) then prepsqxx cadr j
  70. else if numberp j then j
  71. else <<bool := t; j>>;
  72. if u and car u=0
  73. and flagp(fn,'odd) and not flagp(fn,'nonzero)
  74. then return nil ./ 1;
  75. u := fn . u;
  76. if flagp(fn,'noncom) then ncmp!* := t;
  77. if null subfg!* then go to c
  78. else if flagp(fn,'linear) and (z := formlnr u) neq u
  79. then return simp z
  80. else if z := opmtch u then return simp z
  81. else if z := get(car u,'opvalfn) then return apply1(z,u);
  82. % else if null bool and (z := domainvalchk(fn,
  83. % for each j in x collect simp j))
  84. % then return z;
  85. c: if flagp(fn,'symmetric) then u := fn . ordn cdr u
  86. else if flagp(fn,'antisymmetric)
  87. then <<if repeats cdr u then return (nil ./ 1)
  88. else if not permp(z:= ordn cdr u,cdr u) then y := t;
  89. % The following patch was contributed by E. Schruefer.
  90. fn := car u . z;
  91. if z neq cdr u and (z := opmtch fn)
  92. then return if y then negsq simp z else simp z;
  93. u := fn>>;
  94. if (flagp(fn,'even) or flagp(fn,'odd))
  95. and x and minusf numr(x := simp car x)
  96. then <<if flagp(fn,'odd) then y := not y;
  97. u := fn . prepsqxx negsq x . cddr u;
  98. if z := opmtch u
  99. then return if y then negsq simp z else simp z>>;
  100. u := mksq(u,1);
  101. return if y then negsq u else u
  102. end;
  103. endmodule;
  104. end;