is an option whose setting gives a pairwise comparison function to determine whether expressions should be considered the same.
SameTest
is an option whose setting gives a pairwise comparison function to determine whether expressions should be considered the same.
Details
- SameTest->f specifies that f[e1,e2] should be evaluated whenever it is necessary to determine whether pairs of expressions e1, e2 should be considered the same.
Examples
open all close allBasic Examples (2)
Union[{0, 3, 2, 4, 2, 0, 2, -5, 2, 0}]Union considering comparison modulo 3:
Union[{0, 3, 2, 4, 2, 0, 2, -5, 2, 0}, SameTest -> (Mod[#1, 3] == Mod[#2, 3]&)]Find a fixed point to a tolerance:
FixedPointList[# / 2 + 1 / #&, 1., SameTest -> (Abs[#1 - #2] < 10 ^ -4&)]Scope (5)
Union of a set of machine-precision numbers:
Union[{0., 10.^-13, 2., 2. - 10^-13, 2. + 3 10^-15, 10.^-14}]Union treating roundoff errors of order 10-12 as zeros:
Union[{0., 10.^-13, 2., 2. - 10^-13, 2. + 3 10^-15, 10.^-14}, SameTest -> (Abs[#1 - #2] ≤ 10^-12&)]Alternately, use Chop:
Union[{0., 10.^-13, 2., 2. - 10^-13, 2. + 3 10^-15, 10.^-14}, SameTest -> (Chop[#1 - #2, 10^-12] == 0&)]Intersection of two sets of integers:
Intersection[{0, 3, 5, 2}, {0, 2, 5}]Intersection considering comparison modulo 3:
Intersection[{0, 3, 5, 2}, {0, 2, 5}, SameTest -> (Mod[#1 - #2, 3] == 0&)]This matrix is antihermitian for a positive real
, but AntihermitianMatrixQ gives False:
m = {{I, Exp[Log[I x]]}, {I x, 2I}};AntihermitianMatrixQ[m]Use the option SameTest:
AntihermitianMatrixQ[m, SameTest -> (Simplify[#1 - #2, x > 0] == 0&)]This matrix is symmetric for a positive real
, but SymmetricMatrixQ gives False:
m = {{1, Log[x ^ 2]}, {2 Log[x], 2}};SymmetricMatrixQ[m]Use the option SameTest:
SymmetricMatrixQ[m, SameTest -> (Simplify[#1 - #2, x > 0] == 0&)]This matrix is unitary for a positive real
, but UnitaryMatrixQ gives False:
m = {{1, Exp[x I]}, {Cos[x] - I Sin[x], -1}} / Sqrt[2];UnitaryMatrixQ[m]Use the option SameTest:
UnitaryMatrixQ[m, SameTest -> (Simplify[#1 - #2, x > 0] == 0&)]Related Guides
History
Introduced in 1991 (2.0)
Text
Wolfram Research (1991), SameTest, Wolfram Language function, https://reference.wolfram.com/language/ref/SameTest.html.
CMS
Wolfram Language. 1991. "SameTest." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SameTest.html.
APA
Wolfram Language. (1991). SameTest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SameTest.html
BibTeX
@misc{reference.wolfram_2026_sametest, author="Wolfram Research", title="{SameTest}", year="1991", howpublished="\url{https://reference.wolfram.com/language/ref/SameTest.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_sametest, organization={Wolfram Research}, title={SameTest}, year={1991}, url={https://reference.wolfram.com/language/ref/SameTest.html}, note=[Accessed: 12-June-2026]}