WolframLang: Equality Test

By Xah Lee. Date: . Last updated: .

There are basically only two functions to test equality:

In general,

here's detail:

SameQ[expr1, expr2]
(short syntax: ===)
return True if two expressions are symbolically identical, else False.

examples:

  • 3 === 3.0 return False because one is exact number while the other is approx.
  • 3 === xyz return False because if xyz is not defined.
SameQ
x = 3;
y = 3.0;
x === y
(* False *)
Equal[expr1, expr2]
(short syntax: ==)
  • return True if two expressions are semantically equal,
  • return False if two expressions are not semantically equal,
  • return whole expression as is, if semantical equality cannot be determined.
Equal
x = 3;
y = 3.0;
x == y
(* True *)
result = (a == 3);

result
(* result is a == 3, because the equality cannot be determined *)

(* if we replace a by 3, then True *)
ReplaceAll[ result , a -> 3 ]
(* True *)

Inequality

UnsameQ
(short syntax: =!=)
Same as Not[SameQ[x, y]] . UnsameQ
Unequal
(short syntax: !=)
Same as Not[Equal[x, y]]. Unequal

WolframLang Boolean

WolframLang in Depth

Basics

Comment, Print

String

Arithmetic

List

Expression, Atom, Head

Boolean

Conditional

Variable

Loop

Data Structure

Function

Pattern Matching

Advanced

Shell Tasks

Misc