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