MathGroup Archive 2011

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

Search the Archive

Re: Pattern Matching Question

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

On 2/24/11 at 6:23 AM, forpeopleidontknow at (Just A Stranger)

>I'm new to pattern matching, and am stuck on a seemingly simple

>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

  • Prev by Date: making a parameter in an integrand real
  • Next by Date: Re: Pattern Matching Question
  • Previous by thread: Pattern Matching Question
  • Next by thread: Re: Pattern Matching Question