# sum(y) is sum of y index k from a to b step c # sum is reverse of backward difference; sum(y_,j_,a_,b_,c_) := If(b>=a, If(isfree(y,j), y*(b-a+1)/c, block(sum:=0, For(j,a,b,c,sum:=sum+y), sum))); #sum(y_,x_,a_,b_) := If(isfree(y,x), y*b-y*a+y, If(isnumber(b) and b<>inf, sum(y,x,a,b,1) )); sum(y_+z_,x_,a_,b_) := sum(y,x,a,b)+sum(z,x,a,b); sum(y_-z_,x_,a_,b_) := sum(y,x,a,b)-sum(z,x,a,b); sum(x_^k_,k_,a_,b_) := (x^(1+b)-x^a)/(x-1); #sum(x_^k_/k_!,k_,a_,b_) := exp(x)*(gamma(b+1,x)/gamma(b+1)-gamma(a,x)/gamma(a)); #sum(1/k_!,k_,a_,n_) := e*gamma(n+1,1)/gamma(n+1)-e*gamma(a,1)/gamma(a); #sum(x_^k_*k_^s_,k_,a_,b_) := x^a*lerch(x,-s,a)-x^(b+1)*lerch(x,-s,b+1); #sum(x_^k_*(c_+k_)^s_,k_,a_,b_) := x^a*lerch(x,-s,a+c)-x^(b+1)*lerch(x,-s,b+c+1); #sum((c_+x_)^n_,x_,a_,b_) := zeta(-n,a+c)-zeta(-n,1+b+c); #sum(x_^n_,x_,a_,b_) := zeta(-n,a)-zeta(-n,b+1); sum(x_^5,x_,a_,b_) := 1/6*b^6+1/2*b^5+5/12*b^4-1/12*b^2-1/6*a^6+1/2*a^5-5/12*a^4+1/12*a^2; sum(x_^4,x_,a_,b_) := 1/5*b^5+1/2*b^4+1/3*b^3-1/30*b-a^5/5+a^4/2-a^3/3+a/30; sum(x_^3,x_,a_,b_):= b^4/4+b^3/2+b^2/4-a^4/4+a^3/2-a^2/4; sum(x_^2,x_,a_,b_):= b^3/3+b^2/2+b/6-a^3/3+a^2/2-a/6; #sum(k_,k_,a_,b_):= b^2/2+b/2-a^2/2+a/2; #sum((-1)^k_*x_^n_,x_,a_,b_) := eta(-n,b+1)-eta(-n,a); sum(e^(k_*x_),x_,a_,b_) := (exp((1+b)*k)-exp(a*k))/(exp(k)-1); sum(e^(x_),x_,a_,b_) := (exp(1+b)-exp(a))/(e-1); sum(e^(-x_),x_,a_,b_) := (exp(1-a)-exp(-b))/(e-1); sum(abs(x_),x_,a_,b_):= b^2/2+abs(b)/2+a^2/2+abs(a)/2; #sum(y_,k_,1,n_) := sum(y,k,0,n)-replace(y,k,0); #sum(-y_,k_,1,n_) := -sum(y,k,1,n); sum(k_*k_!, k_,0,n_) := (n+1)!-1; sum(k_/(k_+1)!, k_,0,n_) := 1-1/(n+1)!; sum(k_^r_,k_,0,n_) := harmonic(-r,n)+0^r; #sum(k_^r_,k_,1,n_) := harmonic(-r,n); sum((-1)^k_*k_^2,k_,1,n_) := (-1)^n*n*(n+1)/2; sum(k_,k_,1,n_) := (n^2+n)/2; sum((2*k_-1)^2,k_,1,n_) := 4*n^3/3-n/3; sum((2*k_-1)^3,k_,1,n_) := 2*n^4-n^2; sum(log(x_),x_,1,b_) := log(b!); sum(k_,k_,a_,inf):= infinity; sum(binomial(n_, k_)*x_^k_, k_, 0, Infinity):=(1+x)^n; sum((-1)^k*binomial(n_, k_)*x_^k_, k_, 0, Infinity):=(1-x)^n; sum(x_^(2k_+1)*1/(2k_+1)! *(-1)^k_,k_,0,inf):= sin(x); sum(x_^(2k_)*1/(2k_)!*(-1)^k_,k_,0,inf):= cos(x); sum((-1)^k_*e^(2i*k_*x_),k_,0,inf):= -i/2*tan(x); sum(x_^(2k_+1)*1/(2k_+1)*(-1)^k_,k_,0,inf):= atan(x); sum(x_^(2k_+1)/(2k_+1)!,k_,0,inf):= sinh(x); sum(x_^(2k_)/(2k_)!,k_,0,inf):= cosh(x); sum((-1)^k_*e^(2k_*x_),k_,0,inf):= -1/2*tanh(x); sum(x_^(2k_+1)/(2k_+1),k_,0,inf):=atanh(x); sum(x_^k_,k_,0,inf):= when(abs(x)<1, 1/(1-x)); sum(x_^(-k_),k_,0,inf):= when(abs(x)>1, x/(x-1)); sum(k_*x_^(k_-1),k_,0,inf):= when(abs(x)<1,1/(1-x)^2); sum(x_^k_/k_,k_,0,inf):= when(abs(x)<1, -log(1-x)); sum((1-x_)^k_/k_,k_,0,inf):= when(abs(x)<1, -log(x)); sum((-1)^(k_+1)*x_^k_/k_,k_,0,inf):= when(abs(x)<1, log(1+x)); sum(x_^k_/k_!,k_,0,inf):= exp(x); sum(x_^(a_+k_)/k_!,k_,0,inf):= x^a*e^x; #sum(x_^(a_*k_)/k_!,k_,0,inf):= exp(x^a); sum((-1)^k_/k_!*x_^k_,k_,0,inf):= exp(-x); sum(k_/k_!*x_^k_,k_,0,inf):= x*exp(x); sum((-1)^k_*k_/k_!*x_^k_,k_,0,inf):= x*exp(-x); #sum(x_^k_/(a_*k_)!, k_,0,inf):=mittag(a,x); #sum(x_^k_/(a_*k_+b_)!, k_,0,inf):=mittag(a,b-1,x); #sum(x_^k_/gamma(a_*k_+b_), k_,0,inf):=mittag(a,b,x); sum(1/k_!,k_,0,inf):= e; sum(k_/k_!,k_,0,inf):= e; sum(k_^2/k_!,k_,0,inf):= 2e; sum(k_^3/k_!,k_,0,inf):= 5e; sum((-1)^k_/k_!, k_,0,inf):= exp(-1); sum(e^(a_*x_),x_,0,inf) := when(a<0, exp(-a)/(exp(-a)-1)); sum(exp(-k_*x_),k_,0,inf):=1/(exp(x)-1); sum(e^(-x_),x_,0,inf) := exp(1)/(exp(1)-1); sum(exp(-x_),x_,0,inf) := exp(1)/(exp(1)-1); sum(x_*e^(-x_),x_,0,inf) := exp(1)/(exp(1)-1)^2; sum(1/k_!,k_,1,inf) := e-1; sum(k_^x_/k_!,k_,1,inf) := exp(x)-1; #sum(k_^x_,k_,1,inf) := zeta(-x); #sum(x_^k_*k_^b_,k_,1,inf):= polylog(-b,x); #sum((-1)^k_*k_^x_,k_,1,inf):= -eta(-x); #sum((-1)^k_*k_^b_*x_^k,k_,1,inf):= polylog(-b,-x); #sum(x_^k_*(a_+k_)^b_,k_,1,inf):= polylog(a,-b,x); sum((-1)^k_/k_,k_,1,inf):= -log(2); sum(y_,x_,b_) := sum(y, x,0,b); #sum(k_*y_,x_,a_) := If(isfree(k,x), k*sum(y,x,a)); sum(a_+b_,x_) := sum(a,x)+sum(b,x); sum(a_-b_,x_) := sum(a,x)-sum(b,x); sum(a_*b_*c_,x_) := If(isfree(a,x), a*sum(b*c,x)); sum(f(x_)-f(x_-1),x_):=f(x); sum(a_^k_,k_):=If(isfree(a,k), (a^(k+1)-1)/(a-1)); sum(k_^a_, k_) :=If(isfree(a,k), harmonic(-a,k)); sum((c_+k_)^a_, k_) :=If(isfree(a,c,k), zeta(-a,c,k+1)); sum((z_+k_)^a_, k_) :=If(isfree(a,z,k), zeta(-a,z,k+1)); sum((-1)^k_*k_^a_, k_) :=If(isfree(a,k), -eta(-a,1,k)); sum((-1)^k_*(c_+k_)^a_, k_) :=If(isfree(a,c,k), -eta(-a,c,k+1)); sum(k_^p_*x_^k_,k_):= -lerch(x,-p,1+k); sum((a_+k_)^p_*x_^k_,k_):= -lerch(x,-p,1+a+k); sum((z_+k_)^p_*x_^k_,k_):= -lerch(x,-p,1+z+k); sum(x_^k_/k_!,k_):= -mittag(1,k+2,x); sum(x_^k_/(b_*k_)!,k_):= if(isfree(b,k), -mittag(b,k+2,x)); sum(x_^k_/(b_+k_)!,k_):= if(isfree(b,k), -mittag(1,k+2+b,x)); sum(x_^k_/(a_*k_+b_)!, k_):=if(isfree(a,b,k), -mittag(a,b+2+k,x)); sum(x_^k_/gamma(a_*k_), k_):=if(isfree(a,k), -mittag(a,1+k,x)); sum(x_^k_/gamma(k_+b_), k_):=if(isfree(b,k), -mittag(1,b+1+k,x)); sum(x_^k_/gamma(a_*k_+b_), k_):=if(isfree(a,b,k), -mittag(a,b+1+k,x)); sum(x_^k_/k_!/k_,k_):= -Ein(-x,k); sum(k_/k_!,k_) := -e*gamma(1,k)/gamma(k); sum(1/k_!,k_) := -e*gamma(1,k+1)/gamma(k+1); sum(x_^(a_*k_)/k_!,k_):=-mittag(1,k+2,x^a); sum(x_^(a_*k_)/(b_*k_)!,k_):=-mittag(b,k+2,x^a); sum((-1)^k*x_^k_/k_!,k_):= -mittag(1,k+2,-x); sum((-1)^k*x_^(a_*k_)/k_!,k_):=-mittag(1,k+2,-x^a); sum((-1)^k_/k_!/k_*x_^k_,k_):= -Ein(x,k); sum(sin(x_)^2,x_):= x/2+csc(1)*sin(1-2x)/4; sum(cos(x_)^2,x_):= x/2-csc(1)*sin(1-2x)/4; sum(sin(a_*x_)^2,x_):= x/2+csc(a)*sin(a-2a*x)/4; sum(cos(a_*x_)^2,x_):= x/2-csc(a)*sin(a-2a*x)/4; sum(sin(x_),x_):= -csc(1/2)*cos(x-1/2)/2; sum(cos(x_),x_):=cot(1/2)*sin(x)/2-cos(x)/2; sum(sinh(x_),x_):=csch(1/2)*cosh(x-1/2)/2; sum(cosh(x_),x_):=coth(1/2)*sinh(x)/2-cosh(x)/2; sum(sin(a_*x_),x_):= -csc(a/2)*cos(a*x-a/2)/2; sum(cos(a_*x_),x_):=cot(a/2)*sin(a*x)/2-cos(a*x)/2; sum(sinh(a_*x_),x_):=csch(a/2)*cosh(a/2-a*x)/2; sum(cosh(a_*x_),x_):=coth(a/2)*sinh(a*x)/2-cosh(a*x)/2; sum(log(a_*x_),x):=If(isfree(a,x), log(a^(x-1)*gamma(x))); sum(log(x_),x_) :=loggamma(x); #sum(exp(x_),x_):=exp(x+1)/(e-1); sum(x_,x_) := (x^2+x)/2; sum(y_) := sum(y,k);