# Get rid of a certain variable in a fraction's numerator

Consider expression $$\frac{a - b}{a + b}$$. When I apply $$FullSimplify[\frac{a - b}{a + b}]$$, I get $$-1 + \frac{2a}{a+b}$$, effectively getting rid of $$b$$ in the numerator. However, I want to get rid of $$a$$ and get $$1 - \frac{2b}{a+b}$$. How do I do this?

In general, I have a more complicated fraction, with multiple variables (and $$FullSimplify$$ simply does nothing). You can assume that the variable I want to get rid of participates linearly in both numerator and denominator (but its coefficients can be mildly complicated expressions in terms of other variables).

• FullSimplify[(a - b)/(a + b) /. a -> d] /. d -> a answers your question as written but is not very satisfying. In general, the user's idea of simplification often differs from Mathematica's idea.. Using a combination of Collect and FullSimplify sometimes is useful. By the way, I would have expected cf[e_] := LeafCount[e] + 100 Count[e, a, {0, Infinity}]; FullSimplify[(a - b)/(a + b), ComplexityFunction -> cf] to solve your specific problem, but it does not. Oct 6, 2021 at 1:02

Try this:

PolQuotient[num_, den_, var_] := PolynomialQuotient[num, den, var] + 1/den*PolynomialRemainder[num, den, var]


Test:

PolQuotient[a - b, a + b, a]
(*1 - (2 b)/(a + b)*)


Improving the above function:

  PolyQR[expr_, var_, opts___] := Block[{num, den, pq, pr, pqr},
num := Numerator[expr];
den := Denominator[expr];
pq := PolynomialQuotient[num, den, var];
pr := PolynomialRemainder[num, den, var]/den;
pqr := pq + pr;
Return[
Piecewise[{{pqr, opts === None}, {pq, opts === "Quotient"},{pr,
opts === "Remainder"}}]];];


Test:

  expr = (a - b)/(a + b);
PolyQR[expr, a]
(*1 - (2 b)/(a + b)*)
PolyQR[expr, a, "Quotient"]
(*1*)
PolyQR[expr, a, "Remainder"]
(*-((2 b)/(a + b))*)

• Thanks! This solution is great for me, it also solves some other issues by explicitly separating the integer and the fractional parts. Oct 6, 2021 at 1:00
Clear["Global*"]

\$Version

(* "12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021)" *)

expr = (a - b)/(a + b);

expr // FullSimplify

(* -1 + (2 a)/(a + b) *)


The form of the result is determined by the canonical order of the variables. You can temporarily change the order through substitution

expr2 = (expr /. a -> c // FullSimplify) /. c -> a

(* 1 - (2 b)/(a + b) *)

expr2 == expr // Simplify

(* True *)

• Thanks for the reply, it's good to know. Unfortunately, it fails for me when my fractions are more complicated (and FullSimplify` doesn't do anything at all). Oct 6, 2021 at 1:00