File r34/xlog/sum.log artifact 101df9aeb7 on branch master


Sat Jun 29 13:58:16 PDT 1991
REDUCE 3.4, 15-Jul-91 ...

1: 1: 
2: 2: 
3: 3: % Tests of the SUM package.

% Author: Fujio Kako (kako@kako.math.sci.hiroshima-u.ac.jp)

% 1) Summations.

sum(n,n);


 N*(N + 1)
-----------
     2


for i:=2:10 do write sum(n**i,n);


       2
 N*(2*N  + 3*N + 1)
--------------------
         6

  2   2
 N *(N  + 2*N + 1)
-------------------
         4

       4       3       2
 N*(6*N  + 15*N  + 10*N  - 1)
------------------------------
              30

  2     4      3      2
 N *(2*N  + 6*N  + 5*N  - 1)
-----------------------------
             12

       6       5       4      2
 N*(6*N  + 21*N  + 21*N  - 7*N  + 1)
-------------------------------------
                 42

  2     6       5       4      2
 N *(3*N  + 12*N  + 14*N  - 7*N  + 2)
--------------------------------------
                  24

        8       7       6       4       2
 N*(10*N  + 45*N  + 60*N  - 42*N  + 20*N  - 3)
-----------------------------------------------
                      90

  2     8       7       6       4       2
 N *(2*N  + 10*N  + 15*N  - 14*N  + 10*N  - 3)
-----------------------------------------------
                      20

       10       9       8       6       4       2
 N*(6*N   + 33*N  + 55*N  - 66*N  + 66*N  - 33*N  + 5)
-------------------------------------------------------
                          66


sum((n+1)**3,n);


     3      2
 N*(N  + 6*N  + 13*N + 12)
---------------------------
             4


sum(x**n,n);


  N
 X *X
-------
 X - 1


sum(n**2*x**n,n);


  N     2  2      2      2
 X *X*(N *X  - 2*N *X + N  - 2*N*X + 2*N + X + 1)
--------------------------------------------------
                3      2
               X  - 3*X  + 3*X - 1


sum(1/n,n);


     1
SUM(---,N)
     N


sum(1/n/(n+2),n);


   N*(3*N + 5)
------------------
     2
 4*(N  + 3*N + 2)


sum(log (n/(n+1)),n);


       1
LOG(-------)
     N + 1


% 2) Expressions including trigonometric functions.

sum(sin(n*x),n);


         2*N*X + X
  - COS(-----------)
             2
---------------------
            X
     2*SIN(---)
            2


sum(n*sin(n*x),n,1,k);


 SIN(K*X + X)*K - SIN(K*X)*K - SIN(K*X)
----------------------------------------
             2*(COS(X) - 1)


sum(cos((2*r-1)*pi/n),r);


      2*R*PI
 SIN(--------)
        N
---------------
         PI
  2*SIN(----)
         N


sum(cos((2*r-1)*pi/n),r,1,n);


0


sum(cos((2*r-1)*pi/(2*n+1)),r);


       2*R*PI
  SIN(---------)
       2*N + 1
------------------
          PI
 2*SIN(---------)
        2*N + 1


sum(cos((2*r-1)*pi/(2*n+1)),r,1,n);


       2*N*PI
  SIN(---------)
       2*N + 1
------------------
          PI
 2*SIN(---------)
        2*N + 1


sum(sin((2*r-1)*x),r,1,n);


  - COS(2*N*X) + 1
-------------------
     2*SIN(X)


sum(cos((2*r-1)*x),r,1,n);


 SIN(2*N*X)
------------
  2*SIN(X)


sum(sin(n*x)**2,n);


  - SIN(2*N*X + X) + 2*SIN(X)*N
--------------------------------
            4*SIN(X)


sum(cos(n*x)**2,n);


 SIN(2*N*X + X) + 2*SIN(X)*N
-----------------------------
          4*SIN(X)


sum(sin(n*x)*sin((n+1)*x),n);


  - SIN(2*N*X + 2*X) + SIN(2*X)*N
----------------------------------
             4*SIN(X)


sum(sec(n*x)*sec((n+1)*x),n);


SUM(SEC(N*X + X)*SEC(N*X),N)


sum(1/2**n*tan(x/2**n),n);


          X
     TAN(----)
           N
          2
SUM(-----------,N)
         N
        2


sum(sin(r*x)*sin((r+1)*x),r,1,n);


  - SIN(2*N*X + 2*X) + SIN(2*X)*N + SIN(2*X)
