sum.log 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. Sat Jun 29 13:58:16 PDT 1991
  2. REDUCE 3.4, 15-Jul-91 ...
  3. 1: 1:
  4. 2: 2:
  5. 3: 3: % Tests of the SUM package.
  6. % Author: Fujio Kako (kako@kako.math.sci.hiroshima-u.ac.jp)
  7. % 1) Summations.
  8. sum(n,n);
  9. N*(N + 1)
  10. -----------
  11. 2
  12. for i:=2:10 do write sum(n**i,n);
  13. 2
  14. N*(2*N + 3*N + 1)
  15. --------------------
  16. 6
  17. 2 2
  18. N *(N + 2*N + 1)
  19. -------------------
  20. 4
  21. 4 3 2
  22. N*(6*N + 15*N + 10*N - 1)
  23. ------------------------------
  24. 30
  25. 2 4 3 2
  26. N *(2*N + 6*N + 5*N - 1)
  27. -----------------------------
  28. 12
  29. 6 5 4 2
  30. N*(6*N + 21*N + 21*N - 7*N + 1)
  31. -------------------------------------
  32. 42
  33. 2 6 5 4 2
  34. N *(3*N + 12*N + 14*N - 7*N + 2)
  35. --------------------------------------
  36. 24
  37. 8 7 6 4 2
  38. N*(10*N + 45*N + 60*N - 42*N + 20*N - 3)
  39. -----------------------------------------------
  40. 90
  41. 2 8 7 6 4 2
  42. N *(2*N + 10*N + 15*N - 14*N + 10*N - 3)
  43. -----------------------------------------------
  44. 20
  45. 10 9 8 6 4 2
  46. N*(6*N + 33*N + 55*N - 66*N + 66*N - 33*N + 5)
  47. -------------------------------------------------------
  48. 66
  49. sum((n+1)**3,n);
  50. 3 2
  51. N*(N + 6*N + 13*N + 12)
  52. ---------------------------
  53. 4
  54. sum(x**n,n);
  55. N
  56. X *X
  57. -------
  58. X - 1
  59. sum(n**2*x**n,n);
  60. N 2 2 2 2
  61. X *X*(N *X - 2*N *X + N - 2*N*X + 2*N + X + 1)
  62. --------------------------------------------------
  63. 3 2
  64. X - 3*X + 3*X - 1
  65. sum(1/n,n);
  66. 1
  67. SUM(---,N)
  68. N
  69. sum(1/n/(n+2),n);
  70. N*(3*N + 5)
  71. ------------------
  72. 2
  73. 4*(N + 3*N + 2)
  74. sum(log (n/(n+1)),n);
  75. 1
  76. LOG(-------)
  77. N + 1
  78. % 2) Expressions including trigonometric functions.
  79. sum(sin(n*x),n);
  80. 2*N*X + X
  81. - COS(-----------)
  82. 2
  83. ---------------------
  84. X
  85. 2*SIN(---)
  86. 2
  87. sum(n*sin(n*x),n,1,k);
  88. SIN(K*X + X)*K - SIN(K*X)*K - SIN(K*X)
  89. ----------------------------------------
  90. 2*(COS(X) - 1)
  91. sum(cos((2*r-1)*pi/n),r);
  92. 2*R*PI
  93. SIN(--------)
  94. N
  95. ---------------
  96. PI
  97. 2*SIN(----)
  98. N
  99. sum(cos((2*r-1)*pi/n),r,1,n);
  100. 0
  101. sum(cos((2*r-1)*pi/(2*n+1)),r);
  102. 2*R*PI
  103. SIN(---------)
  104. 2*N + 1
  105. ------------------
  106. PI
  107. 2*SIN(---------)
  108. 2*N + 1
  109. sum(cos((2*r-1)*pi/(2*n+1)),r,1,n);
  110. 2*N*PI
  111. SIN(---------)
  112. 2*N + 1
  113. ------------------
  114. PI
  115. 2*SIN(---------)
  116. 2*N + 1
  117. sum(sin((2*r-1)*x),r,1,n);
  118. - COS(2*N*X) + 1
  119. -------------------
  120. 2*SIN(X)
  121. sum(cos((2*r-1)*x),r,1,n);
  122. SIN(2*N*X)
  123. ------------
  124. 2*SIN(X)
  125. sum(sin(n*x)**2,n);
  126. - SIN(2*N*X + X) + 2*SIN(X)*N
  127. --------------------------------
  128. 4*SIN(X)
  129. sum(cos(n*x)**2,n);
  130. SIN(2*N*X + X) + 2*SIN(X)*N
  131. -----------------------------
  132. 4*SIN(X)
  133. sum(sin(n*x)*sin((n+1)*x),n);
  134. - SIN(2*N*X + 2*X) + SIN(2*X)*N
  135. ----------------------------------
  136. 4*SIN(X)
  137. sum(sec(n*x)*sec((n+1)*x),n);
  138. SUM(SEC(N*X + X)*SEC(N*X),N)
  139. sum(1/2**n*tan(x/2**n),n);
  140. X
  141. TAN(----)
  142. N
  143. 2
  144. SUM(-----------,N)
  145. N
  146. 2
  147. sum(sin(r*x)*sin((r+1)*x),r,1,n);
  148. - SIN(2*N*X + 2*X) + SIN(2*X)*N + SIN(2*X)
  149. ---------------------------------------------
  150. 4*SIN(X)
  151. sum(sec(r*x)*sec((r+1)*x),r,1,n);
  152. SUM(SEC(R*X + X)*SEC(R*X),R,1,N)
  153. sum(1/2**r*tan(x/2**r),r,1,n);
  154. X
  155. TAN(----)
  156. R
  157. 2
  158. SUM(-----------,R,1,N)
  159. R
  160. 2
  161. sum(k*sin(k*x),k,1,n - 1);
  162. - SIN(N*X - X)*N + SIN(N*X)*N - SIN(N*X)
  163. -------------------------------------------
  164. 2*(COS(X) - 1)
  165. sum(k*cos(k*x),k,1,n - 1);
  166. - COS(N*X - X)*N + COS(N*X)*N - COS(N*X) + 1
  167. -----------------------------------------------
  168. 2*(COS(X) - 1)
  169. sum(sin((2k - 1)*x),k,1,n);
  170. - COS(2*N*X) + 1
  171. -------------------
  172. 2*SIN(X)
  173. sum(sin(x + k*y),k,0,n);
  174. 2*N*Y + 2*X + Y 2*X - Y
  175. - COS(-----------------) + COS(---------)
  176. 2 2
  177. --------------------------------------------
  178. Y
  179. 2*SIN(---)
  180. 2
  181. sum(cos(x + k*y),k,0,n);
  182. 2*N*Y + 2*X + Y 2*X - Y
  183. SIN(-----------------) - SIN(---------)
  184. 2 2
  185. -----------------------------------------
  186. Y
  187. 2*SIN(---)
  188. 2
  189. sum((-1)**(k - 1)*sin((2k - 1)*x),k,1,n + 1);
  190. N
  191. ( - 1) *SIN(2*N*X + 2*X)
  192. --------------------------
  193. 2*COS(X)
  194. sum((-1)**(k - 1)*cos((2k - 1)*x),k,1,n + 1);
  195. N
  196. ( - 1) *COS(2*N*X + 2*X) + 1
  197. ------------------------------
  198. 2*COS(X)
  199. sum(r**k*sin(k*x),k,1,n - 1);
  200. N N
  201. - R *SIN(N*X - X)*R + R *SIN(N*X) - SIN(X)*R
  202. -----------------------------------------------
  203. 2
  204. 2*COS(X)*R - R - 1
  205. sum(r**k*cos(k*x),k,0,n - 1);
  206. N N
  207. - R *COS(N*X - X)*R + R *COS(N*X) + COS(X)*R - 1
  208. ---------------------------------------------------
  209. 2
  210. 2*COS(X)*R - R - 1
  211. sum(sin(k*x)*sin((k + 1)*x),k,1,n);
  212. - SIN(2*N*X + 2*X) + SIN(2*X)*N + SIN(2*X)
  213. ---------------------------------------------
  214. 4*SIN(X)
  215. sum(sin(k*x)*sin((k + 2)*x),k,1,n);
  216. - SIN(2*N*X + 3*X) + SIN(3*X)*N + SIN(3*X) - SIN(X)*N
  217. --------------------------------------------------------
  218. 4*SIN(X)
  219. sum(sin(k*x)*sin((2k - 1)*x),k,1,n);
  220. 6*N*X + X 2*N*X - 3*X 2*N*X - X
  221. ( - SIN(-----------) + SIN(-------------) + SIN(-----------)
  222. 2 2 2
  223. 2*N*X + X 3*X X 3*X
  224. + SIN(-----------) + SIN(-----) + SIN(---))/(4*SIN(-----))
  225. 2 2 2 2
  226. % The next examples cannot be summed in closed form.
  227. sum(1/(cos(x/2**k)*2**k)**2,k,1,n);
  228. 1
  229. SUM(-----------------,K,1,N)
  230. 2*K X 2
  231. 2 *COS(----)
  232. K
  233. 2
  234. sum((2**k*sin(x/2**k)**2)**2,k,1,n);
  235. 2*K X 4
  236. SUM(2 *SIN(----) ,K,1,N)
  237. K
  238. 2
  239. sum(tan(x/2**k)/2**k,k,0,n);
  240. X
  241. TAN(----)
  242. K
  243. 2
  244. SUM(-----------,K,0,N)
  245. K
  246. 2
  247. sum(cos(k**2*2*pi/n),k,0,n - 1);
  248. 2
  249. 2*K *PI
  250. SUM(COS(---------),K,0,N - 1)
  251. N
  252. sum(sin(k*pi/n),k,1,n - 1);
  253. 2*N*PI - PI PI
  254. - COS(-------------) + COS(-----)
  255. 2*N 2*N
  256. ------------------------------------
  257. PI
  258. 2*SIN(-----)
  259. 2*N
  260. % 3) Expressions including the factorial function.
  261. for all n,m such that fixp m let
  262. factorial(n+m)=if m > 0 then factorial(n+m-1)*(n+m)
  263. else factorial(n+m+1)/(n+m+1);
  264. sum(n*factorial(n),n);
  265. FACTORIAL(N)*(N + 1)
  266. sum(n/factorial(n+1),n);
  267. - 1
  268. ----------------------
  269. FACTORIAL(N)*(N + 1)
  270. sum((n**2+n-1)/factorial(n+2),n);
  271. - 1
  272. ----------------------
  273. FACTORIAL(N)*(N + 2)
  274. sum(n*2**n/factorial(n+2),n);
  275. N
  276. - 2*2
  277. -----------------------------
  278. 2
  279. FACTORIAL(N)*(N + 3*N + 2)
  280. sum(n*x**n/factorial(n+2),n);
  281. N
  282. X *N
  283. SUM(-----------------------------------------------------,N)
  284. 2
  285. FACTORIAL(N)*N + 3*FACTORIAL(N)*N + 2*FACTORIAL(N)
  286. for all n,m such that fixp m and m > 3 let
  287. factorial((n+m)/2)= factorial((n+m)/2-1)*((n+m)/2),
  288. factorial((n-m)/2)= factorial((n-m)/2+1)/((n-m)/2+1);
  289. sum(factorial(n-1/2)/factorial(n+1),n);
  290. 2*N - 1
  291. FACTORIAL(---------)
  292. 2
  293. SUM(-------------------------------,N)
  294. FACTORIAL(N)*N + FACTORIAL(N)
  295. for all n,m such that fixp m and m > 3 clear factorial((n+m)/2);
  296. for all n,m such that fixp m and m > 3 clear factorial((n-m)/2);
  297. % 4) Expressions including combination.
  298. operator comb;
  299. % Combination function.
  300. for all n ,m let comb(n,m)=factorial(n)/factorial(n-m)/factorial(m);
  301. sum((-1)**k*comb(n,k),k,1,m);
  302. M M
  303. ( - ( - 1) *FACTORIAL(N)*M + ( - 1) *FACTORIAL(N)*N
  304. - FACTORIAL( - M + N)*FACTORIAL(M)*N)/(FACTORIAL( - M + N)
  305. *FACTORIAL(M)*N)
  306. sum(comb(n + p,q)/comb(n + r,q + 2),n,1,m);
  307. ( - FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)*FACTORIAL(M + R)
  308. *FACTORIAL(P)*M*P*Q - 2*FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)
  309. *FACTORIAL(M + R)*FACTORIAL(P)*M*P - FACTORIAL( - Q + R)
  310. *FACTORIAL(M + P - Q)*FACTORIAL(M + R)*FACTORIAL(P)*M*Q - 2
  311. *FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)*FACTORIAL(M + R)
  312. *FACTORIAL(P)*M + FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)
  313. 2
  314. *FACTORIAL(M + R)*FACTORIAL(P)*P*Q - FACTORIAL( - Q + R)
  315. *FACTORIAL(M + P - Q)*FACTORIAL(M + R)*FACTORIAL(P)*P*Q*R + 2
  316. *FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)*FACTORIAL(M + R)
  317. *FACTORIAL(P)*P*Q - 2*FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)
  318. *FACTORIAL(M + R)*FACTORIAL(P)*P*R + FACTORIAL( - Q + R)
  319. 2
  320. *FACTORIAL(M + P - Q)*FACTORIAL(M + R)*FACTORIAL(P)*Q -
  321. FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)*FACTORIAL(M + R)
  322. *FACTORIAL(P)*Q*R + 2*FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)
  323. *FACTORIAL(M + R)*FACTORIAL(P)*Q - 2*FACTORIAL( - Q + R)
  324. *FACTORIAL(M + P - Q)*FACTORIAL(M + R)*FACTORIAL(P)*R -
  325. FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)
  326. 2
  327. *M*Q + FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)
  328. *FACTORIAL(R)*M*Q*R - 2*FACTORIAL(M - Q + R)*FACTORIAL(M + P)
  329. *FACTORIAL(P - Q)*FACTORIAL(R)*M*Q + 2*FACTORIAL(M - Q + R)
  330. *FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)*M*R -
  331. FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)
  332. 2
  333. *P*Q + FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)
  334. *FACTORIAL(R)*P*Q*R - 2*FACTORIAL(M - Q + R)*FACTORIAL(M + P)
  335. *FACTORIAL(P - Q)*FACTORIAL(R)*P*Q + 2*FACTORIAL(M - Q + R)
  336. *FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)*P*R -
  337. FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)
  338. 2
  339. *Q + FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)
  340. *FACTORIAL(R)*Q*R - 2*FACTORIAL(M - Q + R)*FACTORIAL(M + P)
  341. *FACTORIAL(P - Q)*FACTORIAL(R)*Q + 2*FACTORIAL(M - Q + R)
  342. *FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)*R)/(
  343. FACTORIAL(M + P - Q)*FACTORIAL(M + R)*FACTORIAL(P - Q)
  344. 2 2
  345. *FACTORIAL(R)*(M*P*Q - M*P*R - M*Q*R + M*Q + M*R - M*R - P*Q
  346. 2 2 2 2 3 2
  347. + 2*P*Q*R - P*R + Q *R - Q - 2*Q*R + 2*Q*R + R - R ))
  348. sum((-1)**(k + 1)*comb(n,k)/(k + 1),k,1,n);
  349. N
  350. -------
  351. N + 1
  352. for all n ,m clear comb(n,m);
  353. for all n,m such that fixp m clear factorial(n+m);
  354. % 3) Examples taken from
  355. % "Decision procedure for indefinite hypergeometric summation"
  356. % Proc. Natl. Acad. Sci. USA vol. 75, no. 1 pp.40-42 (1978)
  357. % R. William Gosper, Jr.
  358. %
  359. % n
  360. % ____ 2
  361. % f = || (b*k +c*k+d)
  362. % k=1
  363. %
  364. % n
  365. % ____ 2
  366. % g = || (b*k +c*k+e)
  367. % k=1
  368. %
  369. operator f,g;
  370. for all n,m such that fixp m let
  371. f(n+m)=if m > 0 then f(n+m-1)*(b*(n+m)**2+c*(n+m)+d)
  372. else f(n+m+1)/(b*(n+m+1)**2+c*(n+m+1)+d);
  373. for all n,m such that fixp m let
  374. g(n+m)=if m > 0 then g(n+m-1)*(b*(n+m)**2+c*(n+m)+e)
  375. else g(n+m+1)/(b*(n+m+1)**2+c*(n+m+1)+e);
  376. sum(f(n-1)/g(n),n);
  377. F(N)
  378. --------------
  379. G(N)*(D - E)
  380. sum(f(n-1)/g(n+1),n);
  381. 2 2 2 2
  382. (F(N)*(2*B *N + 4*B *N + 2*B + 2*B*C*N + 2*B*C + 2*B*D*N + 3*B*D
  383. 2 2
  384. - 2*B*E*N - B*E + C*D - C*E + D - 2*D*E + E ))/(G(N)*(
  385. 3 2 3 3 3 2 3 3
  386. B *D*N + 2*B *D*N + B *D - B *E*N - 2*B *E*N - B *E
  387. 2 2 2 2 2 2 2
  388. + B *C*D*N + B *C*D - B *C*E*N - B *C*E + 2*B *D *N
  389. 2 2 2 2 2 2 2 2 2 2
  390. + 4*B *D *N + 2*B *D + B *D*E - 2*B *E *N - 4*B *E *N
  391. 2 2 2 2 2 2 2 2
  392. - 3*B *E - B*C *D*N - 2*B*C *D*N - B*C *D + B*C *E*N
  393. 2 2 2 2 2
  394. + 2*B*C *E*N + B*C *E + 2*B*C*D *N + 2*B*C*D - 2*B*C*E *N
  395. 2 3 2 3 3 2 2
  396. - 2*B*C*E + B*D *N + 2*B*D *N + B*D - 3*B*D *E*N
  397. 2 2 2 2 2 2
  398. - 6*B*D *E*N - B*D *E + 3*B*D*E *N + 6*B*D*E *N + 3*B*D*E
  399. 3 2 3 3 3 3 3 3
  400. - B*E *N - 2*B*E *N - 3*B*E - C *D*N - C *D + C *E*N + C *E
  401. 2 2 2 3 3 2 2
  402. - C *D*E + C *E + C*D *N + C*D - 3*C*D *E*N - 3*C*D *E
  403. 2 2 3 3 3 2 2
  404. + 3*C*D*E *N + 3*C*D*E - C*E *N - C*E + D *E - 3*D *E
  405. 3 4
  406. + 3*D*E - E ))
  407. for all n,m such that fixp m clear f(n+m);
  408. for all n,m such that fixp m clear g(n+m);
  409. clear f,g;
  410. % 4) Products.
  411. prod(n/(n+2),n);
  412. 2
  413. --------------
  414. 2
  415. N + 3*N + 2
  416. prod(x**n,n);
  417. 2
  418. (N + N)/2
  419. X
  420. prod(e**(sin(n*x)),n);
  421. 1
  422. ----------------------------------
  423. COS((2*N*X + X)/2)/(2*SIN(X/2))
  424. E
  425. end;
  426. 4: 4:
  427. Quitting
  428. Sat Jun 29 13:59:23 PDT 1991