$Version
(* 10.2.0 for Microsoft Windows (64-bit) (July 7, 2015) *)
Information[SameQ]
(* lhs===rhs yields True if the expression
lhs is identical to rhs, and yields False otherwise. >> *)
a = SparseArray[Automatic, {1}, 0, {1, {{0, 0}, {}}, {}}] &;
b = With[{s = SparseArray[Automatic, {1}, 0, {1, {{0, 0}, {}}, {}}]}, s &];
SameQ[a, b]
(* True *)
Depth /@ {a, b}
(* {6, 3} *)
LeafCount /@ {a, b}
(* {14, 2} *)
Position[a, _]
(* {{0}, {1, 0}, {1, 1}, {1, 2, 0}, {1, 2, 1}, {1, 2}, {1, 3},
{1, 4, 0}, {1, 4, 1}, {1, 4, 2, 0}, {1, 4, 2, 1, 0}, {1, 4, 2, 1, 1},
{1, 4, 2, 1, 2}, {1, 4, 2, 1}, {1, 4, 2, 2, 0}, {1, 4, 2, 2},
{1, 4, 2}, {1, 4, 3, 0}, {1, 4, 3}, {1, 4}, {1}, {}} *)
Position[b, _]
(* {{0}, {1}, {}} *)
Is it expected behavior? Are the expressions stored in variables a and b identical?
Update: I found function System`Private`VerbatimSameQ that appears to check if two expressions are really completely identical.
FullForm /@ {a, b}? In casea,SparseArrayhas not evaluated, but in caseb, it has and become atomic, which affectsDepthandLeafCount, but not theFullForm(nor, therefore,SameQ). – Michael E2 Mar 03 '16 at 04:50FullForms look character-wise identical,StandardForms look different.TreeForms are also slightly different. – Vladimir Reshetnikov Mar 03 '16 at 04:53Hashes are the same. – Vladimir Reshetnikov Mar 03 '16 at 05:02SameQwill give true for two arrays that differ in whether they are packed or not,Needs["Developer"]; ara = RandomReal[1, {5, 5}]; ara2 = FromPackedArray[ara]; {PackedArrayQ /@ {ara, ara2}, SameQ[ara, ara2]}. They do end up having the sameFullFormandHash`, but they aren't perfectly the same under the hood. – Jason B. Mar 03 '16 at 08:33Uncompress[Compress[b]]does not round-tripbexactly, but rather converts it to the same form asa. – Vladimir Reshetnikov Mar 03 '16 at 18:18