Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg55116] Re: [mg55090] Pattern gremlins.
  • From: Andrzej Kozlowski <akoz at>
  • Date: Sun, 13 Mar 2005 04:57:35 -0500 (EST)
  • Sender: owner-wri-mathgroup at

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
> FreeBSD (cvs meister, admin and hacker)
> Physics Particle Theory (student)
> ================ 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:

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, 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

  • 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