yields True if the expression lhs is identical to rhs, and yields False otherwise.


  • SameQ requires exact correspondence between expressions, except that it still considers Real numbers equal if they differ in their last binary digit.
  • 2===2. gives False.
  • e1===e2===e3 gives True if all the are identical.
  • SameQ[] and SameQ[expr] always yield True. »

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.


open allclose all

Basic Examples  (2)

Test whether two expressions are identically the same:

== remains symbolic unless literal values are given:

Full form:

Scope  (4)

Test equivalence of strings:

Numbers in different representations are not the same:

== nevertheless treats them as equal:

Approximate numbers that differ in their last bit are still considered identical:

Test whether multiple expressions are all the same:

Applications  (1)

Make a Kronecker delta (identity) tensor:

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:

SameQ[] and SameQ[expr] always give True:

Wolfram Research (1988), SameQ, Wolfram Language function,


Wolfram Research (1988), SameQ, Wolfram Language function,


Wolfram Language. 1988. "SameQ." Wolfram Language & System Documentation Center. Wolfram Research.


Wolfram Language. (1988). SameQ. Wolfram Language & System Documentation Center. Retrieved from


@misc{reference.wolfram_2024_sameq, author="Wolfram Research", title="{SameQ}", year="1988", howpublished="\url{}", note=[Accessed: 14-July-2024 ]}


@online{reference.wolfram_2024_sameq, organization={Wolfram Research}, title={SameQ}, year={1988}, url={}, note=[Accessed: 14-July-2024 ]}