Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: MatchQ, silly question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105188] Re: MatchQ, silly question
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Tue, 24 Nov 2009 05:46:07 -0500 (EST)
  • References: <he5v9i$3gh$1@smc.vnet.net> <he896k$q8g$1@smc.vnet.net> <heb6gi$ah5$1@smc.vnet.net>

janos wrote:
> An alternative solution from my student, Attila L=E1szl=F3 NAGY is:
> 
> MatchQ[3 x^2, #] & /@ {3 x_^2,
>   3 x_^_, _ x_^_, _ _Symbol^_, _ (_Symbol^_), _*(_Symbol^_)}
> 
> J=E1nos
> **************************************************************************
> 
> On nov. 21, 09:43, David Bailey <d... at removedbailey.co.uk> wrote:
>> janos wrote:
>>> MatchQ[3 x^2, #] & /@ {3 x_^2,  3 x_^_, _ x_^_, _ _^_, _ (_^_), _ *
>>> (_^_)}
>>> dives False in the last cases. Why? The FullForm
>>> Power[Blank[ ],Plus[1,Blank[ ]]]
>>> contains Plus, why?
>>> Thank you.
>>> J=E1nos
>> Because expressions still evaluate, even if they contain Blank[] - this
>> can be easily seen by entering the expression _+_ .
>>
>> Wrap the pattern in HoldPattern to prevent evaluation.
>>
>> David Baileyhttp://www.dbaileyconsultancy.co.uk
> 
> 
This works because _ and _Symbol don't look the same to Mathematica when 
it does its arithmetic. The only problem with that approach, is that you 
might re-use the code in a slightly more complicated context and hit 
problems again.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: compositions with the restricted set of integers
  • Next by Date: Re: Re: Color depth - Wikipedia, the free encyclopedia
  • Previous by thread: Re: MatchQ, silly question
  • Next by thread: PolarPlot goes upto 1.2 on axis, not 1?