I want to understand OneIdentity.
I will clear f so I have so values associated with it.
In[]:=
f//ClearAll
In[]:=
Attributes[f]
Out[]=
{}
In[]:=
SetAttributes[f,OneIdentity]
In[]:=
Attributes[f]
Out[]=
{OneIdentity}
The documentation states this
OneIdentity
​is an attribute that can be assigned to a symbol
f
to indicate that
f[x]
,
f[f[x]]
, etc. are all equivalent to
x
for the purpose of pattern matching.
For some reason this returns False:
In[]:=
MatchQ[x,f[x]]
Out[]=
False
In[]:=
MatchQ[x,f[f[x]]]
Out[]=
False
In[]:=
AllTrue[MatchQ[x]][NestList[f,x,10]]
Out[]=
False
Why doesn’t this return True?