SUM.TST 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. % Tests of the SUM package.
  2. % Author: Fujio Kako (kako@kako.math.sci.hiroshima-u.ac.jp)
  3. % 1) Summations.
  4. sum(n,n);
  5. for i:=2:10 do write sum(n**i,n);
  6. sum((n+1)**3,n);
  7. sum(x**n,n);
  8. sum(n**2*x**n,n);
  9. sum(1/n,n);
  10. sum(1/n/(n+2),n);
  11. sum(log (n/(n+1)),n);
  12. % 2) Expressions including trigonometric functions.
  13. sum(sin(n*x),n);
  14. sum(n*sin(n*x),n,1,k);
  15. sum(cos((2*r-1)*pi/n),r);
  16. sum(cos((2*r-1)*pi/n),r,1,n);
  17. sum(cos((2*r-1)*pi/(2*n+1)),r);
  18. sum(cos((2*r-1)*pi/(2*n+1)),r,1,n);
  19. sum(sin((2*r-1)*x),r,1,n);
  20. sum(cos((2*r-1)*x),r,1,n);
  21. sum(sin(n*x)**2,n);
  22. sum(cos(n*x)**2,n);
  23. sum(sin(n*x)*sin((n+1)*x),n);
  24. sum(sec(n*x)*sec((n+1)*x),n);
  25. sum(1/2**n*tan(x/2**n),n);
  26. sum(sin(r*x)*sin((r+1)*x),r,1,n);
  27. sum(sec(r*x)*sec((r+1)*x),r,1,n);
  28. sum(1/2**r*tan(x/2**r),r,1,n);
  29. sum(k*sin(k*x),k,1,n - 1);
  30. sum(k*cos(k*x),k,1,n - 1);
  31. sum(sin((2k - 1)*x),k,1,n);
  32. sum(sin(x + k*y),k,0,n);
  33. sum(cos(x + k*y),k,0,n);
  34. sum((-1)**(k - 1)*sin((2k - 1)*x),k,1,n + 1);
  35. sum((-1)**(k - 1)*cos((2k - 1)*x),k,1,n + 1);
  36. sum(r**k*sin(k*x),k,1,n - 1);
  37. sum(r**k*cos(k*x),k,0,n - 1);
  38. sum(sin(k*x)*sin((k + 1)*x),k,1,n);
  39. sum(sin(k*x)*sin((k + 2)*x),k,1,n);
  40. sum(sin(k*x)*sin((2k - 1)*x),k,1,n);
  41. % The next examples cannot be summed in closed form.
  42. sum(1/(cos(x/2**k)*2**k)**2,k,1,n);
  43. sum((2**k*sin(x/2**k)**2)**2,k,1,n);
  44. sum(tan(x/2**k)/2**k,k,0,n);
  45. sum(cos(k**2*2*pi/n),k,0,n - 1);
  46. sum(sin(k*pi/n),k,1,n - 1);
  47. % 3) Expressions including the factorial function.
  48. for all n,m such that fixp m let
  49. factorial(n+m)=if m > 0 then factorial(n+m-1)*(n+m)
  50. else factorial(n+m+1)/(n+m+1);
  51. sum(n*factorial(n),n);
  52. sum(n/factorial(n+1),n);
  53. sum((n**2+n-1)/factorial(n+2),n);
  54. sum(n*2**n/factorial(n+2),n);
  55. sum(n*x**n/factorial(n+2),n);
  56. for all n,m such that fixp m and m > 3 let
  57. factorial((n+m)/2)= factorial((n+m)/2-1)*((n+m)/2),
  58. factorial((n-m)/2)= factorial((n-m)/2+1)/((n-m)/2+1);
  59. sum(factorial(n-1/2)/factorial(n+1),n);
  60. for all n,m such that fixp m and m > 3 clear factorial((n+m)/2);
  61. for all n,m such that fixp m and m > 3 clear factorial((n-m)/2);
  62. % 4) Expressions including combination.
  63. operator comb; % Combination function.
  64. for all n ,m let comb(n,m)=factorial(n)/factorial(n-m)/factorial(m);
  65. sum((-1)**k*comb(n,k),k,1,m);
  66. sum(comb(n + p,q)/comb(n + r,q + 2),n,1,m);
  67. sum((-1)**(k + 1)*comb(n,k)/(k + 1),k,1,n);
  68. for all n ,m clear comb(n,m);
  69. for all n,m such that fixp m clear factorial(n+m);
  70. % 3) Examples taken from
  71. % "Decision procedure for indefinite hypergeometric summation"
  72. % Proc. Natl. Acad. Sci. USA vol. 75, no. 1 pp.40-42 (1978)
  73. % R. William Gosper, Jr.
  74. %
  75. % n
  76. % ____ 2
  77. % f = || (b*k +c*k+d)
  78. % k=1
  79. %
  80. % n
  81. % ____ 2
  82. % g = || (b*k +c*k+e)
  83. % k=1
  84. %
  85. operator f,gg; % gg used to avoid possible conflict with high energy
  86. % physics operator.
  87. for all n,m such that fixp m let
  88. f(n+m)=if m > 0 then f(n+m-1)*(b*(n+m)**2+c*(n+m)+d)
  89. else f(n+m+1)/(b*(n+m+1)**2+c*(n+m+1)+d);
  90. for all n,m such that fixp m let
  91. gg(n+m)=if m > 0 then gg(n+m-1)*(b*(n+m)**2+c*(n+m)+e)
  92. else gg(n+m+1)/(b*(n+m+1)**2+c*(n+m+1)+e);
  93. sum(f(n-1)/gg(n),n);
  94. sum(f(n-1)/gg(n+1),n);
  95. for all n,m such that fixp m clear f(n+m);
  96. for all n,m such that fixp m clear gg(n+m);
  97. clear f,gg;
  98. % 4) Products.
  99. prod(n/(n+2),n);
  100. prod(x**n,n);
  101. prod(e**(sin(n*x)),n);
  102. end;