1
$\begingroup$

I have a list of factored polynomials:

{x^3, x^2 (1 + x), x (1 + x)^2, x (1 + x + x^2), (1 + x) (1 + x + x^2), 1 + x^2 + x^3, 1 + x + x^3, (1 + x)^3}

I want a corresponding list of the exponents of the irreducible factors. I want this:

{{3},{2,1},{1,2},{1,1},{1,1},{1},{1},{3}}
$\endgroup$
1
  • 2
    $\begingroup$ In[314]:= Map[ Rest[FactorList[#]][[All, 2]] &, {x^3, x^2 (1 + x), x (1 + x)^2, x (1 + x + x^2), (1 + x) (1 + x + x^2), 1 + x^2 + x^3, 1 + x + x^3, (1 + x)^3}] Out[314]= {{3}, {2, 1}, {1, 2}, {1, 1}, {1, 1}, {1}, {1}, {3}} $\endgroup$ – Daniel Lichtblau May 22 at 17:42
1
$\begingroup$

First, define a function to get an exponent from a factor. If it's a Power, it's explicit, if it's a numeric quantity, it's 0, otherwise it's 1.

getExponent[Power[_, n_]] := n
getExponent[_?NumericQ] := 0
getExponent[_] := 1

Next, deconstruct a product into factors and map getExponent to the factors. Handle the special case where there's only one factor.

getExponents[product_Times] := getExponent /@ (product /. Times -> List)
getExponents[poly_] := {getExponent[poly]}

Finally, map it to a list of polynomials.

exponentList[polys_List] := getExponents /@ polys

exponentList[{x^3, x^2 (1 + x), x (1 + x)^2, x (1 + x + x^2), (1 + x) (1 + x + x^2), 1 + x^2 + x^3, 1 + x + x^3, (1 + x)^3}]
(* {{3}, {2, 1}, {1, 2}, {1, 1}, {1, 1}, {1}, {1}, {3}} *)
$\endgroup$
2
$\begingroup$

As @DanielLichtblau comments, FactorList does this (and more):

L = {x^3, x^2 (1 + x), x (1 + x)^2, x (1 + x + x^2), (1 + x) (1 + x + x^2),
     1 + x^2 + x^3, 1 + x + x^3, (1 + x)^3};

FactorList[#][[2 ;;, 2]] & /@ L
(*    {{3}, {2, 1}, {1, 2}, {1, 1}, {1, 1}, {1}, {1}, {3}}    *)

According to the documentation,

The first element of the list is always the overall numerical factor. It is {1,1} if there is no overall numerical factor.

which is the reason why we can simply chop off the first element (with Rest or 2;;).

Also, there is no need to pre-factorize the polynomials, as FactorList automatically factorizes:

FactorList[1 - x^2]
(*    {{-1, 1}, {-1 + x, 1}, {1 + x, 1}}    *)
$\endgroup$

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.