MathGroup Archive 2011

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

Search the Archive

Re: Pattern Matching Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116734] Re: Pattern Matching Question
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Fri, 25 Feb 2011 06:36:53 -0500 (EST)

I think, Except is your friend. Also, when constructing the Plus pattern,
you should use
HoldPattern to prevent evaluation of Plus[_,_] into 2_. Here is the rule:

x : _^Except[HoldPattern[Plus[_, _]]] :> newForm

A simple test:

In[2]:= {a^b, a^(b + c)} /.
 x : _^Except[HoldPattern[Plus[_, _]]] :> newForm

Out[2]= {newForm, a^(b + c)}

Regards,
Leonid



On Thu, Feb 24, 2011 at 2:23 PM, Just A Stranger <
forpeopleidontknow at gmail.com> 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?
>
> x^_ -> NewForm
>
> Applies the rule to (II), which I don't want.
>
> Thank you for your help :)
>
>
>
>


  • Prev by Date: Re: Pattern Matching Question
  • Next by Date: Re: Pattern Matching Question
  • Previous by thread: Re: Pattern Matching Question
  • Next by thread: Re: Pattern Matching Question