Inconsistencies in pattern matching.
- To: mathgroup at smc.vnet.net
- Subject: [mg12937] Inconsistencies in pattern matching.
- From: Sean Ross <seanross at worldnet.att.net>
- Date: Wed, 24 Jun 1998 03:44:55 -0400
- Sender: owner-wri-mathgroup at wolfram.com
This is an example taken from Ken Wagners Power Programming book: In[1]:={{x1,y1},{x2,y2},{x3,y3}}/.{x_,y_}->{x,Log[y]} Out[1]:={{x1,Log[y1]},{x2,Log[y2]},{x3,Log[y3]}} In[2]:={{x1,y1}}/.{x_,y_}->{x,Log[y]} Out[2]:={{x1,Log[y1]}} As long as the list of {x,y} data points has one point or greater than two points, it transforms as one would expect. If there are two {x,y} data points, it transforms differently. In[3]:={{x1,y1},{x2,y2}}/.{x_,y_}->{x,Log[y]} Out[3]:={{x1,y1},{Log[x2],Log[y2]}} Now, if x_ is seen to match {x1,y1} in example 3, then why doesn't it also match it in example number 1 and 2? This behavior can be fixed with a /;Head[x]=!=List pattern restricting rule, but that is not the point. This seems grossly inconsistent to me. Can anyone explain why it does this and/or justify that this is a good thing?