Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: basic pattern matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114340] Re: basic pattern matching
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Wed, 1 Dec 2010 02:13:52 -0500 (EST)

Hi Peter,

Cases does not include the zero-th level by default. Both this:

Cases[x, a_.*x :> a, {0}]

or this:

Cases[{x}, a_.*x :> a]

will work.

Regards,
Leonid


On Tue, Nov 30, 2010 at 2:22 PM, Peter Pein <petsie at dordos.net> wrote:

> 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: Replacement Rule with Sqrt in denominator
  • Next by Date: Re: Re-virginating Manipulates?
  • Previous by thread: Re: Cuda offline installation in M8
  • Next by thread: Re: basic pattern matching