---------------------------------------------
                  4*SIN(X)


sum(sec(r*x)*sec((r+1)*x),r,1,n);


SUM(SEC(R*X + X)*SEC(R*X),R,1,N)


sum(1/2**r*tan(x/2**r),r,1,n);


          X
     TAN(----)
           R
          2
SUM(-----------,R,1,N)
         R
        2


sum(k*sin(k*x),k,1,n - 1);


  - SIN(N*X - X)*N + SIN(N*X)*N - SIN(N*X)
-------------------------------------------
              2*(COS(X) - 1)


sum(k*cos(k*x),k,1,n - 1);


  - COS(N*X - X)*N + COS(N*X)*N - COS(N*X) + 1
-----------------------------------------------
                2*(COS(X) - 1)


sum(sin((2k - 1)*x),k,1,n);


  - COS(2*N*X) + 1
-------------------
     2*SIN(X)


sum(sin(x + k*y),k,0,n);


         2*N*Y + 2*X + Y          2*X - Y
  - COS(-----------------) + COS(---------)
                2                    2
--------------------------------------------
                        Y
                 2*SIN(---)
                        2


sum(cos(x + k*y),k,0,n);


      2*N*Y + 2*X + Y          2*X - Y
 SIN(-----------------) - SIN(---------)
             2                    2
-----------------------------------------
                      Y
               2*SIN(---)
                      2


sum((-1)**(k - 1)*sin((2k - 1)*x),k,1,n + 1);


       N
 ( - 1) *SIN(2*N*X + 2*X)
--------------------------
         2*COS(X)


sum((-1)**(k - 1)*cos((2k - 1)*x),k,1,n + 1);


       N
 ( - 1) *COS(2*N*X + 2*X) + 1
------------------------------
           2*COS(X)


sum(r**k*sin(k*x),k,1,n - 1);


     N                   N
  - R *SIN(N*X - X)*R + R *SIN(N*X) - SIN(X)*R
-----------------------------------------------
                            2
              2*COS(X)*R - R  - 1


sum(r**k*cos(k*x),k,0,n - 1);


     N                   N
  - R *COS(N*X - X)*R + R *COS(N*X) + COS(X)*R - 1
---------------------------------------------------
                              2
                2*COS(X)*R - R  - 1


sum(sin(k*x)*sin((k + 1)*x),k,1,n);


  - SIN(2*N*X + 2*X) + SIN(2*X)*N + SIN(2*X)
---------------------------------------------
                  4*SIN(X)


sum(sin(k*x)*sin((k + 2)*x),k,1,n);


  - SIN(2*N*X + 3*X) + SIN(3*X)*N + SIN(3*X) - SIN(X)*N
--------------------------------------------------------
                        4*SIN(X)


sum(sin(k*x)*sin((2k - 1)*x),k,1,n);


         6*N*X + X          2*N*X - 3*X          2*N*X - X
( - SIN(-----------) + SIN(-------------) + SIN(-----------)
             2                   2                   2

         2*N*X + X          3*X          X            3*X
  + SIN(-----------) + SIN(-----) + SIN(---))/(4*SIN(-----))
             2               2           2             2



% The next examples cannot be summed in closed form.

sum(1/(cos(x/2**k)*2**k)**2,k,1,n);


            1
SUM(-----------------,K,1,N)
      2*K      X   2
     2   *COS(----)
                K
               2


sum((2**k*sin(x/2**k)**2)**2,k,1,n);


     2*K      X   4
SUM(2   *SIN(----) ,K,1,N)
               K
              2


sum(tan(x/2**k)/2**k,k,0,n);


          X
     TAN(----)
           K
          2
SUM(-----------,K,0,N)
         K
        2


sum(cos(k**2*2*pi/n),k,0,n - 1);


            2
         2*K *PI
SUM(COS(---------),K,0,N - 1)
            N


sum(sin(k*pi/n),k,1,n - 1);


         2*N*PI - PI          PI
  - COS(-------------) + COS(-----)
             2*N              2*N
------------------------------------
                   PI
            2*SIN(-----)
                   2*N


% 3) Expressions including the factorial function.

for all n,m such that fixp m let
        factorial(n+m)=if m > 0 then factorial(n+m-1)*(n+m)
                   else factorial(n+m+1)/(n+m+1);



sum(n*factorial(n),n);


FACTORIAL(N)*(N + 1)


