MathGroup Archive 2011

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

Search the Archive

Re: Pattern Matching Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116724] Re: Pattern Matching Question
  • From: Just A Stranger <forpeopleidontknow at gmail.com>
  • Date: Fri, 25 Feb 2011 06:35:04 -0500 (EST)

Cool, thanks guys. So many ways of doing it! :)

I think I'm starting to get how pattern matching works.

On 02/24/2011 06:29 AM, Scot T. Martin wrote:
> One way would be with PatternTest[...], abbreviated as ?.
>
> For instance, Power[x,_?AtomQ] would match for Power[x,5] but not Power[x,Plus[_,_]]. That might be what you're looking for.
>
> If you are looking for something more advanced, you might need to go with Power[x,_?(Head[#]!=Plus&)]
>
>
> -----Original Message-----
> From: Just A Stranger [mailto:forpeopleidontknow at gmail.com]
> Sent: Thursday, February 24, 2011 06:24
> To: mathgroup at smc.vnet.net
> Subject: [mg116702] Pattern Matching Question
>
> 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: How to deal with big matrix 2
  • Next by Date: Re: How to deal with big matrix 2
  • Previous by thread: Re: Pattern Matching Question
  • Next by thread: Which, Switch, If, and Piecewise