Scope (5)
Associations must agree on keys:
A reordering of keys only changes the shape if the corresponding values have a different shape:
Compare expressions without evaluation:
The Unevaluated wrapper is not considered part of the expression:
Any number of arguments can be given:
Properties and Relations (6)
An expression is always the same shape as itself, so SameExpressionShapeQ is always true for a single argument:
SameExpressionShapeQ[] is defined to be True:
This is consistent with the behavior of SameQ:
For normal expressions, SameExpressionShapeQ[expr1,…,exprn] is effectively equivalent to testing if all the ExpressionGraph[expri] are equivalent under IsomorphicGraphQ:
Compare using TreeForm:
These two have different shapes:
Compare using TreeForm:
Represent the underlying "shape" of expressions by replacing all atomic values with one identical value:
These have the same shape:
These do not:
Highlight differences:
Another way to understand the shape of a normal expression is by looking at the positions of all subexpressions:
When the positions are the same, the expressions have the same shape:
For associations to be considered the same shape, their corresponding parts must be the same shape whether indexed by key or numeric position:
Check subexpressions by key indexing:
Check subexpressions by their ordinal positions:
Since both methods of indexing are in agreement, these have the same shape:
Here is another Association that only differs in key order:
Check subexpressions by key indexing:
Check subexpressions by their ordinal positions:
It is not considered the same shape, since indexing by numeric position yields incompatible subexpressions:
Possible Issues (2)
For associations, SameExpressionShapeQ considers keys to be structural positions rather than subexpressions:
For lists of rules, the keys are normal subexpressions: