# difference(f) is backward difference f(x)-f(x-1); difference(a_+b_,x_) := difference(a,x)+difference(b,x); difference(a_*b_,x_) := If(isfree(a,x), a*difference(b,x)); difference(sum(y_,x_),x_) := y; difference(mittag(a_,k_,x_),k_):=If(isfree(a,k), -x^k/(a*k-2)! ); difference(mittag(a_,b_+k_,x_),k_):=If(isfree(a,b,k), -x^k/(b+a*k-2)! ); difference(Phi(x_,p_,k_),k_):=If(isfree(a,k), -x^k/(k-1)^p); difference(Phi(x_,p_,a_+k_),k_):=If(isfree(a,k), -x^k/(a+k-1)^p); difference(L(x_,1,k_),k_):= -x^k/k; difference(L(x_,1,c_+k_),k_):= -x^k/(c-1+k); difference(harmonic(c_+x_),x_) := if(isfree(c,x),1/(c+x)); difference(harmonic(r_,c_+x_),x_) := if(isfree(c,r,x),1/(c+x)^r); difference(harmonic(r_,x_),x_) := if(isfree(r,x),1/x^r); difference(harmonic(x_),x_) := 1/x; difference(psi(x_),x_) := 1/x; difference(gamma(x_),x_) := x*gamma(x-1)-gamma(x-1); difference(sin(x_),x_) := sin(1/2)*cos(x+1/2)/2; difference(cos(x_),x_) := -sin(1/2)*sin(x+1/2)/2; difference(tan(x_),x_) := sin(1)/cos(x+1)/cos(x); difference(cot(x_),x_) := -sin(1)/sin(x+1)/sin(x); difference(exp(x_),x_) := (exp(1)-1)*exp(x); difference(a_^x_,x_) := if(a==e, (exp(1)-1)*e^(x), If(isfree(a,x),(a-1)*a^x )); difference(a_^(b_*x_),x_) := If(isfree(a,x),(a^b-1)*a^(b*x)); difference(a_^(b_+x_),x_) := if(a==e, (exp(1)-1)*e^(b+x), If(isfree(a,x),(a-1)*a^(b+x) )); difference(x_^n_,x_) := If(n>1, -sum((-1)^kk*combination(n,kk)*x^(n-kk),kk,1,n,1)); difference(x_,x_) := 1; difference(y_):= difference(y,k);