MathGroup Archive 2010

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

Search the Archive

Re: Why does this pattern fail to match?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114164] Re: Why does this pattern fail to match?
  • From: Simon <simonjtyler at gmail.com>
  • Date: Fri, 26 Nov 2010 05:25:52 -0500 (EST)
  • References: <iclfej$lb7$1@smc.vnet.net>

Actually, Trace is quite enlightening:

Your first example is
In[1]:= MatchQ[Times[-1, Power[s, -1]], Times[___, Power[___],
___]] // Trace
Out[2]= {{{Power[___],___},___ ___ ___,___^3},MatchQ[-(1/
s),___^3],False}

So you see that before the pattern is tested, it is evaluated to
Times[___, Power[___], ___] ___^3
Since Power[___] _-> ___ and ___*___*___ --> ___^3
So all you need to do is use HoldPattern:
In[2]:=
MatchQ[Times[-1,Power[s,-1]],HoldPattern[Times[___,Power[___],___]]]
Out[2]= True

Hope that helps,

Simon

On Nov 25, 6:57 pm, kj <no.em... at please.post> wrote:
> I'm tearing my hair out over this one.  Could someone please explain
> to me why all the following MatchQ expressions
>
> MatchQ[Times[ -1, Power[s, -1]      ],
>        Times[___, Power[___],    ___]]
>
> MatchQ[Times[ -1, Power[s, -1]],
>        Times[___, Power[___]  ]]
>
> MatchQ[Times[ -1,  Power[s, -1]      ],
>        Times[___, _Power        , ___]]
>
> return False?  (In all cases, s is undefined).  And yet, this succeed=
s:
>
> MatchQ[Times[ -1,  Power[s, -1]],
>        Times[___, _Power       ]]
>
> Is there a systematic way to debug/troubleshoot such pattern matching
> problems? Trace is useless here.
>
> Also, whatever the reason is for the failure of this pattern to
> match, where is this reason documented?  I've gone blind poring
> over the documentation trying to find an answer, without success.
>
> TIA!
>
> ~kj



  • Prev by Date: Re: understanding code
  • Next by Date: Re: Rendering transparent objects changed in M8
  • Previous by thread: Re: Why does this pattern fail to match?
  • Next by thread: Re: Why does this pattern fail to match?