Re: Flat, OneIdentity Again
- To: mathgroup at smc.vnet.net
- Subject: [mg21659] Re: Flat, OneIdentity Again
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Fri, 21 Jan 2000 04:00:10 -0500 (EST)
- References: <86190a$l92@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
More examples: Attributes[f] = {Flat}; f[2, 2, 3] /. f[x_ ..] :> h[x] f[h[2], 3] f[2,2,3] was regarded as f[f[2,2],3] -------------------------------------------------- f[2, 2, 3] /. f[x_ .., y_] :> h[x, k[y]] h[2, k[f[2, 3]]] f[2,2,3] was regarded as f[2,f[2,3]] ---------------------------------------------------- f[2, 2, 3] /. f[x_ .., y__] :> h[x, k[y]] h[2, k[2, 3]] f[2,2,3] was regarded as f[2,Sequence[2,3]] Adding the attribute OneIdentity makes no difference Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Ersek, Ted R" <ErsekTR at navair.navy.mil> wrote in message news:86190a$l92 at smc.vnet.net... > Thanks to all who answered my question on Flat and OneIdentity. > I have more strange behavior on this subject. > > At http://support.wolfram.com/Kernel/Symbols/System/Flat.html > it says in so many words .... > If (f) has the Flat attribute you better not have a definition like > f[p_]:=p > because if you do, then an attempt to evaluate f[1,2] will not work and the > kernel will have to quit when the infinite iteration limit is exceeded. > > In addition I found that you can't even evaluate f[2] in the above case, and > it doesn't help if (f) also has the OneIdentity attribute! > > I wanted to understand just what the kernel is doing to exceed the iteration > limit when we try to evaluate f[1,2] or f[2] above. The lines below offer > some clues, but also add to the mystery. I wonder if any of you have an > explanation. > > In[1]:= > ClearAll[f]; > Attributes[f]={Flat}; > > After the input above (f) has the Flat attribute and no definitions. > f[1,2] as f[f[1,2]]. > > > In[3]:= > f[1,2]/.f[p_]:>{p} > Out[3]= > {f[1,2]} > > The idea that the pattern matcher treats > f[1,2] as f[f[1,2]] is sort of verified > at Out[4] below. > > In[4]:= > MatchQ[f[1,2],f[_f]] > Out[4]= > True > > But if the pattern matcher treats f[1,2] as f[f[1,2]] > why doesn't MatchQ return True in Out[4] below ? > > In[5]:= > MatchQ[f[1,2],HoldPattern[f[f[_Integer,_Integer]]]] > Out[5]= > False > > Even stranger is the next line where the pattern is much more general! > Notice that is a triple blank inside (f). > > In[6]:= > MatchQ[f[1,2],HoldPattern[f[f[___]]]] > Out[6]= > False > > All the results above come out the same if (f) has the attributes Flat, > OneIdentity. > > I have a hunch what may be going on here. Perhaps this is a bug. Could it be > that the part of the pattern matcher that handles Flat is oblivious to > HoldPattern and checks for a match with the patterns f[_Integer,_Integer] > and f[___] > when it should check for a match with f[f[_Integer,_Integer]] and f[f[___]] > > respectively in the lines above? > > I did all this using Version 4. > > -------------------- > Regards, > Ted Ersek > > On 12-18-99 Mathematica tips, tricks at > http://www.dot.net.au/~elisha/ersek/Tricks.html > had a major update > >