# d(y,x,x0, n) is a function to differentiate y with x for n order at x=x0; d(y_, x_=x0_, n_) := d(y,x,x0,n); d(a_+b_,x_,n_):=d(a,x,n)+d(b,x,n); d(a_=b_,x_,n_):=d(a,x,n)=d(b,x,n); d(-y_,x_,n_):= -d(y,x,n); d(ds(y_,x_,n_),x_,m_) := ds(y,x,n+m); d(d(y_,x_,n_),x_,m_) := d(y,x,n+m); d(d(y_,x_),x_,n_) := d(y,x,n+1); d(d(y_,x_,n_),x_) := d(y,x,n+1); d(d(y_,x_),x_) := d(y,x,2); d(a_*x_^m_,x_,n_):= If(isfree(a,x), a*d(x^m,x,n), If(n>0 and isinteger(n), sum(binomial(n,r)*fallingfactorial(m,r)*d(a,x,n-r)*x^(m-r), r,0,n), If(m>0 and (n>0 or isinteger(m)), sum(binomial(n,r)*fallingfactorial(m,r)*d(a,x,n-r)*x^(m-r), r,0,ceil(abs(m))) ))); d(x_^m_*y_,x_,n_):= If(isfree(y,x), y*d(x^m,x,n), If(n>0 and isinteger(n), sum(binomial(n,r)*fallingfactorial(m,r)*d(y,x,n-r)*x^(m-r), r,0,n), If(m>0 and (n>0 or isinteger(m)), sum(binomial(n,r)*fallingfactorial(m,r)*d(y,x,n-r)*x^(m-r), r,0,ceil(abs(m))) ))); d(a_*(c_+x_)^m_,x_,n_):= If(isfree(a,c,x), a*d((c+x)^m,x,n), If(n>0 and isinteger(n), sum(binomial(n,r)*fallingfactorial(m,r)*d(a,x,n-r)*(c+x)^(m-r), r,0,n), If(m>0 and (n>0 or isinteger(m)), sum(binomial(n,r)*fallingfactorial(m,r)*d(a,x,n-r)*(c+x)^(m-r), r,0,ceil(abs(m))) ))); d((c_+x_)^m_*y_,x_,n_):= If(isfree(y,c,x), y*d((c+x)^m,x,n), If(n>0 and isinteger(n), sum(binomial(n,r)*fallingfactorial(m,r)*d(y,x,n-r)*(c+x)^(m-r), r,0,n), If(m>0 and (n>0 or isinteger(m)), sum(binomial(n,r)*fallingfactorial(m,r)*d(y,x,n-r)*(c+x)^(m-r), r,0,ceil(abs(m))) ))); d(x_*y_,x_,n_):=If(isfree(y,x),If(n>1,0), If(n> -1,x*d(y,x,n)+n*d(y,x,n-1) )); d(a_*x_,x_,n_):=If(isfree(a,x),If(n>1,0), x*d(a,x,n)+n*d(a,x,n-1)); d(a_^x_,x_,n_):= If(isfree(a,x), log(a)^n*a^x); d(c_^(a_*x_),x_,n_) := If(isfree(c,a,x),(a*log(c))^n*c^(a*x)); d(c_^(x_+b_),x_,n_) := If(isfree(c,b,x), log(c)^n*c^(x+b)); d(c_^(b_+a_*x_),x_,n_) := If(isfree(c,b,a,x), (a*log(c))^n*c^(a*x+b)); d(e^f_*y_,x_,p_):= If(p<=0 and p>= -1 and isfree(y*d(f,x)^p,x), e^f*y*d(f,x)^p, If(p>=0 and p<=1 and f<>x, d(f,x)^p*replace(d(e^x*y,x,p),e^x,e^f) )); #d(e^f_*y_,x_,p_):= If(p<=0 and p>= -1 and isfree(y*d(f,x)^p,x), e^f*y*d(f,x)^p); d(e^(a_+x_)*y_,x_,p_):= e^a*d(e^x*y,x,p); d(e^(x_^m_)*x_,x_,n_):=If(n>= -1 and n<0 and m*n==(n-1), exp(x^m)*m^n); d(e^(-x_^m_)*x_,x_,n_):=If(n>= -1 and n<0 and m*n==(n-1), exp(-x^m)*(-m)^n); d(e^f_,x_,p_):= If(p>=0 and p<=1, d(f,x)^p*e^f); d(e^x_,x_,n_) := e^x; d(e^(a_*x_),x_,n_) := If(isfree(a,x), a^n*e^(a*x)); d(e^(x_+b_),x_,n_) := If(isfree(b,x), e^(x+b)); d(e^(b_+a_*x_),x_,n_) := If(isfree(b,a,x), a^n*e^(a*x+b)); #d(x_^m_,x_,n_) := If(isfree(m,x), If(m<0 and isinteger(m) and (m>=n or n=n or n0, atan(1+n,x/sqrt(k))/sqrt(k), atanh(1+n,x/sqrt(-k))/sqrt(-k) )); d(1/(k_-x_^2),x_,n_) := If(isfree(k,x), If(k<0, -atan(1+n,x/sqrt(-k))/sqrt(-k), -atanh(1+n,x/sqrt(k))/sqrt(k) )); d(x_*log(x_),x_,n_) := If(n>1, (-1)^n*(n-2)!*x^(1-n), (psi(2)-psi(2-n)+log(x))/gamma(2-n)*x^(1-n)); d(x_^m_*log(x_),x_,n_) := If(n>= -1 and n<=0, If(n==m, -(-1)^n*(m+1)^(-2)*log(x)^(1-m), If(m== -1, 1/2*d(log(x)^2,x,n+1), -(m+1)^(-2)*gamma(1-n, (-m+n)*log(x)) )), -(m+1)^(-2)*gamma(1+n,2, (-m-1)*log(x))); #d(x_^m_*log(x_),x_,n_) := If(n>= -1 and n<=0, If(n==m,log(x)^(1-m), If(m== -1, 1/2*d(log(x)^2,x,n+1), -(m+1)^(-2)*gamma(1-n, (-m+n)*log(x)) )), If(isinteger(n-m) and n>m, -(-1)^(n-m)*(n-m-1)!*gamma(1+m)*x^(m-n), If(m> -1, fallingfactorial(m,n)*(psi(1+m)-psi(1+m-n)+log(x))*x^(m-n), If(m< -1, fallingfactorial(m,n)*(psi(abs(m))-psi(abs(m-n))+log(x))*x^(m-n) )))); d(log(x_)^m_,x_,p_):= If(abs(m)==abs(p), (-1)^(-m)*gamma(p+1, m+1, -log(x)), If(p>= -1 and p<=0, (-1)^(-m)*gamma(m-p, p*log(x)) )); d(log(x_+c_)^m_,x_,p_):= If(isfree(c,x) and p>= -1 and p<=0, (-1)^(-m)*gamma(m-p, p*log(x+c))); d(x_^n_*log(x_)^m_,x_,p_):= If(p>= -1 and p<=0, If(n==-1, 1/(m+1)*d(log(x)^(m+1),x,p+1), If(n==p, (-1)^(m-p)*(-n-1)^(-m)/(n+1)*log(x)^(m-p), (-n-1)^(-m)/(n+1)*gamma(m-p, (-n+p)*log(x)) )), (-n-1)^(-m)/(n+1)*gamma(1+p,m+1, (-n-1)*log(x)) ); #d(x_^n_*log(x_)^m_,x_,p_):= If(p>= -1 and p<=0, If(n==-1, 1/(m+1)*d(log(x)^(m+1),x,p+1), If(n==p, (-1)^(-m)*(-n-1)^(-m)/(n+1)*log(x)^(m-p), 1/(1+n)*d(gamma(m+1, (-n-1)*log(x)),x,p+1) ))); d(e^x_*x_^m_,x_,n_):= If(n>0 and isinteger(n), exp(x)*sum(binomial(n,r)*fallingfactorial(m,r)*x^(m-r), r,0,n), If(m>0 and n>0 and isinteger(m), exp(x)*sum(binomial(n,r)*fallingfactorial(m,r)*x^(m-r), r,0,m), If(m== -1, -ei(-n,-x), (-1)^(-m)*gamma(n+1,m+1,-x) ))); d(e^(a_*x_)*x_^m_,x_,n_):= If(isfree(m,a,x), If(n>0 and isinteger(n), exp(a*x)*sum(a^(n-r)*binomial(n,r)*fallingfactorial(m,r)*x^(m-r), r,0,n), If(m>0 and n>0 and isinteger(m), exp(a*x)*sum(a^(n-r)*binomial(n,r)*fallingfactorial(m,r)*x^(m-r), r,0,m), If(m== -1, (a)^(-n)*ei(-n,-a*x), (-a)^(-m)*gamma(n+1,m+1, -a*x) )))); d(e^(c_+a_*x_)*x_^m_,x_,n_):= If(isfree(m,c,a,x), If(n>0 and isinteger(n), exp(c+a*x)*sum(a^(n-r)*binomial(n,r)*fallingfactorial(m,r)*x^(m-r), r,0,n), If(m>0 and (n>0 or isinteger(m)), exp(c+a*x)*sum(a^(n-r)*binomial(n,r)*fallingfactorial(m,r)*x^(m-r), r,0,m), If(m== -1, exp(c)*(a)^(-n)*ei(-n,-a*x), exp(c)*(-a)^(-m)*gamma(n+1,m+1, -a*x) )))); d(e^x_*(c_+x_)^m_,x_,n_):= If(isfree(c,m,x), If(n>0 and isinteger(n), exp(x)*sum(binomial(n,r)*fallingfactorial(m,r)*(c+x)^(m-r), r,0,n), If(m>0 and n>0 and isinteger(m), exp(x)*sum(binomial(n,r)*fallingfactorial(m,r)*(c+x)^(m-r), r,0,m), If(m== -1, -1/e^c*ei(-n,-c-x), (-1)^(-m)/e^c*gamma(n+1,m+1, -c-x) )))); d(x_^m_*sin(x_),x_,p_):= If(m<0, si(1+m-p,x), sum(binomial(p,r)*fallingfactorial(m,r)*x^(m-r)*sin(x+(p-r)*pi/2), r,0,m,1)); d(x_^m_*cos(x_),x_,p_):= If(m<0, ci(1+m-p,x),sum(binomial(p,r)*fallingfactorial(m,r)*x^(m-r)*cos(x+(p-r)*pi/2), r,0,m,1)); d(x_^m_*sinh(x_),x_,p_):= If(m<0, shi(1+m-p,x),sum(binomial(p,r)*fallingfactorial(m,r)*x^(m-r)*(exp(x)-(-1)^(p-r)*exp(-x))/2, r,0,m,1)); d(x_^m_*cosh(x_),x_,p_):= If(m<0, chi(1+m-p,x),sum(binomial(p,r)*fallingfactorial(m,r)*x^(m-r)*(exp(x)+(-1)^(p-r)*exp(-x))/2, r,0,m,1)); d(e^(x_^m_),x_,p_):= If(p>= -1 and p<=0, (-1)^(p/m-p)*m^p*gamma(1+p-p/m, -x^m), If(p>=0 and p<=1, (m*x^(m-1))^p*e^(x^m) )); d(e^(a_*x_^m_),x_,p_):= If(p>= -1 and p<=0, (-a)^(p/m-p)*(a*m)^p*gamma(1+p-p/m, -a*x^m), If(p>=0 and p<=1, (a*m*x^(m-1))^p*e^(a*x^m) )); #d(e^(x_^m_)*x_^n_,x_,p_):= If(p>= -1 and p<0, If(n==p*(1-m), exp(x^m)*m^p, -(-1)^((n-p)/(p*m))*m^p*gamma((n-p)/(-p*m),-x^m) )); d(e^(x_^m_)*x_^n_,x_,p_):= If(p>= -1 and p<0 and n==p*(1-m), exp(x^m)*m^p, -(-1)^((-1-n)/m)/m*gamma(p+1,(n+1)/m,-x^m) ); d(e^(a_*x_^m_)*x_^n_,x_,p_):= If(isfree(a,x), If(p>= -1 and p<0 and n==p*(1-m), exp(a*x^m)*(a*m)^p, -(-a)^((-1-n)/m)/m*gamma(p+1,(1+n)/m, -a*x^m) )); d(x_^d_*mittag(a_,b_,x_^a_),x_,a2_) := If(d==b-1, If(a2==a,x^(b-a-1)/gamma(b-a)+x^d*mittag(a,b,x^a),If(a2== -a,x^(a+b-1)*mittag(a,a+b,x^a),x^(d-n)*mittag(a,b-n,x^a) ))); d(x_^d_*mittag(a_,b_,c_*x_^a_),x_,a2_) := If(isfree(c,x) and d==b-1, If(a2==a,x^(b-a-1)/gamma(b-a)+c*x^d*mittag(a,b,c*x^a), If(a2== -a,x^(a+b-1)*mittag(a,a+b,c*x^a),c*x^(d-n)*mittag(a,b-n,c*x^a) ))); d(mittag(a_,a_,c_*x_^a2_),x_,a_) := If(isfree(c,x) and a2== -a, c*x^(-2a)*mittag(a,a,c*x^a2) ); d(mittag(a_,a_,x_^a2_),x_,a_) := If( a2== -a, x^(-2a)*mittag(a,a,x^a2) ); d(mittag(a_,b_,x_^a_),x_,a_) := 1/x^a/gamma(b-a)+mittag(a,b,x^a); d(mittag(a_,b_,c_*x_^a_),x_,a_) := If(isfree(c,x), 1/x^a/gamma(b-a)+c*mittag(a,b,c*x^a) ); d(mittag(p_,f_),x_,p_):= d(f,x,p)*mittag(p,f) ; d(k_*mittag(p_,f_),x_, p2_):= If(p2==-p and isfree(d(f,x,p)/k,x), mittag(p,f)/(d(f,x,p)/k)) ; d(mittag(a_,x_^a_),x_,a2_) := If(a2==a, a!*mittag(a,x^a), If(a2== -a, mittag(a,x^a)/a! )); d(mittag(a_,c_*x_^a_),x_,a2_) := If(isfree(c,x),If(a2== -a, mittag(a,c*x^a)/c/a!, a!*c*mittag(a,c*x^a) )); #d(mittag(a_,c_*x_^a_),x_,a_) := If(isfree(c,x), c*mittag(a,c*x^a) ); d(gamma(n_,a_*log(x_)),x_,p_) := If(a+p<>0 and ((p> -1 and p<=0) or n==p), gamma(n-p, (a+p)*log(x)) ); d(gamma(n_,a_*log(c_+x_)),x_,p_) := If(a+p<>0 and ((p> -1 and p<=0) or n==p), gamma(n-p, (a+p)*log(c+x)) ); d(gamma(n_,log(x_)),x_,p_) := If(p> -1 and p<=0, gamma(n-p, (1+p)*log(x)), If(p>=0 and p<=1, (-1)^(n-p)*x^(-1-p)*log(x)^(n-p) )); #d(gamma(n_,a_*log(x_)),x_,p_) := If(p>= -1 and p<=0, d(log(x)^n/n+x^(-p)*gamma(n, a*log(x)),x,1+p), If(p>=0 and p<=1, fallingfactorial(n,p)*(-a^n)*x^(-p-a)*log(x)^(n-p)/n )); #d(gamma(n_,log(x_)),x_,p_) := If(p>= -1 and p<=0, d(log(x)^n/n+x^(-p)*gamma(n, log(x)),x,1+p), If(p>=0 and p<=1, (-1)^p*x^(-2p)*log(x)^(n-p) )); #d(gamma(n_,x_^m_),x_,p_):= If(p>= -1 and p<=0, (-m)^p*gamma(n+p-p/m,x^m) ); #d(gamma(n_,a_*x_^m_),x_,p_):= If(p>0 and p<=1 and isfree(a,x) and n+p-p/m==1, (a)^(p/m-p)*(-a*m)^p*e^(-a*x^m) ); #d(gamma(m_, x_), x_,p_) := If(p> -1 and p<=0, (-1)^(-p)*gamma(m-p,x), If( p>0 and p<=1, If(m<0, (-1)^(-p)*x^(m-p)*exp(-x), sum((-1)^(p+r)*binomial(p,r)*fallingfactorial(m-1,r)*gamma(m-r,x), r,0,ceil(abs(m-1))) ))); #d(gamma(m_, x_), x_,p_) := If(p> -1 and p<=0, (-1)^(-p)*gamma(m-p,x) ); d(gamma(b_,m_, y_), x_,p_) := If(b+p==1, d(gamma(m,y),x),gamma(b+p,m,y) ); d(gamma(a_,m_, x_), x_,p_) := gamma(a+p,m,x); d(gamma(a_,m_, x_), x_) := gamma(a+1,m,x); d(gamma(m_, x_), x_,p_) := gamma(p,m,x); d(gamma(x_), x_,p_) :=factorial(p,x-1); d(factorial(m_,xx_), x_,p_) :=factorial(m+p,xx); d(factorial(m_,xx_), x_) :=factorial(m+1,xx); d(factorial(xx_), x_,p_) :=factorial(p,xx); d(factorial(xx_), x_) :=factorial(1,xx); d(si(xx_), x_,p_) := si(p,xx); d(ci(xx_), x_,p_) := ci(p,xx); d(si(m_,xx_), x_,p_) := si(m+p,xx); d(ci(m_,xx_), x_,p_) := ci(m+p,xx); d(shi(xx_), x_,p_) := shi(p,xx); d(chi(xx_), x_,p_) := chi(p,xx); d(shi(m_,xx_), x_,p_) := shi(m+p,xx); d(chi(m_,xx_), x_,p_) := chi(m+p,xx); #d(zeta(x_),x_,p_):= gamma(p)*zeta(p,x); #d(zeta(m_,x_),x_,p_):= risingfactorial(m,p)*zeta(m+p,x); d(zeta(xx_),x_,p_):= zeta(p,xx); d(zeta(m_,xx_),x_,p_):= zeta(m+p,xx); d(li(x_),x_,p_):= -gamma(-p, (p-1)*log(x)); d(ei(xx_),x_,p_):= -ei(1-p, -xx); d(ei(m_, xx_), x_,p_) := (-1)^(-p)*ei(m-p,xx); #d(erf(x_),x_,p_):= If(abs(p)<= 1, -(-2)^p*gamma((p+1)/2,x^2)/sqrt(pi) ); d(erf(xx_), x_,p_) := erf(p,xx); d(erf(m_,xx_), x_,p_) := erf(m+p,xx); #d(erfi(x_),x_,p_):= If(abs(p)<= 1, (-2)^p*gamma((p+1)/2,-x^2)/sqrt(pi) ); d(erfi(xx_),x_,p_) := erfi(p,xx); d(erfi(m_,xx_), x_,p_) := erfi(m+p,xx); d(erfc(xx_),x_,p_) := erfc(-p,xx); d(erfc(m_,xx_), x_,p_) := erfc(m-p,xx); d(psi(xx_),x_,p_) := psi(p,xx); d(psi(m_,xx_), x_,p_) := psi(m+p,xx); d(loggamma(xx_),x_,p_) := psi(p-1,xx); d(sin(x_),x_,n_) := sin(x+n*pi/2); d(cos(x_),x_,n_) := cos(x+n*pi/2); #d(sinh(x_),x_,n_) := If(iseven(n), sinh(x), If(isodd(n), cosh(x), exp(x)/2-exp(-x)*(-1)^n/2)); d(sinh(xx_),x_,n_) :=sinh(n,xx); d(sinh(m_,xx_),x_,n_) :=sinh(m+n,xx); d(cosh(xx_),x_,n_) :=cosh(n,xx); d(cosh(m_,xx_),x_,n_) :=cosh(m+n,xx); #d(cosh(x_),x_,n_) := If(iseven(n), cosh(x), If(isodd(n), sinh(x), exp(x)/2+(-1)^n*exp(-x)/2)); d(abs(y_),x_,n_) := d(y,x,n)/sgn(y); d(abs(x_),x_,n_) := If(n>1,0, If(n<1, 1/sgn(x)/(-n)!*x^(1-n) )); d(sgn(y_),x_,n_) := If(n>0,0, If(n<0, 1/gamma(1-n)*sgn(y)*x^(-n) )); d(csgn(y_),x_,n_) := If(n>0,0, If(n<0, csgn(y)*x^(-n)/(-n)! )); d(delta(y_),x_,n_):=If(n>0,0, If(n<0, theta(y)*x^(-n)/(-n)! )); #d(log(x_),x_,n_):= If(n>0 and isinteger(n), -(-1)^n*(n-1)!/x^n, If(n>= -1 and n<=0, -gamma(1-n, n*log(x)), If(abs(n)<=1,(log(x)+psi(1)-psi(1-n))/gamma(1-n)/x^n ))); #d(log(x_),x_,n_):= If(n>0, If(isinteger(n), -(-1)^n*(n-1)!/x^n, log(n,x)), If(n>= -1 and n<=0, -gamma(1-n, n*log(x)) )); d(log(xx_),x_,n_):= log(n,xx); #d(log(a_*x_+b_),x_,n_):= If(isfree(a,b,x),If(n>0 and isinteger(n), -(-1)^n*(n-1)!/(x+b/a)^n,If(abs(n)<=1,(log(x+b/a)+psi(1)-psi(1-n))/gamma(1-n)/(x+b/a)^n ) )); d(exp(x_),x_,n_) := exp(x); d(asin(xx_),x_,n_):= asin(n,xx); d(acos(xx_),x_,n_):= acos(n,xx); d(atan(xx_),x_,n_):= atan(n,xx); d(asin(m_,xx_),x_,n_):= asin(n+m,xx); d(acos(m_,xx_),x_,n_):= acos(n+m,xx); d(atan(m_,xx_),x_,n_):= atan(n+m,xx); d(asinh(xx_),x_,n_):= asinh(n,xx); d(acosh(xx_),x_,n_):= acosh(n,xx); d(atanh(xx_),x_,n_):= atanh(n,xx); d(asinh(m_,xx_),x_,n_):= asinh(n+m,xx); d(acosh(m_,xx_),x_,n_):= acosh(n+m,xx); d(atanh(m_,xx_),x_,n_):= atanh(n+m,xx); #d(atanh(x_),x_,n_):= (psi(1)-psi(-n)+log(x+1))*(x+1)^(-n)/(-n)!/2+(psi(1)-psi(-n)+log(1-x))*(1-x)^(-n)/(-n)!/2; #d(acoth(x_),x_,n_):= (psi(1)-psi(-n)+log(x+1))*(x+1)^(-n)/(-n)!/2+(psi(1)-psi(-n)+log(1-x))*(1-x)^(-n)/(-n)!/2; #d(atan(x_),x_,n_):= (psi(1)-psi(-n)+log(x-i))*(x-i)^(-n)/(-n)!/2-(psi(1)-psi(-n)+log(i+x))*(i+x)^(-n)/(-n)!/2; #d(acot(x_),x_,n_):= (psi(1)-psi(-n)+log(x+i))*(x+i)^(-n)/(-n)!/2-(psi(1)-psi(-n)+log(x-i))*(x-i)^(-n)/(-n)!/2; d(sqrt(x_),x_, n_):= If(n==0.5, i/(-1.5)!*log(x), (1/2)!/(1/2-n)!*x^(1/2-n)); d(1/sqrt(x_),x_,n_):= If(n==-0.5, sqrt(pi)/2*log(x), (-1)^(-n)*gamma(n+1/2)/gamma(1/2)*x^(-1/2-n)); d(a_*b_*c_,x_,p_):=If(isfree(a,x), a*d(b*c,x,p), If(isfree(b,x), b*d(a*c,x,p) )); d(x_,x_,n_) := If(n>1, 0, x^(1-n)/(1-n)!); d(y_,x_,1) := d(y,x); d(y_,x_,0) := y; d(y_,xx_=a_) := block(p:=d(y,xx), replace(p,xx,a)); d(infsums(x_^k_/k_!,k_),x_,n_) := infsums(x^k/k!,k); d(infsums(x_^k_/k_!,k_),x_) := infsums(x^k/k!,k); d(infsums(x_^(2k_)/(2k_)!,k_),x_) := infsums(x^(2k+1)/(2k+1)!,k); d(infsums(x_^(1+2k_)*1/(1+2k_)!,k_),x_) := infsums(x^(2k)/(2k)!,k); d(infsums((-1)^k_*x_^(2k_)*1/(2k_)!,k_),x_) := -infsums((-1)^k*x^(2k+1)/(2k+1)!,k); d(infsums((-1)^k_*x_^(1+2k_)*1/(1+2k_)!,k_),x_) := infsums((-1)^k*x^(2k)/(2k)!,k); d(mittag(a_,b_, x_), x_) := (mittag(a,b-1,x)-(b-1)*mittag(a,b,x))/(a*x); d(mittag(a_,x_), x_) := mittag(a,0,x)/a/x; d(gamma(n_, x_), x_) := -x^(n-1)*exp(-x); #d(zeta(n_,xx_), x_) := n*zeta(1+n,xx); d(ei(n_, xx_), x_) := -ei(n-1,xx); #d(erf(n_, x_), x_) := n!/sqrt(pi)*exp(-x^n); d(li(n_,xx_), x_) := li(n-1,xx)/xx; d(log(n_,xx_), x_) := log(n+1,xx) ; d(log(n_,xx_), x_,p_) := log(n+p,xx) ; d(sin(n_,xx_), x_) := sin(1+n,xx); d(cos(n_,xx_), x_) := cos(1+n,xx); d(sin(n_,xx_), x_,p_) := sin(p+n,xx); d(cos(n_,xx_), x_,p_) := cos(p+n,xx); d(tan(n_,xx_), x_) := tan(1+n,xx); d(cot(n_,xx_), x_) := cot(1+n,xx); d(tan(n_,xx_), x_,p_) := tan(p+n,xx); d(cot(n_,xx_), x_,p_) := cot(p+n,xx); d(tan(xx_), x_,p_) := tan(p,xx); d(cot(xx_), x_,p_) := cot(p,xx); d(tanh(n_,xx_), x_,p_) := tanh(p+n,xx); d(tanh(xx_), x_,p_) := tanh(p,xx); d(atan(n_,xx_), x_) := atan(1+n,xx); d(sgn(y_),x_) := 0; d(csgn(y_),x_) := 0; d(theta(y_),x_) := 0; d(delta(y_),x_) := 0; d(e^(k_*x_),x_) := If(isfree(k,x),k*e^(k*x)); d(log10(x_),x_) := 1/x/log(10); d(atan2(x_,y_),y_) := y/(x^2+y^2); d(atan2(x_,y_),x_) := -y/(x^2+y^2); d(acot(x_),x_) := -1/(x^2+1); d(asec(x_),x_) := 1/(x*sqrt(1-x^2)); d(acsc(x_),x_) := -1/(x*sqrt(1+x^2)); d(tanh(x_),x_) := sech(x)^2; d(coth(x_),x_) := -csch(x)^2; d(sech(x_),x_) := -tanh(x)*sech(x); d(csch(x_),x_) := -coth(x)*csch(x); d(asin(x_),x_) := 1/(1-x^2)^(1/2); d(acos(x_),x_) := -1/sqrt(1-x^2); d(asinh(x_),x_) := 1/sqrt(x^2+1); d(acosh(x_),x_) := 1/sqrt(x^2-1); d(atanh(x_),x_) := 1/(1-x^2); d(acoth(x_),x_) := 1/(1-x^2); d(asech(x_),x_) := -1/(x*sqrt(1-x^2)); d(acsch(x_),x_) := -1/(x*sqrt(1+x^2)); d(gaussian(x_), x_) := -e^(-x^2/2)/sqrt(2pi)*x; d(erf(x_), x_) := 2/sqrt(pi)*exp(-x^2); d(erfi(x_), x_) := 2/sqrt(pi)*exp(x^2); d(gamma(x_), x_) := gamma(x)*psi(x); d(loggamma(x_), x_) := psi(x); #d(zeta(x_), x_) := -sums(log(k)/k^x,k,1,inf); #d(psi(x_), x_) := psi(1,x); d(factorial(x_), x_) := gamma(x+1)*psi(x+1); d(li(x_),x_) := 1/log(x); d(ei(x_),x_) := exp(x)/x; d(si(x_),x_) := sin(x)/x; d(ci(x_),x_) := cos(x)/x; d(shi(x_),x_) := sinh(x)/x; d(chi(x_),x_) := cosh(x)/x; d(sqrt(x_),x_):= 1/2*x^(-1/2); d(cbrt(x_),x_):= 1/3*x^(-2/3); d(integrate(y_,x_),x_) := y; d(integrate(y_,t_,a_,b_),x_) := If(not(isfree(a,x)), -replace(y,t,a)*d(a,x), If(not(isfree(b,x)), replace(y,t,b)*d(b,x) )); d(integrates(y_,t_,a_,b_),x_) := If(not(isfree(a,x)), -replace(y,t,a)*d(a,x), If(not(isfree(b,x)), replace(y,t,b)*d(b,x) )); d(y_):=d(y,x);