defint0.red 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. module defint0; % Rules for definite integration.
  2. global '(unknown_tst product_tst transform_tst transform_lst);
  3. transform_lst := '();
  4. fluid '(!*precise);
  5. global '(spec_cond);
  6. symbolic smacro procedure mynumberp(n);
  7. begin; if numberp n then t
  8. else if listp n and car n = 'quotient and (numberp cadr n or
  9. mynumberp cadr n) and (numberp caddr n or mynumberp caddr n) then 't
  10. else if listp n and car n = 'sqrt and (numberp cadr n or cadr n = 'pi)
  11. then t else nil;
  12. end;
  13. symbolic operator mynumberp;
  14. put('intgggg,'simpfn,'simpintgggg);
  15. % put('defint,'psopfn,'new_defint);
  16. symbolic procedure new_defint(lst);
  17. begin scalar var,result,n1,n2,n3,n4,!*precise;
  18. if eqcar(car lst,'times)
  19. then return new_defint append(cdar lst,cdr lst);
  20. unknown_tst := nil;
  21. var := nth(lst,length lst);
  22. if length lst = 2 and listp car lst then
  23. lst := test_prod(lst,var);
  24. transform_tst := reval algebraic(transform_tst);
  25. if transform_tst neq t then lst := hyperbolic_test(lst);
  26. for each i in lst do specfn_test(i);
  27. if length lst = 5 then
  28. <<n1 := car lst;
  29. n2 := cadr lst;
  30. n3 := caddr lst;
  31. n4 := cadddr lst;
  32. result := reval algebraic defint2(n1,n2,n3,n4,var)>>
  33. else if length lst = 4 then
  34. <<n1 := car lst;
  35. n2 := cadr lst;
  36. n3 := caddr lst;
  37. result := reval algebraic defint2(n1,n2,n3,var)>>
  38. else if length lst = 3 then
  39. <<n1 := car lst;
  40. n2 := cadr lst;
  41. result := reval algebraic defint2(n1,n2,var)>>
  42. else if length lst = 2 then
  43. <<n1 := car lst;
  44. result := reval algebraic defint2(n1,var)>>;
  45. algebraic(transform_tst := nil);
  46. if pairp result then <<for each i in result do test_unknown(i);
  47. % Tidy up result by ensuring that just unknown is returned
  48. % and not multiples of it.
  49. if unknown_tst then return 'UNKNOWN else return result>>
  50. else return result
  51. end;
  52. symbolic procedure specfn_test(n);
  53. begin;
  54. if listp n and car n = 'times then
  55. << if listp caddr n and (car caddr n = 'm_gegenbauerp or
  56. car caddr n = 'm_jacobip)
  57. then off exp; >>;
  58. end;
  59. symbolic procedure test_prod(lst,var);
  60. begin scalar temp,ls;
  61. temp := caar lst;
  62. if temp = 'times then
  63. << if listp caddar lst then
  64. % test for special cases of Meijer G-functions of compoud functions
  65. << if car caddar lst neq 'm_chebyshevt and
  66. car caddar lst neq 'm_chebyshevu and
  67. car caddar lst neq 'm_gegenbauerp and
  68. car caddar lst neq 'm_jacobip then
  69. ls := append(cdar lst,{var})
  70. %else returned without change
  71. else ls := lst;>>
  72. else ls := append(cdar lst,{var});
  73. >>
  74. else if temp = 'minus and caadar lst = 'times then
  75. << if length cadar lst = 3 then
  76. ls := {{'minus,car cdadar lst},cadr cdadar lst,var}
  77. else if length cadar lst = 4 then
  78. ls := {{'minus,car cdadar lst},cadr cdadar lst,
  79. caddr cdadar lst,var}>>
  80. else ls := lst;
  81. return ls;
  82. end;
  83. symbolic procedure test_unknown(n);
  84. % A procedure to test for unknown as the result of the integration
  85. % process
  86. if pairp n then << for each i in n do test_unknown(i)>>
  87. else if n = 'unknown then unknown_tst := 't;
  88. algebraic<<
  89. heaviside_rules :=
  90. { heaviside(~x) => 1 when numberp x and x >= 0,
  91. heaviside(~x) => 0 when numberp x and x < 0 };
  92. let heaviside_rules;
  93. operator defint2,defint_choose;
  94. SHARE MELLINCOEF$
  95. defint2_rules:=
  96. { defint2(~n,cos((~x*~~A)/~~C)-cos((~x*~~B)/~~D),~x) =>
  97. defint2(-2,n,sin((A/C+B/D)*x/2),sin((A/C-B/D)*x/2),x),
  98. defint2(cos((~x*~~A)/~~C)-cos((~x*~~B)/~~D),~x) =>
  99. defint2(-2,sin((A/C+B/D)*x/2),sin((A/C-B/D)*x/2),x),
  100. defint2(~b,~f1,~f2,~x) => b*defint2(f1,f2,x) when freeof (b,x),
  101. defint2(~~b*~f1,~~c*~f2,~x) => b*c*defint2(f1,f2,x)
  102. when freeof (b,x) and freeof (c,x) and not(b = 1 and c = 1),
  103. defint2(~b/~f1,~c/~f2,~x) => c*b*defint2(1/f1,1/f2,x)
  104. when freeof (b,x) and freeof (c,x) and not(b = 1 and c = 1),
  105. defint2(~~b*~f1,~c/~f2,~x) => c*b*defint2(f1,1/f2,x)
  106. when freeof (b,x) and freeof (c,x) and not(b = 1 and c = 1),
  107. defint2(~b/~f1,~~c*~f2,~x) => c*b*defint2(1/f1,f2,x)
  108. when freeof (b,x) and freeof (c,x) and not(b = 1 and c = 1),
  109. defint2(~f1/~~b,~~c*~f2,~x) => c/b*defint2(f1,f2,x)
  110. when freeof (b,x) and freeof (c,x) and not(b = 1 and c = 1),
  111. defint2(~b/~f1,~x) => b*defint2(1/f1,x)
  112. when freeof (b,x) and not(b = 1),
  113. defint2(~~b*~f1,~x) => b*defint2(f1,x)
  114. when freeof (b,x) and not(b = 1),
  115. defint2(~f1/~~b,~x) => 1/b*defint2(f1,x)
  116. when freeof (b,x) and not(b = 1),
  117. defint2((~f2+ ~~f1)/~~f3,~x) => defint2(f2/f3,x) + defint2(f1/f3,x)
  118. when not(f1=0),
  119. defint2(-~f1,~x) => - defint2(f1,x),
  120. defint2((~f2+ ~~f1)/~~f3,~n,~x) =>
  121. defint2(f2/f3,n,x) + defint2(f1/f3,n,x)
  122. when not(f1=0),
  123. defint2(-~f1,~n,~x) => - defint2(f1,n,x),
  124. defint2(~n,(~f2+ ~~f1)/~~f3,~x) =>
  125. defint2(n,f2/f3,x) + defint2(n,f1/f3,x)
  126. when not(f1=0),
  127. defint2(~n,-~f1,~x) => - defint2(n,f1,x),
  128. defint2(~n,(~f2+ ~~f1)/~~f3,~nn,~x) =>
  129. defint2(n,f2/f3,nn,x) + defint2(n,f1/f3,nn,x)
  130. when not(f1=0),
  131. defint2(~n,-~f1,~nn,~x) => - defint2(n,f1,nn,x),
  132. defint2(~n,~nn,(~f2+ ~~f1)/~~f3,~x) =>
  133. defint2(n,nn,f2/f3,x) + defint2(n,nn,f1/f3,x)
  134. when not(f1=0),
  135. defint2(~n,~nn,-~f1,~x) => - defint2(n,nn,f1,x),
  136. defint2(~n,~x^~a,~f1,~f2,~x) =>
  137. n*intgggg(defint_choose(f1,x),defint_choose(f2,x),a,x)
  138. when numberp n ,
  139. defint2(~n,~x,~f1,~f2,~x) =>
  140. n*intgggg(defint_choose(f1,x),defint_choose(f2,x),1,x)
  141. when numberp n ,
  142. defint2(~n,1/~x^~~a,~f1,~f2,~x) =>
  143. n*intgggg(defint_choose(f1,x),defint_choose(f2,x),-a,x)
  144. when numberp n ,
  145. defint2(~n,1/~x,~f1,~f2,~x) =>
  146. n*intgggg(defint_choose(f1,x),defint_choose(f2,x),-1,x)
  147. when numberp n ,
  148. defint2(~n,sqrt(~x),~f1,~f2,~x) =>
  149. n*intgggg(defint_choose(f1,x),defint_choose(f2,x),1/2,x)
  150. when numberp n ,
  151. defint2(~n,sqrt(~x)*~x,~f1,~f2,~x) =>
  152. n*intgggg(defint_choose(f1,x),defint_choose(f2,x),3/2,x)
  153. when numberp n ,
  154. defint2(~n,sqrt(~x)*~x^~a,~f1,~f2,~x) =>
  155. n*intgggg(defint_choose(f1,x),defint_choose(f2,x),1/2+a,x)
  156. when numberp n ,
  157. defint2(~n,1/sqrt(~x),~f1,~f2,~x) =>
  158. n*intgggg(defint_choose(f1,x),defint_choose(f2,x),-1/2,x)
  159. when numberp n ,
  160. defint2(~n,1/(sqrt(~x)*~x),~f1,~f2,~x) =>
  161. n*intgggg(defint_choose(f1,x),defint_choose(f2,x),-3/2,x)
  162. when numberp n ,
  163. defint2(~n,1/(sqrt(~x)*~x^~a),~f1,~f2,~x) =>
  164. n*intgggg(defint_choose(f1,x),defint_choose(f2,x),-1/2-a,x)
  165. when numberp n ,
  166. defint2(~n,1/~x,~f1,~x) => n*intgggg(defint_choose(f1,x),0,-1,x)
  167. when numberp n ,
  168. defint2(~n,1/~x^(~a),~f1,~x) => n*intgggg(defint_choose(f1,x),0,-a,x)
  169. when numberp n ,
  170. defint2(~n,1/sqrt(~x),~f1,~x) =>
  171. n*intgggg(defint_choose(f1,x),0,-1/2,x) when numberp n,
  172. defint2(~n,1/(sqrt(~x)*~x),~f1,~x) =>
  173. n*intgggg(defint_choose(f1,x),0,-3/2,x)
  174. when numberp n ,
  175. defint2(~n,1/(sqrt(~x)*~x^~a),~f1,~x) =>
  176. n*intgggg(defint_choose(f1,x),0,-1/2-a,x)
  177. when numberp n ,
  178. defint2(~n,~x**(~a),~f1,~x) => n*intgggg(defint_choose(f1,x),0,a,x)
  179. when numberp n ,
  180. defint2(~n,~x,~f1,~x) => n*intgggg(defint_choose(f1,x),0,1,x)
  181. when numberp n ,
  182. defint2(~n,sqrt(~x),~f1,~x) => n*intgggg(defint_choose(f1,x),0,1/2,x)
  183. when numberp n ,
  184. defint2(~n,sqrt(~x)*~x,~f1,~x) =>
  185. n*intgggg(defint_choose(f1,x),0,3/2,x)
  186. when numberp n ,
  187. defint2(~n,sqrt(~x)*~x^~a,~f1,~x) =>
  188. n*intgggg(defint_choose(f1,x),0,1/2+a,x)
  189. when numberp n ,
  190. defint2(~~b*~x^~~a/~~c,~f1,~f2,~x) =>
  191. b/c*intgggg(defint_choose(f1,x),defint_choose(f2,x),a,x)
  192. when freeof(b,x) and freeof (c,x),
  193. defint2(~b/(~~c*~x^~~a),~f1,~f2,~x) =>
  194. b/c*intgggg(defint_choose(f1,x),defint_choose(f2,x),-a,x)
  195. when freeof(b,x) and freeof(c,x),
  196. defint2(sqrt(~x),~f1,~f2,~x) =>
  197. intgggg(defint_choose(f1,x),defint_choose(f2,x),1/2,x),
  198. defint2(sqrt(~x)*~x^~~a,~f1,~f2,~x) =>
  199. intgggg(defint_choose(f1,x),defint_choose(f2,x),1/2+a,x),
  200. defint2(~b/(~~c*sqrt(~x)),~f1,~f2,~x) =>
  201. b/c*intgggg(defint_choose(f1,x),defint_choose(f2,x),-1/2,x),
  202. defint2(1/(sqrt(~x)*~x^~~a),~f1,~f2,~x) =>
  203. intgggg(defint_choose(f1,x),defint_choose(f2,x),-1/2-a,x),
  204. defint2(1/~x^(~~a),~f1,~x) => intgggg(defint_choose(f1,x),0,-a,x),
  205. defint2(1/sqrt(~x),~f1,~x) => intgggg(defint_choose(f1,x),0,-1/2,x),
  206. defint2(1/(sqrt(~x)*~x^~~a),~f1,~x) =>
  207. intgggg(defint_choose(f1,x),0,-1/2-a,x),
  208. defint2(~x**(~~a),~f1,~x) => intgggg(defint_choose(f1,x),0,a,x),
  209. defint2(sqrt(~x),~f1,~x) => intgggg(defint_choose(f1,x),0,1/2,x),
  210. defint2(sqrt(~x)*~x^~~a,~f1,~x) =>
  211. intgggg(defint_choose(f1,x),0,1/2+a,x),
  212. defint2(~b,~f1,~x) => b*defint2(f1,x) when freeof(b,x),
  213. defint2(~f1,~f2,~x) =>
  214. intgggg(defint_choose(f1,x),defint_choose(f2,x),0,x),
  215. defint2(~n,~f1,~x) => n*intgggg(defint_choose(f1,x),0,0,x),
  216. defint2(~f1,~x) => intgggg(defint_choose(f1,x),0,0,x),
  217. defint2((~f1-~f2)/~f3,~f4,~x) =>
  218. defint2(f1/f3,f4,x) - defint2(f2/f3,f4,x),
  219. defint2(-~b,~f1,~f2,~x) => -b*defint2(f1,f2,x) when freeof(b,x)
  220. };
  221. let defint2_rules;
  222. >>;
  223. endmodule;
  224. end;