1
$\begingroup$

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]

False

False

False

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?

$\endgroup$
4
  • 3
    $\begingroup$ You probably want =!= instead of !=. $\endgroup$ Commented Aug 12, 2019 at 22:21
  • $\begingroup$ @AccidentalFourierTransform Yup, that worked! Thank you! If you add this as the answer I'll accept it. $\endgroup$
    – Natavi
    Commented Aug 12, 2019 at 22:23
  • 1
    $\begingroup$ But why use TrueQ at all? {{1, 1, 1}} =!= 0 evaluates to True directly. $\endgroup$
    – march
    Commented Aug 12, 2019 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$
    – Greg Hurst
    Commented Aug 13, 2019 at 12:43

1 Answer 1

6
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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