Re: Converting an expression to a list of terms?
- To: mathgroup at smc.vnet.net
- Subject: [mg71619] Re: Converting an expression to a list of terms?
- From: "dimitris" <dimmechan at yahoo.com>
- Date: Sat, 25 Nov 2006 05:36:58 -0500 (EST)
- References: <200611200743.CAA09240@smc.vnet.net><ejtdhl$j0v$1@smc.vnet.net>
It's not a good programming practise to treat independently each element of one expression. Treat the expession as a whole. lst=a+b-c+d-e; List@@lst {a,b,-c,d,-e} lst/.x_+y___\[RuleDelayed]{x,y} {a,b,-c,d,-e} I highly recomend you reading Chapter 2 of the Mathematica Book. FrontEndExecute[{HelpBrowserLookup["MainBook", "2"]}] Regards Dimitris János wrote: > On Nov 20, 2006, at 2:43 AM, 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? > > My newbie approach would be: > > In[1]:= > expr = a + b - c + d - e; > > In[2]:= > Table[expr[[i]], > {i, 1, Length[expr]}] > Out[2]= > {a, b, -c, d, -e} > > János > > > ---------------------------------------------- > Trying to argue with a politician is like lifting up the head of a > corpse. > (S. Lem: His Master Voice)
- References:
- Converting an expression to a list of terms?
- From: AES <siegman@stanford.edu>
- Converting an expression to a list of terms?