expand(x_,y_):=(expand(x),expand(y)); expand((a_*b_)^n_):=a^n*b^n; #expand(b_^(n_+m_)):=b^n*b^m; expand(a_ and b_) := expand(a) and expand(b); expand(a_+b_) := expand(a)+expand(b); expand(a_-b_) := expand(a)-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 and isinteger(n), expand(sum(binomial(n,k)*a^(n-k)*b^k, k,0,n,1))); 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_^2/(c_+x_)):= c^2/(c+x)-c+x; expand(x_^2/(c_-x_)):= c^2/(c-x)-c-x; expand(x_^n_/(c_+x_^n_)):= 1-c/(c+x^n); 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(sqrt(a_*b_)):=sqrt(a)*sqrt(b); expand(e^(x_)):= e^(expand(x)); expand(e^(a_+b_)):=exp(a)*exp(b); expand(log(a_*b_)):=log(a)+log(b); expand(log(a_^b_)):= b*log(a); expand(infsum1s(y_,k_)) := sum(y,k,1,4,1); expand(infsums(y_,k_)) := sum(y,k,0,3,1); expand(infsums(y_,k_),n_) := sum(y,k,0,n,1); expand(sums(y_,k_,0,n_)):= sum(y,k,0,if(n==inf,3,n),1); expand(sums(y_,k_,1,n_)):= sum(y,k,1,if(n==inf,4,n),1); expand(Gamma(n_,a_,x_)) :=Gamma(n,a)-Gamma(n,x); expand(Gamma(n_,x_)) := If(n >=0.5, (n-1)*expand(Gamma(n-1,x))+x^(n-1)*e^(-x), If(n <= -0.5, (expand(Gamma(n+1,x))-x^n*e^(-x))/n) ); expand(En(n_,x_)) := If(n>=0.5, (1-n)*expand(En(n-1,x))+x^(n-1)*e^x, If(n<= -0.5, (-expand(En(n+1,x))+x^n*e^x)/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) ));