# WolframLang: Equality Test

By Xah Lee. Date: . Last updated: .

There are basically only two functions to test equality:

• `SameQ` (`===`) → tests if two expressions are the same symbolically. This always return `True` or `False`. (any function name ending in Q always return `True` or `False`)
• `Equal` (`==`) → Tests if two expressions have the same meaning. E.g. `3` vs `3.0`. When `Equal` cannot determine it, e.g. `x == y` when `x` or `y` are not defined, it returns the expression as is.

In general,

• use `SameQ` if you want to compare symbolic expressions or structure.
• use `Equal` if you want to compare numbers, or expressions that contain just numbers, such as a list/tree/matrix whose elements are all numbers. [see WolframLang: Nested List, Array, Tree, Dimensions]

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