I'm trying to test the following logical statement:

state = {{1,1,1}};
Or[state != 0, state != Null]

but it's returning False rather than True as I expect it to.

I ran the following TrueQ tests, getting the following results:

TrueQ[Or[{{1, 1, 1}} != 0, {{1, 1, 1}} != Null]]
TrueQ[{{1, 1, 1}} !=  0]
TrueQ[{{1, 1, 1}} != Null]




I'm not sure why I'm getting these results: I don't understand why TrueQ is failing to resolve as True in these situations. What can I do to make the logical test give me the results I'm looking for -- namely, when state is either 0 or Null, I get False, and get True otherwise?

  • 3
    $\begingroup$ You probably want =!= instead of !=. $\endgroup$ – AccidentalFourierTransform Aug 12 at 22:21
  • $\begingroup$ @AccidentalFourierTransform Yup, that worked! Thank you! If you add this as the answer I'll accept it. $\endgroup$ – Natavi Aug 12 at 22:23
  • 1
    $\begingroup$ But why use TrueQ at all? {{1, 1, 1}} =!= 0 evaluates to True directly. $\endgroup$ – march Aug 12 at 22:50
  • $\begingroup$ TrueQ returns True if and only if its argument is identically equal to True. Now {{1, 1, 1}} != Null remains unevaluated and hence is not True, which means TrueQ returns False. $\endgroup$ – Chip Hurst Aug 13 at 12:43

You probably want =!= instead of !=. See Unequal v UnsameQ for more details.


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.