UnequalsEval

UnequalsEval

a <<>> b checks if two expressions are different, and returns True or False.

Usages

a <<>> b or UnequalsEval[ a, b ]

a <<>> b returns:

  • True if the expressions are certainly different, for example two different numbers;
  • False if they are the same expression, or have the same value;
  • the comparison itself, unevaluated, if it cannot be decided, for example because the expressions contain variables.
Example in out
Two different numbers. 4 <<>> 2 True
The same value, where x is a script variable. x := 5
r := UnequalsEval[x+2, x+4-2]
r = False
The same expression, in a different order. x+1 <<>> 1+x False
Lists of different lengths. {1,2} <<>> {1,2,3} True
Cannot be decided. x <<>> y x <<>> y

a <> b as a condition

a <> b represents the relation a ≠ b. In a script it is not checked, but as a condition in If or While it is.

Example in out
Not checked in a script. 4 <> 2 4 <> 2
Checked as a condition. a := 4
If[a <> 4]
  r := 1
Else
  r := 0
End
r = 0
Options

CompareLiteral

If set to True, the expressions are compared as they are written, without calculating their values. This option requires the UnequalsEval[ ... ] notation.

Syntax Example out
UnequalsEval[ a, b, CompareLiteral=>True ] UnequalsEval[ 1/2, 0.5, CompareLiteral=>True ] True
Details
  • NaN is different from everything: NaN <<>> 1 is True.
Warning

A fraction and a decimal number are not compared: 1/2 <<>> 0.5 and 2.4 <<>> 12/5 are left unevaluated, although 1/2 == 0.5 gives True. Use == with If ... Else to test whether such values differ.

See also: EqualsEval, Smaller, If