MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Converting an expression to a list of terms?


Something like the following?

E.g.

Factor[1 - x^9, Extension -> (x /. Solve[1 - x^9 == 0])]
(-((-1)^(2/9) - x))*(-1 + (-1)^(1/3) - x)*((-1)^(4/9) - x)*(-(-1)^(2/9)
+ (-1)^(5/9) - x)*(-1 + x)*((-1)^(1/9) + x)*((-1)^(1/3) +
x)*(-(-1)^(1/9) + (-1)^(4/9) + x)*((-1)^(5/9) + x)

List @@ %
{-1, (-1)^(2/9) - x, -1 + (-1)^(1/3) - x, (-1)^(4/9) - x, -(-1)^(2/9) +
(-1)^(5/9) - x, -1 + x, (-1)^(1/9) + x, (-1)^(1/3) + x, -(-1)^(1/9) +
(-1)^(4/9) + x, (-1)^(5/9) + x}

Expand[(1 - x)^9]
1 - 9*x + 36*x^2 - 84*x^3 + 126*x^4 - 126*x^5 + 84*x^6 - 36*x^7 + 9*x^8
- x^9

List @@ %
{1, -9*x, 36*x^2, -84*x^3, 126*x^4, -126*x^5, 84*x^6, -36*x^7, 9*x^8,
-x^9}

Another way

Factor[1 - x^9, Extension -> (x /. Solve[1 - x^9 == 0])] /. (a_)*(b___)
:> {a, b}
{-1, (-1)^(2/9) - x, -1 + (-1)^(1/3) - x, (-1)^(4/9) - x, -(-1)^(2/9) +
(-1)^(5/9) - x, -1 + x,
(-1)^(1/9) + x, (-1)^(1/3) + x,  -(-1)^(1/9) + (-1)^(4/9) + x,
(-1)^(5/9) + x}

Expand[(1 - x)^9] /. (a_) + (b___) :> {a, b}
{1, -9*x, 36*x^2, -84*x^3, 126*x^4, -126*x^5, 84*x^6, -36*x^7, 9*x^8,
-x^9}

Regards
Dimitris




AES wrote:
> How to convert an expression consisting of a sum of terms in an Output
> cell:
>
>    A + B - C + . . .
>
> (where A, B, C are themselves product expressions) to a list
>
>    {A, B, -C, . . . }
>
> in some easier fashion than doing it by hand using Find and Replace?


  • Prev by Date: Re: How to determine whether a message has been switched
  • Next by Date: Send graphics to file AND/OR to notebook with one DisplayFunction
  • Previous by thread: Re: Converting an expression to a list of terms?
  • Next by thread: Best practice for naming of options