2

Start with:

    b = Blue; r = Red;

According to the docs, one should use Equal (==) and Unequal (!=) only for testing equality of such things as numeric objects and string objects; and one should use SameQ (===) and UnsameQ (=!=) otherwise.

So as expected, the following return unevaluated (except that the names of colors get replaced by color blobs):

    Red == Blue
    r == b
    Red != Blue
    r != b

Now, however, let:

    x = b;

Now all the below do evaluate to give True or False:

    x == Blue
(* True *)
    x == b
(* True *)
    x != Blue
(* False *)
    x != b
(* False *)

Why does Mathematica permit this?

murray
  • 11,888
  • 2
  • 26
  • 50

1 Answers1

1

The difference is that x=y assigns a value to x. So, if x does not have a value, it evaluates to itself. However try

ClearAll[x];
Print[x==x,":",x==0,":",x==Unevaluated[x]]

Now do x=0 and the Print statement again to see the difference. Note that I used 0 as just an example. Almost any Mathematica expression would do, but it is certain for atomic objects like integers and colors. Verify this for yourself.

Somos
  • 4,897
  • 1
  • 9
  • 15