# Extract common factor

Example: g[x_] = (x^3 - 27)/((x - 3)*(x + 1))


Here the common factor is x-3, how can i extract that common factor from a function (g(x)) and put it as a separate ..

Example: f[x] = x-3

• f[x_] = Numerator[g[x]]/Numerator[g[x] // Cancel] // Cancel – Bob Hanlon Jan 28 '17 at 14:46

I think PolynomialGCD is the most direct tool:

g[x_] = (x^3 - 27)/((x - 3)*(x + 1));

PolynomialGCD @@ Through @ {Numerator,Denominator} @ g[x]


-3+x

If you don't like operator notation, you might find this version preferable:

With[{n = Numerator[g[x]], d = Denominator[g[x]]}, PolynomialGCD[n,d]]


-3+x

• May I ask why you enclosed your second example in a With statement? E.g., what about just: PolynomialGCD[Numerator[g[x_]], Denominator[g[x_]]]? – theorist Mar 24 '18 at 1:16