Re: Sum of terms --> list

• To: mathgroup at smc.vnet.net
• Subject: [mg110601] Re: Sum of terms --> list
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Sun, 27 Jun 2010 04:56:51 -0400 (EDT)

On 6/26/10 at 3:09 AM, dxcqp2000 at gmail.com (uno) wrote:

>I have an expression that is a sum of terms, like a+b+c and I want to
>convert it to a list, with as many elements as the number of terms in
>the sum of terms, and with each element being each of the terms, like
>{a,b,c}

The way to do this is to use Apply. That is

In[1]:= sum = a + b + c;
List @@ sum

Out[2]= {a,b,c}

Mathematica stores sum as:

In[3]:= FullForm[sum]

Out[3]//FullForm= Plus[a,b,c]

The @@ (shorthand for Apply) replaces the head Plus in sum with
the head List yielding the desired result. And since this works
on any expression, your product can be converted to a list in
the same manner

>Also, the same to go from a product of terms like a*b*c to a list like
>{a,b,c}

In[4]:= prod = a b c;
List @@ prod

Out[5]= {a,b,c}

• Prev by Date: Re: Sum of terms --> list
• Next by Date: Re: precedence for ReplaceAll?
• Previous by thread: Re: Sum of terms --> list
• Next by thread: Re: Sum of terms --> list