MathGroup Archive 2006

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

Search the Archive

Re: Converting an expression to a list of terms?


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?
> 
Do you mean applying the head List to the output expression?

In[1]:=
A + B - C

Out[1]=
A + B - C

In[2]:=
Head[%]

Out[2]=
Plus

In[3]:=
List @@ %%

Out[3]=
{A, B, -C}

In[4]:=
Head[%]

Out[4]=
List

In[5]:=
(x - 1)*(x - 2) + (x + 1)*(x + 3) - (x*y + 1)*x^2

Out[5]=
                                        2
(-2 + x) (-1 + x) + (1 + x) (3 + x) - x  (1 + x y)

In[6]:=
Head[%]

Out[6]=
Plus

In[7]:=
List @@ %%

Out[7]=
                                        2
{(-2 + x) (-1 + x), (1 + x) (3 + x), -x  (1 + x y)}

In[8]:=
Head[%]

Out[8]=
List

Regards,
Jean-Marc


  • Prev by Date: Re: Converting an expression to a list of terms?
  • Next by Date: Re: Why does this lead to an answer with complex numbers?
  • Previous by thread: Re: Converting an expression to a list of terms?
  • Next by thread: RE: Converting an expression to a list of terms?