odd behaviour in 2.2
- To: mathgroup at yoda.physics.unc.edu
- Subject: odd behaviour in 2.2
- From: wmm at chem.wayne.edu (Martin McClain)
- Date: Thu, 2 Sep 93 18:55:05 EDT
Here is some new behaviour in 2.2 that seems like it needs professional
attention:
In[137]:=
$Version
Out[137]=
Macintosh 2.2 (May 4, 1993)
In[138]:=
Remove[nameRule,aName,mat,matSq] (*everything*)
Suppose there is a matrix you want to recognize by name:
In[139]:=
nameRule=Sin[1]^2 {{1,0},{0,1}}->aName
Out[139]=
2 2
{{Sin[1] , 0}, {0, Sin[1] }} -> aName
Now generate the same matrix in a slightly different way:
In[140]:=
mat = {{1,0},
{0,1}}//Sin;
matSq = mat.mat
Out[141]=
2 2
{{Sin[1] , 0}, {0, Sin[1] }}
and test it to see if it is the named matrix:
In[142]:=
matSq/.nameRule
Out[142]=
2 2
{{Sin[1] , 0}, {0, Sin[1] }}
The nameRule did not work in 2.2, though this same script works well in
2.1, giving output "aName".
However, the nameRule can be made to work in 2.2 if you Expand:
In[143]:=
Expand[matSq]/.nameRule
Out[143]=
aName
Why did it work this time? What is the difference?
In[146]:=
matSq == Expand[matSq]
Out[146]=
True
In[147]:=
FullForm[matSq]
Out[147]//FullForm=
List[List[Power[Sin[1], 2], 0], List[0, Power[Sin[1], 2]]]
In[148]:=
FullForm[Expand[matSq]]
Out[148]//FullForm=
List[List[Power[Sin[1], 2], 0], List[0, Power[Sin[1], 2]]]
They seem truly identical. However, the pattern matcher uses SameQ, or ===
(the Bible, 2nd ed., p. 289). So try it:
In[145]:=
matSq === Expand[matSq]
Out[145]=
False
How come two things that look identical in FullForm come up False in SameQ,
and therefore in the pattern matcher? They used to match in 2.1...