Re: MatchQ, silly question
- To: mathgroup at smc.vnet.net
- Subject: [mg105123] Re: [mg105087] MatchQ, silly question
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sat, 21 Nov 2009 03:36:48 -0500 (EST)
- References: <200911201140.GAA03512@smc.vnet.net>
Hi Janos. I assume you are back home ;-)
The problem is that your last three patterns evaluate to something that 3 x^2 does not match, namely
FullForm[_ (_^_)]
Power[Blank[],Plus[1,Blank[]]]
To understand this better look a this:
x*x^x
x^(x + 1)
exactly the same thing will happen if you replace x by Blank[] - you will just get Blank[] to the power Blank[]+1. One way to avoid this sort of problems is to use HoldPattern. So:
MatchQ[3 x^2, #] & /@ {3 x_^2, 3 x_^_, _ x_^_,
HoldPattern[_ _^_], HoldPattern[_ (_^_)], HoldPattern[_*(_^_)]}
{True,True,True,True,True,True}
Andrzej
On 20 Nov 2009, at 20:40, 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
>
- References:
- MatchQ, silly question
- From: janos <janostothmeister@gmail.com>
- MatchQ, silly question