# Simplification of complex number factors out an extra i

When I evaluate

Simplify[ - a - I Sqrt[3] a - b - I Sqrt[3] b ]


Mathematica returns

-I (-I + Sqrt[3]) (a + b)


Personally, I find it annoying that it factors out an extra I since it doesn't make the expression simpler (and I think in this case it is unambiguous that (- 1 - I Sqrt[3]) (a + b) is actually simpler...). FullSimplify does the same. For 1 complex number, I could use Expand but for expressions with variables this screws up the simplification.

Why does Mathematica do this and is there an easy way to get rid of these extra factors of I?

• FullSimplify[-a - I Sqrt[3] a - b - I Sqrt[3] b] gives what you want: (-1 - I Sqrt[3]) (a + b) (Mathematica v12.2) Jun 29, 2022 at 15:32

Use FullSimplify and restrict the ComplexityFunction to only look at the LeafCount

FullSimplify[-a - I Sqrt[3] a - b - I Sqrt[3] b,
ComplexityFunction -> LeafCount]

(* (-1 - I Sqrt[3]) (a + b) *)


For the complex expressions, one has to use ComplexExpand and combine it with Simplify or other functions if necessary. For example, for your expression

expr1 = -a - I Sqrt[3] a - b - I Sqrt[3] b;


the application of the ComplexExpand returns the following:

expr2 = ComplexExpand[expr1]

(*  -a - b + I (-Sqrt[3] a - Sqrt[3] b)  *)


Then one can do, for example, this:

MapAt[Factor, expr2, 3]

(*  -a - b - I Sqrt[3] (a + b)  *)


Or something else.

On the other hand, one can apply the replacement a+b->x, then simplify and replace back:

(expr1 /. a -> x - b // Simplify) /. x -> a + b

(*   (-1 - I Sqrt[3]) (a + b)  *)


One can go also this way:

(ComplexExpand[(expr1 // Simplify) /. a -> x - b] // Simplify) /.
x -> a + b

(* (-1 - I Sqrt[3]) (a + b)  *)


Have fun!

Building a small SimplifyComplex function:

 SimplifyComplex[expr_, assumptions___] :=
If[NumericQ[expr] === True,
Plus[Factor@
Part[Refine[Map[ComplexExpand, {FullSimplify[Re[expr]]}]], 1],
I*Factor@
Part[Refine[Map[ComplexExpand, {FullSimplify[Im[expr]]}]], 1]],
Plus[Factor@
Part[Refine[Map[ComplexExpand, {FullSimplify[Re[expr]]}],
Assumptions -> assumptions], 1],
I*Factor@
Part[Refine[Map[ComplexExpand, {FullSimplify[Im[expr]]}],
Assumptions -> assumptions], 1]]]


Test 1:

SimplifyComplex[-a - I Sqrt[3] a - b - I Sqrt[3] b, {a, b} \[Element] Reals]
(*-a - b - I Sqrt[3] (a + b)*)


Test 2:

SimplifyComplex[(a - b I)/(c + d I), {a, b, c, d} \[Element] Reals]
(*-((I (b c + a d))/(c^2 + d^2)) + (a c - b d)/(c^2 + d^2)*)


Test 3:

SimplifyComplex[(1 - 2 I)/(3 + 2 I)]
(*-(1/13) - (8 I)/13*)