Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
2  
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
2  
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
2  
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
add comment

2 Answers

up vote 2 down vote accepted

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[1]:= FullForm /@ {Infinity, -Infinity, ComplexInfinity}
Out[1]= {DirectedInfinity[1], 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.

share|improve this answer
    
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. Feb 7 '13 at 3:37
add comment

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 ==.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.