Re: Pattern gremlins.
- To: mathgroup at smc.vnet.net
- Subject: [mg55116] Re: [mg55090] Pattern gremlins.
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sun, 13 Mar 2005 04:57:35 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
On 12 Mar 2005, at 08:36, Josef Karthauser wrote: > > I obviously don't understand patterns like I thought that I did. > > Can someone tell me why this matches, > > In: a b c d e f g /. d f :> yes > Out: a b c e f g yes > > but this doesn't, > > In: a b c d e f g /. x:d f :> yes > Out: a b c d e f g > > ? > > Joe > -- > Josef Karthauser (joe at tao.org.uk) http://www.josef-k.net/ > FreeBSD (cvs meister, admin and hacker) http://www.uk.FreeBSD.org/ > Physics Particle Theory (student) http://www.pact.cpes.sussex.ac.uk/ > ================ An eclectic mix of fact and theory. ================= > I am not sure this will satisfy you as an explanation but at least the reason comes from the working of the FlatAttribute of Times which is being used to obtain a match. As this has nothing to do with multiplication it maybe illuminating to see it on an abstract example. Consider the following case where everything works as expected: In:= G[a, b, c, G[d, e]] /. G[d, e] -> yes Out= G[a, b, c, yes] In:= G[a, b, c, G[d, e]] /. x:G[d, e] -> yes Out= G[a, b, c, yes] Let us now give G the Flat attribute: SetAttributes[G, Flat]; You can see the phenomenon you had observed: G[a, b, c, G[d, e]] /. G[d, e] -> yes G[a, b, c, yes] G[a, b, c, G[d, e]] /. x:G[d, e] -> yes G[a, b, c, d, e] Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/andrzej/index.html http://www.mimuw.edu.pl/~akoz/