After doing this:

Clear[f, h]
f[z_] = .66 I Cos[z];
h[c_] := {Re[c], Im[c], Nest[f, c, 200]};
complexpts = 
  Flatten[Table[a + b I, {a, 0., 8, 8/249}, {b, -4., 4, 8/249}], 1];
t1 = Map[h, complexpts] // Chop

This works:

Select[t1, Not[#[[3]] === Indeterminate] &]

But why doesn't this work:

Select[t1, Not[#[[3]] == Indeterminate] &]

And why doesn't this work:

Select[t1, (#[[3]] != Indeterminate) &]
  • 4
    $\begingroup$ Equal (==) tests for numerical equality, SameQ(===) and its negation UnsameQ(=!=) test for symbolic equality. Since Indeterminate is not a number, == and != fail. $\endgroup$ – John McGee Nov 7 '15 at 21:10
  • $\begingroup$ Thanks everyone. Nice explanations. $\endgroup$ – David Nov 7 '15 at 22:25
  • $\begingroup$ A related question. $\endgroup$ – J. M. is away Oct 27 '17 at 12:40

=== (SameQ) is structural equality. a === b is True if a and b are exactly the same data structure (expressions), and False otherwise. For === it doesn't matter what a and b represent. Also, like nearly all Mathematica functions ending in Q, === always evaluates to either True or False (but nothing else).

== is mathematical equality. a == b represents the equality of two mathematical expressions. It may or may not evaluate to True or False. Equations are represented in terms of ==

Indeterminate == someNumber never evaluates in Mathematica. You end up with something that is neither False nor True in Select. Select treats that as if it were false. Compare Select[{1,2,3}, foo] where foo is an arbitrary symbol (not True or False). Also consider that Not[foo] doesn't evaluate (because foo is here treated as a yet-unknown logical variable).

  • 1
    $\begingroup$ Why would 12 == "a" evaluate ? $\endgroup$ – eldo Nov 7 '15 at 21:17
  • 3
    $\begingroup$ @eldo - because a string (non-number) can never equal a number, Whereas, a symbolic expression may or may not equal a number. $\endgroup$ – Bob Hanlon Nov 7 '15 at 21:27
  • 1
    $\begingroup$ "a == b represents the equality of two mathematical expressions. It may or may not evaluate to True or False." Maybe it's worth noting that Mma may fail to perform the numerically "obvious" comparison and return an unevaluated, non-Boolean result in surprising situations. For instance, Sqrt[(2 - Sqrt[3])^2 + (-3 + 2 Sqrt[3])^2] == 4 - 2 Sqrt[3] doesn't evaluate straight to True, but does so when "pushed" with Simplify. $\endgroup$ – kirma Nov 10 '15 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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