RE: Question on pattern matching
- To: mathgroup at smc.vnet.net
- Subject: [mg47792] RE: [mg47765] Question on pattern matching
- From: "David Park" <djmp at earthlink.net>
- Date: Tue, 27 Apr 2004 04:46:36 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Roman, Certainly not a stupid question! You would be astonished at how much so called "experts" learn from so called "stupid" questions. SetAttributes[k, Orderless] k[a, b, b] /. k_[x_, x_, y_] -> 0 k[a, b, b] Since you used a pattern, k_, on the lhs of the rule Mathematica did not associate it with the actual k for which you set the Attributes. The following works. k[a, b, b] /. k[x_, x_, y_] -> 0 0 David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Roman Green [mailto:rgreen at mail.ru] To: mathgroup at smc.vnet.net Hi, I am a very newbie in Mathematica so sorry for possibly stupid question. 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_]. Thanks in advance. --- R. Green