Re: Why does this pattern fail to match?
- To: mathgroup at smc.vnet.net
- Subject: [mg114166] Re: Why does this pattern fail to match?
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Fri, 26 Nov 2010 05:26:14 -0500 (EST)
expr = Times[-1, Power[s, -1]]; Attributes[Times] {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected} Note that Times has attribute Orderless and pattern for Power can only have one or two blanks not three. {MatchQ[expr, Times[___, Power[__]]], MatchQ[expr, Times[___, Power[_]]], MatchQ[expr, Times[__, Power[_]]], MatchQ[expr, Times[Power[__], ___]], MatchQ[expr, Times[Power[_], ___]], MatchQ[expr, Times[Power[_], __]], MatchQ[expr, Times[Power[__], _]]} {True, True, True, True, True, True, True} And, as you discovered in part {MatchQ[expr, Times[___, _Power]], MatchQ[expr, Times[__, _Power]], MatchQ[expr, Times[_, _Power]], MatchQ[expr, Times[_Power, ___]], MatchQ[expr, Times[_Power, __]], MatchQ[expr, Times[_Power, _]]} {True, True, True, True, True, True} However, given that these all work, it is not clear why the following fail {MatchQ[expr, Times[_, Power[_]]], MatchQ[expr, Times[__, Power[__]]], MatchQ[expr, Times[Power[__], __]]} {False, False, False} Bob Hanlon ---- kj <no.email 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 succeeds: 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