defintg.red 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. module defintg;
  2. fluid '(!*precise);
  3. symbolic procedure print_conditions;
  4. << if spec_cond neq nil then mathprint ('or . spec_cond) else
  5. rederr "Conditions not valid";
  6. spec_cond := nil;
  7. >>;
  8. symbolic operator print_conditions;
  9. symbolic procedure defint_reform(n);
  10. % A function to rearrange the input to the integration process by
  11. % expanding out multiple powers of the exponential function i.e.
  12. %
  13. % 2 2
  14. % x + x + 1 x x
  15. % e => e * e * e
  16. %
  17. begin scalar n,var,vble,const,result,reform_test,temp_result,
  18. reform_lst,lst,new_lst,res,coef,new_coef;
  19. % test if integral needs to be reformed
  20. on exp;
  21. coef := 1;
  22. var := caddar n;
  23. const := caddr n;
  24. vble := cadddr n;
  25. % test to see if any part of the integral needs reforming
  26. for each i in n do
  27. << if eqcar(i,'defint_choose) then
  28. % test for integrals of a single function multiplied by a constant
  29. << if i neq '(defint_choose e x) and numberp cadr i
  30. and cadr i neq 0 then
  31. << new_coef := cadr i;
  32. coef := reval algebraic(coef*new_coef);
  33. n := const_case(n)>>
  34. % special case for integration of 0
  35. else if i = '(defint_choose 0 x) then coef := 0
  36. % test for special case of integral of e
  37. else if i = '(defint_choose e x) then
  38. coef := reval algebraic(e*coef)
  39. else if caadr i = 'expt then
  40. << reform_test := 't;
  41. % Form a list of the functions which must be reformed
  42. reform_lst := append(reform_lst,{i})>>
  43. else if caadr i = 'quotient
  44. % don't reform special compound functions which are represented as a
  45. % single Meijer G-function
  46. and (listp cadadr i and car cadadr i neq 'm_chebyshevt
  47. or not listp cadadr i) then
  48. << reform_test := 't;
  49. % Form a list of the functions which must be reformed
  50. reform_lst := append(reform_lst,{i})>>
  51. else if caadr i = 'times then
  52. << if listp car cddadr i
  53. and (caar cddadr i = 'm_chebyshevu
  54. or caar cddadr i = 'm_jacobip
  55. % do not reform functions containing the heaviside function
  56. or car cadadr i = 'heaviside)
  57. then
  58. lst := append(lst,{i}) % A list of the functions which do
  59. % not need reforming
  60. else if listp cdr cddadr i and cdr cddadr i neq 'nil
  61. and listp cadr cddadr i
  62. and caadr cddadr i = 'm_gegenbauerp
  63. then
  64. lst := append(lst,{i}) % A list of the functions which do
  65. % not need reforming
  66. else << reform_test := 't;
  67. % Form a list of the functions which must be reformed
  68. reform_lst := append(reform_lst,{i});>>
  69. >>
  70. else lst := append(lst,{i}); % A list of the functions which do
  71. % not need reforming
  72. >>;
  73. >>;
  74. if reform_test = nil then << n := coef . n; return n>>
  75. else
  76. << for each i in reform_lst do
  77. << new_lst := cadr i;
  78. if car new_lst = 'expt and cadr new_lst = 'e then
  79. res := reform_expt(new_lst,var)
  80. else if car new_lst = 'times then
  81. res := reform_const(new_lst,var)
  82. else if car new_lst = 'quotient and cadr new_lst = 1 then
  83. res := reform_denom(new_lst,var)
  84. else if car new_lst = 'quotient then
  85. res := reform_quot(new_lst,var);
  86. new_coef := car res;
  87. coef := reval algebraic(coef*new_coef);
  88. res := cdr res;
  89. temp_result := append(temp_result,res);
  90. >>;
  91. temp_result := coef . temp_result;
  92. result := append(temp_result,lst);
  93. if lst = nil and length result = 2 then result := append(result,{0});
  94. result := append(result,{const});
  95. result := append(result,{vble});
  96. return result;
  97. >>;
  98. end;
  99. % A function to rearrange the integral if it contains exponentials of
  100. % only positive numbers and there is no constant term
  101. symbolic procedure reform_expt(n,var);
  102. begin scalar temp,coef,lst;
  103. % test for exponentials which do not need reforming i.e. e^x
  104. if not listp n then
  105. << lst := {{'defint_choose,n,var}}; lst := 1 . lst>>
  106. else if listp caddr n neq t then
  107. << if numberp caddr n then coef := n
  108. else lst := {{'defint_choose,n,var}}; >>
  109. else if caaddr n = 'quotient then lst := {{'defint_choose,n,var}}
  110. else
  111. << temp := cdaddr n;
  112. for each i in temp do
  113. << lst := ({'defint_choose,{'expt,'e,car temp},var} . lst);
  114. temp := cdr temp>>;
  115. >>;
  116. if coef neq nil then lst := coef . lst else lst := 1 . lst;
  117. return lst;
  118. end;
  119. % A function to rearrange the integral if the exponential is multiplied
  120. % by a constant term
  121. symbolic procedure reform_const(n,var);
  122. begin scalar temp,coef,lst,temp1;
  123. temp := n;
  124. coef := caddr temp;
  125. temp := cadr temp;
  126. if temp neq nil and car temp = 'expt and (atom caddr temp or
  127. caaddr temp neq 'plus) then
  128. << lst := {{'defint_choose,{'expt,'e,caddr temp},var}}>>
  129. else
  130. << temp1 := cdaddr temp;
  131. for each i in temp1 do
  132. << lst := ({'defint_choose,{'expt,'e,car temp1},var} . lst);
  133. temp1 := cdr temp1>>;
  134. >>;
  135. if coef neq nil then lst := coef . lst else lst := 1 . lst;
  136. return lst;
  137. end;
  138. % A function to rearrange the integral if all the exponential powers
  139. % are negative powers
  140. symbolic procedure reform_denom(n,var);
  141. begin scalar temp,coef,lst,temp1;
  142. temp := caddr n;
  143. % if the function contains e^n where n is a number than this can
  144. % be taken outside the integral as a constant.
  145. if not(eqcar(temp,'expt) or eqcar(temp,'times))
  146. then return list(1,list('defint_choose,n,var));
  147. if temp = 'e or fixp caddr temp then <<coef := temp; temp := nil>>
  148. else if car temp = 'times then
  149. <<if fixp cadr temp then
  150. << coef := cadr temp; temp := caddr temp>>
  151. else << coef := caddr temp; temp := cadr temp>>>>;
  152. % test for a single occurrence of e.
  153. if temp and eqcar(caddr temp ,'quotient)
  154. and listp car cdaddr temp and listp cadr cdaddr temp then
  155. << off mcd; temp:= {'expt,'e,quotient_case(reval temp)}; on mcd>>;
  156. if temp and car temp = 'expt and (atom caddr temp or
  157. caaddr temp neq 'plus) then
  158. <<lst := {{'defint_choose,
  159. {'quotient,1,{'expt,'e,caddr temp}},var}}>>
  160. % else if there are multiple occurrences of e
  161. else if pairp caddr temp then
  162. << temp1 := cdaddr temp;
  163. for each i in temp1 do
  164. << lst:=({'defint_choose,
  165. {'quotient,1,{'expt,'e,car temp1}},var}
  166. . lst); temp1 := cdr temp1>>>>;
  167. a: return if coef then lst := ({'quotient,1,coef} . lst)
  168. else lst := 1 . lst
  169. end;
  170. % A function to rearrange the integral if the exponential consists of
  171. % both positive and negative powers
  172. symbolic procedure reform_quot(n,var);
  173. begin scalar num,denom,num_coef,denom_coef,lst,num1,denom1;
  174. num := cadr n;
  175. denom := caddr n;
  176. % Check for constants
  177. if fixp num or atom num then << num_coef := num; num := nil>>
  178. else if num = 'e or fixp caddr num then
  179. << num_coef := num; num := nil>>
  180. else if car num = 'times then
  181. << num_coef := caddr num; num := cadr num>>;
  182. if fixp denom or atom denom then
  183. << denom_coef := denom; denom := nil>>
  184. else if denom = 'e or fixp caddr denom then
  185. << denom_coef := denom; denom := nil>>
  186. else if car denom = 'times then
  187. << denom_coef := caddr denom; denom := cadr denom>>;
  188. if denom and car denom = 'expt and (atom caddr denom or
  189. caaddr denom neq 'plus) then
  190. lst := {{'defint_choose,{'quotient,1,
  191. {'expt,'e,caddr denom}},var}}
  192. else if denom then
  193. << denom1 := cdaddr denom;
  194. % for each i in denom1 do
  195. % << lst := ({'defint_choose,{'quotient,1,
  196. % {'expt,'e,car denom1}},var} . lst);
  197. % denom1 := cdr denom1>>;
  198. for each i in denom1 do
  199. lst := ({'defint_choose,{'quotient,1,
  200. {'expt,'e,i}},var} . lst)>>;
  201. if not atom num and car num = 'expt and (atom caddr num or
  202. caaddr num neq 'plus) then
  203. lst := {'defint_choose,{'expt,'e,caddr num},var} . lst
  204. else if not atom num then
  205. << num1 := cdaddr num;
  206. for each i in num1 do
  207. << lst := ({'defint_choose,{'expt,'e,car num1},var} . lst);
  208. num1 := cdr num1>>;
  209. >>;
  210. if num_coef then lst := (num_coef . lst)
  211. else if denom_coef neq nil then
  212. lst := ({'quotient,1,denom_coef} . lst)
  213. else lst := 1 . lst;
  214. return lst;
  215. end;
  216. symbolic procedure const_case(n);
  217. begin scalar n,new_n;
  218. for i := 0 :length n do
  219. << if not listp car n or listp car n and not numberp cadar n then
  220. new_n := append(new_n,{car n}); n := cdr n>>;
  221. new_n := append(new_n,{0});
  222. new_n := append(new_n,n);
  223. return new_n;
  224. end;
  225. symbolic procedure quotient_case(n);
  226. begin scalar lst,new_lst;
  227. lst := cdaddr n;
  228. new_lst := {caaddr n};
  229. for each i in lst do
  230. << if caddr i < 0 then
  231. << caddr i := minus caddr i;
  232. i := {car i,cadr i, {'minus,caddr i}}>>;
  233. new_lst := append(new_lst,{i});
  234. >>;
  235. return new_lst;
  236. end;
  237. put('transf,'simpfn,'simpinteg);
  238. % put('indefint,'psopfn,'new_indefint);
  239. symbolic procedure new_indefint(lst);
  240. begin scalar var,y,n1,n2,result,!*precise;
  241. if eqcar(car lst,'times)
  242. then return new_indefint append(cdar lst,cdr lst);
  243. result := 'unknown; %%%%%% This line is new %%%%%%%
  244. var := nth(lst,length lst - 1);
  245. y := nth(lst,length lst);
  246. lst := hyperbolic_test(lst);
  247. if length lst = 4 then << n1 := car lst; n2 := cadr lst;
  248. result := reval algebraic indefint2(n1,n2,var,y)>>
  249. else if length lst = 3 then << n1 := car lst;
  250. result := reval algebraic indefint2(n1,var,y)>>;
  251. return result
  252. end;
  253. endmodule;
  254. end;