# How do I remove the symbolic GCD of an expression?

In an expression like

expr = 2 g Pi - (2 I) G Pi - (2 I) Pi V0;


obviously $2 Pi$ is some sort of symbolic GCD. In such a simple case I could eyeball it and divide:

expr/(2 Pi) // Simplify
(* g - I(G + V0) *)


If the expression is more complex I would like to have a function that automatically identifies the symbolic GCD and then divide by it. I managed to write such a function (plus another auxiliary one). Here is the code:

Clear[gcdComplex, gcdPlusExpression];
gcdComplex[cp_Complex] /; And @@ IntegerQ /@ ReIm[4 + 8 I] :=
With[{gcd = GCD @@ ReIm[cp]}, List[gcd, cp/gcd]]
gcdComplex[x_] := x
gcdPlusExpression[expr_Plus] :=
Module[{l1 = List @@ expr, l2, l3, l4, gcd},
l2 = (List @@ # &) /@ l1;
l3 = Map[gcdComplex, l2, 2];
l4 = Flatten /@ l3;
gcd = Times @@ Intersection @@ l4;
{gcd,expr/gcd // Simplify}]

gcdPlusExpression@expr
(* {2 Pi, g - I (G + V0)} *)


I wonder if there is a better/simpler way.

• Wouldn't Factor help you? – halirutan Oct 9 '16 at 20:47
• In two steps (easily combined into one, I wanted to make the process reasonably clear): gcd = PolynomialGCD @@ expr Out= 2 Pi In:= Together[expr/gcd] Out= g - I G - I V0 – Daniel Lichtblau Oct 9 '16 at 21:04
• @DanielLichtblau - Thank you! Your one-liner makes my oversized code look foolish. But at least it was good practice. – Soldalma Oct 10 '16 at 0:19