Re: Why does this pattern fail to match?
- To: mathgroup at smc.vnet.net
- Subject: [mg114175] Re: Why does this pattern fail to match?
- From: Andrea <btlgs2000 at gmail.com>
- Date: Fri, 26 Nov 2010 05:27:53 -0500 (EST)
- References: <iclfej$lb7$1@smc.vnet.net>
On Nov 25, 11:57 am, 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 Patterns evaluate as other expression. So as Times[a, Power[a], a]] -----> a^3 so Times[___, Power[___], ___]] ------> ___^3 as you can try. Trace is not useless. If you execute MatchQ[Times[-1, Power[s, -1]], Times[___, Power[___], ___]] // Trace the resul contains the evaluation of the pattern. If you don't want to evaluate a pattern you have to use HoldPattern. MatchQ[Times[-1, Power[s, -1]], HoldPattern@Times[___, Power[___], ___]] works fine. Andrea