Re: Re: Question on pattern matching

• To: mathgroup at smc.vnet.net
• Subject: [mg47822] Re: [mg47807] Re: Question on pattern matching
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Thu, 29 Apr 2004 00:33:38 -0400 (EDT)
• References: <200404270847.EAA18899@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

On 27 Apr 2004, at 17:47, Bill Rowe wrote:

> On 4/26/04 at 2:40 AM, rgreen at mail.ru (Roman Green) wrote:
>
>
>> In the following Mathematica's output In[1]:= SetAttributes[k,
>> Orderless]
>
>> In[2]:= k[a, b, b] /. k[x_, x_, y_] -> 0
>> Out[2]= 0
>> In[3]:= k[a, b, b] /. k_[x_, x_, y_] -> 0
>> Out[3]= k[a, b, b]
>
>> I can't understand why Mathematica can find match when applying
>> pattern k[x_, x_, y_], but is unable with more general pattern
>> k_[x_, x_, y_].
>
> The pattern k_ matches an expression named k with any head
>
> k[a, b, b] is an expression with head k and no name. The two things
> don't match which is why you get the output you got.
>
> The pattern _k is any expression with head k. So,
>
> k[a,b,b]/._k->0
>
> will result in what you were expecting
> --
> To reply via email subtract one hundred and four
>
>
>
While the above is all true, it seems to me that the key point has to
do with the Orderless attribute. To start wit,h observe the following:

In[1]:=
k[a, b, b] /. k_[x_, y_, y_] -> 0

Out[1]=
0

This matched for obvious reasons.

Now let's give k the attribute Orderless:

SetAttributes[k,Orderless]

Now this matches due to the Orderless attribute:

k[a, b, b] /. k[x_, x_, y_] -> 0

0

k[a, b, b] /. k_[x_, x_, y_] -> 0

k(a,b,b)

This does not match because k_, unlike k,  "does not have" the
attribute Orderless (of course this does not strictly make sense since
only Symbols can have attributes, but I guess you know what i mean): in
other words no required rearrangement takes place for a match to be
found.

Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/

• Prev by Date: Re: Wrong Limit
• Next by Date: Re: Re: Distinguishable From 1.0
• Previous by thread: Re: Re: Question on pattern matching
• Next by thread: Re: Question on pattern matching