[Date Index] [Thread Index] [Author Index]
Re: Pattern gremlins.
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:= a*b*c*d*e*f*g /. d | f -> yes Out= 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:= Sin[x]+Cos[x]/.f:Sin[t_]->1/f-Cos[t]Cot[t] Out= 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