I have a polynomial in two variables x and y.
And I want to collect in y first, and collect its cofficients in x. In Maple, there is "collect"
with the choice "recursive". But it turns out that something not OK in the cofficient of
y^0
>collect(f,[y,x],recursive); a02*y^2+(a11*x+a01)*y+a00+a20*x^2+a10*x ================= \begin{nowrap}\begin{MAPLEinline} where it should be \verb|a20*x^2+a10*x+a00| The problem also same in higher degrees, it looks randomly without any ordering. I have tried to make a function for this, but it doesn't work too. %%%%%%%%%%%%%%%%%%%%% \subsection{\href{mailto:helmut.kahovec@teleweb.at}{Helmut Kahovec }(4.8.01)} The following is a possible solution to your problem: \begin{nowrap}\begin{MAPLEinline} > f:=a00+a01*y+a02*y^2+a10*x+a11*x*y+a20*x^2; > collect(sort(f,x),[y,x],recursive); 2 2 a02 y + (a11 x + a01) y + a20 x + a10 x + a00
Thank you very much for concerning my question. I tried it by your hint, it is perfect for degree 2,3.
But it is again wrong for degree greater than 3. Something really strange!
Well, you are right my first approach does not work with your polynomials when d=4,5,... It seems, however, that the following does work. It is Maple7, too.
> makepoly:=proc(x,y,a,d) local i,j,f; f:=0; for i from 0 to d do for j from 0 to d-i do f:=f+a||i||j*x^i*y^j end do end do; f end proc: > makepoly(x,y,a,2); collect(sort(%,[x]),[y],recursive,u->sort(u,[x])); 2 2 a00 + a01 y + a02 y + a10 x + a11 x y + a20 x 2 2 a02 y + (a11 x + a01) y + a20 x + a10 x + a00 > makepoly(x,y,a,3); collect(sort(%,[x]),[y],recursive,u->sort(u,[x])); 2 3 2 2 a00 + a01 y + a02 y + a03 y + a10 x + a11 y x + a12 x y + a20 x 2 3 + a21 x y + a30 x 3 2 2 3 a03 y + (a12 x + a02) y + (a21 x + a11 x + a01) y + a30 x 2 + a20 x + a10 x + a00 > makepoly(x,y,a,4); collect(sort(%,[x]),[y],recursive,u->sort(u,[x])); 2 3 4 2 a00 + a01 y + a02 y + a03 y + a04 y + a10 x + a11 y x + a12 y x 3 2 2 2 2 3 + a13 x y + a20 x + a21 y x + a22 x y + a30 x 3 4 + a31 x y + a40 x 4 3 2 2 a04 y + (a13 x + a03) y + (a22 x + a12 x + a02) y 3 2 4 3 + (a31 x + a21 x + a11 x + a01) y + a40 x + a30 x 2 + a20 x + a10 x + a00 > makepoly(x,y,a,5); collect(sort(%,[x]),[y],recursive,u->sort(u,[x])); 2 3 4 5 a00 + a01 y + a02 y + a03 y + a04 y + a05 y + a10 x + a11 y x 2 3 4 2 2 + a12 y x + a13 y x + a14 x y + a20 x + a21 y x 2 2 2 3 3 3 3 2 + a22 y x + a23 x y + a30 x + a31 y x + a32 x y 4 4 5 + a40 x + a41 x y + a50 x 5 4 2 3 a05 y + (a14 x + a04) y + (a23 x + a13 x + a03) y 3 2 2 + (a32 x + a22 x + a12 x + a02) y 4 3 2 5 + (a41 x + a31 x + a21 x + a11 x + a01) y + a50 x 4 3 2 + a40 x + a30 x + a20 x + a10 x + a00