dives False in the last cases. Why? The FullForm
Power[Blank[ ],Plus[1,Blank[ ]]]
contains Plus, why?
Thank you.
J=E1nos
Cheers -- Sjoerd
x * x ^ x = x ^ (x + 1)
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
just evaluate this:
(_)*(_)^(_)
to see that it gives
_^(_+1)
just as x*x^x would evaluate to x^(x+1), _ or Blank[] is not treated
special in this case. To prevent the evaluation of the patterns, use
HoldPattern:
MatchQ[3 x^2, #] & /@ {3 x_^2, 3 x_^_, _ x_^_, HoldPattern[_ _^_],
HoldPattern[_ (_^_)], HoldPattern[_*(_^_)]}
works as I think you expect...
hth,
albert
Wrap the pattern in HoldPattern to prevent evaluation.
David Bailey
http://www.dbaileyconsultancy.co.uk
MatchQ[3 x^2, #] & /@ {3 x_^2,
3 x_^_, _ x_^_, _ _Symbol^_, _ (_Symbol^_), _*(_Symbol^_)}
J=E1nos
**************************************************************************
David Bailey
http://www.dbaileyconsultancy.co.uk