Re: Pattern gremlins.

*To*: mathgroup at smc.vnet.net*Subject*: [mg55119] Re: Pattern gremlins.*From*: Peter Pein <petsie at arcor.de>*Date*: Sun, 13 Mar 2005 04:57:38 -0500 (EST)*References*: <d0u6kr$kl6$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

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. ================= > > Hi Joe, 1.) I can just guess, what your intention has been.. I suppose, you wanted to replace each of "d" and "f" in your product "a b c d e f g". That can be done by In[1]:= a*b*c*d*e*f*g /. d | f -> yes Out[1]= a*b*c*e*g*yes^2 The pattern d|f mathes d or f 2.) There's no need to name the pattern in this case. It can be usefull in many applications. Say - for example - you don't like functions beginning with S: In[2]:= Sin[x]+Cos[x]/.f:Sin[t_]->1/f-Cos[t]Cot[t] Out[2]= Cos[x]-Cos[x] Cot[x]+Csc[x] replaces Sin[x], using t (matches x) and f (the name for Sin[t_]) from the pattern. You might want to try the following links: http://library.wolfram.com/infocenter/Articles/1127/ http://library.wolfram.com/infocenter/Articles/1477/ http://library.wolfram.com/infocenter/Articles/3162/ -- Peter Pein Berlin