pmrules.log 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. REDUCE 3.4, 15-Jul-91 ...
  2. 1:
  3. *** ~ already defined as operator
  4. (PMRULES)
  5. % Tests of PM.
  6. % TESTS OF BASIC CONSTRUCTS.
  7. operator f, h$
  8. % A "literal" template.
  9. m(f(a),f(a));
  10. T
  11. % Not literally equal.
  12. m(f(a),f(b));
  13. %Nested operators.
  14. m(f(a,h(b)),f(a,h(b)));
  15. T
  16. % A "generic" template.
  17. m(f(a,b),f(a,?a));
  18. {?A->B}
  19. m(f(a,b),f(?a,?b));
  20. {?A->A,?B->B}
  21. % ??a takes "rest" of arguments.
  22. m(f(a,b),f(??a));
  23. {??A->[A,B]}
  24. % But ?a does not.
  25. m(f(a,b),f(?a));
  26. % Conditional matches.
  27. m(f(a,b),f(?a,?b _=(?a=?b)));
  28. m(f(a,a),f(?a,?b _=(?a=?b)));
  29. {?A->A,?B->A}
  30. % "plus" is symmetric.
  31. m(a+b+c,c+?a+?b);
  32. {?A->A,?B->B}
  33. %It is also associative.
  34. m(a+b+c,c+?a);
  35. {?A->A + B}
  36. % Note the effect of using multi-generic symbol is different.
  37. m(a+b+c,c+??c);
  38. {??C->[A,B]}
  39. %Flag h as associative.
  40. flag('(h),'assoc);
  41. m(h(a,b,d,e),h(?a,d,?b));
  42. {?A->H(A,B),?B->E}
  43. % Substitution tests.
  44. s(f(a,b),f(a,?b)->?b^2);
  45. 2
  46. B
  47. s(a+b,a+b->a*b);
  48. A*B
  49. % "associativity" is used to group a+b+c in to (a+b) + c.
  50. s(a+b+c,a+b->a*b);
  51. A*B + C
  52. % Only substitute top at top level.
  53. s(a+b+f(a+b),a+b->a*b,inf,0);
  54. F(A + B) + A*B
  55. % SIMPLE OPERATOR DEFINITIONS.
  56. % Numerical factorial.
  57. operator nfac$
  58. s(nfac(3),{nfac(0)->1,nfac(?x)->?x*nfac(?x-1)},1);
  59. 3*NFAC(2)
  60. s(nfac(3),{nfac(0)->1,nfac(?x)->?x*nfac(?x-1)},2);
  61. 6*NFAC(1)
  62. si(nfac(3),{nfac(0)->1,nfac(?x)->?x*nfac(?x-1)});
  63. 6
  64. % General factorial.
  65. operator gamma,fac;
  66. fac(?x _=Natp(?x)) ::- ?x*fac(?x-1);
  67. HOLD(?X*FAC(?X - 1))
  68. fac(0) :- 1;
  69. 1
  70. fac(?x) :- Gamma(?x+1);
  71. GAMMA(?X + 1)
  72. fac(3);
  73. 6
  74. fac(3/2);
  75. 5
  76. GAMMA(---)
  77. 2
  78. % Legendre polynomials in ?x of order ?n, ?n a natural number.
  79. operator legp;
  80. legp(?x,0) :- 1;
  81. 1
  82. legp(?x,1) :- ?x;
  83. ?X
  84. legp(?x,?n _=natp(?n))
  85. ::- ((2*?n-1)*?x*legp(?x,?n-1)-(?n-1)*legp(?x,?n-2))/?n;
  86. (2*?N - 1)*?X*LEGP(?X,?N - 1) - (?N - 1)*LEGP(?X,?N - 2)
  87. HOLD(----------------------------------------------------------)
  88. ?N
  89. legp(z,5);
  90. 4 2
  91. Z*(63*Z - 70*Z + 15)
  92. ------------------------
  93. 8
  94. legp(a+b,3);
  95. 3 2 2 3
  96. 5*A + 15*A *B + 15*A*B - 3*A + 5*B - 3*B
  97. ---------------------------------------------
  98. 2
  99. legp(x,y);
  100. LEGP(X,Y)
  101. % TESTS OF EXTENSIONS TO BASIC PATTERN MATCHER.
  102. comment *: MSet[?exprn,?val] or ?exprn ::: ?val
  103. assigns the value ?val to the projection ?exprn in such a way
  104. as to store explicitly each form of ?exprn requested. *;
  105. Nosimp('mset,(t t));
  106. Newtok '((!: !: !: !-) Mset);
  107. infix :::-;
  108. precedence Mset,RSetd;
  109. ?exprn :::- ?val ::- (?exprn ::- (?exprn :- ?val ));
  110. HOLD(?EXPRN::-(?EXPRN:-?VAL))
  111. scs := sin(?x)^2 + Cos(?x)^2 -> 1;
  112. 2 2
  113. SCS := SIN(?X) + COS(?X) ->1
  114. % The following pattern substitutes the rule sin^2 + cos^2 into a sum of
  115. % such terms. For 2n terms (ie n sin and n cos) the pattern has a worst
  116. % case complexity of O(n^3).
  117. operator trig,u;
  118. trig(?i) :::- Ap(+, Ar(?i,sin(u(?1))^2+Cos(u(?1))^2));
  119. 2 2
  120. HOLD(TRIG(?I):-AP(PLUS,AR(?I,SIN(U(?1)) + COS(U(?1)) )))
  121. if si(trig 1,scs) = 1 then write("Pm ok") else Write("PM failed");
  122. Pm ok
  123. if si(trig 10,scs) = 10 then write("Pm ok") else Write("PM failed");
  124. Pm ok
  125. % The next one takes about 70 seconds on an HP 9000/350, calling UNIFY
  126. % 1927 times.
  127. % if si(trig 50,scs) = 50 then write("Pm ok") else Write("PM failed");
  128. % Hypergeometric Function simplification.
  129. newtok '((!#) !#);
  130. *** # redefined
  131. flag('(#), 'symmetric);
  132. operator #,@,ghg;
  133. xx := ghg(4,3,@(a,b,c,d),@(d,1+a-b,1+a-c),1);
  134. XX := GHG(4,3,@(A,B,C,D),@(D,A - B + 1,A - C + 1),1)
  135. S(xx,sghg(3));
  136. *** SGHG declared operator
  137. GHG(4,3,@(A,B,C,D),@(D,A - B + 1,A - C + 1),1)
  138. s(ws,sghg(2));
  139. GHG(4,3,@(A,B,C,D),@(D,A - B + 1,A - C + 1),1)
  140. yy := ghg(3,2,@(a-1,b,c/2),@((a+b)/2,c),1);
  141. C A + B
  142. YY := GHG(3,2,@(A - 1,B,---),@(-------,C),1)
  143. 2 2
  144. S(yy,sghg(1));
  145. C A + B
  146. GHG(3,2,@(A - 1,B,---),@(-------,C),1)
  147. 2 2
  148. yy := ghg(3,2,@(a-1,b,c/2),@(a/2+b/2,c),1);
  149. C A + B
  150. YY := GHG(3,2,@(A - 1,B,---),@(-------,C),1)
  151. 2 2
  152. S(yy,sghg(1));
  153. C A + B
  154. GHG(3,2,@(A - 1,B,---),@(-------,C),1)
  155. 2 2
  156. % Some Ghg theorems.
  157. flag('(@), 'symmetric);
  158. % Watson's Theorem.
  159. SGhg(1) := Ghg(3,2,@(?a,?b,?c),@(?d _=?d=(1+?a+?b)/2,?e _=?e=2*?c),1) ->
  160. Gamma(1/2)*Gamma(?c+1/2)*Gamma((1+?a+?b)/2)*Gamma((1-?a-?b)/2+?c)/
  161. (Gamma((1+?a)/2)*Gamma((1+?b)/2)*Gamma((1-?a)/2+?c)
  162. *Gamma((1-?b)/2+?c));
  163. SGHG(1) := GHG(3,2,@(?A,?B,?C),
  164. 1 + ?A + ?B
  165. @(?D _= ?D=-------------,?E _= ?E=2*?C),1)->(
  166. 2
  167. - ?A - ?B + 2*?C + 1 2*?C + 1
  168. GAMMA(-----------------------)*GAMMA(----------)
  169. 2 2
  170. ?A + ?B + 1 1
  171. *GAMMA(-------------)*GAMMA(---))/(
  172. 2 2
  173. - ?A + 2*?C + 1 - ?B + 2*?C + 1
  174. GAMMA(------------------)*GAMMA(------------------)
  175. 2 2
  176. ?A + 1 ?B + 1
  177. *GAMMA(--------)*GAMMA(--------))
  178. 2 2
  179. % Dixon's theorem.
  180. SGhg(2) := Ghg(3,2,@(?a,?b,?c),@(?d _=?d=1+?a-?b,?e _=?e=1+?a-?c),1) ->
  181. Gamma(1+?a/2)*Gamma(1+?a-?b)*Gamma(1+?a-?c)*Gamma(1+?a/2-?b-?c)/
  182. (Gamma(1+?a)*Gamma(1+?a/2-?b)*Gamma(1+?a/2-?c)*Gamma(1+?a-?b-?c));
  183. SGHG(2) := GHG(3,2,@(?A,?B,?C),
  184. @(?D _= ?D=1 + ?A - ?B,?E _= ?E=1 + ?A - ?C),1)->(
  185. ?A - 2*?B - 2*?C + 2 ?A + 2
  186. GAMMA(----------------------)*GAMMA(--------)
  187. 2 2
  188. *GAMMA(?A - ?B + 1)*GAMMA(?A - ?C + 1))/(
  189. ?A - 2*?B + 2 ?A - 2*?C + 2
  190. GAMMA(---------------)*GAMMA(---------------)
  191. 2 2
  192. *GAMMA(?A - ?B - ?C + 1)*GAMMA(?A + 1))
  193. SGhg(3) := Ghg(?p,?q,@(?a,??b),@(?a,??c),?z)
  194. -> Ghg(?p-1,?q-1,@(??b),@(??c),?z);
  195. SGHG(3) := GHG(?P,?Q,@(??B,?A),@(?A,??C),?Z)
  196. ->GHG(?P - 1,?Q - 1,@(??B),@(??C),?Z)
  197. SGhg(9) := Ghg(1,0,@(?a),?b,?z ) -> (1-?z)^(-?a);
  198. 1
  199. SGHG(9) := GHG(1,0,@(?A),?B,?Z)->---------------
  200. ?A
  201. ( - ?Z + 1)
  202. SGhg(10) := Ghg(0,0,?a,?b,?z) -> E^?z;
  203. ?Z
  204. SGHG(10) := GHG(0,0,?A,?B,?Z)->E
  205. SGhg(11) := Ghg(?p,?q,@(??t),@(??b),0) -> 1;
  206. SGHG(11) := GHG(?P,?Q,@(??T),@(??B),0)->1
  207. % If one of the bottom parameters is zero or a negative integer the
  208. % hypergeometric functions may be singular, so the presence of a
  209. % functions of this type causes a warning message to be printed.
  210. % Note it seems to have an off by one level spec., so this may need
  211. % changing in future.
  212. %
  213. % Reference: AS 15.1; Slater, Generalized Hypergeometric Functions,
  214. % Cambridge University Press,1966.
  215. s(Ghg(3,2,@(a,b,c),@(b,c),z),SGhg(3));
  216. GHG(2,1,@(A,B),@(B),Z)
  217. si(Ghg(3,2,@(a,b,c),@(b,c),z),{SGhg(3),Sghg(9)});
  218. 1
  219. -------------
  220. A
  221. ( - Z + 1)
  222. S(Ghg(3,2,@(a-1,b,c),@(a-b,a-c),1),sghg 2);
  223. A - 2*B - 2*C + 1 A + 1
  224. GAMMA(-------------------)*GAMMA(-------)*GAMMA(A - B)*GAMMA(A - C)
  225. 2 2
  226. ---------------------------------------------------------------------
  227. A - 2*B + 1 A - 2*C + 1
  228. GAMMA(-------------)*GAMMA(-------------)*GAMMA(A - B - C)*GAMMA(A)
  229. 2 2
  230. end;
  231. Quitting