# d(y,x,n,a) is fractional differentiation of y with x in n order from a; d(y_,x_,n_,0):=d(y,x,n); d(e^(y_),x_,n_,-oo):=exp(y)*d(y,x)^n; d(e^x_,x_,n_,-oo):=exp(x); d(a_ and b_,x_,n_):=d(a,x,n) and d(b,x,n); d(a_ and b_,x_):=d(a,x) and d(b,x); 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(a_+b_,x_):=d(a,x)+d(b,x); 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(psolution(c_,d_,y_,x_,n_),x_,n_):=d; d(nsolve(y_),x_,n_):=0; d(a_*x_^m_,x_,n_):= If(isfree(a,x), a*d(x^m,x,n), If(n>0, if(isinteger(n), sum(binomial(n,k)*fallingfactorial(m,k)*d(a,x,n-k)*x^(m-k), k,0,n,1), If(isinteger(m), sum(binomial(n,k)*fallingfactorial(m,k)*d(a,x,n-k)*x^(m-k), k,0,ceil(abs(m)),1) )))); d(a_*(c_+x_)^m_,x_,n_):= If(isfree(a,c,x), y*d((c+x)^m,x,n), If(n>0, If(isinteger(n), sum(binomial(n,k)*fallingfactorial(m,k)*d(a,x,n-k)*(c+x)^(m-k), k,0,n,1), If(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(a_*(c_+b_*x_)^m_,x_,n_):= If(isfree(a,b,c,x), a*d((c+b*x)^m,x,n), If(n>0, If(isinteger(n), b^m*sum(binomial(n,k)*fallingfactorial(m,k)*d(a,x,n-k)*(c/b+x)^(m-k), k,0,n,1), If(isinteger(m), b^m*sum(binomial(n,k)*fallingfactorial(m,k)*d(a,x,n-k)*(c/b+x)^(m-k), k,0,ceil(abs(m)),1) )))); d(x_*y_,x_,n_):=If(isfree(y,x),If(n>1,0), if(n>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), if(n>= -1,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((a_+x_^m_)^b_,x_,n_):= if(hasnot(a,b,x) and n>0 and n<=1, fallingfactorial(b,n)*(a+x^m)^(b-n)*m^n*x^(m*n-n)); d((a_+c_*x_^m_)^b_,x_,n_):= if(hasnot(a,b,c,x) and n>0 and n<=1, fallingfactorial(b,n)*(a+c*x^m)^(b-n)*c^n*m^n*x^(m*n-n)); 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_^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^(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_^m_,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)*d(Gamma(2, -(m+1)*log(x)),x,1+n)); 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)*d(Gamma(2, -(m+1)*log(x)),x,1+n)); 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)*d(Gamma(m+1, -log(x)),x,1+p), 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(log(x_)^m_*x_^n_,x_,p_):= if(n== -1 and m== -1, ln(1+p,log(x)), 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)*d(Gamma(m+1, (-n-1)*log(x)),x,1+p) )); #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(n>1, exp(x)*log(x)+exp(x)*sum((-1)^(1+k)*binomial(n,k)*Gamma(k)*x^(-k), k,1,n,1) ); d(e^(-x_)*log(x_),x_,n_):= if(n>1, (-1)^n*exp(-x)*(log(x)-sum(binomial(n,k)*Gamma(k)*x^(-k), k,1,n,1)) ); d(e^x_*x_^m_,x_,n_):= If(n== -m, exp(x)*(x^m-m!),If(n==m, exp(x)*(x^m+m!),If(n>0, if(isinteger(n), exp(x)*sum(binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,n,1), If(isinteger(m), exp(x)*sum(binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,abs(m),1) ))))); #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-k)*binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,n,1), If(m>0 and n> -1 and isinteger(m), exp(a*x)*sum(a^(n-k)*binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,abs(m),1), If(m== -1, Ei(1+n,a*x), (-a)^(-m)*Gamma(n+1,m+1, -a*x) )))); d(e^(a_*x_)*x_^m_,x_,n_):= If(isfree(m,a,x), If(n>0, if(isinteger(n), exp(a*x)*sum(a^(n-k)*binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,n,1), If(isinteger(m), exp(a*x)*sum(a^(n-k)*binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,abs(m),1), If(m== -1, Ei(1+n,a*x) ))))); d(e^(c_+a_*x_)*x_^m_,x_,n_):= If(isfree(m,c,a,x), If(n>0, if(isinteger(n), exp(c+a*x)*sum(a^(n-k)*binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,n,1), If(isinteger(m), exp(c+a*x)*sum(a^(n-k)*binomial(n,k)*fallingfactorial(m,k)*x^(m-k), k,0,abs(m),1), If(m== -1, exp(c)*Ei(1+n,a*x) ))))); d(e^x_*(c_+x_)^m_,x_,n_):= If(isfree(c,m,x) and n>0, if(isinteger(n), exp(x)*sum(binomial(n,k)*fallingfactorial(m,k)*(c+x)^(m-k), k,0,n,1), If(isinteger(m), exp(x)*sum(binomial(n,k)*fallingfactorial(m,k)*(c+x)^(m-k), k,0,abs(m),1) ))); d(e^x_*(c_+b_*x_)^m_,x_,n_):= If(isfree(b,c,m,x) and n>0, if(isinteger(n), b^m*exp(x)*sum(binomial(n,k)*fallingfactorial(m,k)*(c/b+x)^(m-k), k,0,n,1), If(isinteger(m), b^m*exp(x)*sum(binomial(n,k)*fallingfactorial(m,k)*(c/b+x)^(m-k), k,0,abs(m),1) ))); d(e^x_*x_,x_,p_) := e^x*x+p*e^x; d(e^x_/x_,x_,p_) := Ei(1+p,x); d(e^x_/(c_+x_),x_,p_) := if(hasnot(c,x), e^(-c)*Ei(1+p,c+x)); d(e^x_/(c_+b_*x_),x_,p_) := if(hasnot(b,c,x), e^(-c)/b*Ei(1+p,c+b*x)); #d(exp(x_)*x_^a_,x_,a2_) := If(a2== -a, exp(x)*(x^a-a!),If(a2==a, exp(x)*(x^a+a!) )); d(exp(-x_)*x_^a_,x_,a2_) := If(a2== -a, -i*exp(-x)*(x^a-a!),If(a2==a, i*exp(-x)*(x^a+a!) )); d(sin(x_)*x_^m_,x_,p_):= If(p>-1 and p<0, -(-i)^(-m)* d(Gamma(1 + m, (-i)* x),x,1+p)/2 - d(Gamma(1 + m, i* x),x,p+1)*i^(-m)/2, if(p>0 and isinteger(m),sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*sin(x+(p-k)*pi/2), k,0,abs(m),1) )); d(cos(x_)*x_^m_,x_,p_):= If(p>-1 and p<0, -(-i)^(-m)* d(Gamma(1 + m, (-i)* x),x,1+p)/2 + d(Gamma(1 + m, i* x),x,p+1)*i^(-m)/2, if(p>0 and isinteger(m),sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*cos(x+(p-k)*pi/2), k,0,abs(m),1) )); d(sinh(x_)*x_^m_,x_,p_):= If(p>-1 and p<0, (-1)^(-m)* d(Gamma(1 + m, -x),x,1+p)/2 + d(Gamma(1 + m, x),x,p+1)/2, if(p>0 and isinteger(m),sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*sinh(x+(p-k)*pi*i/2), k,0,abs(m),1) )); #d(cosh(x_)*x_^m_,x_,p_):= If(m<0, (-1)^(-m)* d(Gamma(1 + m, -x),x,1+p)/2 - d(Gamma(1 + m, x),x,p+1)/2, sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*cosh(x+(p-k)*pi*i/2), k,0,m,1)); d(cosh(x_)*x_^m_,x_,p_):= If(p>-1 and p<0, (-1)^(-m)*d(Gamma(1 + m, -x),x,1+p)/2 - d(Gamma(1 + m, x),x,p+1)/2, if(p>0 and isinteger(m), sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*cosh(x+(p-k)*pi*i/2), k,0,abs(m),1) )); #d(cosh(x_)*x_^m_,x_,p_):= if(p>0, if(isinteger(p), sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*cosh(x+(p-k)*pi*i/2), k,0,p,1), If(isinteger(m),sum(binomial(p,k)*fallingfactorial(m,k)*x^(m-k)*cosh(x+(p-k)*pi*i/2), k,0,abs(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(e^(a_*x_^m_)*x_^n_,x_,p_):= If(isfree(a,x), If(p>= -1 and p<0, if(n==p*(1-m), exp(a*x^m)*(a*m)^p, -(-a)^((n-p)/(p*m))*m^p*Gamma((n-p)/(-p*m),-a*x^m) ))); #d(e^x_,x_,p_):=if(p>0 and p<1,exp(p,x)); 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(c_*mittag(p_,f_),x_, p2_):= If(p2<0 and p2> -1 and isfree(d(f,x,p)/c,x), mittag(p,f)/d(f,x,p)*c*p!,if(p2==p, c*d(f,x,p)*mittag(p,f)/(p!)+d(c,x,p2)*mittag(p,f) )); d(mittag(p_,f_)*y_,x_, p2_):= If(p2<0 and p2> -1 and isfree(d(f,x,p)/y,x), mittag(p,f)/d(f,x,p)*y*p!, if(p2==p, y*d(f,x,p)*mittag(p,f)/(p!)+d(y,x,p2)*mittag(p,f) )); d(mittag(p_,f_),x_,p_):= if(p>0 and p<1, d(f,x,p)*mittag(p,f)/(abs(p))!); d(mittag(a_,c_*x_^a_),x_,a2_) := If(isfree(c,x),if(a2==a or a2== -a, c^sgn(a*a2)*mittag(a,c*x^a) )); d(mittag(a_,x_^a_),x_,a2_) := If(abs(a2)==abs(a), mittag(a,x^a)); #d(mittag(a_,c_*x_^a_*y_),x_,a2_) := If(isfree(c,y,x) and a==a2, c*mittag(a,c*x^a)*y, c^sgn(a2)*mittag(a,c*x^a)*y^sgn(a2) ); #d(c_*mittag(p_,f_),x_, p2_):= If(p2<0 and p2> -1 and isfree(d(f,x,p)/c,x), mittag(p,f)/d(f,x,p)*c*p!, if(p2==p, c*d(f,x,p)*mittag(p,f)/(p!)+d(c,x,p2)*mittag(p,f) )); d(mittag(a_,x_^a_)*x_^a_,x_,a2_) := If(a2== -a, E(a,x^a)*(x^a-a!),If(a2==a, E(a,x^a)*(x^a+a!) )); d(mittag(a_,-x_^a_)*x_^a_,x_,a2_) := If(a2== -a, -E(a,-x^a)*(x^a+a!),If(a2==a, -E(a,-x^a)*(x^a-a!) )); d(mittag(a_,x_^a_)*x_,x_,a2_) := If(a2== -a, E(a,x^a)*(x-x^a/a!+1),If(a2==a, E(a,x^a)*(x+x^a/a!-1) )); d(mittag(a_,-x_^a_)*x_,x_,a2_) := If(a2== -a, -E(a,-x^a)*(x+x^a/a!+1),If(a2==a, -E(a,-x^a)*(x-x^a/a!-1) )); #d(Gamma(a_,m_,x_), x_,p_) := Gamma(a+p,m,x); #d(Gamma(a_,x_,0),x_,p_):=Gamma(a+p,x,0); #d(Gamma(a_,x_), x_,p_) := -d(exp(-x)*(x)^(a-1),x,p-1); #d(Gamma(a_,x_), x_,n_) := if(n>0 and (n)<1,(-1)^n* x^(-n)* sum(binomial(n, k) *Gamma(a - k + n, x)* risingfactorial(a,k),k,0,n)); #d(Gamma(a_,x_), x_,n_) := if(abs(n)<1, Gamma(n,a,x)); #d(Gamma(x_), x_,p_) := if(p>0 and p<1, Gamma(x)*sum(binomial(p-1,k)*psi(x)^(p-1)*psi(k,x)^(k),k,0,p)); #d(Gamma(x_), x_,p_) := Gamma(p,x,0); 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>= -1 and p<=0, a^(-1/m)*(-m)^p*Gamma(n+p-p/m,a*x^m), 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(x_), x_,p_) := infints(exp((-t))*t^(-1+x)*log(t)^p,t); d(factorial(x_), x_,p_) := infints(exp((-t))*t^x*log(x)^p,t); d(zeta(x_),x_,p_):= If(p>0,(-1)^p*sum(log(k)^p/k^x,k,2,oo)); 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(En(m_, x_), x_,p_) := (-1)^p*En(m-p,-x); d(erf(x_),x_,p_):= If(abs(p)<= 1, -(-2)^p*Gamma((p+1)/2,x^2)/sqrt(pi) ); d(erfc(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(loggamma(x_),x_,p_) := psi(p-1,x); d(sin(x_),x_,n_) := If(iseven(n/2), sin(x),sin(x+pi/2*n)); d(cos(x_),x_,n_) := If(iseven(n/2), cos(x),cos(x+pi/2*n)); d(sinh(x_),x_,n_) := If(iseven(n), sinh(x), If(isodd(n), cosh(x), sinh(x+n*pi*i/2) )); d(cosh(x_),x_,n_) := If(iseven(n), cosh(x), If(isodd(n), sinh(x), cosh(x+n*pi*i/2) )); d(abs(y_),x_,n_) := d(y,x,n)/sgn(y); d(abs(x_),x_,n_) := If(n>1,0, If(n<0, 1/sgn(x)/(-n)!*x^(1-n), 1/sgn(x)*(1-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 and has(xx,x),ln(n,xx)); d(log(x_),x_,n_):= If(n>0, -(-1)^n*(n-1)!/x^n, If(abs(n)<1,expand((log(x)+psi(1)-psi(1-n))/Gamma(1-n)/x^n) )); d(log(c_+x_),x_,n_):= if(hasnot(c,x),If(n>0, -(-1)^n*(n-1)!/(c+x)^n, If(abs(n)<1,expand((log(c+x)+psi(1)-psi(1-n))/Gamma(1-n)/(c+x)^n) ))); #d(log(x_),x_,n_):= If(n>0, -(-1)^n*(n-1)!/x^n, If(n>= -1 and n<0, -Gamma(1-n, n*log(x)) )); #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(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, 1/2 i *(-1)^n *((-i + x)^(-n) - (i + x)^(-n))* (-1 + 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, 1/2 i *(-1)^n *(-(-i + x)^(-n) + (i + x)^(-n))* (-1 + 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((a_+x_)^n_,x_,n_):= if(n<0,n!*log(a+x)); d(sqrt(x_),x_, n_):= (1/2)!/(1/2-n)!*x^(1/2-n); d(1/(a_+log(x_)),x_,n_):=exp(-a)*li(1+n,exp(a)*x); d(1/log(a_+x_),x_,n_):=if(isfree(a,x),li(1+n,a+x)); d(1/(x_^2+b_*x_+c_),x_,n_):=if(isfree(b,c,x),(-1)^n*b^n*n!*(x^2+b*x+c)^(-n-1)); d(sin(x_)/x_,x_,n_):=si(1+n,x); d(cos(x_)/x_,x_,n_):=ci(1+n,x); d(sin(a_*x_)/x_,x_,n_):=if(isfree(a,x),si(1+n,a*x)); d(cos(a_*x_)/x_,x_,n_):=if(isfree(a,x),ci(1+n,a*x)); d(sinh(a_*x_)/x_,x_,n_):=if(isfree(a,x),shi(1+n,a*x)); d(cosh(a_*x_)/x_,x_,n_):=if(isfree(a,x),chi(1+n,a*x)); d(x_,x_,n_) := If(n>1, 0, x^(1-n)/(1-n)!); d(y_, x_=x0_, n_) := d(y,x,x0,n); d(y_,x_,1) := d(y,x); d(y_,x_,0) := y; d(y_,x_=a_) := d(y,x,a,1); d(integrate(y_,x_),x_) := y; d(integrates(y_,x_),x_) := y; d(integrates(y_,t_,a_,b_),x_) := block(f(t)=y,replace(f(t),t,b)*d(b,x)-replace(f(t),t,a)*d(a,x)+integrate(d(f(t),x),t,a,b)); d(integrate(y_,t_,a_,b_),x_) := replace(y,t,b)*d(b,x)-replace(y,t,a)*d(a,x)+integrate(d(y,x),t,a,b); d(integrate(y(t_-x_),t_,a_,b_),x_) := y(b-x)*(d(b,x)-1)-y(a-x)*(d(a,x)-1); d(integrate(y(x_-t_),t_,a_,b_),x_) := y(x-a)*(1-d(a,x))-y(x-b)*(1-d(b,x)); #d(infsums(y_,k_),x_,n_) := infsums(d(y,x,n),k); 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(1/(1+2k_)!*x_^(1+2k_),k_),x_) := infsums(x^(2k)/(2k)!,k); d(infsums((-1)^k_/(2k_)!*x_^(2k_),k_),x_) := -infsums((-1)^k*x^(2k+1)/(2k+1)!,k); d(infsums((-1)^k_/(1+2k_)!*x_^(1+2k_),k_),x_) := infsums((-1)^k*x^(2k)/(2k)!,k); d(vector(x_,y_),xx_):=y/x; 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(a_,m_,x_), x_) := Gamma(a+1,m,x); d(Gamma(a_,x_,0),x_):=Gamma(a+1,x,0); d(Gamma(n_, x_), x_) := -exp(-x)*x^(n-1); d(zeta(x_), x_) := -sum(log(k)/k^x,k,2,oo); 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(x_), x_) := -sum((-1)^k*log(k)/k^x,k,2,oo); 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_,x_), x_) := -En(n-1,x); #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(L(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(W(x_),x_):=W(x)/(x+x*W(x)); d(Sophomore(x_),x_):=x^x; d(Sophomore1(x_),x_):=1/x^x; d(harmonic(x_),x_):= psi(1,x+1); d(psi(x_),x_):= psi(1,x); d(S(x_),x_):=sin(pi/2*x^2); d(C(x_),x_):=cos(pi/2*x^2); d(theta(y_),x_) := delta(x); d(gauss(x_), x_) := -x*gauss(x); d(Phi(x_),x_):=gauss(x); d(inverseerf(x_), x_) := 1/2*sqrt(pi)*exp(inverseerf(x)^2); 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((x_)!, x_) := x!*psi(x+1); 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_) := sinc(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(tanhi(x_),x_) := tanh(x)/x; d(cothi(x_),x_) := coth(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(step(x_),x_):=0; d(x_,x_):=1; d(y_):=d(y,x);