expand(a_,x_,y_):=(expand(a), expand(x),expand(y)); expand(x_,y_):=(expand(x),expand(y)); expand(a_ and b_) := expand(a) and expand(b); #expand(a_/b_) := expand(a)/expand(b); expand(a_=b_) := expand(a)=expand(b); expand(x_=(a_ and b_)) := expand((x-a)*(x-b))=0; expand(x_b_) := expand((x-a)*(x-b))>0; expand(x_<=a_ and x>=b_) := expand((x-a)*(x-b))>=0; expand(a_0,eta(x)- sum((-1)^k/(k)^x,k,1,abs(a)-1) ); expand(zeta(x_,a_)) := if(a>0,zeta(x)-sum(1/k^x,k,1,a-1), if(a<0,zeta(x)+sum(1/(k)^x,k,a+1,-1) )); expand(eta(x_,a_,b_)) := simplify(toseries(eta(x,a,b))); expand(zeta(x_,a_,b_)) := simplify(toseries(zeta(x,a,b))); expand(bernoulli(n_,x_) ) := simplify(toseries(bernoulli(n,x))); expand(harmonic(n_,a_,b_)) :=if(a==1 and not(isconstant(b)),harmonic(n,b), sum(1/k^n,k,a,b) ); #expand(H(n_,a_,b_)):=H(n,b)-H(n,a-1); expand(harmonic(n_,x_)) := if(n>0,sum(1/k^x,k,1,n) ); expand(harmonic(-5,x_)) := (-1/12)*x^2+5/12*x^4+1/2*x^5+1/6*x^6; expand(harmonic(-4,x_)) := (-1/30)*x+1/3*x^3+1/2*x^4+1/5*x^5; expand(harmonic(-3,x_)) := x^4/4+x^3/2+x^2/4; expand(harmonic(-2,x_)) := x^3/3+x^2/2+x/6; expand(harmonic(-1,x_)) := (x^2+x)/2; #expand(hermite(n_,x_)) :=if(n>1, expand(2x*hermite(n-1,x)-2*(n-1)*hermite(n-2,x)) ); expand(hermite(n_,x_)) :=if(n>0, expand(2x*hermite(n-1,x)-2*(n-1)*hermite(n-2,x)), if(n<0, expand(2x*hermite(n+1,x)-2*(n+1)*hermite(n+2,x)) )); #expand(sinh(a_)^n_):= If(n>0 and isodd(n), expand(sum(binomial(n,k)*(-1)^(n+k+1)*sinh((n-2k)*a), k,0,(n-1)/2,1)/(2^(n-1))), If(n>0 and iseven(n), expand(sum(binomial(n,k)*cosh((n-2k)*a)+(-1)^(n/2+k)*binomial(n,n/2)/2, k,0,n/2-1,1)/(2^(n-1))))); #expand(cosh(a_)^n_):= If(n>0 and isodd(n), expand(sum(binomial(n,k)*cosh((n-2k)*a), k,0,(n-1)/2,1)/(2^(n-1))), If(n>0 and iseven(n), expand(sum(binomial(n,k)*cosh((n-2k)*a)+binomial(n,n/2)/2, k,0,n/2-1,1)/(2^(n-1))))); expand(sin(a_)^n_):= If(n>0 and isodd(n), expand(sum(binomial(n,k)*(-1)^(n+k)*sin((n-2k)*a), k,0,(n-1)/2,1)/(2^(n-1))), If(n>0 and iseven(n), expand(sum((-1)^(n/2+k)*binomial(n,k)*cos((n-2k)*a)+binomial(n,n/2)/2, k,0,n/2-1,1)/(2^(n-1))))); expand(cos(a_)^n_):= If(n>0 and isodd(n), expand(sum(binomial(n,k)*cos((n-2k)*a), k,0,(n-1)/2,1)/(2^(n-1))), If(n>0 and iseven(n), expand(sum(binomial(n,k)*cos((n-2k)*a)+binomial(n,n/2)/2, k,0,n/2-1,1)/(2^(n-1))))); expand(sin(x_)^2) := 1/2-cos(2x)/2; expand(sin(x_)^3) := 3*sin(2x)/4-sin(3x)/4; expand(sin(x_)^4) := 3/8-cos(2x)/2+cos(4x)/8; expand(cos(x_)^2) := 1/2+cos(2x)/2; expand(cos(x_)^3) := 3*cos(x)/4+ cos(3x)/4; expand(cos(x_)^4) := 3/8+cos(2x)/2+cos(4x)/8; expand(sin(a_)*sin(b_)):= cos(a-b)/2-cos(a+b)/2; expand(cos(a_)*cos(b_)):= cos(a-b)/2+cos(a+b)/2; expand(sin(a_)*cos(b_)):= sin(a-b)/2+sin(a+b)/2; expand(sin(a_)*cos(b_)*exp_):= exp*sin(a-b)/2+exp*sin(a+b)/2; expand(sinc(x_)):=sin(x)/x; expand(log(a_*b_)):=log(a)+log(b); expand(log(a_^b_)):= b*log(a); expand(En(n_,x_)) :=expand( expand(Gamma(1-n,x))*x^(-1+n)); expand(polylog(n_,x_)) := If(n>=1, -n*expand(polylog(n-1,x))+ln(x)^n*x, If(n<-1, (-expand(polylog(n+1,x))+ln(x)^(n+1)*x)/(n+1) )); expand(Gamma(n_,x_)) := If(n >1, (n-1)*expand(Gamma(n-1,x))+x^(n-1)*exp(-x), If(n <= -1, (expand(Gamma(n+1,x))-x^n*exp(-x))/n) ); expand((a_*b_)^n_):=a^n*b^n; #expand(b_^(n_+m_)):=b^n*b^m; expand((a_+b_)^n_):= If(n>0 and isinteger(n), expand(sum(binomial(n,k)*a^(n-k)*b^k, k,0,n,1))); expand(sqrt(a_*b_)):=sqrt(a)*sqrt(b); expand((a_+b_)*c_) := expand(a*c+b*c); expand(a_*(b_+c_)) := expand(a*b+a*c); expand((a_+b_)*(c_+d_)):= expand(a*c+b*c+a*d+b*d); expand(a_*(b_+c_)*d_) := expand(a*b*d+a*c*d); expand(1/(c_+x_^2)):= If(c==x, 1/x-1/(x+1), if(c<0, 1/2/((x-sqrt(-c))*sqrt(-c))-1/2/((sqrt(-c)+x)*sqrt(-c)) )); expand(1/(c_-x_^2)):= If(c==x, 1/x+1/(1-x), if(c>0, 1/2/((x+sqrt(c))*sqrt(c))-1/2/((sqrt(c)-x)*sqrt(c)) )); expand(x_/(c_+x_)):= 1-c/(c+x); expand(x_/(c_-x_)):= -1+c/(c-x); expand(-x_/(c_+x_)):= -1+c/(c+x); expand(-x_/(c_-x_)):= 1-c/(c-x); expand(x_^n_/(c_+x_^n_)):= 1/(1+c/x^n); expand(1/x_*1/(a_+b_*x_)):= 1/(a* x) - b/(a *a + a*b *x); expand(x_^2/(c_+x_)):=x+c^2/(c+x)-c;