# convert polynomial to polynomial holder polys(x) for x, or poly2s(x,y) for x and y; # e.g. topolys(x^2+2x+3,x) gives polys(1,2,3,x); # e.g. topolys(x+2y+3,x,y) gives poly2s(1,2,3,x,y); # polys() can be activated by activate() or remove its last letter "s"; topolys(x_+c_, x_) := If(isfree(c,x), polys(1,c,x)); topolys(a_*x_, x_) := If(isfree(a,c,x), polys(a,0,x)); topolys(a_*x_+c_, x_) := If(isfree(a,c,x), polys(a,c,x)); topolys(a_+x_+c_*x_, x_) := If(isfree(a,c,x), polys(1+c,a,x)); topolys(a_+b_*x_+c_*x_, x_) := If(isfree(a,b,c,x), polys(b+c,a,x)); topolys(a_+b_*x_+c_*x_+d_*x_, x_) := If(isfree(a,b,c,x), polys(b+c+d,a,x)); topolys(a_+b_*x_+c_*x_+d_*x_+y_, x_) := If(isfree(a,b,c,x), polys(b+c+d,a+y,x)); topolys(x_^2+c_, x_) := If(isfree(a,c,x), polys(1,0,c,x)); topolys(a_*x_^2+c_, x_) := If(isfree(a,c,x), polys(a,0,c,x)); topolys(x_^2+x_, x_) := If(isfree(a,c,x), polys(1,1,0,x)); topolys(a_*x_^2+x_, x_) := If(isfree(a,c,x), polys(a,1,0,x)); topolys(x_^2+b_*x_, x_) := If(isfree(a,c,x), polys(1,b,0,x)); topolys(a_*x_^2+b_*x_, x_) := If(isfree(a,c,x), polys(a,b,0,x)); topolys(x_^2+x_+c_, x_) := If(isfree(a,c,x), polys(1,1,c,x)); topolys(a_*x_^2+x_+c_, x_) := If(isfree(a,c,x), polys(a,1,c,x)); topolys(x_^2+b_*x_+c_, x_) := If(isfree(b,c,x), polys(1,b,c,x)); topolys(a_*x_^2+b_*x_+c_, x_) := If(isfree(a,b,c,x), polys(a,b,c,x)); topolys(x_^3+c_, x_) := If(isfree(a,c,x), polys(1,0,0,c,x)); topolys(a_*x_^3+c_, x_) := If(isfree(a,c,x), polys(a,0,0,c,x)); topolys(x_^3+x_, x_) := If(isfree(a,c,x), polys(1,0,1,0,x)); topolys(a_*x_^3+x_, x_) := If(isfree(a,c,x), polys(a,0,1,0,x)); topolys(x_^3+b_*x_, x_) := If(isfree(a,c,x), polys(1,0,b,0,x)); topolys(a_*x_^3+b_*x_, x_) := If(isfree(a,c,x), polys(a,0,b,0,x)); topolys(x_^3+x_+c_, x_) := If(isfree(a,c,x), polys(1,0,1,c,x)); topolys(a_*x_^3+x_+c_, x_) := If(isfree(a,c,x), polys(a,0,1,c,x)); topolys(x_^3+b_*x_+c_, x_) := If(isfree(b,c,x), polys(1,0,b,c,x)); topolys(a_*x_^3+b_*x_+c_, x_) := If(isfree(a,b,c,x), polys(a,0,b,c,x)); topolys(x_^3+x_^2+x_+d_, x_) := If(isfree(d,x), polys(1,1,1,d,x)); topolys(x_^3+b_*x_^2+c_*x_+d_, x_) := If(isfree(b,c,d,x), polys(1,b,c,d,x)); topolys(a_*x_^3+x_^2+c_*x_+d_, x_) := If(isfree(a,c,d,x), polys(a,1,c,d,x)); topolys(a_*x_^3+b_*x_^2+c_*x_+d_, x_) := If(isfree(a,b,c,d,x), polys(a,b,c,d,x)); topolys(x_^4+f_, x_) := If(isfree(f,x), polys(1,0,0,0,f,x)); topolys(x_^4+d_*x_+f_, x_) := If(isfree(f,x), polys(1,0,0,d,f,x)); topolys(x_^4+c_*x_^2+f_, x_) := If(isfree(c,f,x), polys(1,0,c,0,f,x)); topolys(x_^4+b_*x_^3+f_, x_) := If(isfree(b,f,x), polys(1,b,0,0,f,x)); topolys(x_^4+c_*x_^2+d_*x+f_, x_) := If(isfree(c,f,x), polys(1,0,c,d,f,x)); topolys(x_^4+a_*x_^3+c_*x_+d_, x_) := If(isfree(a,c,d,x), polys(1,a,0,c,d,x)); topolys(x_^4+a_*x_^3+b_*x_^2+d_, x_) := If(isfree(a,b,d,x), polys(1,a,b,0,d,x)); topolys(x_^4+a_*x_^3+b_*x_^2+c_*x_+d_, x_) := If(isfree(a,b,c,d,x), polys(1,a,b,c,d,x)); topolys(a_ and b_, x_) := x^2-a*x-b*x+a*b; topolys(a_ and b_ and c_, x_) := expand((x-a)*(x-b)*(x-c)); #topolys(a_ and b_,c_, x_) := expand((x-a)*(x-b)*(x-c)); #topolys(a_ and b_ and c_,d_, x_) := expand((x-a)*(x-b)*(x-c)*(x-d)); topolys(a_ and b_ and c_ and d_, x_) := expand((x-a)*(x-b)*(x-c)*(x-d)); topolys(x_+y_, x_,y_) := poly2s(1,1,0,x,y); topolys(x_+b_*y_, x_,y_) := If(isfree(b, x) and isfree(b, y), poly2s(1,b,0,x,y)); topolys(a_*x_+y_, x_,y_) := If(isfree(a, x) and isfree(a, y), poly2s(a,1,0,x,y)); topolys(a_*x_+b_*y_, x_,y_):=If(isfree(a,b, x) and isfree(a,b, y), poly2s(a,b,0,x,y)); topolys(x_+y_+c_, x_,y_) := If(isfree(c,x) and isfree(c,y), poly2s(1,1,c,x,y)); topolys(x_+b_*y_+c_, x_,y_) := If(isfree(b,c,x) and isfree(b,c,y), poly2s(1,b,c,x,y)); topolys(a_*x_+y_+c_, x_,y_) := If(isfree(a,c,x) and isfree(a,c,y), poly2s(a,1,c,x,y)); topolys(a_*x_+b_*y_+c_, x_,y_) := If(isfree(a,b,c,x) and isfree(a,b,c,y), poly2s(a,b,c,x,y)); topolys(x_^2+y_^2+c_*x_*y_+d_*x_+ee_*y_+f_, x_,y_) := If(isconstant(c,d,ee,f), poly2s(1,1,c,d,ee,f,x,y)); topolys(a_*x_^2+b_*y_^2+c_*x_*y_+d_*x_+ee_*y_+f_, x_,y_) := If(isconstant(a,b,c,d,ee,f), poly2s(a,b,c,d,ee,f,x,y)); topolys(y_):=topolys(y,x);