# Checking equality with ComplexInfinity and testing whether a function is (mathematically) undefined

This seems ridiculously basic, but I cannot find anywhere explaining how to do it.

If you evaluate certain undefined functions like 1/0 or Tan[\[Pi]/2], Mathematica evaluates to ComplexInfinity. For some reason, however, the following expression does not act as expected:

1/0 == ComplexInfinity


This results in

ComplexInfinity == ComplexInfinity

rather than the expected

True

So the question is, how do you test whether a function evaluates to ComplexInfinity, or better yet, how do you test if a function is (mathematically, not programmatically) undefined?

• If you need to test if something returns ComplexInfinity, you can use something === ComplexInfinity. This is a structural test that'll only return True if the two symbols are identical. It's not a mathematical test like == is. – Szabolcs Feb 6 '13 at 17:05
• I think the reason why ComplexInfinity == ComplexInfinity doesn't evaluate is that the direction in the complex plane is considered unknown. Check this. – Szabolcs Feb 6 '13 at 17:07
• Something I didn't know before: it seems all of Infinity, -Infinity, ComplexInfinity are just special printed forms of DirectedInfinity. Check their FullForm or their Head: they have structure. – Szabolcs Feb 6 '13 at 17:09
• @Szabolcs Probably enough info in your three comments to combine them in an answer. – Sjoerd C. de Vries Feb 6 '13 at 21:19

To understand why ComplexInfinity == ComplexInfinity, let's look at how Mathematica handles infinities. All of Infinity, -Infinity, ComplexInfinity are just displayed forms of DirectedInfinity:

In:= FullForm /@ {Infinity, -Infinity, ComplexInfinity}
Out= {DirectedInfinity, DirectedInfinity[-1], DirectedInfinity[]}


DirectedInfinity[z] represents an infinite quantity in the direction of z on the complex plane. ComplexInfinity is DirectedInfinity[]; i.e., an infinite quantity with an unknown direction. The reason it cannot be compared is that the direction is unknown.

If you need to test for ComplexInfinity in particular, you can use

something === ComplexInfinity


=== is a structural test that, unlike ==, does not take any mathematical meaning into account.

Finally, for your purpose, I think NumericalQ (your answer) is a very good solution.

• Posted answer per request. – Szabolcs Feb 6 '13 at 23:38
• If all you want is to test if an input is infinite: MatchQ[(* stuff *), _DirectedInfinity]. +1 of course. – J. M. will be back soon Feb 7 '13 at 3:37

I found an easy way to do this, simply test the value of the function with NumericQ to determine if it evaluates to a number or not. I would still be interested to know what sort of object or entity ComplexInfinity is that I can't test whether it is equal to itself with ==.