# how to cancel arbitrary term in fractional formula

I often encounter this kind of problem that I want the fractional formula to be looked like the way I want it to be. For example, this one

$$\frac{R^2 \left(g m_1-g m_2\right)}{J+m_1 R^2+m_2 R^2}$$

I want it to be like this

$$\frac{g \left(m_1-m_2\right)}{\frac{J}{R^2}+m_1+m_2}$$

to change $g m_1-g m_2$ into $g \left(m_1-m_2\right)$ is easy by using Factor in algebraic palette.

but I have not figured out an easy way to cancel $R^2$ in both enumerator and denominator, unless I deleted $R^2$ manually.

A more general question is how to cancel arbitrary term in fractional formula?

You might find it helpful to define TransformationFunctions, which is an option to FullSimplify.

For example:

t[term_][expr_] :=
Simplify[Numerator[expr]/term]/Simplify[Denominator[expr]/term]

expr = R^2 (g m[1] - g m[2])/(J + m[1] R^2 + m[2] R^2);

FullSimplify[expr,
TransformationFunctions -> {Automatic, t[R^2]}]
(* (g (m[1] - m[2]))/(J/R^2 + m[1] + m[2]) *)


While not automatic (and you should be careful that term cannot be 0), it does add something to a toolbox.

• It seems it only works with t[R^2]. I tried t[p^2], then nothing happens. May 7, 2015 at 14:15
• @matheorem I don't know what you mean, but FullSimplify will reject a transformation if the result is more complex, as defined by the ComplexityFunction. May 7, 2015 at 16:01
• @matheorem can you provide what you actually did?
– chuy
May 7, 2015 at 17:28
• @MichaelE2 Well, the reason that I want to divide numerator and denominator by $R^2$ is that I want the $J/R^2$, because $J/R^2$ has a special meaning. If $J/p^2$ has a special meaning, then I have to divide $p^2$. May 8, 2015 at 0:38
• @matheorem What I meant is that t[p^2] works for me on the example in the Q. I assumed you tried it on another expression and it didn't work. You might try applying t[p^2] directly to the expression. May 8, 2015 at 0:45

There are many ways to make this. For example, this one is simple, but is a bit not regular, that is, depends upon the structure of the expression at hand:

  expr = (R^2*(g*m1 - g*m2))/(J + m1*R^2 + m2*R^2);

(expr /. J -> j*R^2 // Simplify) /. j -> J/R^2

(* (g (m1 - m2))/(m1 + m2 + J/R^2)   *)


This one is more regular though a bit longer:

(Factor[Numerator[expr]]/R^2)/Map[Divide[#, R^2] &, Denominator[expr]]

(*   (g (m1 - m2))/(m1 + m2 + J/R^2)   *)


Generally, there is a package "Presentation Master" of David Park, that has a subpackage "Manipulations". The latter contains a dozen of functions designed precisely for such purposes. With the help of that one can transform any expression to any desired form. I strongly recommend using it.

Have fun!

Ok, another version of Chuy's answer, only simpler:

expr = R^2 (g m[1] - g m[2])/(J + m[1] R^2 + m[2] R^2);
Simplify[Numerator[expr]/R^2]/Simplify[Denominator[expr]/R^2]


This could be put into a function, but the point is that the use of TransformationFunction inside Simplify is unnecessary, I think.

I'm new to this game and I'm struggling with exactly these issues myself.

Hope this helps

• Please post the output of your solution too, so that it can be compared with that of other answers. May 26, 2015 at 21:05
• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. May 26, 2015 at 21:06

Perhaps,

With[{n = Simplify[Numerator[expr]/R^2],
d = Simplify[Denominator[expr]/R^2]}, n/d]


this yields:(g (m1 - m2))/(m1 + m2 + J/R^2)