0
$\begingroup$

I thought that === is shorthand for SameQ? Then why do these two expressions yield True for one and False for the other?

SameQ[((k^2 (k + 1)^2)/4 + (k + 1)^3) == (((k + 1)^2 (k + 2)^2)/4)]
((k^2 (k + 1)^2)/4 + (k + 1)^3) === (((k + 1)^2 (k + 2)^2)/4)
$\endgroup$
6
  • 2
    $\begingroup$ The useless, but correct answer is, because SameQ[blub] gives True and you don't do what you think you do. $\endgroup$
    – halirutan
    Commented May 12, 2017 at 17:18
  • 3
    $\begingroup$ Replace the == in the first line with a comma; SameQ[a, b] is equivalent to a === b, but SameQ[a == b] should evaluate as either SameQ[True] or SameQ[False]. $\endgroup$
    – nben
    Commented May 12, 2017 at 17:21
  • $\begingroup$ Perhaps for the first line you thought you were doing something like SameQ @@ (((k^2 (k + 1)^2)/4 + (k + 1)^3) == (((k + 1)^2 (k + 2)^2)/4))? $\endgroup$
    – Michael E2
    Commented May 12, 2017 at 17:41
  • $\begingroup$ @user16054 Can you elaborate on the difference between SameQ[False] and SameQ[True]? $\endgroup$
    – halirutan
    Commented May 12, 2017 at 18:37
  • 1
    $\begingroup$ @user16054 Look, this is exactly why I asked :) 1. No! SameQ[a == b] will always evaluate to True. Try SameQ[1 == 1] and SameQ[1 == 2]. 2. Yes, a==b usually evaluates to True or False. In the case of the question above, it is not. This is, why the result of the first line is SameQ[a==b] with unevaluated equation :) $\endgroup$
    – halirutan
    Commented May 13, 2017 at 0:26

2 Answers 2

4
$\begingroup$

The syntax for SameQ is SameQ[x,y], with two (or more) arguments and yields True if all the arguments are the same. Your first line is merely SameQ[.] with a single argument, which of course yields True.

$\endgroup$
3
$\begingroup$

The documentation is admittedly lacking in detail, but basically

SameQ[a, b, c,...]

"returns True if all the" a, b, c,... "are identical." In SameQ[a], all the arguments are identical.

Likewise,

UnsameQ[a, b, c,...]

"gives True if no two of"" a, b, c,... "are identical." In UnsameQ[a], no two of the arguments are identical.

Hence both SameQ[a] and UnsameQ[a] return True, which might seem a paradox if you forget how the quantifiers work.

$\endgroup$

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