# 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_ and b_,x_,n_):=d(a,x,n) and 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(integrate(y_,x_),x_, p_) := d(y,x,p-1); d(a_*x_^m_,x_,n_):= If(isfree(a,x), a*d(x^m,x,n), If(isnatural(n), sum(binomial(n,k)*fallingfactorial(m,k)*d(a,x,n-k)*x^(m-k), k,0,n,1), If(m>0 and (n>0 or isinteger(m)), sum(binomial(n,k)*fallingfactorial(m,k)*d(a,x,n-k)*x^(m-k), k,0,ceil(abs(m)),1) ))); #d(x_^m_*y_,x_,n_):= If(isfree(y,x), y*d(x^m,x,n), If(isnatural(n), sum(binomial(n,k)*fallingfactorial(m,k)*d(y,x,n-k)*x^(m-k), k,0,n,1), If(m>0 and (n>0 or isinteger(m)), sum(binomial(n,k)*fallingfactorial(m,k)*d(y,x,n-k)*x^(m-k), k,0,ceil(abs(m)),1) ))); d(a_*(c_+x_)^m_,x_,n_):= If(isfree(a,c,x), a*d((c+x)^m,x,n), If(isnatural(n), sum(binomial(n,k)*fallingfactorial(m,k)*d(a,x,n-k)*(c+x)^(m-k), k,0,n,1), If(m>0 and (n>0 or isinteger(m)), sum(binomial(n,k)*fallingfactorial(m,k)*d(a,x,n-k)*(c+x)^(m-k), k,0,ceil(abs(m)),1) ))); #d((c_+x_)^m_*y_,x_,n_):= If(isfree(y,c,x), y*d((c+x)^m,x,n), If(isnatural(n), sum(binomial(n,k)*fallingfactorial(m,k)*d(y,x,n-k)*(c+x)^(m-k), k,0,n,1), If(m>0 and (n>0 or isinteger(m)), sum(binomial(n,k)*fallingfactorial(m,k)*d(y,x,n-k)*(c+x)^(m-k), k,0,ceil(abs(m)),1) ))); d(x_*y_,x_,n_):=If(isfree(y,x),If(n>1,0), 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),x,f) )); #d(exp(x_)*y_,x_,p_):= If(p>=0 and p<=1, exp(x)*(p*d(y,x,p)+y)); d(e^(a_+x_)*y_,x_,p_):= If(isfree(a,x), e^a*d(e^x*y,x,p)); d(exp(a_+x_)*y_,x_,p_):= If(isfree(a,x), exp(a)*d(e^x*y,x,p)); d(e^x_*x_,x_,p_) := e^x*x+p*e^x; 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(f==x, e^x,If(p>=0 and p<=1, d(f,x)^p*e^f )); 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 n1, (-1)^n*(n-2)!*x^(1-n), (psi(2)-psi(2-n)+log(x))/gamma(2-n)*x^(1-n)); d(log(x_)/x_,x_,nn_):=If(nn<0,1/2*d(log(x)^2,x,nn+1)); 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(log(x_)/x_,x_,n_):=If(n<0,1/2*d(log(x)^2,x,n+1)); #d(x_^m_*log(x_),x_,n_) := If(m== -1, 1/2*d(log(x)^2,x,n+1), If(n>= -1 and n<=0, If(n==m, -(-1)^n*(m+1)^(-2)*log(x)^(1-m), -(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(1/log(y_),x_,p_):=li(p+1,y); d(log(x_)^m_,x_,p_):= If(m== -1, li(p+1,x), 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),If(m= -1, li(p+1,x+c), If(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_*log(x_),x_,n_):= If(isnatural(n), exp(x)*log(x)-exp(x)*sum((-1)^k*binomial(n,k)*Gamma(k)*x^(-k), k,0,n,1) ); d(e^(-x)*log(x_),x_,n_):= If(isnatural(n), (-1)^n*exp(-x)*(log(x)-sum(binomial(n,k)*Gamma(k)*x^(-k), k,0,n,1)) ); d(e^x_*x_^m_,x_,n_):= If(isnatural(n), exp(x)*sum(binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,n,1), If(n>0 and isnatural(m), exp(x)*sum(binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,m,1), If(m== -1, (-1)^n*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(isnatural(n), exp(a*x)*sum(a^(n-k)*binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,n,1), If(n>0 and isnatural(m), exp(a*x)*sum(a^(n-k)*binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,m,1), 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(isnatural(n), exp(c+a*x)*sum(a^(n-k)*binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,n,1), If(m>0 and (n>0 or isinteger(m)), exp(c+a*x)*sum(a^(n-k)*binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,m,1), 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(isnatural(n), exp(x)*sum(binomial(n,k)*fallingfactorial(m,k)*(c+x)^(m-k), k,0,n,1), If(n>0 and isnatural(m), exp(x)*sum(binomial(n,k)*fallingfactorial(m,k)*(c+x)^(m-k), k,0,m,1), If(m== -1, -1/e^c*Ei(-n,-c-x), (-1)^(-m)/e^c*gamma(n+1,m+1, -c-x) )))); d(sin(x_)*x_^m_,x_,p_):= If(m<0, d((-(-1)^(-m)* Gamma(1 + m, (-i)* x) - Gamma(1 + m, i* x)),x,p+1)*i^(-m)/2, sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*sin(x+(p-k)*pi/2), k,0,m,1)); d(cos(x_)*x_^m_,x_,p_):= If(m<0, d((-(-1)^(-m)* Gamma(1 + m, (-i)* x) + Gamma(1 + m, i* x)),x,p+1)*i^(1-m)/2,sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*cos(x+(p-k)*pi/2), k,0,m,1)); d(sinh(x_)*x_^m_,x_,p_):= If(m<0, d(((-1)^(-m)* Gamma(1 + m, -x) + Gamma(1 + m, x)),x,p+1)/2,sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*(exp(x)-(-1)^(p-k)*exp(-x))/2, k,0,m,1)); d(cosh(x_)*x_^m_,x_,p_):= If(m<0, d(((-1)^(-m)* Gamma(1 + m, -x) - Gamma(1 + m, x)),x,p+1)/2,sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*(exp(x)+(-1)^(p-k)*exp(-x))/2, k,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(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(a_,b_,x_^a_)*x_^d_,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-a)*mittag(a,b-a,x^a) ))); d(mittag(a_,b_,c_*x_^a_)*x_^d_,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-a)*mittag(a,b-a,c*x^a) ))); d(mittag(p_,f_),x_,p_):= If(p>0,d(f,x,p)*mittag(p,f)) ; d(mittag(a_,x_^a_),x_,a2_) := If(abs(a2)==a, if(isinteger(a), mittag(a,x^a),(a!)^sgn(a2)*mittag(a,x^a) )); #d(mittag(a_,x_^a_),x_,a2_) := If(abs(a2)==a, mittag(a,x^a)); d(mittag(a_,c_*x_^a_),x_,a2_) := If(isfree(c,x) and a==abs(a2), if(isintegter(a), (c)^sgn(a2)*mittag(a,c*x^a),(a!*c)^sgn(a2)*mittag(a,c*x^a) )); d(mittag(a_,c_*x_^a_*y_),x_,a2_) := If(isfree(c,y,x) and a==abs(a2),(a!*c*y)^sgn(a2)*mittag(a,c*x^a*y)); d(c_*mittag(p_,f_),x_, p2_):= If(p2<0 and isfree(d(f,x,p)/c,x), mittag(p,f)/(d(f,x,p)/c)) ; #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)),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_, xx_), x_,p_) := gamma(a+p,m,xx); d(gamma(a_,m_, xx_), x_) := gamma(a+1,m,xx); d(gamma(m_, xx_), x_,p_) := gamma(p,m,xx); d(gamma(x_), x_,p_) := factorial(p,x-1); 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(factorial(xx_), x_,p_) := If(xx<>x and p<> -1, factorial(p,xx)); #d(zeta(x_),x_,p_):= If(p<> -1,gamma(p)*zeta(p,x)); d(zeta(m_,x_),x_,p_):= (-1)^p*risingfactorial(m,p)*zeta(m+p,x); d(li(x_),x_,p_):= If(abs(p)<= 1,(-1)^p*gamma(-p, (p-1)*log(x)) ); d(En(x_),x_,p_):= (-1)^p*En(1-p, -x); #d(Ei(m_, xx_), x_,p_) := (-1)^p*Ei(m-p,xx); d(En(m_, xx_), x_,p_) := (-1)^p*En(m-p,xx); d(erf(x_),x_,p_):= If(abs(p)<= 1, -(-2)^p*gamma((p+1)/2,x^2)/sqrt(pi) ); d(erfi(x_),x_,p_):= If(abs(p)<= 1, (-2)^p*gamma((p+1)/2,-x^2)/sqrt(pi) ); d(erfc(xx_),x_,p_) := erfc(-p,xx); d(erfc(m_,xx_), x_,p_) := erfc(m-p,xx); d(loggamma(xx_),x_,p_) := psi(p-1,xx); d(sin(xx_),x_,n_) := If(xx==x, sin(x+pi/2*n), If(n>=0 and n<=1, d(xx,x)^n*sin(xx+pi*n/2) )); #d(sin(x_),x_,n_) := sin(x+pi/2*n); d(cos(xx_),x_,n_) := If(xx==x, cos(x+pi/2*n), If(n>=0 and n<=1, d(xx,x)^n*cos(xx+pi*n/2) )); #d(cos(x_),x_,n_) := cos(b*x+pi/2*n); #d(sinh(xx_),x_,n_) :=If(n>=0 and n<=1,d(xx,x)^n*sinh(n,xx)); d(sinh(x_),x_,n_) := If(iseven(n), sinh(x), If(isodd(n), cosh(x), exp(x)/2-exp(-x)*(-1)^n/2)); #d(cosh(xx_),x_,n_) := If(n>=0 and n<=1,d(xx,x)^n*cosh(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(theta(y_),x_,n_):= delta(n-1,y); d(log(xx_),x,n_):= If(abs(n)<1,ln(n,xx)); d(log(x_),x_,n_):= If(isnatural(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 and isinteger(n), (-1)^(n+1)*(n-1)!/x^n, If(n>= -1 and n<0, -gamma(1-n, n*log(x)) )); #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(xx_),x_,n_) := if(xx==x,exp(x), If(n>=0 and n<=1, d(xx,x)^n*exp(xx) )); d(gauss(x_), x_,p_) := If(p>=0 and p<=1,(-x)^p*gauss(x)); d(asin(x_),x_,n_):=if(n>0 and isinteger(n), sum(binomial(n-1,n-1-2k)*(2k-1)!!*(2n-2k-3)!!*x^(n-2k-1)*(1-x^2)^(k-n+1/2),k,0,floor(n/2),1) ); d(acos(x_),x_,n_):=if(n>0 and isinteger(n), -sum((-1)^k*binomial(n-1,k)*(2k-1)!!*(2n-2k-3)!!/(1+x)^k*(1-x)^(k-n+1),k,0,n-1,1)/2^(n-1)/sqrt(1-x^2) ); d(atan(x_),x_,n_):= if(n>0 and isinteger(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_):= if(n>0 and isinteger(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(asinh(x_),x_,n_):=if(n>0 and isinteger(n), (-1)^(n-1)*sum((-1)^k*binomial(n-1,n-1-2k)*(2k-1)!!*(2n-2k-3)!!*x^(n-2k-1)*(x^2-1)^(k-n+1/2),k,0,floor(n/2),1) ); d(acosh(x_),x_,n_):=if(n>0 and isinteger(n), (-1/2)^(n-1)*sum(binomial(n-1,k)*(2k-1)!!*(2n-2k-3)!!/(1+x)^(-k-1/2)*(x-1)^(k-n+1/2),k,0,n-1,1) ); #d(atanh(x_),x_,n_):= if(n>0 and isinteger(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(atanh(x_),x_,n_):= if(n>0 and isinteger(n),(-1)^n*(n-1)!/(x^2+1)^n*sum(binomial(n,n+1-2k)*x^(n+1-2k),k,1,ceil(n/2),1)); d(acoth(x_),x_,n_):= d(atanh(x),x,n); d(sqrt(x_),x_, n_):= If(n==0.5, sqrt(pi)/2, if(isinteger(n),(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(sqrt(x_),x_, n_):= (1/2)!/(1/2-n)!*x^(1/2-n); #d(1/sqrt(x_),x_,n_):= (-1)^(-n)*gamma(n+1/2)/gamma(1/2)*x^(-1/2-n); d(x_,x_,n_) := If(n>1, 0, x^(1-n)/(1-n)!); d(y_,xx_=a_) := block(p:=d(y,xx), replace(p,xx,a)); d(e^(k_*x_),x_) := If(isfree(k,x),k*e^(k*x)); d(e^x_,x_):=e^x; 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(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,a,x)/a; d(gamma(n_, x_), x_) := -x^(n-1)*exp(-x); d(zeta(n_,x_), x_) := -n*zeta(1+n,x); d(zeta(n_,b_,x_), x_) := exp((1-b)*x)*x^(n-1)/(e^x-1)/gamma(n); d(eta(n_,b_,x_), x_) := exp((1-b)*x)*x^(n-1)/(e^x+1)/gamma(n); d(eta(n_,x_), x_) := -n*eta(1+n,x); d(En(n_, xx_), x_) := -En(n-1,xx); #d(En(n_, x_), x_) := exp(-x)/x^n; #d(erf(n_, x_), x_) := n!/sqrt(pi)*exp(-x^n); d(polylog(n_,x_), x_) := polylog(n-1,x)/x; d(polylog(a_,n_,x_), x_) := -n*x^(a-1)/(e^x-n)/gamma(a); d(Phi(a_,b_,c_,x_), x_) := e^((1-c)*x)/(-a+e^(x))*x^(b-1)/gamma(b); d(when(a_,y_),x_):=when(a,d(y,x)); d(Beta(a_,b_,x_),x_):=x^(a-1)*(1-x)^(b-1); d(Beta(x_,y_),x_):=Beta(x,y)*(psi(x)-psi(x+y)); d(Beta(x_,y_),y_):=Beta(x,y)*(psi(y)-psi(x+y)); d(beta(s_,x_),x_):=x^(s-1)/(e^(-x)+e^x)/Gamma(s); d(harmonic(n_,1,x_),x_):=(1-x^n)/(1-x); d(harmonic(n_,x_),x_):= -n*zeta(1+n,x+1); d(Cl(a_,x_),x_):= (-1)^a*Cl(a-1,x); d(harmonic(x_),x_):= psi(1,x+1); d(Sophomore(x_),x_):=x^x; d(FresnelS(x_),x_):=sin(pi/2*x^2); d(FresnelC(x_),x_):=cos(pi/2*x^2); d(theta(y_),x_) := delta(x); d(log10(x_),x_) := 1/x/log(10); d(gauss(x_), x_) := -x*gauss(x); d(gaussi(x_),x_):=gauss(x); d(erf(x_), x_) := 2/sqrt(pi)*exp(-x^2); d(erfi(x_), x_) := 2/sqrt(pi)*exp(x^2); d(factorial(x_), x_) := gamma(x+1)*psi(x+1); d(gamma(x_), x_) := gamma(x)*psi(x); d(loggamma(x_), x_) := psi(x); d(li(x_),x_) := 1/log(x); d(Ei(x_),x_) := exp(x)/x; d(Ein(x_),x_) := (1-exp(-x))/x; d(si(x_),x_) := sin(x)/x; d(ci(x_),x_) := cos(x)/x; d(tani(x_),x_) := tan(x)/x; d(coti(x_),x_) := cot(x)/x; d(csci(x_),x_) := csc(x)/x; d(seci(x_),x_) := sec(x)/x; d(asini(x_),x_) := asin(x)/x; d(acosi(x_),x_) := acos(x)/x; d(atani(x_),x_) := atan(x)/x; d(shi(x_),x_) := sinh(x)/x; d(chi(x_),x_) := cosh(x)/x; d(thi(x_),x_) := tanh(x)/x; d(sqrt(x_),x_):= 1/2*x^(-1/2); d(cbrt(x_),x_):= 1/3*x^(-2/3); d(log(x_),x_):=1/x; d(log(abs(x_)),x_):=1/x; d(abs(x_),x_):=1/sgn(x); d(exp(x_),x_):=exp(x); d(sin(x_),x_):= cos(x); d(cos(x_),x_):= -sin(x); d(tan(x_),x_):= sec(x)^2; d(cot(x_),x_):= -csc(x)^2; d(sec(x_),x_) := tan(x)*sec(x); d(csc(x_),x_) := -cot(x)*csc(x); d(asin(x_),x_) := (1-x^2)^(-1/2); d(acos(x_),x_) := -(1-x^2)^(-1/2); d(atan(x_),x_):= 1/(x^2+1); d(atan2(x_,y_),y_) := -x/(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(x^2-1)); d(acsc(x_),x_) := -1/(x*sqrt(x^2-1)); d(sinh(x_),x_):= cosh(x); d(cosh(x_),x_):= sinh(x); 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(asinh(x_),x_) := (x^2+1)^(-1/2); d(acosh(x_),x_) := (x^2-1)^(-1/2); 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(sgn(y_),x_) := 0; d(csgn(y_),x_) := 0; d(y_,x_,1) := d(y,x); d(y_,x_,0) := y; d(x_,x_):=1; d(y_):=d(y,x);