sum(n/factorial(n+1),n);


          - 1
----------------------
 FACTORIAL(N)*(N + 1)


sum((n**2+n-1)/factorial(n+2),n);


          - 1
----------------------
 FACTORIAL(N)*(N + 2)


sum(n*2**n/factorial(n+2),n);


                 N
            - 2*2
-----------------------------
                2
 FACTORIAL(N)*(N  + 3*N + 2)


sum(n*x**n/factorial(n+2),n);


                             N
                            X *N
SUM(-----------------------------------------------------,N)
                   2
     FACTORIAL(N)*N  + 3*FACTORIAL(N)*N + 2*FACTORIAL(N)


for all n,m such that fixp m and m > 3 let
        factorial((n+m)/2)= factorial((n+m)/2-1)*((n+m)/2),
        factorial((n-m)/2)= factorial((n-m)/2+1)/((n-m)/2+1);



sum(factorial(n-1/2)/factorial(n+1),n);


                    2*N - 1
         FACTORIAL(---------)
                       2
SUM(-------------------------------,N)
     FACTORIAL(N)*N + FACTORIAL(N)


for all n,m such that fixp m and m > 3 clear factorial((n+m)/2);



for all n,m such that fixp m and m > 3 clear factorial((n-m)/2);



% 4) Expressions including combination.

operator comb;

          % Combination function.

for all n ,m let comb(n,m)=factorial(n)/factorial(n-m)/factorial(m);



sum((-1)**k*comb(n,k),k,1,m);


          M                        M
( - ( - 1) *FACTORIAL(N)*M + ( - 1) *FACTORIAL(N)*N

  - FACTORIAL( - M + N)*FACTORIAL(M)*N)/(FACTORIAL( - M + N)

   *FACTORIAL(M)*N)


sum(comb(n + p,q)/comb(n + r,q + 2),n,1,m);


( - FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)*FACTORIAL(M + R)

 *FACTORIAL(P)*M*P*Q - 2*FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)

 *FACTORIAL(M + R)*FACTORIAL(P)*M*P - FACTORIAL( - Q + R)

 *FACTORIAL(M + P - Q)*FACTORIAL(M + R)*FACTORIAL(P)*M*Q - 2

 *FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)*FACTORIAL(M + R)

 *FACTORIAL(P)*M + FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)

                                   2
 *FACTORIAL(M + R)*FACTORIAL(P)*P*Q  - FACTORIAL( - Q + R)

 *FACTORIAL(M + P - Q)*FACTORIAL(M + R)*FACTORIAL(P)*P*Q*R + 2

 *FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)*FACTORIAL(M + R)

 *FACTORIAL(P)*P*Q - 2*FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)

 *FACTORIAL(M + R)*FACTORIAL(P)*P*R + FACTORIAL( - Q + R)

                                                      2
 *FACTORIAL(M + P - Q)*FACTORIAL(M + R)*FACTORIAL(P)*Q  - 

 FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)*FACTORIAL(M + R)

 *FACTORIAL(P)*Q*R + 2*FACTORIAL( - Q + R)*FACTORIAL(M + P - Q)

 *FACTORIAL(M + R)*FACTORIAL(P)*Q - 2*FACTORIAL( - Q + R)

 *FACTORIAL(M + P - Q)*FACTORIAL(M + R)*FACTORIAL(P)*R - 

 FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)

     2
 *M*Q  + FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)

 *FACTORIAL(R)*M*Q*R - 2*FACTORIAL(M - Q + R)*FACTORIAL(M + P)

 *FACTORIAL(P - Q)*FACTORIAL(R)*M*Q + 2*FACTORIAL(M - Q + R)

 *FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)*M*R - 

 FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)

     2
 *P*Q  + FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)

 *FACTORIAL(R)*P*Q*R - 2*FACTORIAL(M - Q + R)*FACTORIAL(M + P)

 *FACTORIAL(P - Q)*FACTORIAL(R)*P*Q + 2*FACTORIAL(M - Q + R)

 *FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)*P*R - 

 FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)

   2
 *Q  + FACTORIAL(M - Q + R)*FACTORIAL(M + P)*FACTORIAL(P - Q)

 *FACTORIAL(R)*Q*R - 2*FACTORIAL(M - Q + R)*FACTORIAL(M + P)

 *FACTORIAL(P - Q)*FACTORIAL(R)*Q + 2*FACTORIAL(M - Q + R)

 *FACTORIAL(M + P)*FACTORIAL(P - Q)*FACTORIAL(R)*R)/(

   FACTORIAL(M + P - Q)*FACTORIAL(M + R)*FACTORIAL(P - Q)

                                                   2            2
   *FACTORIAL(R)*(M*P*Q - M*P*R - M*Q*R + M*Q + M*R  - M*R - P*Q

                      2    2      2        2            3    2
       + 2*P*Q*R - P*R  + Q *R - Q  - 2*Q*R  + 2*Q*R + R  - R ))


