Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull out minus sign to get a unified list?

Given the following list:

{a + b, c + d + e, - a + b, a - b, - c - d - e}

I would like to get as a result:

{a + b, a - b, c + d + e}

To clarify: I'd like to transform the first list in such a way that the first term in each element is normalized to a plus sign and throw away any elements that can be obtained from the final result by multiplying with -1.

I have tried Collect[] and FactorTerms[] and some other functions that look remotely like they would be able to do what I need, but they never touch minus signs ....

Any help is greatly appreciated.

like image 335
bbtrb Avatar asked Jun 15 '11 15:06

bbtrb


1 Answers

Use FactoredTermsList:

In[5]:= FactorTermsList /@ {a + b, c + d + e, -a + b, 
  a - b, -c - d - e}

Out[5]= {{1, a + b}, {1, c + d + e}, {-1, a - b}, {1, a - b}, {-1, 
  c + d + e}}

In[6]:= DeleteDuplicates[%[[All, 2]]]

Out[6]= {a + b, c + d + e, a - b}
like image 111
Sasha Avatar answered Oct 20 '22 19:10

Sasha