# Equality of expressions containing complex numbers [closed]

I am using Mathematica to test the equivalence of symbolic expressions. I run into what appears to be a bug when I test the equivalence of expressions involving an imaginary number taken to a complex power. When I test the equivalence of such expressions that are clearly equal, mathematica does not recognize their equivalence. Here is an example:

Assuming[k > 0 && m > 0,
{TrueQ[(2*I*k)^(1 + 0.1*I) (2 I k)^(I*m) == (2*I*k)^(1 + 0.1*I + I*m)]}]


False

Interestingly, when I repeat the above test, except changing the 2 I k to I k, Mathematica recognizes the equivalence:

Assuming[k > 0 && m > 0,
{TrueQ[(I*k)^(1 + 0.1*I)* (I k)^(I m) == (I*k)^(1 + 0.1*I + I*m)]}]

True


Another interesting example I encountered was when taking an imaginary number to the power Pi vs. N[Pi]:

Assuming[k > 0 && m > 0, {TrueQ[(I k)^(Pi) (I k)^(I m) == (I k)^(Pi + I m)]}]

True

Assuming[k > 0 && m > 0, {TrueQ[(I k)^(N[Pi]) (I k)^(I m) == (I k)^(N[Pi] + I m)]}]

False


I suspect these to be a bug in Mathematica. Has anyone encountered similar problems with equivalence tests in Mathematica, or does anyone have an idea of what might be the cause if this apparent problem?

• You will want to avoid inexact numbers in this application. Try replacing 0.1 with 1/10 in your first example, for instance. – J. M. is in limbo Jul 12 '15 at 11:19
• Please, try to format your questions properly. If you visit the help centre you can read more about it. – Sektor Jul 12 '15 at 11:23

This is not a bug. It's a misunderstanding about what TrueQ does.

From the documentation,

TrueQ will return True only if the input is explicitly True

To put it more explicitly, it's equivalent to trueQ[expr_] := If[expr === True, True, False].

The expression (2*I*k)^(1 + 0.1*I) (2 I k)^(I*m) == (2*I*k)^(1 + 0.1*I + I*m) is not the symbol True (regardless of the fact whether it's mathematically true or not), so TrueQ returns False.

(I k)^(Pi) (I k)^(I m) == (I k)^(Pi + I m) evaluates to True immediately due to canonicalization of the power expression, so TrueQ returns True.

TrueQ does not deal with symbolic mathematics at all. It simply checks if an expression is True, literally, or something else. It does not even care about the meaning of the symbol True.

The correct way to handle this problem is to use Simplify instead of TrueQ and to only use exact numbers. 0.1 is not exact.

• Assuming[k > 0 && m > 0, Simplify[(2*I*k)^(1 + 0.1*I) (2 I k)^(I*m) == (2*I*k)^(1 + 0.1*I + I*m)]] ( i.e., with inexact numbers) evaluates to True on my system (Mma v10.1 with Mac OS 10.10.4). Although I agree that generally it is best when checking for equality to use exact numbers to avoid potential problems. – Bob Hanlon Jul 12 '15 at 12:40

What you are encountering is something all Mathematica users encounter because it is the way Mathematica works. Szabolcs has explained this well. However, I would like to add that you can fix the "problem" by using Simplify

Simplify[(2*I*k)^(1 + 0.1*I) (2*I*k)^(I*m) == (2*I*k)^(1 + 0.1*I + I*m)]

True

Simplify[(I k)^(N[Pi]) (I k)^(I m) == (I k)^(N[Pi] + I m)]

True