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[55]:= monomialList[poly_, vars_] := Times @@ (vars^#) & /@ CoefficientRules[poly, vars][[All, 1]]
         monomialList[a x^2 + b x y + c y^2, {x, y}]

Out[56]= {x^2, x y, y^2}
| improve this answer | |

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}
| improve this answer | |
  • $\begingroup$ Thank you so much. It is very clever and efficient! $\endgroup$ – panda.G Jul 21 '15 at 16:43
  • $\begingroup$ @user29373 Don't miss my last update; I like it best. And you're welcome. $\endgroup$ – Mr.Wizard Jul 21 '15 at 16:44
  • $\begingroup$ Thanks again @Mr.Wizard! That is really fantastic. $\endgroup$ – panda.G Jul 21 '15 at 16:54
  • 1
    $\begingroup$ Maybe add Expand in there? Try fn2[x(x^2 + y^2)] as it is now. $\endgroup$ – Marius Ladegård Meyer Jul 21 '15 at 17:02
  • $\begingroup$ @Marius Thank you. I think the simple change I just made catches that case. Would you please test it? $\endgroup$ – 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 = GroebnerBasis`DistributedTermsList[poly, vars];
Inner[Power, vars, #, Times] & /@ dl[[1, All, 1]]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.