Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

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[17]:=
G[a, b, c, G[d, e]] /. G[d, e] -> yes

Out[17]=
G[a, b, c, yes]

In[18]:=
G[a, b, c, G[d, e]] /. x:G[d, e] -> yes

Out[18]=
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/


  • Prev by Date: Re: Simplfying inside Sqrt
  • Next by Date: Re: Nested iterators in Compile
  • Previous by thread: Re: Pattern gremlins.
  • Next by thread: webMathematica