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$
  • $\begingroup$ CoefficientList[ ]? $\endgroup$ – andre314 Apr 2 '18 at 18:13
  • $\begingroup$ func[expr_, x_Symbol] := Cases[Expand[expr], Power[x, _], Infinity] // Union $\endgroup$ – Bob Hanlon Apr 2 '18 at 20:15
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$
  • $\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$ – Romke Bontekoe Dec 31 '18 at 13:45
  • $\begingroup$ The "@*" is the in-line form of Composition[.]. $\endgroup$ – Romke Bontekoe Feb 22 at 6:00

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.