0
$\begingroup$

How can we understand why Mathematica does not evaluate this expression to False?

{{1, 2, 3, 4}, {4, 3, 2, 1}} == 0
$\endgroup$
5
$\begingroup$

Answer

Your example uses Equal (==) and it's returned not-evaluated because both sides are not identical and not raw data, therefore they constitute an equality expression. It would return False if you used SameQ instead of Equal.

SameQ,Equal, Set

SameQ[lhs,rhs] or lhs === rhs yields True if the expression lhs is identical to rhs, and will always be False otherwise.

Equal[lhs,rhs] is used to represent a symbolic equation, to be manipulated using functions like Solve. It will yield True for identical expressions or False if determined to be unequal by comparisons between numbers or other raw data, such as strings. But most importantly it will not always evaluate to True or False, otherwise you wouldn't be able to use expression such as x^2==4.

Also consider Set (=), Set[lhs,rhs] or lhs=rhs evaluates rhs and assigns the result to be the value of the symbol lhs.

I suggest you read this answer.

$\endgroup$
3
$\begingroup$

What does {{1, 2, 3, 4}, {4, 3, 2, 1}} == 0 mean in a mathematical sense? Comparing matrices to scalars is strange. To make a comparison like this, Mathematica needs some set of rules that could possibly reduce the expression to something that's an identity, or recognize the impossibility. I guess it has no such set for a matrix to scalar comparison. However:

{{1, 2, 3, 4}, {4, 3, 2, 1}} == {{0}}
(* False *)
$\endgroup$
  • $\begingroup$ absolutely relevant point. my mistake was to assume data comparisons (so to speak) would work with the same syntax as mathematical (logical) comparisons $\endgroup$ – Benjamin Márkus Jul 10 at 9:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.