Cancel opposite terms, and only that [closed]

I have the following problem: I have a formula which looks like $$A = \sum \frac{1}{p_1 p_2 p_3 \dots},$$ where the $$p_i$$ are linear expression in some variables X. In the sum there are many opposite terms, such as $$\frac{1}{(a-b)} + \frac{1}{-a+b}+ \dots,$$ and I would like mathematica to recognise this fact and cancel them. However, I want mathematica to do ONLY this, nothing more. The problem is that if I use Simplify, mathematica will do more than that: it will try to put everything together, i.e. it will find the (foreboding) polynomials such that $$A = \frac{P}{Q}.$$ If I don't do anything, instead, mathematica will not recognise the cancellations: even just $$\frac{1}{(a-b)} + \frac{1}{-a+b},$$ does not get simplified automatically.

closed as unclear what you're asking by Michael E2, m_goldberg, John Doty, José Antonio Díaz Navas, LCarvalhoJan 21 at 18:32

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

It is a little risky to suggest a solution without a concrete example to test it on first, but see if this does approximately what you want.

1/(r-s)+1/(a-b)+1/(-t+u)+1/(-a+b)+1/(-m+n)+1/(c-d)+1/(-c+d)//. 1/(a_-b_)+1/(-a_+b_)->0


which returns

(* 1/(-m+n)+1/(r-s)+1/(-t+u) *)


It may be much more difficult to get Mathematica to do "ONLY this, nothing more."

Here is a slight modification of the Bill's approach:

expr = 1/(a - b) + 1/(-a + b) + 1/(2 a + 3 b) + 1/(a + 2 b)
(*1/(a - b) + 1/(-a + b) + 1/(a + 2 b) + 1/(2 a + 3 b)*)
expr //. x_ + y_ /; Simplify[x + y == 0] -> 0
(*1/(a + 2 b) + 1/(2 a + 3 b)*)


In its most general form it is not very efficient, but you can adjust the pattern, e.g.

expr //. x_Power + y_Power /; Simplify[x + y == 0] -> 0
(*1/(a + 2 b) + 1/(2 a + 3 b)*)


or

expr //. 1/x_ + 1/y_ /; Simplify[x + y == 0] -> 0
(*1/(a + 2 b) + 1/(2 a + 3 b)*)