Re: Pattern Matching Question
- To: mathgroup at smc.vnet.net
- Subject: [mg116714] Re: Pattern Matching Question
- From: "Scot T. Martin" <smartin at seas.harvard.edu>
- Date: Fri, 25 Feb 2011 06:33:16 -0500 (EST)
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: [mg116714] [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 :)