2
$\begingroup$

Is there a command equivalent to that of Coefficient to get the terms of a polynomial which are a power of the variables?

For example:

func[(x^3 + x)^2]

{x^2, x^4, x^6}

Thank you in advance

$\endgroup$
2
  • $\begingroup$ CoefficientList[ ]? $\endgroup$
    – andre314
    Apr 2, 2018 at 18:13
  • $\begingroup$ func[expr_, x_Symbol] := Cases[Expand[expr], Power[x, _], Infinity] // Union $\endgroup$
    – Bob Hanlon
    Apr 2, 2018 at 20:15

1 Answer 1

4
$\begingroup$

The function MonomialList extracts the monomials, including the overall factor. You can remove the overall factor using FactorTermsList. So, a function to do what you want could be:

Last @* FactorTermsList /@ MonomialList[(x^3+x)^2, x, "NegativeLexicographic"]

{x^2, x^4, x^6}

where I used the non-default order "NegativeLexicographic" to obtain the ordering requested.

$\endgroup$
2
  • $\begingroup$ What is the name of the "@*" operator? It appears to work here the same as replacing it by "/@". But not in general as in Last@*{{1,x^2},{2,x^4},{1,x^6}}. $\endgroup$ Dec 31, 2018 at 13:45
  • $\begingroup$ The "@*" is the in-line form of Composition[.]. $\endgroup$ Feb 22, 2019 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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