123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729 |
- Tue Apr 15 00:35:15 2008 run on win32
- % 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*pi*r
- 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*pi*r
- 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 2*n*x + x
- ( - sin(-----------) + sin(-------------) + sin(-----------) + sin(-----------)
- 2 2 2 2
- 3*x x 3*x
- + sin(-----) + sin(---))/(4*sin(-----))
- 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
- 2
- + factorial( - q + r)*factorial(m + p - q)*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
- 2
- + factorial( - q + r)*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
- 2
- - factorial(m - q + r)*factorial(m + p)*factorial(p - q)*factorial(r)*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
- 2
- - factorial(m - q + r)*factorial(m + p)*factorial(p - q)*factorial(r)*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
- 2
- - factorial(m - q + r)*factorial(m + p)*factorial(p - q)*factorial(r)*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)*factorial(r)*(m*p*q
- 2 2 2 2 2
- - m*p*r - m*q*r + m*q + m*r - m*r - p*q + 2*p*q*r - p*r + q *r - q
- 2 3 2
- - 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,gg;
- % gg used to avoid possible conflict with high energy
- % physics operator.
- 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
- gg(n+m)=if m > 0 then gg(n+m-1)*(b*(n+m)**2+c*(n+m)+e)
- else gg(n+m+1)/(b*(n+m+1)**2+c*(n+m+1)+e);
- sum(f(n-1)/gg(n),n);
- f(n)
- ---------------
- gg(n)*(d - e)
- sum(f(n-1)/gg(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*b*e*n
- 2 2 3 2 3 3
- - b*e + c*d - c*e + d - 2*d*e + e ))/(gg(n)*(b *d*n + 2*b *d*n + b *d
- 3 2 3 3 2 2 2 2
- - b *e*n - 2*b *e*n - b *e + b *c*d*n + b *c*d - b *c*e*n - b *c*e
- 2 2 2 2 2 2 2 2 2 2 2 2 2
- + 2*b *d *n + 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 2
- - 3*b *e - b*c *d*n - 2*b*c *d*n - b*c *d + b*c *e*n + 2*b*c *e*n
- 2 2 2 2 2 3 2
- + b*c *e + 2*b*c*d *n + 2*b*c*d - 2*b*c*e *n - 2*b*c*e + b*d *n
- 3 3 2 2 2 2 2 2
- + 2*b*d *n + b*d - 3*b*d *e*n - 6*b*d *e*n - b*d *e + 3*b*d*e *n
- 2 2 3 2 3 3 3 3
- + 6*b*d*e *n + 3*b*d*e - b*e *n - 2*b*e *n - 3*b*e - c *d*n - c *d
- 3 3 2 2 2 3 3 2 2
- + c *e*n + c *e - 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 4
- + 3*c*d*e *n + 3*c*d*e - c*e *n - c*e + d *e - 3*d *e + 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 gg(n+m);
- clear f,gg;
- % 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;
- Time for test: 187 ms, plus GC time: 2 ms
|