MathGroup Archive 1997

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

Search the Archive

Re: MatchQ

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8590] Re: [mg8542] MatchQ
  • From: David Withoff <withoff>
  • Date: Sun, 7 Sep 1997 22:13:09 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

> Hello, 
> 
> Can anybody explain me why  
>
> MatchQ[E^(a*I*b), E^(I*freq_)] gives False ???
> 
> (while for instance MatchQ[E^(a*I*b), E^(a*freq_)] gives True)
> 
> What patterns  should be used for expressions with I ?
> 
> Many thanks,
>                 Raya Khanin

Are you sure that this is the example that you tried?  This
returned True when I tried it.

In[1]:= MatchQ[E^(a*I*b), E^(I*freq_)]

Out[1]= True

In general, probably the best way of answering questions involving
patterns is to compare the FullForm of the expression that you want
to match with the FullForm of the pattern.  For example

In[2]:= FullForm[E^(a*I*b)]

Out[2]//FullForm= Power[E, Times[Complex[0, 1], a, b]]

shows what Mathematica sees when it compares this expression
with a pattern.  The pattern

In[3]:= FullForm[ E^(I*freq_)]

Out[3]//FullForm= Power[E, Times[Complex[0, 1], Pattern[freq, Blank[]]]]

should match this expression.

As a counterexample, here is a match that returns False

In[4]:= MatchQ[E^(2 I b), E^(I freq_)]

Out[4]= False

for reasons that can be seen by looking at the FullForm of the expression

In[4]:= E^(2 I b) //FullForm

Out[4]//FullForm= Power[E, Times[Complex[0, 2], b]]

The match fails because Complex[0, 2] doesn't match Complex[0, 1].

Dave Withoff
Wolfram Research


  • Prev by Date: Re: MeijerG special function
  • Next by Date: Re: Sort[]
  • Previous by thread: MatchQ
  • Next by thread: Re: MatchQ