MathGroup Archive 2010

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

Search the Archive

basic pattern matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114310] basic pattern matching
  • From: Peter Pein <petsie at dordos.net>
  • Date: Tue, 30 Nov 2010 06:22:55 -0500 (EST)

Dear group,

I'm confused regarding defaults.
In[1]:= MatchQ[x,a_*x]
Out[1]= False
this has been expected

In[2]:= MatchQ[x,a_. *x]
Out[2]= True
this one too, but:

In[3]:= Cases[x,a_.*x:>a]
Out[3]= {}
should have been {1} shouldn't it? If the pattern matches (see
Out[2]) then with a_. == 1. (Bug or feature?)

In[4]:= Cases[y+x,a_.*x:>a]
Out[4]= {1}
is OK.

Any enlightenment is highly welcome,
thanks in advance, Peter

P.S.: $Version is 8.0 for Linux 64-bit (November 7, 2010)


  • Prev by Date: Re: Problems with Mathematica 8.0 Solve
  • Next by Date: Re: How to assume that a function is positive?
  • Previous by thread: Difficulty in obtaining a numerical solution for a partial