Question:Extracting multivariable polynomial coefficients

Question:Extracting multivariable polynomial coefficients

Maple

I have encountered the problem of extracting multivariable polynomial coefficients, such as using the remove command,

eq2 := 3*p^4*a[2]^2+6*p^2*q^2*a[2]*b[2]+3*q^4*b[2]^2+p^4;
eq2 :=convert(eq2,list);

eq2 := [3*p^4*a[2]^2, 6*p^2*q^2*a[2]*b[2], 3*q^4*b[2]^2, p^4]

map(t->remove(has,t,{p,q}),eq2);
[3*a[2]^2, 6*a[2]*b[2], 3*b[2]^2, undefined]

eq3 := 3*p^4*a[2]^2+6*p^2*q^2*a[2]*b[2]+3*q^4*b[2]^2;
eq3 :=convert(eq3,list);

map(t->remove(has,t,{p,q}),eq3);

[3*a[2]^2, 6*a[2]*b[2], 3*b[2]^2]

Because the term p ^ 4 similar to power appears, a program should be written to calculate it,      Programming

extractxishu:=proc(p)

local i,xishulist,teamlist;

teamlist:=convert(p,list);

xishulist:=[]:

for i in teamlist do

if type(i,`^`) then

xishulist:=[xishulist[],1];

else

xishulist:=[xishulist[],remove(has,i,{p,q})];

end if;

end do:

end proc:

Inspection procedure:

eq2 := 3*p^4*a[2]^2+6*p^2*q^2*a[2]*b[2]+3*q^4*b[2]^2+p^4*c[3]+p^3*q*c[3]+6*p^3*a[1]*a[2]+6*p^2*q*a[2]*b[1]+p*q^3*d[3]+6*p*q^2*a[1]*b[2]+q^4*d[3]+6*q^3*b[1]*b[2]+p^4+4*p^3*q+p^3*c[2]+6*p^2*q^2+p^2*q*c[2]+6*p^2*a[0]*a[2]+3*p^2*a[1]^2+6*p^2*a[2]*b[0]+4*p*q^3+p*q^2*d[2]+6*p*q*a[1]*b[1]+q^4+q^3*d[2]+6*q^2*a[0]*b[2]+6*q^2*b[0]*b[2]+3*q^2*b[1]^2+p^2*c[1] +p*q*c[1]+p*q*d[1]+6*p*a[0]*a[1]+6*p*a[1]*b[0]+q^2*d[1]+6*q*a[0]*b[1]+6*q*b[0]*b[1]+p*c[0]+p*d[0]+q*c[0]+q*d[0]+3*a[0]^2+6*a[0]*b[0]+3*b[0]^2            extractxishu(eq2);

The result is incorrect  ， It is found that the command is successful in a separate calculation, but extractxishu is invalid in the program. Why?

Can any expert tell me where this mistake is? How to modify this program!

﻿