#factor(a_*b_) := If(isatom(a) or isnumber(a), a*factor(b)); factor(x_^n_-y_^n_):=(x-y)*sum(x^(n-k-1)*y^k,k,0,n-1,1); factor(x_^n_+1):=if(iseven(n),(x^2+x+1)*sum(x^(n-k-1),k,0,n-1,2)); factor(-1+x_^n_):=(x-1)*sum(x^k,k,0,n-1,1); factor(c_+a_*c_):=(1+a)*c; factor(a_*b_+b_):=(1+a)*b; factor(a_+a_*c_):=a*(1+c); factor(a_^2+a_*c_):=a*(a+c); factor(a_^2-b_):=(a+sqrt(b))*(a-sqrt(b)); factor(a_-b_^2):=(sqrt(a)+b)*(sqrt(a)-b); factor(a_^2-b_^2):=(a+b)*(a-b); factor(a_*b_-b_^2):=b*(a-b); factor(a_*b_+b_*c_):=b*(a+c); factor(a_*b_+a_*c_):=a*(b+c); factor(a_*b_-a_*c_):=a*(b-c); factor(a_*c_+b_*c_):=c*(b+a); factor(a_*c_-b_*c_):=c*(a-b); factor(x_+c_*x_+y_):=(1+c)*x+y; factor(b_*x_+c_*x_+y_):=(b+c)*x+y; factor(a_+b_*x_+x_):=a+(b+1)*x; factor(a_+b_*x_+c_*x_):=a+(b+c)*x; factor(x_^3+1):=(x+1)*(x^2-x+1); factor(a_^3+b_^3):=(a+b)*(a^2-a*b+b^2); factor(c_+x_^2) := If(c<0, (x-sqrt(-c))*(x+sqrt(-c))); factor(c_+x_+x_^2):= if(hasnot(c,y),if(hasnot(c,x),factor(solve(c+x+x^2,x),x), x*(c/x+1+x) )); factor(c_+b_*x_+x_^2):= if(hasnot(c,y),if(hasnot(c,x),factor(solve(c+b*x+x^2,x),x), x*(c/x+b+x) )); factor(c_+b_*x_+a_*x_^2):= if(hasnot(c,y),if(hasnot(c,x),factor(solve(c+b*x+a*x^2,x),x), x*(c/x+b+a*x) )); factor(x_^2+b_*x_*y_+c_*y_^2):=(x+(b/2+(b^2-4c)^0.5/2)*y)*(x+(b/2-(b^2-4c)^0.5/2)*y); factor(c_+x_+c_*y_+x_*y_):=(c+x)*(1+y); factor(c_+f_*x_+g_*y_+x_*y_):=(c/f+x)*(c/g+y); factor(1+x_+x_*y_+y_):=(1+x)*(1+y); factor(2*a_*b_+a_^2+b_^2):=(a+b)^2; factor((-2)*a_*b_+a_^2+b_^2):=(a-b)^2; factor(1+2*a_+a_^2):=(a+1)^2; factor(-1-2*a_-a_^2):= -(a+1)^2; factor(1-2*a_+a_^2):=(a-1)^2; factor(a_^3+3*a_^2*b_+3*a_*b_^2+b_^3):=(a+b)^3; factor(a_^3+(-3)*a_^2*b_+3*a_*b_^2-b_^3):=(a-b)^3; factor(-a_^3+3*a_^2*b_+(-3)*a_*b_^2+b_^3):=(b-a)^3; factor(-a_^3+(-3)*a_^2*b_+(-3)*a_*b_^2-b_^3):= -(a+b)^3; factor(1+3*x_+3*x_^2+x_^3):=(1+x)^3; factor(-1+3*x_+(-3)*x_^2+x_^3):=(x-1)^3; factor(1+(-3)*x_+3*x_^2-x_^3):=(1-x)^3; factor(-1+(-3)*x_+(-3)*x_^2-x_^3):= -(1+x)^3; factor(1+2*t_+t_^2+2*t_*x_+2*x_+x_^2):=(1+t+x)^2; factor(cos(x_)*sin(x_)) := sin(2x)/2; factor(sin(a_)*cos(b_)+cos(a_)*sin(b_)):=sin(a+b); factor(sin(a_)*cos(b_)-cos(a_)*sin(b_)):=sin(a-b); factor(cos(a_)*cos(b_)- sin(a_)*sin(b_)):=cos(a+b); factor(cos(a_)*cos(b_)+ sin(a_)*sin(b_)):=cos(a-b); factor(b_*cos(2x_)+a_) := if(a==-b,2a*sin(x)^2); factor(a_*cos(2x_)+a_) := 2a*cos(x)^2; factor(cos(2x_)+1) := 2cos(x)^2; factor(1-cos(2x_)) := 2sin(x)^2; factor(sqrt(a_)*sqrt(b_)):=sqrt(a*b); factor(exp(a_)*exp(b_)):=exp(a*b); factor(log(a_)+log(b_)):=log(a*b); factor(a_^n_*b_^n_):=(a*b)^n; factor(x_=a_,y_=b_):=(x-a)*(y-b); factor(x_=a_,y_=b_,z_=c_):=(x-a)*(y-b)*(z-c); factor(x_=(a_ or b_)):=(x-a)*(x-b); factor(x_=(a_,b_)):=(x-a)*(x-b); factor(x_=(a_,b_,c_)):=(x-a)*(x-b)*(x-c); factor(x_=(a_,b_,c_,d_)):=(x-a)*(x-b)*(x-c)*(x-d); factor(a_ and b_,x_):=(x-a)*(x-b); factor(a_ and b_ and c_,x_):=(x-a)*(x-b)*(x-c); factor(x_=a_ and x_=b_)):=(x-a)*(x-b);