INT.TST 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. COMMENT
  2. THE REDUCE INTEGRATION TEST PACKAGE
  3. Edited By
  4. Anthony C. Hearn
  5. The RAND Corporation
  6. This file is designed to provide a set of representative tests of the
  7. Reduce integration package. Not all examples go through, even when an
  8. integral exists, since some of the arguments are outside the domain of
  9. applicability of the current package. However, future improvements to
  10. the package will result in more closed-form evaluations in later
  11. releases. We would appreciate any additional contributions to this test
  12. file either because they illustrate some feature (good or bad) of the
  13. current package, or suggest domains which future versions should handle.
  14. Any suggestions for improved organization of this test file (e.g., in a
  15. way which corresponds more directly to the organization of a standard
  16. integration table book such as Gradshteyn and Ryznik) are welcome.
  17. Acknowledgments:
  18. The examples in this file have been contributed by the following.
  19. Any omissions to this list should be reported to the Editor.
  20. David M. Dahm
  21. James H. Davenport
  22. John P. Fitch
  23. Steven Harrington
  24. Anthony C. Hearn
  25. K. Siegfried Koelbig
  26. Ernst Krupnikov
  27. Arthur C. Norman
  28. Herbert Stoyan
  29. ;
  30. Comment we first set up a suitable testing functions;
  31. fluid '(gcknt!*);
  32. global '(faillist!* gcnumber!* inittime number!-of!-integrals
  33. unintlist!*);
  34. symbolic operator time;
  35. symbolic procedure initialize!-integral!-test;
  36. begin
  37. faillist!* := unintlist!* := nil;
  38. number!-of!-integrals := 0;
  39. gcnumber!* := gcknt!*;
  40. inittime := time()
  41. end;
  42. symbolic procedure summarize!-integral!-test;
  43. begin scalar totaltime;
  44. totaltime := time()-inittime;
  45. prin2t
  46. " ***** SUMMARY OF INTEGRAL TESTS *****";
  47. terpri();
  48. prin2 "Number of integrals tested: ";
  49. prin2t number!-of!-integrals;
  50. terpri();
  51. prin2 "Total time taken: ";
  52. prin2 totaltime;
  53. prin2t " ms";
  54. terpri();
  55. if gcnumber!*
  56. then <<prin2 "Number of garbage collections: ";
  57. prin2t (gcknt!* - gcnumber!*);
  58. terpri()>>;
  59. prin2 "Number of incorrect integrals: ";
  60. prin2t length faillist!*;
  61. terpri();
  62. prin2 "Number of unevaluated integrals: ";
  63. prin2t length unintlist!*;
  64. terpri();
  65. if faillist!*
  66. then <<prin2t "Integrands of incorrect integrals are:";
  67. for each x in reverse faillist!* do mathprint car x>>;
  68. if unintlist!*
  69. then <<prin2t "Integrands of unevaluated integrals are:";
  70. terpri();
  71. for each x in reverse unintlist!* do mathprint car x>>
  72. end;
  73. procedure testint(a,b);
  74. begin scalar der,diffce,res,tt;
  75. tt:=time();
  76. symbolic (number!-of!-integrals := number!-of!-integrals + 1);
  77. res:=int(a,b);
  78. % write "time for integral: ",time()-tt," ms";
  79. off precise;
  80. der := df(res,b);
  81. diffce := der-a;
  82. if diffce neq 0
  83. then begin for all x let cot x=cos x/sin x,
  84. sec x=1/cos x,
  85. sin x**2=1-cos x**2,
  86. tan(x/2)=sin x/(1+cos x),
  87. tan x=sin x/cos x,
  88. tanh x=
  89. (e**(x)-e**(-x))/(e**x+e**(-x)),
  90. coth x= 1/tanh x;
  91. diffce := diffce;
  92. for all x clear cot x,sec x,sin x**2,tan x,tan(x/2),
  93. tanh x,coth x
  94. end;
  95. %hopefully, difference appeared non-zero due to absence of
  96. %above transformations;
  97. if diffce neq 0
  98. then <<on combineexpt; diffce := diffce; off combineexpt>>;
  99. if diffce neq 0
  100. then begin scalar !*reduced;
  101. !*reduced := t;
  102. for all x let cos(2x)= 1-2sin x**2, sin x**2=1-cos x**2;
  103. diffce := diffce;
  104. for all x clear cos(2x),sin x**2
  105. end;
  106. if diffce neq 0
  107. then <<write
  108. " ***** DERIVATIVE OF INTEGRAL NOT EQUAL TO INTEGRAND *****";
  109. symbolic(faillist!* := list(a,b,res,der) . faillist!*)>>;
  110. symbolic if smemq('int,res)
  111. then unintlist!* := list(a,b,res) . unintlist!*;
  112. on precise;
  113. return res
  114. end;
  115. symbolic initialize!-integral!-test();
  116. % References are to Gradshteyn and Ryznik.
  117. testint(1+x+x**2,x);
  118. testint(x**2*(2*x**2+x)**2,x);
  119. testint(x*(x**2+2*x+1),x);
  120. testint(1/x,x); % 2.01 #2;
  121. testint((x+1)**3/(x-1)**4,x);
  122. testint(1/(x*(x-1)*(x+1)**2),x);
  123. testint((a*x+b)/((x-p)*(x-q)),x);
  124. testint(1/(a*x**2+b*x+c),x);
  125. testint((a*x+b)/(1+x**2),x);
  126. testint(1/(x**2-2*x+3),x);
  127. % Rational function examples from Hardy, Pure Mathematics, p 253 et seq.
  128. testint(1/((x-1)*(x**2+1))**2,x);
  129. testint(x/((x-a)*(x-b)*(x-c)),x);
  130. testint(x/((x**2+a**2)*(x**2+b**2)),x);
  131. testint(x**2/((x**2+a**2)*(x**2+b**2)),x);
  132. testint(x/((x-1)*(x**2+1)),x);
  133. testint(x/(1+x**3),x);
  134. testint(x**3/((x-1)**2*(x**3+1)),x);
  135. testint(1/(1+x**4),x);
  136. testint(x**2/(1+x**4),x);
  137. testint(1/(1+x**2+x**4),x);
  138. % Examples involving a+b*x.
  139. z := a+b*x;
  140. testint(z**p,x);
  141. testint(x*z**p,x);
  142. testint(x**2*z**p,x);
  143. testint(1/z,x);
  144. testint(1/z**2,x);
  145. testint(x/z,x);
  146. testint(x**2/z,x);
  147. testint(1/(x*z),x);
  148. testint(1/(x**2*z),x);
  149. testint(1/(x*z)**2,x);
  150. testint(1/(c**2+x**2),x);
  151. testint(1/(c**2-x**2),x);
  152. % More complicated rational function examples, mostly contributed
  153. % by David M. Dahm, who also developed the code to integrate them.
  154. testint(1/(2*x**3-1),x);
  155. testint(1/(x**3-2),x);
  156. testint(1/(a*x**3-b),x);
  157. testint(1/(x**4-2),x);
  158. testint(1/(5*x**4-1),x);
  159. testint(1/(3*x**4+7),x);
  160. testint(1/(x**4+3*x**2-1),x);
  161. testint(1/(x**4-3*x**2-1),x);
  162. testint(1/(x**4-3*x**2+1),x);
  163. testint(1/(x**4-4*x**2+1),x);
  164. testint(1/(x**4+4*x**2+1),x);
  165. testint(1/(x**4+x**2+2),x);
  166. testint(1/(x**4-x**2+2),x);
  167. testint(1/(x**6-1),x);
  168. testint(1/(x**6-2),x);
  169. testint(1/(x**6+2),x);
  170. testint(1/(x**8+1),x);
  171. testint(1/(x**8-1),x);
  172. testint(1/(x**8-x**4+1),x);
  173. testint(x**7/(x**12+1),x);
  174. % Examples involving logarithms.
  175. testint(log x,x);
  176. testint(x*log x,x);
  177. testint(x**2*log x,x);
  178. testint(x**p*log x,x);
  179. testint((log x)**2,x);
  180. testint(x**9*log x**11,x);
  181. testint(log x**2/x,x);
  182. testint(1/log x,x);
  183. testint(1/log(x+1),x);
  184. testint(1/(x*log x),x);
  185. testint(1/(x*log x)**2,x);
  186. testint((log x)**p/x,x);
  187. testint(log x *(a*x+b),x);
  188. testint((a*x+b)**2*log x,x);
  189. testint(log x/(a*x+b)**2,x);
  190. testint(x*log (a*x+b),x);
  191. testint(x**2*log(a*x+b),x);
  192. testint(log(x**2+a**2),x);
  193. testint(x*log(x**2+a**2),x);
  194. testint(x**2*log(x**2+a**2),x);
  195. testint(x**4*log(x**2+a**2),x);
  196. testint(log(x**2-a**2),x);
  197. testint(log(log(log(log(x)))),x);
  198. % Examples involving circular functions.
  199. testint(sin x,x); % 2.01 #5;
  200. testint(cos x,x); % #6;
  201. testint(tan x,x); % #11;
  202. testint(1/tan(x),x); % 2.01 #12;
  203. testint(1/(1+tan(x))**2,x);
  204. testint(1/cos x,x);
  205. testint(1/sin x,x);
  206. testint(sin x**2,x);
  207. testint(x**3*sin(x**2),x);
  208. testint(sin x**3,x);
  209. testint(sin x**p,x);
  210. testint((sin x**2+1)**2*cos x,x);
  211. testint(cos x**2,x);
  212. testint(cos x**3,x);
  213. testint(sin(a*x+b),x);
  214. testint(1/cos x**2,x);
  215. testint(sin x*sin(2*x),x);
  216. testint(x*sin x,x);
  217. testint(x**2*sin x,x);
  218. testint(x*sin x**2,x);
  219. testint(x**2*sin x**2,x);
  220. testint(x*sin x**3,x);
  221. testint(x*cos x,x);
  222. testint(x**2*cos x,x);
  223. testint(x*cos x**2,x);
  224. testint(x**2*cos x**2,x);
  225. testint(x*cos x**3,x);
  226. testint(sin x/x,x);
  227. testint(cos x/x,x);
  228. testint(sin x/x**2,x);
  229. testint(sin x**2/x,x);
  230. testint(tan x**3,x);
  231. % z := a+b*x;
  232. testint(sin z,x);
  233. testint(cos z,x);
  234. testint(tan z,x);
  235. testint(1/tan z,x);
  236. testint(1/sin z,x);
  237. testint(1/cos z,x);
  238. testint(sin z**2,x);
  239. testint(sin z**3,x);
  240. testint(cos z**2,x);
  241. testint(cos z**3,x);
  242. testint(1/cos z**2,x);
  243. testint(1/(1+cos x),x);
  244. testint(1/(1-cos x),x);
  245. testint(1/(1+sin x),x);
  246. testint(1/(1-sin x),x);
  247. testint(1/(a+b*sin x),x);
  248. testint(1/(a+b*sin x+cos x),x);
  249. testint(x**2*sin z**2,x);
  250. testint(cos x*cos(2*x),x);
  251. testint(x**2*cos z**2,x);
  252. testint(1/tan x**3,x);
  253. testint(x**3*tan(x)**4,x);
  254. testint(x**3*tan(x)**6,x);
  255. testint(x*tan(x)**2,x);
  256. testint(sin(2*x)*cos(3*x),x);
  257. testint(sin x**2*cos x**2,x);
  258. testint(1/(sin x**2*cos x**2),x);
  259. testint(d**x*sin x,x);
  260. testint(d**x*cos x,x);
  261. testint(x*d**x*sin x,x);
  262. testint(x*d**x*cos x,x);
  263. testint(x**2*d**x*sin x,x);
  264. testint(x**2*d**x*cos x,x);
  265. testint(x**3*d**x*sin x,x);
  266. testint(x**3*d**x*cos x,x);
  267. testint(sin x*sin(2*x)*sin(3*x),x);
  268. testint(cos x*cos(2*x)*cos(3*x),x);
  269. testint(sin(x*kx)**3*x**2,x);
  270. testint(x*cos(xi/sin(x))*cos(x)/sin(x)**2,x);
  271. % Mixed angles and half angles.
  272. int(cos(x)/(sin(x)*tan(x/2)),x);
  273. % This integral produces a messy result because the code for
  274. % converting half angle tans to sin and cos is not effective enough.
  275. testint(sin(a*x)/(b+c*sin(a*x))**2,x);
  276. % Examples involving logarithms and circular functions.
  277. testint(sin log x,x);
  278. testint(cos log x,x);
  279. % Examples involving exponentials.
  280. testint(e**x,x); % 2.01 #3;
  281. testint(a**x,x); % 2.01 #4;
  282. testint(e**(a*x),x);
  283. testint(e**(a*x)/x,x);
  284. testint(1/(a+b*e**(m*x)),x);
  285. testint(e**(2*x)/(1+e**x),x);
  286. testint(e**(2*x)*e**(a*x),x);
  287. testint(1/(a*e**(m*x)+b*e**(-m*x)),x);
  288. testint(x*e**(a*x),x);
  289. testint(x**20*e**x,x);
  290. testint(a**x/b**x,x);
  291. testint(a**x*b**x,x);
  292. testint(a**x/x**2,x);
  293. testint(x*a**x/(1+b*x)**2,x);
  294. testint(x*e**(a*x)/(1+a*x)**2,x);
  295. testint(x*k**(x**2),x);
  296. testint(e**(x**2),x);
  297. testint(x*e**(x**2),x);
  298. testint((x+1)*e**(1/x)/x**4,x);
  299. testint((2*x**3+x)*(e**(x**2))**2*e**(1-x*e**(x**2))/(1-x*e**(x**2))**2,
  300. x);
  301. testint(e**(e**(e**(e**x))),x);
  302. % Examples involving exponentials and logarithms.
  303. testint(e**x*log x,x);
  304. testint(x*e**x*log x,x);
  305. testint(e**(2*x)*log(e**x),x);
  306. % Examples involving square roots.
  307. testint(sqrt(2)*x**2 + 2*x,x);
  308. testint(log x/sqrt(a*x+b),x);
  309. u:=sqrt(a+b*x);
  310. v:=sqrt(c+d*x);
  311. testint(u*v,x);
  312. testint(u,x);
  313. testint(x*u,x);
  314. testint(x**2*u,x);
  315. testint(u/x,x);
  316. testint(u/x**2,x);
  317. testint(1/u,x);
  318. testint(x/u,x);
  319. testint(x**2/u,x);
  320. testint(1/(x*u),x);
  321. testint(1/(x**2*u),x);
  322. testint(u**p,x);
  323. testint(x*u**p,x);
  324. testint(atan((-sqrt(2)+2*x)/sqrt(2)),x);
  325. testint(1/sqrt(x**2-1),x);
  326. testint(sqrt(x+1)*sqrt x,x);
  327. testint(sin(sqrt x),x);
  328. testint(x*(1-x^2)^(-9/4),x);
  329. testint(x/sqrt(1-x^4),x);
  330. testint(1/(x*sqrt(1+x^4)),x);
  331. testint(x/sqrt(1+x^2+x^4),x);
  332. testint(1/(x*sqrt(x^2-1-x^4)),x);
  333. % Examples from James Davenport's thesis:
  334. testint(1/sqrt(x**2-1)+10/sqrt(x**2-4),x); % p. 173
  335. testint(sqrt(x+sqrt(x**2+a**2))/x,x);
  336. % Examples generated by differentiating various functions.
  337. testint(df(sqrt(1+x**2)/(1-x),x),x);
  338. testint(df(log(x+sqrt(1+x**2)),x),x);
  339. testint(df(sqrt(x)+sqrt(x+1)+sqrt(x+2),x),x);
  340. testint(df(sqrt(x**5-2*x+1)-sqrt(x**3+1),x),x);
  341. % Another such example from James Davenport's thesis (p. 146).
  342. % It contains a point of order 3, which is found by use of Mazur's
  343. % bound on the torsion of elliptic curves over the rationals;
  344. testint(df(log(1+sqrt(x**3+1)),x),x);
  345. % Examples quoted by Joel Moses:
  346. testint(1/sqrt(2*h*r**2-alpha**2),r);
  347. testint(1/(r*sqrt(2*h*r**2-alpha**2-epsilon**2)),r);
  348. testint(1/(r*sqrt(2*h*r**2-alpha**2-2*k*r)),r);
  349. testint(1/(r*sqrt(2*h*r**2-alpha**2-epsilon**2-2*k*r)),r);
  350. testint(r/sqrt(2*e*r**2-alpha**2),r);
  351. testint(r/sqrt(2*e*r**2-alpha**2-epsilon**2),r);
  352. testint(r/sqrt(2*e*r**2-alpha**2-2*k*r**4),r);
  353. testint(r/sqrt(2*e*r**2-alpha**2-2*k*r),r);
  354. testint(1/(r*sqrt(2*h*r**2-alpha**2-2*k*r**4)),r);
  355. testint(1/(r*sqrt(2*h*r**2-alpha**2-epsilon**2-2*k*r**4)),r);
  356. Comment many of these integrals used to require Steve Harrington's
  357. code to evaluate. They originated in Novosibirsk as examples
  358. of using Analytik. There are still a few examples that could
  359. be evaluated using better heuristics;
  360. testint(a*sin(3*x+5)**2*cos(3*x+5),x);
  361. testint(log(x**2)/x**3,x);
  362. testint(x*sin(x+a),x);
  363. testint((log(x)*(1-x)-1)/(e**x*log(x)**2),x);
  364. testint(x**3*(a*x**2+b)**(-1),x);
  365. testint(x**(1/2)*(x+1)**(-7/2),x);
  366. testint(x**(-1)*(x+1)**(-1),x);
  367. testint(x**(-1/2)*(2*x-1)**(-1),x);
  368. testint((x**2+1)*x**(1/2),x);
  369. testint(x**(-1)*(x-a)**(1/3),x);
  370. testint(x*sinh(x),x);
  371. testint(x*cosh(x),x);
  372. testint(sinh(2*x)/cosh(2*x),x);
  373. testint((i*eps*sinh x-1)/(eps*i*cosh x+i*a-x),x);
  374. testint(sin(2*x+3)*cos(x)**2,x);
  375. testint(x*atan(x),x);
  376. testint(x*acot(x),x);
  377. testint(x*log(x**2+a),x);
  378. testint(sin(x+a)*cos(x),x);
  379. testint(cos(x+a)*sin(x),x);
  380. testint((1+sin(x))**(1/2),x);
  381. testint((1-sin(x))**(1/2),x);
  382. testint((1+cos(x))**(1/2),x);
  383. testint((1-cos(x))**(1/2),x);
  384. testint(1/(x**(1/2)-(x-1)**(1/2)),x);
  385. testint(1/(1-(x+1)**(1/2)),x);
  386. testint(x/(x**4+36)**(1/2),x);
  387. testint(1/(x**(1/3)+x**(1/2)),x);
  388. testint(log(2+3*x**2),x);
  389. testint(cot(x),x);
  390. testint(cot x**4,x);
  391. testint(tanh(x),x);
  392. testint(coth(x),x);
  393. testint(b**x,x);
  394. testint((x**4+x**(-4)+2)**(1/2),x);
  395. testint((2*x+1)/(3*x+2),x);
  396. testint(x*log(x+(x**2+1)**(1/2)),x);
  397. testint(x*(e**x*sin(x)+1)**2,x);
  398. testint(x*e**x*cos(x),x);
  399. Comment the following set came from Herbert Stoyan;
  400. testint(1/(x-3)**4,x);
  401. testint(x/(x**3-1),x);
  402. testint(x/(x**4-1),x);
  403. testint(log(x)*(x**3+1)/(x**4+2),x);
  404. testint(log(x)+log(x+1)+log(x+2),x);
  405. testint(1/(x**3+5),x);
  406. testint(1/sqrt(1+x**2),x);
  407. testint(sqrt(x**2+3),x);
  408. testint(x/(x+1)**2,x);
  409. COMMENT The following integrals were used among others as a test of
  410. Moses' SIN program;
  411. testint(asin x,x);
  412. testint(x**2*asin x,x);
  413. testint(sec x**2/(1+sec x**2-3*tan x),x);
  414. testint(1/sec x**2,x);
  415. testint((5*x**2-3*x-2)/(x**2*(x-2)),x);
  416. testint(1/(4*x**2+9)**(1/2),x);
  417. testint((x**2+4)**(-1/2),x);
  418. testint(1/(9*x**2-12*x+10),x);
  419. testint(1/(x**8-2*x**7+2*x**6-2*x**5+x**4),x);
  420. testint((a*x**3+b*x**2+c*x+d)/((x+1)*x*(x-3)),x);
  421. testint(1/(2-log(x**2+1))**5,x);
  422. % The next integral appeared in Risch's 1968 paper.
  423. testint(2*x*e**(x**2)*log(x)+e**(x**2)/x+(log(x)-2)/(log(x)**2+x)**2+
  424. ((2/x)*log(x)+(1/x)+1)/(log(x)**2+x),x);
  425. % The following integral would not evaluate in REDUCE 3.3.
  426. testint(exp(x*ze+x/2)*sin(pi*ze)**4*x**4,ze);
  427. % This one evaluates:
  428. testint(erf(x),x);
  429. % So why not this one?
  430. testint(erf(x+a),x);
  431. Comment here is an example of using the integrator with pattern
  432. matching;
  433. for all m,n let int(k1**m*log(k1)**n/(p**2-k1**2),k1)=foo(m,n),
  434. int(k1*log(k1)**n/(p**2-k1**2),k1)=foo(1,n),
  435. int(k1**m*log(k1)/(p**2-k1**2),k1)=foo(m,1),
  436. int(k1*log(k1)/(p**2-k1**2),k1)=foo(1,1),
  437. int(log(k1)**n/(k1*(p**2-k1**2)),k1)=foo(-1,n);
  438. int(k1**2*log(k1)/(p**2-k1**2),k1);
  439. COMMENT It is interesting to see how much of this one can be done;
  440. let f1s= (12*log(s/mc**2)*s**2*pi**2*mc**3*(-8*s-12*mc**2+3*mc)
  441. + pi**2*(12*s**4*mc+3*s**4+176*s**3*mc**3-24*s**3*mc**2
  442. -144*s**2*mc**5-48*s*mc**7+24*s*mc**6+4*mc**9-3*mc**8))
  443. /(384*e**(s/y)*s**2);
  444. int(f1s,s);
  445. factor ei,log;
  446. ws;
  447. Comment the following integrals reveal deficiencies in the current
  448. integrator;
  449. %high degree denominator;
  450. %testint(1/(2-log(x**2+1))**5,x);
  451. %this example should evaluate;
  452. testint(sin(2*x)/cos(x),x);
  453. %this example, which appeared in Tobey's thesis, needs factorization
  454. %over algebraic fields. It currently gives an ugly answer and so has
  455. %been suppressed;
  456. % testint((7*x**13+10*x**8+4*x**7-7*x**6-4*x**3-4*x**2+3*x+3)/
  457. % (x**14-2*x**8-2*x**7-2*x**4-4*x**3-x**2+2*x+1),x);
  458. symbolic summarize!-integral!-test();
  459. end;