# 1 is not the SameQ as Null, but why might 1 be Equal to Null?

The command

SameQ[1, Null]


returns

False


which is what I would expect, but the command

Equal[1, Null]


returns

1==Null


Why is Mathematica agnostic as to whether 1 is equal to Null ? Surely it is not ?

• It does not evaluate if non numeric symbols are involved, unless both sides are exactly (full form) the same. "lhs==rhs returns False if lhs and rhs are determined to be unequal by comparisons between numbers or other raw data, such as strings. "
– Kuba
Commented Nov 10, 2017 at 9:30
• It's not agnostic: Equal only evaluates arguments if they have numeric or string values. 1==Automatic and Null == Automatic are all left unevaluated. 1 == 1 + Null is left unevaluated just as 1 == 1 + x is, which perfectly makes sense, as you don't have a value for x (or for Null) yet. Think of it (as the doc states) that Equal tries to be as symbolic as possible, and does not evaluate symbols without values. Commented Nov 10, 2017 at 9:32
• I think the deeper reason is that Mathematica does not treat Null as special in that case and thus behaves like it would for any unassigned symbol and returns unevaluated. Commented Nov 10, 2017 at 9:32
• Food for thought: if things like 3 == x + 2 evaluated at once (or with any symbol in general like Null), we wouldn't be able to use them in functions like Solve[] and Reduce[]. Commented Nov 10, 2017 at 11:51

=== (SameQ) tests structural equality and is meant mainly for programming uses. Like nearly all functions named as ...Q, it evaluates immediately to either True or False.

== both represents and tests mathematical equality, and is meant for symbolic algebra use.

Thus when == is used with a symbol (or expression containing symbols) on either side, it will not evaluate. It stays unevaluated and it can be used to represent a mathematical statement. This is how we write equations in Mathematica, e.g. x^2 - 2 == 0.

Null has no meaning in symbolic algebra uses so here it is just treated as a symbol, which it is. Thus 1 == Null stays unevaluated the same way 1 == x does.

Mathematica is loosely typed: everything is an expression. You may put just about anything on either side of ==. The nature of the language does not make it practical or worthwhile for functions to try to give a special treatment for each kind of object. Since Null has no special meaning or use in symbolic algebra, it receives no special treatment from Equal.

Also consider that Mathematica will take things like Solve[Null^2 == 2, Null] with no complaint.

• From the docs: lhs == rhs returns True if lhs and rhs are ordinary identical expressions. Thus, == yields True in some symbolic cases, like x==x, where === also yields True. Commented Nov 10, 2017 at 12:40
• @JohnDoty Sure, and there are cases when it doesn't evaluate even though both sides are NumericQ. But the whole story doesn't fit in a single post. Commented Nov 10, 2017 at 12:43