MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Flat, OneIdentity attributes

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21614] Re: [mg21600] Flat, OneIdentity attributes
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Tue, 18 Jan 2000 02:35:06 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

If f is a function without any attributes we have:
In[1]:=
ClearAll[f]

In[2]:=
MatchQ[f[2], f[x_Integer]]

Out[2]=
True

If you give f the attribute Flat this is no longer true:

In[3]:=
SetAttributes[f, Flat]

In[4]:=
MatchQ[f[2], f[x_Integer]]

Out[4]=
False

but what is true instead (in fact always) is:

In[5]:=
MatchQ[f[2], f[x__Integer]]
Out[5]=
True

Note however that even in this case (with the Flat attribute present) you
get 

In[6]:=
MatchQ[f[2], f[x_]]

Out[6]=
True

The reason why this works is that f[2] is re-written as f[f[2]] which
matches f[x_] but not f[x_Integer], thus

In[7]:=
MatchQ[f[f[2]], f[2]]

Out[7]=
True

In[8]:=
MatchQ[f[2], f[f[2]]]

Out[8]=
True

The presence of the OneIdentity attribute however means that again the
single argument match is used:

In[9]:=
SetAttributes[f, OneIdentity]

In[10]:=
MatchQ[f[2], f[x_Integer]]

Out[10]=
True

In fact when f has the Flat and the OneIdentity attributes you also get
matches like

In[11]:=
MatchQ[f[f[f[f[2]]]], f[x_Integer]]
Out[10]=
True

which do not work with only Flat attribute present.

Andrzej Kozlowski
Toyama International University
Toyama, Japan
http://sigma.tuins.ac.jp/


> From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
To: mathgroup at smc.vnet.net
> Date: Sun, 16 Jan 2000 22:43:47 -0500 (EST)
> To: mathgroup at smc.vnet.net
> Subject: [mg21614] [mg21600] Flat, OneIdentity attributes
> 
> 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]
> 
> ---------------------------------------------
> Regards,
> Ted Ersek



  • Prev by Date: Re: Question:Polar Field Plot
  • Next by Date: Flat, OneIdentity Again
  • Previous by thread: Re: Flat, OneIdentity attributes
  • Next by thread: Re: Flat, OneIdentity attributes