Re: Sum of terms --> list

• To: mathgroup at smc.vnet.net
• Subject: [mg110593] Re: Sum of terms --> list
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Sun, 27 Jun 2010 04:55:21 -0400 (EDT)

```expr = a + b + c;

List @@ expr

{a,b,c}

expr /. Plus -> List

{a,b,c}

expr = a*b*c;

List @@ expr

{a,b,c}

expr /. Times -> List

{a,b,c}

expr = a*b + c + e*f*g;

List @@ expr

{a b,c,e f g}

List @@ (List @@@ expr) // Quiet

{c,{a,b},{e,f,g}}

expr /. {Times -> List, Plus -> List}

{{a,b},c,{e,f,g}}

Bob Hanlon

---- uno <dxcqp2000 at gmail.com> wrote:

=============
Hi,

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}

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

Is there any way, in Mathematica, to do this?
I've been looking for an answer in the Help, and in the web, with no
help.

I ask this because "a*b+c+e*f*g" needs to be evaluated by an external
(.NET) program, which is not able to parse expressions. I have to
"break" everything inside Mathematica, before sending information to
that external program, which will evaluate that expression many times,
for different values of {a,b,c,d,e,f,g}.

Thank you.

```

• Prev by Date: Absolute value
• Next by Date: Re: Sum of terms --> list
• Previous by thread: Re: Sum of terms --> list
• Next by thread: Re: Sum of terms --> list