# inverse function; #inverse(a_+b_,x_):= If(isfree(a,x), replace(inverse(b,x),x,x-a), If(isfree(b,x), replace(inverse(a,x),x,x-b) )); #inverse(a_+b_+c_,x_):= If(isfree(a,x), replace(inverse(b+c,x),x,x-a) ); #inverse(a_*b_,x_):=If(isfree(a,x), replace(inverse(b,x),x,x/a),If(isfree(b,x), replace(inverse(a,x),x,x/b) )); inverse(c_+y_+y_^2, x_) := If(isfree(c,x), inverse(-y-1/2+sqrt(1-4*c)/2 and -y-1/2-sqrt(1-4*c)/2,x)); inverse(c_+b_*y_+y_^2, x_) := If(isfree(b,c,x), inverse(-y-b/2+sqrt(b^2-4*c)/2 and -y-b/2-sqrt(b^2-4*c)/2,x)); inverse(c_+y_+a_*y_^2, x_) := If(isfree(a,c,x), inverse(-y+(-1+sqrt(b^2-4*c))/(2a) and -y+(-1-sqrt(b^2-4*c))/(2a),x)); inverse(c_+b_*y_+a_*y_^2, x_) := If(isfree(a,b,c,x), inverse(-y+(-b+sqrt(b^2-4*c))/(2a) and -y+(-b-sqrt(b^2-4*c))/(2a),x)); inverse(c_+x_+x_^2, x_) := If(isfree(c,x), (-1/2+sqrt(1-4*c+4*x)/2 and -1/2-sqrt(1-4*c+4*x)/2)); inverse(c_+x_+a_*x_^2, x_) := If(isfree(a,c,x), ((-1+sqrt(1+4*a*x-4*a*c))/(2*a) and (-1-sqrt(1+4*a*x-4*a*c))/(2*a)) ); inverse(c_+b_*x_+x_^2, x_) := If(isfree(b,c,x), (-b/2+sqrt(b^2+4*x-4*c)/2 and -b/2-sqrt(b^2+4*x-4*c)/2)); inverse(c_+b_*x_+a_*x_^2, x_) := If(isfree(a,b,c,x), ((-b+sqrt(b^2-4*a*c+4*a*x))/(2*a) and (-b-sqrt(b^2-4*a*c+4*a*x))/(2*a))); inverse(e^(-y_)+e^y_,x_):= replace(inverse(y,x),x,acosh(x/2)); inverse(e^(-x_)+e^x_,x_):= acosh(x/2); inverse(y_+log(y_),x_):= replace(inverse(y,x),x,LambertW(e^x)); inverse(b_*y_+log(y_),x_):= if(isfree(b,x), replace(inverse(y,x),x,LambertW(e^(x/b))) ); inverse(b_*y_+log(y_)*y_,x_):= if(isfree(b,x), replace(inverse(y,x),x,x/LambertW(x*exp(b))) ); inverse(y_^a_,x_):=If(isfree(a,x), replace(inverse(y,x),x,x^(1/a)), If(isfree(y,x), replace(inverse(a,x),x,log(y,x)) )); inverse(y_^2,x_):=replace(inverse(y,x),x,sqrt(x)) and replace(inverse(y,x),x,-sqrt(x)); inverse(1/(1+y_)*y_,x_):=replace(inverse(y,x),x,x/(1-x)); inverse(y_*1/(1-y_),x_):=replace(inverse(y,x),x,x/(x+1)); inverse(e^y_/y_,x_):=replace(inverse(y,x),x, -LambertW(-1/x)); inverse(e^(-y_)/y_,x_):=replace(inverse(y,x),x, LambertW(1/x)); inverse(e^y_*y_,x_):= replace(inverse(y,x),x,LambertW(x)); inverse(e^(-y_)*y_,x_):= replace(inverse(y,x),x, -LambertW(-x)); inverse(log(y_)*y_,x_):= replace(inverse(y,x),x,x/LambertW(x)); inverse(log(y_)/y_,x_):= replace(inverse(y,x),x, -LambertW(-x)/x); inverse(y_/LambertW(y_),x_):= replace(inverse(y,x),x,x*log(x)); inverse(y_/LambertW(b_*y_),x_):= replace(inverse(y,x),x,x*log(x)+log(b)*x); inverse(LambertW(y_)/y_,x_):= replace(inverse(y,x),x, -log(x)/x); inverse(d(y_,x_,n_),x_):=d(y,x,-n); inverse(d(y_,x_),x_):=integrate(y,x); inverse(integrate(y_,x_),x_):=d(y,x); inverse(difference(y_,x_),x_):=sum(y,x); inverse(sum(y_,x_),x_):=difference(y,x); inverse(inverse(y_,x_),x_):=y; inverse(when(a_,y_),x_):=when(a,inverse(y,x)); inverse(mittag(a_,y_),x_):=replace(inverse(y,x),x,ln(1-a,x)); inverse(ln(a_,y_),x_):=replace(inverse(y,x),x,mittag(1-a,x)); inverse(sin(a_,x_),x_):= asin(x)-pi/2*a; inverse(cos(a_,x_),x_):= acos(x)-pi/2*a; inverse(atan(a_,x_),x_):= inverse(simplify(atan(a,x)),x); inverse(atanh(a_,x_),x_):= tanh(-d(y,y,-a)); inverse(pow(a_,b_),x_):=replace(inverse(a,x),x,pow(x,1/b)); inverse(pow(x_,b_),x_):=pow(x,1/b); #inverse(mod(y_,b_)+c_,x_):=replace(inverse(y,x),x,mod(-c,b)+b); inverse(e^(y_),x_):=replace(inverse(y,x),x,log(x)); inverse(exp(x_),x_):= log(x); inverse(LambertW(x_),x_):=exp(x)*x; inverse(Phi(x_),x_):=sqrt(2)*inverseerf(2x-1); inverse(log(x_),x_):= exp(x); inverse(log(a_,x_),x_):=a^x; inverse(log10(x_),x_):= 10^(x); inverse(log(x_+sqrt(1+x_^2)),x_):=sinh(x); inverse(log(x_+sqrt(x_^2-1)),x_):=cosh(x); inverse(log((1+x_)/(1-x_)),x_):= 2tanh(x); inverse(log((1+x_)/(x_-1)),x_):= 2coth(x); inverse(log((1+sqrt(x_^2+1))/x_),x_):=2csch(x); inverse(log((1+sqrt(1-x_^2))/(1-(1-x_^2)^(1/2))),x_):=2sech(x); inverse(sin(x_),x_):= asin(x); inverse(cos(x_),x_):= acos(x); inverse(tan(x_),x_):= atan(x); inverse(cot(x_),x_):= acot(x); inverse(sec(x_),x_):= asec(x); inverse(csc(x_),x_):= acsc(x); inverse(sinh(x_),x_):= asinh(x); inverse(cosh(x_),x_):= acosh(x); inverse(tanh(x_),x_):= atanh(x); inverse(coth(x_),x_):= acoth(x); inverse(sech(x_),x_):= asech(x); inverse(csch(x_),x_):= acsch(x); inverse(asin(x_),x_):= sin(x); inverse(acos(x_),x_):= cos(x); inverse(atan(x_),x_):= tan(x); inverse(acot(x_),x_):= cot(x); inverse(asec(x_),x_):= sec(x); inverse(acsc(x_),x_):= csc(x); inverse(asinh(x_),x_):= sinh(x); inverse(acosh(x_),x_):= cosh(x); inverse(atanh(x_),x_):= tanh(x); inverse(acoth(x_),x_):= coth(x); inverse(asech(x_),x_):= sech(x); inverse(acsch(x_),x_):= csch(x); inverse(sqrt(x_),x_):= x^2; inverse(cbrt(x_),x_):= x^3; inverse(1/(x_+1),x_):=1/x-1; inverse(1/(x_-1),x_):=1/x+1; inverse(1/x_,x_):=1/x; inverse(x_,x_):=x; inverse(a_=b_,x_):=swap(a=b,x,y); inverse(a_ and b_, x_):= (inverse(a,x) and inverse(b,x)); inverse(y_):=inverse(y,x);