4
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – bbgodfrey
    Oct 6 at 1:02
7
$\begingroup$

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)*)
$\endgroup$
1
  • 1
    $\begingroup$ Thanks! This solution is great for me, it also solves some other issues by explicitly separating the integer and the fractional parts. $\endgroup$
    – Dmitry
    Oct 6 at 1:00
3
$\begingroup$
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 *)
$\endgroup$
1
  • $\begingroup$ 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). $\endgroup$
    – Dmitry
    Oct 6 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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