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: [mg114347] Re: basic pattern matching
  • From: Peter Pein <petsie at dordos.net>
  • Date: Wed, 1 Dec 2010 02:15:12 -0500 (EST)
  • References: <id2mqa$isu$1@smc.vnet.net>

Am Tue, 30 Nov 2010 11:22:50 +0000 (UTC)
schrieb Peter Pein <petsie at dordos.net>:

> 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)
> 
Same Nonsense (?) holds for:
In[1]:= MatchQ[x, a_. + x]

Out[1]= True

In[2]:= Cases[x, a_. + x :> a] == {Default[Plus]}

Out[2]= False

Is there a hidden sense beyond this?

In[4]:= 5/.x_+a_.:>{x,a}
Out[4]= {5,0}

is again perfectly OK




  • Prev by Date: Help Browser CPU Usage
  • Next by Date: Re: How to assume that a function is positive?
  • Previous by thread: Re: basic pattern matching
  • Next by thread: Re: basic pattern matching