# How to get a list of monomials of a polynomial without coefficients?

Giving a polynomial, say

a x^2 + b x y + c y^2


MonomialList[a x^2 + b x y + c y^2, {x, y}] just gives

{a x^2, b x y, c y^2}


How can I get a list without the coefficients? I mean, the following list

{x^2, x y, y^2}


The motivation of this question is, I am only interested in the structure of the polynomial itself, i.e., which kinds of of monomials are there, while their explicit coefficient are not relevant.

You can generate the monomials by using CoefficientRules, like this

In:= monomialList[poly_, vars_] := Times @@ (vars^#) & /@ CoefficientRules[poly, vars][[All, 1]]
monomialList[a x^2 + b x y + c y^2, {x, y}]

Out= {x^2, x y, y^2}


A pattern matching method:

fn[x_, {var__}] := List @@ Pick[x, x, Alternatives[var]^_.]

fn[a x^2 + b x y + c y^2, {x, y}]

{x^2, x y, y^2}


But a better approach I believe is (hopefully now corrected at last):

fn2[x_, var_] := Collect[List @@ Expand @ x, var, 1 &]

fn2[a x^2 + b x y + c y^2, {x, y}]

{x^2, x y, y^2}

fn2[x (x^2 + y^2), {x, y}]

{x^3, x y^2}

fn2[p x + a x^2 + b x y, {x, y}]

{x, x^2, x y}

• Thank you so much. It is very clever and efficient! – panda.G Jul 21 '15 at 16:43
• @user29373 Don't miss my last update; I like it best. And you're welcome. – Mr.Wizard Jul 21 '15 at 16:44
• Thanks again @Mr.Wizard! That is really fantastic. – panda.G Jul 21 '15 at 16:54
• Maybe add Expand in there? Try fn2[x(x^2 + y^2)] as it is now. – Marius Ladegård Meyer Jul 21 '15 at 17:02
• @Marius Thank you. I think the simple change I just made catches that case. Would you please test it? – Mr.Wizard Jul 21 '15 at 17:07

This uses some undocumented functionality:

poly = a x^2 + b x y + c y^2; vars = {x, y};
dl = GroebnerBasisDistributedTermsList[poly, vars];
Inner[Power, vars, #, Times] & /@ dl[[1, All, 1]]
`