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: [mg55119] Re: Pattern gremlins.
  • From: Peter Pein <petsie at>
  • Date: Sun, 13 Mar 2005 04:57:38 -0500 (EST)
  • References: <d0u6kr$kl6$>
  • Sender: owner-wri-mathgroup at

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. =================
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:

Peter Pein

  • Prev by Date: Re: Simplfying inside Sqrt
  • Next by Date: Re: Simplfying inside Sqrt
  • Previous by thread: Re: Pattern gremlins.
  • Next by thread: Re: Pattern gremlins.