SameQ
Background & Context
- SameQ[expr1,expr2] returns True if expr1 is identical to expr2 and otherwise returns False. Here, "identical" means there is exact correspondence between the underlying FullForm representations of expressions expr1 and expr2, with the exception that real numbers are considered SameQ if they differ only in their last binary digit. SameQ[expr1,expr2] may be input using triple equal signs as expr1===expr2. The multiple-argument form SameQ[expr1,expr2,…], which may also be input as expr1===expr2===…, returns True if and only if all expressions expri are identical.
- Different input forms of expressions may be SameQ if their underlying representations are identical, for example n! ===Factorial[n] returns True. On the other hand, SameQ differentiates between representations of numbers that are numerically equal but that do not have identical representations. For example, SameQ[1,1.] and SameQ[1.,1.+0.I] both return False. This behavior is expressly different from that exhibited by Equal, which performs equality testing and remains unevaluated in cases that cannot be resolved.
- SameQ considers only literal correspondence, not isomorphism. In the case of graphs, IsomorphicGraphQ should be used to check sameness up to isomorphism. (Alternately, SameQ may be used after first converting graphs to canonical form using CanonicalGraph.)
- SameQ is related to a number of other symbols. Set[expr1,expr2] (which may be input using the "single equals" syntax expr1=expr2) evaluates expr2 and assigns the result to be the value of expr1, while Equal[expr1,expr2] (which may be input using the "double equals" syntax expr1==expr2) returns True if expr1 and expr2 are numerically equal. UnsameQ (which may be input as …=!=…) is the converse of SameQ.
- PossibleZeroQ can be used to indicate if a given expression has value in some cases where SameQ returns False. For example, SameQ[Erf[Log[4]+2Log[Sin[Pi/8]]]-Erf[Log[2-Sqrt[2]]],0] returns False, whereas calling PossibleZeroQ on its first argument returns True (together with an informative message indicating that a zero value could not be rigorously established). Symbolic simplifiers like Simplify, FullSimplify and RootReduce can sometimes also be used to rigorously establish equality (including in the example just given) when SameQ and Equal cannot.
Examples
open allclose allBasic Examples (2)
Scope (4)
Properties & Relations (4)
SameQ accepts any number of arguments:
SameQ[expr1,expr2,…] gives True if SameQ[expri,exprj] is True for all i and j:
If one of the expressions is not the same as the others, then SameQ gives False:
SameQ[expr1,expr2] is equivalent to !UnsameQ[expr1,expre2]:
SameQ[…] and !UnsameQ[…] are not equivalent for an argument count other than two:
Text
Wolfram Research (1988), SameQ, Wolfram Language function, https://reference.wolfram.com/language/ref/SameQ.html.
CMS
Wolfram Language. 1988. "SameQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SameQ.html.
APA
Wolfram Language. (1988). SameQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SameQ.html