sum((-1)**(k + 1)*comb(n,k)/(k + 1),k,1,n);


   N
-------
 N + 1


for all n ,m clear comb(n,m);



for all n,m such that fixp m clear factorial(n+m);



% 3) Examples taken from
%         "Decision procedure for indefinite hypergeometric summation"
%          Proc. Natl. Acad. Sci. USA  vol. 75, no. 1 pp.40-42 (1978)
%          R. William Gosper, Jr.
%

%            n
%           ____     2
%       f =  ||  (b*k +c*k+d)
%           k=1
%
%            n
%           ____     2
%       g =  ||  (b*k +c*k+e)
%           k=1
%
operator f,g;



for all n,m such that fixp m let
        f(n+m)=if m > 0 then f(n+m-1)*(b*(n+m)**2+c*(n+m)+d)
                   else f(n+m+1)/(b*(n+m+1)**2+c*(n+m+1)+d);



for all n,m such that fixp m let
        g(n+m)=if m > 0 then g(n+m-1)*(b*(n+m)**2+c*(n+m)+e)
                   else g(n+m+1)/(b*(n+m+1)**2+c*(n+m+1)+e);



sum(f(n-1)/g(n),n);


     F(N)
--------------
 G(N)*(D - E)


sum(f(n-1)/g(n+1),n);


          2  2      2        2
(F(N)*(2*B *N  + 4*B *N + 2*B  + 2*B*C*N + 2*B*C + 2*B*D*N + 3*B*D

                                       2            2
        - 2*B*E*N - B*E + C*D - C*E + D  - 2*D*E + E ))/(G(N)*(

       3    2      3        3      3    2      3        3
      B *D*N  + 2*B *D*N + B *D - B *E*N  - 2*B *E*N - B *E

          2          2        2          2          2  2  2
       + B *C*D*N + B *C*D - B *C*E*N - B *C*E + 2*B *D *N

            2  2        2  2    2          2  2  2      2  2
       + 4*B *D *N + 2*B *D  + B *D*E - 2*B *E *N  - 4*B *E *N

            2  2      2    2        2          2        2    2
       - 3*B *E  - B*C *D*N  - 2*B*C *D*N - B*C *D + B*C *E*N

              2          2            2            2          2
       + 2*B*C *E*N + B*C *E + 2*B*C*D *N + 2*B*C*D  - 2*B*C*E *N

                2      3  2        3        3        2    2
       - 2*B*C*E  + B*D *N  + 2*B*D *N + B*D  - 3*B*D *E*N

              2          2            2  2          2            2
       - 6*B*D *E*N - B*D *E + 3*B*D*E *N  + 6*B*D*E *N + 3*B*D*E

            3  2        3          3    3        3      3        3
       - B*E *N  - 2*B*E *N - 3*B*E  - C *D*N - C *D + C *E*N + C *E

          2        2  2      3        3        2            2
       - C *D*E + C *E  + C*D *N + C*D  - 3*C*D *E*N - 3*C*D *E

                2            2      3        3    3        2  2
       + 3*C*D*E *N + 3*C*D*E  - C*E *N - C*E  + D *E - 3*D *E

              3    4
       + 3*D*E  - E ))


for all n,m such that fixp m clear f(n+m);



for all n,m such that fixp m clear g(n+m);



clear f,g;



% 4) Products.

prod(n/(n+2),n);


      2
--------------
  2
 N  + 3*N + 2


prod(x**n,n);


   2
 (N  + N)/2
X


prod(e**(sin(n*x)),n);


                1
----------------------------------
  COS((2*N*X + X)/2)/(2*SIN(X/2))
 E


end;

4: 4: 
Quitting
Sat Jun 29 13:59:23 PDT 1991


REDUCE Historical
REDUCE Sourceforge Project | Historical SVN Repository | GitHub Mirror | SourceHut Mirror | NotABug Mirror | Chisel Mirror | Chisel RSS ]