Re: Flat, OneIdentity attributes

*To*: mathgroup at smc.vnet.net*Subject*: [mg21633] Re: [mg21600] Flat, OneIdentity attributes*From*: BobHanlon at aol.com*Date*: Tue, 18 Jan 2000 02:35:18 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

Ted, ClearAll[f]; Attributes[f] = {Flat}; f[2] /. f[n_Integer] :> n + 10 f[2] I cannot explain this behavior. Further, this is even more unusual ClearAll[f]; Attributes[f] = {Flat}; f[2] /. f[n_] :> n + 10 f[2] + 10 Mathematica appears to interpret the first case as f[2]/.f[n_Integer]:>(n+10) and the second case as (f[2]/.f[n_]:>n)+10 Bob Hanlon In a message dated 1/17/2000 12:15:24 AM, ErsekTR at navair.navy.mil writes: >For the most part I understand how Flat and OneIdentity are related and >I >demonstrate this using Version 4 in the examples below. > >In the first example (f) has the attributes Flat and OneIdentity. >The pattern matcher treats f[a,2,3] as f[a,f[2,3]] then uses the >replacement rule and {1,{2,3}} is returned. > >In[1]:= >ClearAll[f]; >Attributes[f]={Flat,OneIdentity}; >f[1,2,3]//.f[a_,b_]:>{a,b} > >Out[3]= >{1,{2,3}} > >--------------------------------------------------- >In the next example the only attribute (f) has is Flat. >In this case the pattern matcher treats f[1,2,3] as >f[f[1],f[f[2],f[3]]] then uses the replacement rule and >{f[1],{f[2],f[3]}} is returned. > > >In[4]:= >ClearAll[f]; >Attributes[f]={Flat}; >f[1,2,3]//.f[a_,b_]:>{a,b} > >Out[6]= >{f[1],{f[2],f[3]}} > >OneIdentity the pattern matcher doesn't wrap (f) around a single argument >when it tries different ways of nesting (f). > >-------------------------------- >In the next example (f) has the attributes Flat, OneIdentity and the rule >is >used. > >In[7]:= >ClearAll[f] >Attributes[f]={Flat,OneIdentity}; >f[2]/.f[n_Integer]:>n+10 > >Out[9]= >12 > >-------------------------------- >For reasons I can't understand the rule isn't used in the next example. >Can >anyone explain why? > >In[10]:= >ClearAll[f] >Attributes[f]={Flat}; >f[2]/.f[n_Integer]:>n+10 > >Out[12]= >f[2] >