1
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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."

$\endgroup$
1
$\begingroup$

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)*)
$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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