Re: Pattern Matching Question

*To*: mathgroup at smc.vnet.net*Subject*: [mg116739] Re: Pattern Matching Question*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Fri, 25 Feb 2011 06:37:47 -0500 (EST)

On 2/24/11 at 6:23 AM, forpeopleidontknow at gmail.com (Just A Stranger) wrote: >I'm new to pattern matching, and am stuck on a seemingly simple >probem: >If I want to transform a pattern like >(I) Power[x,_] i.e. x^_ >but NOT >(II) Power[x,Plus[_,_]] i.e. x^(_+_) >How would I go about making that rule? Use a pattern test, e.g. In[6]:= rule = Power[x_, _?(! MatchQ[#, Plus[_, __]] &)] -> newform; In[7]:= x^(a + b) /. rule Out[7]= x^(a + b) In[8]:= x^a /. rule Out[8]= newform