int.tst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. der := df(res,b);
  80. diffce := der-a;
  81. if diffce neq 0
  82. then begin for all x let cot x=cos x/sin x,
  83. sec x=1/cos x,
  84. sin x**2=1-cos x**2,
  85. tan x=sin x/cos x,
  86. tan(x/2)=sin x/(1+cos x),
  87. tanh x=
  88. (e**(x)-e**(-x))/(e**x+e**(-x)),
  89. coth x= 1/tanh x;
  90. diffce := diffce;
  91. for all x clear cot x,sec x,sin x**2,tan x,tan(x/2),
  92. tanh x,coth x
  93. end;
  94. %hopefully, difference appeared non-zero due to absence of
  95. %above transformations;
  96. if diffce neq 0
  97. then <<write
  98. " ***** DERIVATIVE OF INTEGRAL NOT EQUAL TO INTEGRAND *****";
  99. symbolic(faillist!* := list(a,b,res,der) . faillist!*)>>;
  100. symbolic if smemq('int,res)
  101. then unintlist!* := list(a,b,res) . unintlist!*;
  102. return res
  103. end;
  104. symbolic initialize!-integral!-test();
  105. % References are to Gradshteyn and Ryznik.
  106. testint(1+x+x**2,x);
  107. testint(x**2*(2*x**2+x)**2,x);
  108. testint(x*(x**2+2*x+1),x);
  109. testint(1/x,x); % 2.01 #2;
  110. testint((x+1)**3/(x-1)**4,x);
  111. testint(1/(x*(x-1)*(x+1)**2),x);
  112. testint((a*x+b)/((x-p)*(x-q)),x);
  113. testint(1/(a*x**2+b*x+c),x);
  114. testint((a*x+b)/(1+x**2),x);
  115. testint(1/(x**2-2*x+3),x);
  116. % Rational function examples from Hardy, Pure Mathematics, p 253 et seq.
  117. testint(1/((x-1)*(x**2+1))**2,x);
  118. testint(x/((x-a)*(x-b)*(x-c)),x);
  119. testint(x/((x**2+a**2)*(x**2+b**2)),x);
  120. testint(x**2/((x**2+a**2)*(x**2+b**2)),x);
  121. testint(x/((x-1)*(x**2+1)),x);
  122. testint(x/(1+x**3),x);
  123. testint(x**3/((x-1)**2*(x**3+1)),x);
  124. testint(1/(1+x**4),x);
  125. testint(x**2/(1+x**4),x);
  126. testint(1/(1+x**2+x**4),x);
  127. % Examples involving a+b*x.
  128. z := a+b*x;
  129. testint(z**p,x);
  130. testint(x*z**p,x);
  131. testint(x**2*z**p,x);
  132. testint(1/z,x);
  133. testint(1/z**2,x);
  134. testint(x/z,x);
  135. testint(x**2/z,x);
  136. testint(1/(x*z),x);
  137. testint(1/(x**2*z),x);
  138. testint(1/(x*z)**2,x);
  139. testint(1/(c**2+x**2),x);
  140. testint(1/(c**2-x**2),x);
  141. % More complicated rational function examples, mostly contributed
  142. % by David M. Dahm, who also developed the code to integrate them.
  143. testint(1/(2*x**3-1),x);
  144. testint(1/(x**3-2),x);
  145. testint(1/(a*x**3-b),x);
  146. testint(1/(x**4-2),x);
  147. testint(1/(5*x**4-1),x);
  148. testint(1/(3*x**4+7),x);
  149. testint(1/(x**4+3*x**2-1),x);
  150. testint(1/(x**4-3*x**2-1),x);
  151. testint(1/(x**4-3*x**2+1),x);
  152. testint(1/(x**4-4*x**2+1),x);
  153. testint(1/(x**4+4*x**2+1),x);
  154. testint(1/(x**4+x**2+2),x);
  155. testint(1/(x**4-x**2+2),x);
  156. testint(1/(x**6-1),x);
  157. testint(1/(x**6-2),x);
  158. testint(1/(x**6+2),x);
  159. testint(1/(x**8+1),x);
  160. testint(1/(x**8-1),x);
  161. testint(1/(x**8-x**4+1),x);
  162. testint(x**7/(x**12+1),x);
  163. % Examples involving logarithms.
  164. testint(log x,x);
  165. testint(x*log x,x);
  166. testint(x**2*log x,x);
  167. testint(x**p*log x,x);
  168. testint((log x)**2,x);
  169. testint(x**9*log x**11,x);
  170. testint(log x**2/x,x);
  171. testint(1/log x,x);
  172. testint(1/log(x+1),x);
  173. testint(1/(x*log x),x);
  174. testint(1/(x*log x)**2,x);
  175. testint((log x)**p/x,x);
  176. testint(log x *(a*x+b),x);
  177. testint((a*x+b)**2*log x,x);
  178. testint(log x/(a*x+b)**2,x);
  179. testint(x*log (a*x+b),x);
  180. testint(x**2*log(a*x+b),x);
  181. testint(log(x**2+a**2),x);
  182. testint(x*log(x**2+a**2),x);
  183. testint(x**2*log(x**2+a**2),x);
  184. testint(x**4*log(x**2+a**2),x);
  185. testint(log(x**2-a**2),x);
  186. testint(log(log(log(log(x)))),x);
  187. % Examples involving circular functions.
  188. testint(sin x,x); % 2.01 #5;
  189. testint(cos x,x); % #6;
  190. testint(tan x,x); % #11;
  191. testint(1/tan(x),x); % 2.01 #12;
  192. testint(1/(1+tan(x))**2,x);
  193. testint(1/cos x,x);
  194. testint(1/sin x,x);
  195. testint(sin x**2,x);
  196. testint(x**3*sin(x**2),x);
  197. testint(sin x**3,x);
  198. testint(sin x**p,x);
  199. testint((sin x**2+1)**2*cos x,x);
  200. testint(cos x**2,x);
  201. testint(cos x**3,x);
  202. testint(sin(a*x+b),x);
  203. testint(1/cos x**2,x);
  204. testint(sin x*sin(2*x),x);
  205. testint(x*sin x,x);
  206. testint(x**2*sin x,x);
  207. testint(x*sin x**2,x);
  208. testint(x**2*sin x**2,x);
  209. testint(x*sin x**3,x);
  210. testint(x*cos x,x);
  211. testint(x**2*cos x,x);
  212. testint(x*cos x**2,x);
  213. testint(x**2*cos x**2,x);
  214. testint(x*cos x**3,x);
  215. testint(sin x/x,x);
  216. testint(cos x/x,x);
  217. testint(sin x/x**2,x);
  218. testint(sin x**2/x,x);
  219. testint(tan x**3,x);
  220. % z := a+b*x;
  221. testint(sin z,x);
  222. testint(cos z,x);
  223. testint(tan z,x);
  224. testint(1/tan z,x);
  225. testint(1/sin z,x);
  226. testint(1/cos z,x);
  227. testint(sin z**2,x);
  228. testint(sin z**3,x);
  229. testint(cos z**2,x);
  230. testint(cos z**3,x);
  231. testint(1/cos z**2,x);
  232. testint(1/(1+cos x),x);
  233. testint(1/(1-cos x),x);
  234. testint(1/(1+sin x),x);
  235. testint(1/(1-sin x),x);
  236. testint(1/(a+b*sin x),x);
  237. testint(1/(a+b*sin x+cos x),x);
  238. testint(x**2*sin z**2,x);
  239. testint(cos x*cos(2*x),x);
  240. testint(x**2*cos z**2,x);
  241. testint(1/tan x**3,x);
  242. testint(x**3*tan(x)**4,x);
  243. testint(x**3*tan(x)**6,x);
  244. testint(x*tan(x)**2,x);
  245. testint(sin(2*x)*cos(3*x),x);
  246. testint(sin x**2*cos x**2,x);
  247. testint(1/(sin x**2*cos x**2),x);
  248. testint(d**x*sin x,x);
  249. testint(d**x*cos x,x);
  250. testint(x*d**x*sin x,x);
  251. testint(x*d**x*cos x,x);
  252. testint(x**2*d**x*sin x,x);
  253. testint(x**2*d**x*cos x,x);
  254. testint(x**3*d**x*sin x,x);
  255. testint(x**3*d**x*cos x,x);
  256. testint(sin x*sin(2*x)*sin(3*x),x);
  257. testint(cos x*cos(2*x)*cos(3*x),x);
  258. testint(sin(x*kx)**3*x**2,x);
  259. testint(x*cos(xi/sin(x))*cos(x)/sin(x)**2,x);
  260. % Mixed angles and half angles.
  261. int(cos(x)/(sin(x)*tan(x/2)),x);
  262. % This integral produces a messy result because the code for
  263. % converting half angle tans to sin and cos is not effective enough.
  264. testint(sin(a*x)/(b+c*sin(a*x))**2,x);
  265. % Examples involving logarithms and circular functions.
  266. testint(sin log x,x);
  267. testint(cos log x,x);
  268. % Examples involving exponentials.
  269. testint(e**x,x); % 2.01 #3;
  270. testint(a**x,x); % 2.01 #4;
  271. testint(e**(a*x),x);
  272. testint(e**(a*x)/x,x);
  273. testint(1/(a+b*e**(m*x)),x);
  274. testint(e**(2*x)/(1+e**x),x);
  275. testint(e**(2*x)*e**(a*x),x);
  276. testint(1/(a*e**(m*x)+b*e**(-m*x)),x);
  277. testint(x*e**(a*x),x);
  278. testint(x**20*e**x,x);
  279. testint(a**x/b**x,x);
  280. testint(a**x*b**x,x);
  281. testint(a**x/x**2,x);
  282. testint(x*a**x/(1+b*x)**2,x);
  283. testint(x*e**(a*x)/(1+a*x)**2,x);
  284. testint(x*k**(x**2),x);
  285. testint(e**(x**2),x);
  286. testint(x*e**(x**2),x);
  287. testint((x+1)*e**(1/x)/x**4,x);
  288. testint((2*x**3+x)*(e**(x**2))**2*e**(1-x*e**(x**2))/(1-x*e**(x**2))**2,
  289. x);
  290. testint(e**(e**(e**(e**x))),x);
  291. % Examples involving exponentials and logarithms.
  292. testint(e**x*log x,x);
  293. testint(x*e**x*log x,x);
  294. testint(e**(2*x)*log(e**x),x);
  295. % Examples involving square roots.
  296. testint(sqrt(2)*x**2 + 2*x,x);
  297. testint(log x/sqrt(a*x+b),x);
  298. u:=sqrt(a+b*x);
  299. v:=sqrt(c+d*x);
  300. testint(u*v,x);
  301. testint(u,x);
  302. testint(x*u,x);
  303. testint(x**2*u,x);
  304. testint(u/x,x);
  305. testint(u/x**2,x);
  306. testint(1/u,x);
  307. testint(x/u,x);
  308. testint(x**2/u,x);
  309. testint(1/(x*u),x);
  310. testint(1/(x**2*u),x);
  311. testint(u**p,x);
  312. testint(x*u**p,x);
  313. testint(atan((-sqrt(2)+2*x)/sqrt(2)),x);
  314. testint(1/sqrt(x**2-1),x);
  315. testint(sqrt(x+1)*sqrt x,x);
  316. % Examples from James Davenport's thesis:
  317. testint(1/sqrt(x**2-1)+10/sqrt(x**2-4),x); % p. 173
  318. testint(sqrt(x+sqrt(x**2+a**2))/x,x);
  319. % Examples generated by differentiating various functions.
  320. testint(df(sqrt(1+x**2)/(1-x),x),x);
  321. testint(df(log(x+sqrt(1+x**2)),x),x);
  322. testint(df(sqrt(x)+sqrt(x+1)+sqrt(x+2),x),x);
  323. testint(df(sqrt(x**5-2*x+1)-sqrt(x**3+1),x),x);
  324. % Another such example from James Davenport's thesis (p. 146).
  325. % It contains a point of order 3, which is found by use of Mazur's
  326. % bound on the torsion of elliptic curves over the rationals;
  327. testint(df(log(1+sqrt(x**3+1)),x),x);
  328. % Examples quoted by Joel Moses:
  329. testint(1/sqrt(2*h*r**2-alpha**2),r);
  330. testint(1/(r*sqrt(2*h*r**2-alpha**2-epsilon**2)),r);
  331. testint(1/(r*sqrt(2*h*r**2-alpha**2-2*k*r)),r);
  332. testint(1/(r*sqrt(2*h*r**2-alpha**2-epsilon**2-2*k*r)),r);
  333. testint(r/sqrt(2*e*r**2-alpha**2),r);
  334. testint(r/sqrt(2*e*r**2-alpha**2-epsilon**2),r);
  335. testint(r/sqrt(2*e*r**2-alpha**2-2*k*r**4),r);
  336. testint(r/sqrt(2*e*r**2-alpha**2-2*k*r),r);
  337. testint(1/(r*sqrt(2*h*r**2-alpha**2-2*k*r**4)),r);
  338. testint(1/(r*sqrt(2*h*r**2-alpha**2-epsilon**2-2*k*r**4)),r);
  339. Comment many of these integrals used to require Steve Harrington's
  340. code to evaluate. They originated in Novosibirsk as examples
  341. of using Analytik. There are still a few examples that could
  342. be evaluated using better heuristics;
  343. testint(a*sin(3*x+5)**2*cos(3*x+5),x);
  344. testint(log(x**2)/x**3,x);
  345. testint(x*sin(x+a),x);
  346. testint((log(x)*(1-x)-1)/(e**x*log(x)**2),x);
  347. testint(x**3*(a*x**2+b)**(-1),x);
  348. testint(x**(1/2)*(x+1)**(-7/2),x);
  349. testint(x**(-1)*(x+1)**(-1),x);
  350. testint(x**(-1/2)*(2*x-1)**(-1),x);
  351. testint((x**2+1)*x**(1/2),x);
  352. testint(x**(-1)*(x-a)**(1/3),x);
  353. testint(x*sinh(x),x);
  354. testint(x*cosh(x),x);
  355. testint(sinh(2*x)/cosh(2*x),x);
  356. testint((i*eps*sinh x-1)/(eps*i*cosh x+i*a-x),x);
  357. testint(sin(2*x+3)*cos(x)**2,x);
  358. testint(x*atan(x),x);
  359. testint(x*acot(x),x);
  360. testint(x*log(x**2+a),x);
  361. testint(sin(x+a)*cos(x),x);
  362. testint(cos(x+a)*sin(x),x);
  363. testint((1+sin(x))**(1/2),x);
  364. testint((1-sin(x))**(1/2),x);
  365. testint((1+cos(x))**(1/2),x);
  366. testint((1-cos(x))**(1/2),x);
  367. testint(1/(x**(1/2)-(x-1)**(1/2)),x);
  368. testint(1/(1-(x+1)**(1/2)),x);
  369. testint(x/(x**4+36)**(1/2),x);
  370. testint(1/(x**(1/3)+x**(1/2)),x);
  371. testint(log(2+3*x**2),x);
  372. testint(cot(x),x);
  373. testint(cot x**4,x);
  374. testint(tanh(x),x);
  375. testint(coth(x),x);
  376. testint(b**x,x);
  377. testint((x**4+x**(-4)+2)**(1/2),x);
  378. testint((2*x+1)/(3*x+2),x);
  379. testint(x*log(x+(x**2+1)**(1/2)),x);
  380. testint(x*(e**x*sin(x)+1)**2,x);
  381. testint(x*e**x*cos(x),x);
  382. Comment the following set came from Herbert Stoyan;
  383. testint(1/(x-3)**4,x);
  384. testint(x/(x**3-1),x);
  385. testint(x/(x**4-1),x);
  386. testint(log(x)*(x**3+1)/(x**4+2),x);
  387. testint(log(x)+log(x+1)+log(x+2),x);
  388. testint(1/(x**3+5),x);
  389. testint(1/sqrt(1+x**2),x);
  390. testint(sqrt(x**2+3),x);
  391. testint(x/(x+1)**2,x);
  392. COMMENT The following integrals were used among others as a test of
  393. Moses' SIN program;
  394. testint(asin x,x);
  395. testint(x**2*asin x,x);
  396. testint(sec x**2/(1+sec x**2-3*tan x),x);
  397. testint(1/sec x**2,x);
  398. testint((5*x**2-3*x-2)/(x**2*(x-2)),x);
  399. testint(1/(4*x**2+9)**(1/2),x);
  400. testint((x**2+4)**(-1/2),x);
  401. testint(1/(9*x**2-12*x+10),x);
  402. testint(1/(x**8-2*x**7+2*x**6-2*x**5+x**4),x);
  403. testint((a*x**3+b*x**2+c*x+d)/((x+1)*x*(x-3)),x);
  404. testint(1/(2-log(x**2+1))**5,x);
  405. % The next integral appeared in Risch's 1968 paper.
  406. testint(2*x*e**(x**2)*log(x)+e**(x**2)/x+(log(x)-2)/(log(x)**2+x)**2+
  407. ((2/x)*log(x)+(1/x)+1)/(log(x)**2+x),x);
  408. % The following integral would not evaluate in REDUCE 3.3.
  409. testint(exp(x*ze+x/2)*sin(pi*ze)**4*x**4,ze);
  410. % This one evaluates:
  411. testint(erf(x),x);
  412. % So why not this one?
  413. testint(erf(x+a),x);
  414. Comment here is an example of using the integrator with pattern
  415. matching;
  416. for all m,n let int(k1**m*log(k1)**n/(p**2-k1**2),k1)=foo(m,n),
  417. int(k1*log(k1)**n/(p**2-k1**2),k1)=foo(1,n),
  418. int(k1**m*log(k1)/(p**2-k1**2),k1)=foo(m,1),
  419. int(k1*log(k1)/(p**2-k1**2),k1)=foo(1,1),
  420. int(log(k1)**n/(k1*(p**2-k1**2)),k1)=foo(-1,n);
  421. int(k1**2*log(k1)/(p**2-k1**2),k1);
  422. COMMENT It is interesting to see how much of this one can be done;
  423. let f1s= (12*log(s/mc**2)*s**2*pi**2*mc**3*(-8*s-12*mc**2+3*mc)
  424. + pi**2*(12*s**4*mc+3*s**4+176*s**3*mc**3-24*s**3*mc**2
  425. -144*s**2*mc**5-48*s*mc**7+24*s*mc**6+4*mc**9-3*mc**8))
  426. /(384*e**(s/y)*s**2);
  427. int(f1s,s);
  428. factor int;
  429. ws;
  430. Comment the following integrals reveal deficiencies in the current
  431. integrator;
  432. %high degree denominator;
  433. %testint(1/(2-log(x**2+1))**5,x);
  434. %this example should evaluate;
  435. testint(sin(2*x)/cos(x),x);
  436. %this example, which appeared in Tobey's thesis, needs factorization
  437. %over algebraic fields. It currently gives an ugly answer and so has
  438. %been suppressed;
  439. % testint((7*x**13+10*x**8+4*x**7-7*x**6-4*x**3-4*x**2+3*x+3)/
  440. % (x**14-2*x**8-2*x**7-2*x**4-4*x**3-x**2+2*x+1),x);
  441. symbolic summarize!-integral!-test();
  442. end;