# Making fractions cancel

I have an equation that Mathematica really wants to display as $$\frac{1}{4\pi G} \bigg( 4\pi G A + 4\pi G B\bigg)$$ where $A$ and $B$ are some terms and $G$ a constant.

No amount of Apart, Simplify, Cancel, Factor, or anything, will make Mathematica cancel the $4\pi$ on the top and bottom.

What do I need to do to get rid of that?

(It would take of several pages to reproduce the calculation that leads to this, and I have no idea why the $4\pi$ is there in the first place so I couldn't give a simpler exampel.)

Update: Let's try this. I have a very complicated function

myFunction[orderG_][xx_?VectorQ]:=
Normal@Series[16 Pi G * complicatedFunction[orderG][xx]
+ evenMoreComplicatedFunction[orderG][xx],{G,0,orderG}]


As it appears in my code, this function is actually a matrix, but treat itas a scalar to demonstrate. Later on, I calculate

txyz = {t,x,y,z}
delbTab = Sum[ D[c^4/(16 Pi G) myFunction[2][txyz],txyz[[a]]], {a,1,4}]
Normal@Series[delbTab, {c,\[inf],1}]


This leads to a term with a factor $\frac{1}{4\pi G}$, then all terms inside the parentheses with their own factors of $4\pi G$. (The factors of $4\pi G$ in the second term is due to its definition)

Here is the FullForm output:

    HoldForm[MatrixForm[Times[Rational[1,4],Power[G,-1],Power[Pi,-1],Plus[Times[4,G,Pi,v3,\[Rho]Star,Derivative[List[0,0,0,1]][v1]],Times[4,G,Pi,v1,\[Rho]Star,Derivative[List[0,0,0,1]][v3]],Times[4,G,Pi,v1,v3,Derivative[List[0,0,0,1]][\[Rho]Star]],Times[4,G,Pi,v2,\[Rho]Star,Derivative[List[0,0,1,0]][v1]],Times[4,G,Pi,v1,\[Rho]Star,Derivative[List[0,0,1,0]][v2]],Times[4,G,Pi,v1,v2,Derivative[List[0,0,1,0]][\[Rho]Star]],Times[4,G,Pi,Derivative[List[0,1,0,0]][P]],Times[8,G,Pi,v1,\[Rho]Star,Derivative[List[0,1,0,0]][v1]],Times[4,G,Pi,Power[v1,2],Derivative[List[0,1,0,0]][\[Rho]Star]],Times[Derivative[List[0,0,0,2]][\[CapitalPhi]],Derivative[List[0,1,0,0]][\[CapitalPhi]]],Times[Derivative[List[0,0,2,0]][\[CapitalPhi]],Derivative[List[0,1,0,0]][\[CapitalPhi]]],Times[Derivative[List[0,1,0,0]][\[CapitalPhi]],Derivative[List[0,2,0,0]][\[CapitalPhi]]],Times[4,G,Pi,\[Rho]Star,Derivative[List[1,0,0,0]][v1]],Times[4,G,Pi,v1,Derivative[List[1,0,0,0]][\[Rho]Star]]]]]]


Applying operations like

(%*4/(G^-1*Pi^-1))


or

Distribute[%, 4 Pi G]


to the output leads to even more absurd output $$4\pi G \frac{1}{4\pi G}\bigg(4\pi G A + 4\pi G B\bigg),$$ where $A$ and $B$ are the functions and $G$ is a parameter.

• Factor[1/(4 Pi) (4 Pi F + 4 Pi G)] works for me (so does Simplify), so the problem is with your code, which you have not shared. :/ – Michael E2 May 23 '18 at 2:52
• I tried to put it in, and the website complained :/ – RBoston May 23 '18 at 3:17

MatrixForm is causing the your problem. MatrixForm is a wrapper for pretty-printing output and blocks all computation on its argument including any attempt at simplification. Without the wrapper

Times[Rational[1, 4], Power[G, -1], Power[Pi, -1],
Plus[
Times[4, G, Pi, v3, ρStar, Derivative[List[0, 0, 0, 1]][v1]],
Times[4, G, Pi, v1, ρStar, Derivative[List[0, 0, 0, 1]][v3]],
Times[4, G, Pi, v1, v3, Derivative[List[0, 0, 0, 1]][ρStar]],
Times[4, G, Pi, v2, ρStar, Derivative[List[0, 0, 1, 0]][v1]],
Times[4, G, Pi, v1, ρStar, Derivative[List[0, 0, 1, 0]][v2]],
Times[4, G, Pi, v1, v2, Derivative[List[0, 0, 1, 0]][ρStar]],
Times[4, G, Pi, Derivative[List[0, 1, 0, 0]][P]],
Times[8, G, Pi, v1, ρStar, Derivative[List[0, 1, 0, 0]][v1]],
Times[4, G, Pi, Power[v1, 2], Derivative[List[0, 1, 0, 0]][ρStar]],
Times[Derivative[List[0, 0, 0, 2]][Φ], Derivative[List[0, 1, 0, 0]][Φ]],
Times[Derivative[List[0, 0, 2, 0]][Φ], Derivative[List[0, 1, 0, 0]][Φ]],
Times[Derivative[List[0, 1, 0, 0]][Φ], Derivative[List[0, 2, 0, 0]][Φ]],
Times[4, G, Pi, ρStar, Derivative[List[1, 0, 0, 0]][v1]],
Times[4, G, Pi, v1, Derivative[List[1, 0, 0, 0]][ρStar]]]] // Simplify


gives

For

expr = HoldForm[MatrixForm[Times[Rational[1, 4], Power[G, -1], Power[Pi, -1],
Plus[Times[4, G, Pi, v3, ρStar,  Derivative[List[0, 0, 0, 1]][v1]],
Times[4, G, Pi, v1, ρStar, Derivative[List[0, 0, 0, 1]][v3]],
Times[4, G, Pi, v1, v3,  Derivative[List[0, 0, 0, 1]][ρStar]],
Times[4, G, Pi, v2, ρStar,  Derivative[List[0, 0, 1, 0]][v1]],
Times[4, G, Pi, v1, ρStar,  Derivative[List[0, 0, 1, 0]][v2]],
Times[4, G, Pi, v1, v2, Derivative[List[0, 0, 1, 0]][ρStar]],
Times[4, G, Pi, Derivative[List[0, 1, 0, 0]][P]],
Times[8, G, Pi, v1, ρStar, Derivative[List[0, 1, 0, 0]][v1]],
Times[4, G, Pi, Power[v1, 2], Derivative[List[0, 1, 0, 0]][ρStar]],
Times[Derivative[List[0, 0, 0, 2]][Φ], Derivative[List[0, 1, 0, 0]][Φ]],
Times[Derivative[List[0, 0, 2, 0]][Φ], Derivative[List[0, 1, 0, 0]][Φ]],
Times[Derivative[List[0, 1, 0, 0]][Φ], Derivative[List[0, 2, 0, 0]][Φ]],
Times[4, G, Pi, ρStar, Derivative[List[1, 0, 0, 0]][v1]],
Times[4, G, Pi, v1, Derivative[List[1, 0, 0, 0]][ρStar]]]]]];


you can also use

Simplify[expr[[1, 1]]]


and

% == Simplify[ReleaseHold[expr][[1]]] ==
Expand[expr[[1, 1]]] == Expand[ReleaseHold[expr][[1]]]


True

Try this:

FullSimplify[1/(4 Pi) (4 Pi f + 4 Pi g)]
f+g


Now that you have placed your code in the question it's easy to see the problem: the MatrixForm and HoldForm expressions. Remove all MatrixForm commands and HoldForm commands. Taking your FullForm output and removing these two leading commands allows it to simplify automatically. MatrixForm is a formatting command and causes simplifications not to work. HoldForm tells it not to change the form (i.e., don't simplify).

• If I copy the output and do that, then it simplifies. If I try to run cancel on the input expression, then it refuses to, and calls to FullSimplify[%] do nothing. – RBoston May 23 '18 at 2:57

If I understand you right, you want to cancel 4Pi, but not G, do you? If yes, there is an easy way. Here is your expression:

expr = 1/(4 \[Pi] G)*(4 \[Pi]*G*A + 4 \[Pi]*G*B)

(*   (4 A G \[Pi] + 4 B G \[Pi])/(4 G \[Pi]) *)


Try this:

expr /. \[Pi] -> 1/4

(* (A G + B G)/G  *)


Have fun!