|
[Date Index]
[Thread Index]
[Author Index]
Re: MatchQ
- To: mathgroup at smc.vnet.net
- Subject: [mg8641] Re: [mg8542] MatchQ
- From: Raya Khanin <raya at mech.ed.ac.uk>
- Date: Fri, 12 Sep 1997 04:10:54 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Hello,
I thought this conversation about
MatchQ[] and Complex numbers
might be interesting.
Raya Khanin
University of Edinburgh
On Mon, 8 Sep 1997, David Withoff wrote:
> Hello,
>
> > Thanks a lot for your explanation.
> > I've indeed tried an example
> >
> > MatchQ[E^(2*I*b), E^(I*freq_)]
> >
> > which gave me False.
> >
> > Do not you agree that there is no principal
> > difference between
> >
> > E^(2*I*b) and E^(a*I*b) and in both cases
> >
> > MatchQ[E^(2*I*b), E^(I*freq_)] and MatchQ[E^(a*I*b), E^(I*freq)]
> >
> > should give True? Certainly, we do not know anything about
> > a in E^(a*I*b) (it can be Complex number), but we do not anything
> > about b or freq_ in the pattern either.
> >
> > > The match fails because Complex[0, 2] doesn't match Complex[0, 1].
> >
> > Should not it be included in the future versions of MatchQ
> > that
> >
> > Complex[0, 2] does match Complex[0, 1]*2,
> > or for any real c Complex[0, c] does match Complex[0,1]*c
> >
> > Thanks,
> > Raya Khanin
> > University of Edinburgh
>
> Here is a related example.
>
> In[2]:= MatchQ[2*3, 2*x_]
>
> Out[2]= False
>
> This match fails because 2*3 evaluates to 6, which does not match
> the pattern, even though 6 could be factored into 2 times 3, which
> would match:
>
> In[3]:= MatchQ[Hold[2*3], Hold[2*x_]]
>
> Out[3]= True
>
> The pattern matcher does not factor integers in an effort to find
> a factoring that will match the pattern.
>
> The same principle applies to an integer that happens to be part
> of a complex number. This match fails:
>
> In[4]:= MatchQ[Complex[0, 2], Complex[0, 1]*x_]
>
> Out[4]= False
>
> because the pattern matcher is not designed to factor Complex[0, 2]
> into 2*Complex[0, 1].
>
> There is a distinct conflict between the way that complex numbers are
> seen in written mathematics, and the way that complex numbers are stored
> in a computer. In written mathematics, complex numbers are usually
> given as the sum of a real part and the product of an imaginary part
> and some notation for the square root of minus one. Complex numbers
> are almost never stored that way on a computer. In nearly all computer
> programs, complex numbers are stored in a separate data structure
> that does not involve sums or products.
>
> It has occasionally been suggested that complex numbers be handled
> as a special case in the pattern matcher, to accommodate the way
> that complex numbers are seen in written mathematics, and it is
> possible that such a change will be made in some future version
> of Mathematica. It is worth pointing out, however, that this
> change is not easy to make, and furthermore that there are some
> common examples that would break as a result of such a change.
>
> Dave Withoff
> Wolfram Research
>
Prev by Date:
Effect of TagSet
Next by Date:
loess regression
Previous by thread:
Re: MatchQ
Next by thread:
NDSolve
|