3
$\begingroup$

Suppose I have an integer polynomial f that is in a factored form, say f = (1 + x) * (2 + x + x^3) * (2 + x^5). I want a function similar to FactorList that accepts f and returns { 1 + x, 2 + x + x^3, 2 + x^5 }.

Normally I would just use FactorList. However, I am worried FactorList will attempt to further factor the factors, which might become a time sink as I work with polynomials whose factors are very high in degree and have many terms. I do NOT need the function to further factor.

Outside of string conversion and manipulation, I don't know what functions can achieve this easily. I would guess, however, that this is easily achievable, without the use of strings.

$\endgroup$

1 Answer 1

4
$\begingroup$

Try the following:

ClearAll[factorlist]
factorlist[exp_Times] := List @@ exp
factorlist[exp_Power] := {First@exp}

Here are a few examples:

f = (1 + x)*(2 + x + x^3)*(2 + x^5)
g = 2 (x^2 + 1)
h = (2 x + 1)^3

factorlist /@ {f, g, h}

(* Out:
{
 {1 + x, 2 + x + x^3, 2 + x^5}, 
 {2, 1 + x^2}, 
 {1 + 2 x}
}
*)
$\endgroup$

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.