# sum(y,k,a,b,c) 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_,j_,a_,b_) := If(isfree(y,j), y*b-y*a+y, If(isnumber(b) and b<>inf, block(sum:=0, For(j,a,b,1,sum:=sum+y), sum) )); 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(a_*b_*c_,x_,a_,b_) := If(isfree(a,x), a*sum(b*c,x,a,b)); sum(x_^k_,k_,a_,b_) := if(hasnot(x,k),(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))/(exp(1)-1); #sum(e^(-x_),x_,a_,b_) := (exp(1-a)-exp(-b))/(exp(1)-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(e^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((-1)^k_*x_^(2k_+1)/(2k_+1)! ,k_,0,inf):= sin(x); sum((-1)^k_*x_^(2k_)/(2k_)!,k_,0,inf):= cos(x); sum(k_*x^(2k_+1)/((2k_+1)!!),k_,0,inf):= tan(x); sum((2k_-1)!!/(2k_)!!/(2k_+1)*x_^(2k_+1),k_,0,inf):=asin(x); sum((-1)^k_*x_^(2k_+1)*1/(2k_+1),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((-1)^k_*(2k_-1)!!/((2k_)!!*(2k_+1))*x_^(2k_+1),k_,0,oo):=asinh(x); sum(x_^(2k_+1)/(2k_+1),k_,0,inf):=atanh(x); sum(x_^k_,k_,0,inf):= if(abs(x)>=1, inf, if(isfree(x,k),1/(1-x) )); sum(b_^k_*k_,k_,1,inf):= if(abs(b)>=1, inf, if(isfree(b,k),b/(1-b)^2 )); sum(x_^(-k_),k_,0,inf):= if(abs(x)<1, inf, if(isfree(x,k),x/(x-1) )); sum(b_^(-k_)*k_,k_,1,inf):= if(abs(b)<1, inf, if(isfree(b,k),b/(b-1)^2 )); sum(x_^k_/k_,k_,1,inf):= when(abs(x)<1, -log(1-x)); sum((-1)^k_*x_^k_/k_,k_,1,inf):= when(abs(x)<1, -log(1+x)); sum(x_^k_/k_!,k_,0,inf):= exp(x); sum(a_^k_*x_^k_/k_!,k_,0,inf):= exp(a*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), oo); #sum(exp(-k_*x_),k_,0,inf):=1/(exp(x)-1); #sum(e^(-x_),x_,0,inf) := e/(exp(1)-1); #sum(exp(-x_),x_,0,inf) := e/(exp(1)-1); sum(x_*e^(-x_),x_,0,inf) := e/(exp(1)-1)^2; #sum(1/k_!,k_,1,inf) := exp(1)-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(f(1+x_)-f(x_),x_):=f(x); sum(a_*x_^(b_*k_),k_):=replace(sum(a*x^k,k),x,x^b); sum(a_*x_^(b_+k_),k_):=sum(a*x^k,k)*x^b; sum((-1)^k_*a_*x_^k_,k_):=replace(sum(a*x^k,k),x,-x); sum(b_^k_*k_,k_):= when(abs(b)<1,b/(1-b)^2*GammaQ(k+1,b)); sum(b_^(-k_)*k_,k_):= when(abs(b)>1,b/(1-b)^2*GammaQ(k+1,b)); sum(x_^(2k_)/(2k_+1),k_):=atanh(x)*GammaQ(k+1,x)/x; sum(x_^(2k_+1)/(2k_+1),k_):=atanh(x)*GammaQ(k+1,x); sum((-1)^k_*x_^(2k_)/(2k_+1),k_):=atan(x)*GammaQ(k+1,x)/x; sum((-1)^k_*x_^(2k_+1)/(2k_+1),k_):=atan(x)*GammaQ(k+1,x); sum(a_^k_,k_):=if(a==e, exp(k)/(exp(1)-1), If(isfree(a,k), a^(k)/(a-1) )); sum(a_^(b_+k_),k_):=if(a==e, exp(b+k)/(exp(1)-1), If(isfree(a,k), a^(b+k)/(a-1) )); sum(a_^(b_*k_),k_):=if(a==e, exp(b*k-1)/(exp(b)-1), If(isfree(a,k), a^(b*k-1)/(a^b-1) )); sum(k_^a_, k_) :=If(isfree(a,k), harmonic(-a,k)); sum((c_+k_)^a_, k_) :=If(isfree(a,c,k), harmonic(-a,c+k)); sum((z_+k_)^a_, k_) :=If(isfree(a,z,k), harmonic(-a,z+k)); sum((c_+d_*k_)^a_, k_) :=If(isfree(a,c,k), d^a*harmonic(-a,c/d+k)); 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_):= -L(x,-p,1+k); sum((a_+k_)^p_*x_^k_,k_):= -L(x,-p,1+a+k)*x^(k+1); sum((z_+k_)^p_*x_^k_,k_):= -L(x,-p,1+z+k)*x^(k+1); sum((a_+b_*k_)^p_*x_^k_,k_):= -L(x,-p,1+a/b+k)*x^(k+1)*b^p; sum((m_+b_*k_)^p_*x_^k_,k_):= -L(x,-p,1+m/b+k)*x^(k+1)*b^p; sum(1/k_/(2k_-1),k_):= -1/(k+1); sum(1/k_/(2k_+1),k_):= -1/(k+1); sum(1/k_!,k_) := e*GammaQ(k+1); sum(1/(a_+k_)!,k_) := e*GammaQ(a+k+1); sum(1/(a_*k_)!,k_) := -mittag(a,k+2,1); sum(1/(a_*k_+b_)!,k_) := -mittag(a,k+2+b,1); sum(k_/k_!,k_) := e*GammaQ(k+1); #sum(k_/k_!,k_) := -mittag(1,k+2,1); sum(x_^k_/(2k_)!!,k_):= exp(x/2)*GammaQ(k+1,x/2); sum(x_^k_/k_!,k_):= -mittag(1,k+2,x)*x^(k+1); 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(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((-1)^k_/k_*x_^k_,k_):= -log(1+x)*GammaQ(k,x); #sum((-1)^k_/k_!*x_^k_,k_):= exp(-x)*GammaQ(k+1,-x); sum(k_^k_,k_):= k*GammaQ(k); sum(k_^(-k_),k_):= Sophomore(1,1)*GammaQ(k); sum((-1)^k_*k_^(-k_),k_):= Sophomore(1)*GammaQ(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+1); #sum(e^x_,x_):=exp(x+1)/(e-1); sum(x_,x_) := (x^2+x)/2; sum(y_) := sum(y,k);