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:
Trueif the expressions are certainly different, for example two different numbers;Falseif 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 = 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 |
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
NaNis different from everything:NaN <<>> 1isTrue.
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