partitsf.red 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. module partitsf;
  2. % Author: Eberhard Schruefer;
  3. fluid '(alglist!* !*exp);
  4. symbolic procedure partitop u;
  5. begin scalar x,alglist!*;
  6. return
  7. if atom u then if x := get(u,'avalue)
  8. then partitsq!* simp!* cadr x
  9. else if get!*fdeg u then mkupf u
  10. else if numr(x := simp!* u)
  11. then 1 .* x .+ nil
  12. else nil
  13. else if x := get(car u,'partitfn)
  14. then if flagp(car u,'full) then apply1(x,u)
  15. else apply1(x,cdr u)
  16. else if car u eq '!*sq then partitsq!* simp!* u
  17. else if car u eq 'plus then
  18. <<for each j in cdr u do
  19. x := addpf(partitop j,x); x>>
  20. else if car u eq 'minus then negpf partitop cadr u
  21. else if car u eq 'difference then
  22. addpf(partitop cadr u,
  23. negpf partitop caddr u)
  24. else if car u eq 'times then
  25. <<x := partitop cadr u;
  26. for each j in cddr u do
  27. x := multpfs(x,partitop j);
  28. x>>
  29. else if car u eq 'quotient then
  30. multpfsq(partitop cadr u,simprecip cddr u)
  31. else if car u eq 'recip then
  32. 1 .* simprecip cdr u .+ nil
  33. else if numr(x := simp!* u)
  34. then 1 .* x .+ nil
  35. else nil
  36. end;
  37. symbolic procedure mkupf u;
  38. begin scalar x;
  39. x := mksq(u,1);
  40. return if null numr x then nil
  41. else if domainp numr x then 1 .* x .+ nil
  42. else if (denr x = 1) and (lc numr x = 1)
  43. and null red numr x and null sfp mvar numr x
  44. then !*k2pf mvar numr x
  45. else partitsq!* x
  46. end;
  47. symbolic procedure partitsq(u,v);
  48. %U is a standardquotient. Result is a form in which expressions
  49. %satisfying the test v are distributed and the rest is kept
  50. %recursive. Leaves unexpanded structure if possible;
  51. (if null x then nil
  52. else if domainp x then 1 .* u .+ nil
  53. else addpsf(if sfp mvar x and apply1(v,mvar x)
  54. then multpsf(exptpsf(partitsq(mvar x ./ 1,v),
  55. ldeg x),
  56. partitsq(cancel(lc x ./ y),v))
  57. else if null sfp mvar x and apply1(v,!*k2f mvar x)
  58. then multpsf(!*p2f lpow x .* (1 ./ 1) .+ nil,
  59. partitsq(cancel(lc x ./ y),v))
  60. else multsqpsf(!*p2q lpow x,
  61. partitsq(cancel(lc x ./ y),v)),
  62. partitsq(cancel(red x ./ y),v)))
  63. where x = numr u, y = denr u;
  64. symbolic procedure exptpsf(u,n);
  65. begin scalar x;
  66. x := u;
  67. while (n := n-1) > 0 do x := multpsf(u,x);
  68. return x
  69. end;
  70. symbolic procedure exptpf(u,n);
  71. begin scalar x;
  72. x := u;
  73. while (n := n-1) > 0 do x := multpfs(u,x);
  74. return x
  75. end;
  76. symbolic procedure addpsf(u,v);
  77. if null u then v
  78. else if null v then u
  79. else if domainp ldpf u then addmpsf(u,v)
  80. else if domainp ldpf v then addmpsf(v,u)
  81. else if ldpf u = ldpf v then
  82. (lambda x,y;
  83. if null numr x then y else ldpf u .* x .+ y)
  84. (addsq(lc u,lc v),addpsf(red u,red v))
  85. else if ordpp(lpow ldpf u,lpow ldpf v) then lt u .+ addpsf(red u,v)
  86. else lt v .+ addpsf(u,red v);
  87. symbolic procedure addpf(u,v);
  88. if null u then v
  89. else if null v then u
  90. else if ldpf u = 1 then addmpf(u,v)
  91. else if ldpf v = 1 then addmpf(v,u)
  92. else if ldpf u = ldpf v then
  93. (lambda x,y;
  94. if null numr x then y else ldpf u .* x .+ y)
  95. (addsq(lc u,lc v),addpf(red u,red v))
  96. else if ordop(ldpf u,ldpf v) then lt u .+ addpf(red u,v)
  97. else lt v .+ addpf(u,red v);
  98. symbolic procedure addmpf(u,v);
  99. if null v then u
  100. else if ldpf v = 1 then 1 .* addsq(lc u,lc v) .+ nil
  101. else lt v .+ addmpf(u,red v);
  102. symbolic procedure addmpsf(u,v);
  103. if null v then u else
  104. if domainp ldpf v then 1 .* addsq(multsq(ldpf u ./ 1,lc u),
  105. multsq(ldpf v ./ 1,lc v)) .+ nil
  106. else lt v .+ addmpsf(u,red v);
  107. symbolic procedure multpsf(u,v);
  108. if null u or null v then nil
  109. else addpsf(addpsf(multtpsf(lt u,lt v),multpsf(red u,v)),
  110. multpsf(!*t2f lt u,red v));
  111. symbolic procedure multpfs(u,v);
  112. if null u or null v then nil
  113. else if ldpf u = 1 then multsqpf(lc u,v)
  114. else if ldpf v = 1 then multpfsq(u,lc v)
  115. else addpf(addpf(multttpf(lt u,lt v),multpfs(red u,v)),
  116. multpfs(lt u .+ nil,red v));
  117. symbolic procedure multttpf(u,v);
  118. if car u = 1 then car v .* multsq(tc u,tc v) .+ nil
  119. else if car v = 1 then car u .* multsq(tc u,tc v) .+ nil
  120. else rerror(excalc,10,"Illegal factor in pf");
  121. symbolic procedure multpfsq(u,v);
  122. if null u or null numr v then nil
  123. else ldpf u .* multsq(lc u,v) .+ multpfsq(red u,v);
  124. symbolic procedure multsqpf(u,v);
  125. if null v or null numr u then nil
  126. else ldpf v .* multsq(u,lc v) .+ multsqpf(u,red v);
  127. symbolic procedure multtpsf(u,v);
  128. begin scalar x,xexp;
  129. xexp := !*exp;
  130. !*exp := t;
  131. x := if car u = 1 then car v
  132. else if car v = 1 then car u
  133. else multf(tpsf u,tpsf v);
  134. !*exp := xexp;
  135. return multsqpsf(multsq(tc u,tc v),x .* (1 ./ 1) .+ nil)
  136. end;
  137. symbolic procedure multsqpsf(u,v);
  138. if null numr u or null v then nil
  139. else ldpf v .* multsq(u,lc v) .+ multsqpsf(u,red v);
  140. symbolic procedure repartit u;
  141. if null u then nil
  142. else addpf(multpfsq(partitop ldpf u,lc u),repartit red u);
  143. symbolic procedure partitsq!* u;
  144. %U is a standardquotient. Partitfunction for *sq's.
  145. %Leaves unexpanded structure if possible;
  146. (if null x then nil
  147. else if domainp x then 1 .* u .+ nil
  148. else addpf(if sfp mvar x and sfexform1p lt mvar x
  149. then multpfsq(exptpf(partitsq!*(mvar x ./ 1),
  150. ldeg x),
  151. cancel(lc x ./ y))
  152. else if null sfp mvar x and deg!*form mvar x
  153. then mvar x .* cancel(lc x ./ y) .+ nil
  154. else multsqpf(!*p2q lpow x,partitsq!*(lc x ./ y)),
  155. partitsq!*(red x ./ y)))
  156. where x = numr u, y = denr u;
  157. symbolic procedure sfexform1p u;
  158. (if sfp tvar u then sfexform1p lt tvar u
  159. else deg!*form tvar u)
  160. or (null domainp tc u and sfexform1p lt tc u);
  161. symbolic procedure !*pf2sq u;
  162. begin scalar res;
  163. res := nil ./ 1;
  164. if null u then return res;
  165. for each j on u do
  166. res := addsq(multsq(if ldpf j = 1 then 1 ./ 1
  167. else !*k2q ldpf j,lc j),res);
  168. return res
  169. end;
  170. symbolic procedure mk!*sqpf u;
  171. if null u then nil
  172. else ldpf u .* mk!*sq lc u .+ mk!*sqpf red u;
  173. symbolic procedure !*pfsq2pf u;
  174. if null u then nil
  175. else (lambda x;
  176. if numr x
  177. then ldpf u .* x .+ !*pfsq2pf red u
  178. else !*pfsq2pf red u)
  179. simp!* lc u;
  180. endmodule;
  181. end;