Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Re: Converting an expression to a list of terms?


Dimitris,

I had my disclaimer:  "newbie approach" as a red flag.   That is a  
clear indication that it is by the grace of god that I am able to  
present a solution and that solution is good just for me.  Good  
programming technique should come from member emeritizeuses of this  
group.  I am just an accidental stalker here nothing more.

I read Chapter 2 from the Book.  As a matter of fact I read it  
multiple times.  I have to confess that even if I would have the time  
to read it ab infinity, I still would not get more out of it than I  
have as it is.  Steven just did not sex it up to get me more exited  
about it :)

With the best,

János

On Nov 23, 2006, at 5:41 AM, dimitris wrote:

> 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)



----------------------------------------------
Trying to argue with a politician is like lifting up the head of a  
corpse.
(S. Lem: His Master Voice)


  • Prev by Date: RE: Not accepting function as parameter
  • Next by Date: Re: Re: SetPrecision vs N
  • Previous by thread: Re: Converting an expression to a list of terms?
  • Next by thread: Re: Converting an expression to a list of terms?