3
$\begingroup$

Basically I have a really large output which looks like a long linear equation

$AAA-BAA-CAA+DAA+...-ZZZ$

And I only am concerned about those terms that have a positive coefficient (i.e. a plus in front). The others I can ignore.

How can I get mathematica to ignore those positive-coefficient terms, or at the very least order the list such that the negative coefficient terms are in the front (or back).

$\endgroup$
3
  • $\begingroup$ aaa - bbb + ccc + dd - eee /. Times[-1, __] :> Sequence[]? $\endgroup$
    – kglr
    Commented Aug 24, 2014 at 14:36
  • $\begingroup$ @kguler Wow, works like a charm! Thanks! But I can't parse it easily, how does it work? $\endgroup$ Commented Aug 24, 2014 at 14:39
  • $\begingroup$ i posted a simpler solution. Regarding how it works, please see ReplaceAll and PatternTest in the docs for many examples. $\endgroup$
    – kglr
    Commented Aug 24, 2014 at 14:48

1 Answer 1

2
$\begingroup$
expr = aaa - 3 bbb + ccc + ddd - eee
expr /. _?Negative :> 0
(* aaa + ccc + ddd *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.