Re: Question on pattern matching

• To: mathgroup at smc.vnet.net
• Subject: [mg47801] Re: [mg47765] Question on pattern matching
• From: "Roman Green" <rgreen at mail.ru>
• Date: Tue, 27 Apr 2004 04:46:56 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Hi David,

I have to say I still do not understand exactly how Mathematica performs
pattern matching in that case.

I supposed the following:
When processing

expression /. rule

Mathematica considers all forms of expression that are invariant
relatively to attributes set for the components of the expression until
a form that matches the rule is found.
For ex. in the simple case of expression = k[a, b, b] when k carries
Orderless attribute, Mathematica should consider forms
k[a,b,b]; k[b,a,b]; k[b,b,a].
And the third form should match pattern f_[x_, x_, y_].
But it does not work...

Here are some more tests I made:

In[1]:= SetAttributes[k, Orderless]

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

Out[2]= k[a, b, b]

In[4]:= ClearAttributes[k, Orderless]

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

Out[5]= 0

So it seems that f_ matches k without any special attributes but does
not matches k with attribute Orderless...
Why ? I thought f_[x_, x_, y_] should be structurally equivalent to <any
symbol with any attributes>[<any  another symbol with any attributes>,
<the same symbol as previous>, <any  another symbol with any
attributes>].

In any case, what is a pattern that matches structure <any symbol with
any attributes>[<any  another symbol with any attributes>, <the same
symbol as previous>, <any  another symbol with any attributes>] ?

Will appreciate any explanation.

---
Cheers

Roman Green

```

• Prev by Date: RE: bug in IntegerPart ?
• Next by Date: i don't understand mapping function over a long list
• Previous by thread: RE: Question on pattern matching
• Next by thread: RE: Question on pattern matching