       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:=
ClearAll[f]

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

Out=
True

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

In:=
SetAttributes[f, Flat]

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

Out=
False

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

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

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

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

Out=
True

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

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

Out=
True

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

Out=
True

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

In:=
SetAttributes[f, OneIdentity]

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

Out=
True

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

In:=
MatchQ[f[f[f[f]]], f[x_Integer]]
Out=
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/.f[n_Integer]:>n+10
>
> Out=
> 12
>
> --------------------------------
> For reasons I can't understand the rule isn't used in the next example. Can
> anyone explain why?
>
> In:=
> ClearAll[f]
> Attributes[f]={Flat};
> f/.f[n_Integer]:>n+10
>
> Out=
> f
>
> ---------------------------------------------
> 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