# Removing terms of certain degree in multivariable polynomial

I am new to Mathematica and I have what I am sure is a basic question, which I unfortunately have not been able to figure out. I am trying to keep terms in a polynomial that are of the same degree only. For example, if I have a polynomial in the variables x and y like the following

poly = ax^2*y - bx*y - cx*y^2 + dx + ey


what could I do to extract, for example, only the terms of third order, i.e the terms

ax^2*y-cx*y^2

• Note that ax is a distinct entity from a x; if you want to multiply different variables, separate them with a space or explicitly use an asterisk. Dec 13 '16 at 14:29
• You can extract the coefficients with CoefficientList and then take out the elements you want, e.g. by using IntegerPartitions but I'm sure there are better methods. Dec 13 '16 at 14:33
• Related: (126553); (41918). Dec 13 '16 at 14:41

poly = a x^2*y - b x*y - c x*y^2 + d x + e y;
var = {x, y};

FromCoefficientRules[Select[CoefficientRules[poly, var], Total@#[] == 3 &], var]


a x^2 y - c x y^2

• Great, thank you so much! Dec 13 '16 at 14:54
Tr[Select[MonomialList[poly],Tr[Exponent[#,{x,y}]]==3&]]


a x^2 y-c x y^2

Another route:

d = 3;
poly = a x^2*y - b x*y - c x*y^2 + d x + e y;
var = {x, y};

Fold[Dot, CoefficientArrays[poly, var][[d + 1]], ConstantArray[var, d]]
x (a x y - c y^2)


Easiest is to use a new variable to collect powers in the ones of interest, then set it to 1.

poly = a*x^2*y - b*x*y - c*x*y^2 + d*x + e*y;
vars = {x, y};
Coefficient[poly /. Thread[vars -> t*vars], t^3] /. t -> 1

(* Out= a x^2 y - c x y^2 *)