Re: substitution rules and patterns
- To: mathgroup at smc.vnet.net
- Subject: [mg3437] Re: substitution rules and patterns
- From: withoff (David Withoff)
- Date: Thu, 7 Mar 1996 02:24:30 -0500
- Organization: Wolfram Research, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
In article <4he6ae$frk at dragonfly.wolfram.com> Susan Rempe <rempe at euclid.chem.washington.edu> writes: > > Could someone tell me why the first substitution rule > works and the second doesn't---- > > In[70]:= (c^2)^(d/2)/.{(a_^2)^(b_ /2)->a^b} > > Out[70]= c^d > > > > In[71]:= (c^2)^(5/2)/.{(a_^2)^(b_ /2)->a^b} > > Out[71]= (c^2)^(5/2) > > Thanks in advance, > > Susan Rempe > rempe at u.washington.edu > The number 5/2 is an atom, and doesn't match the pattern b_ /2, for much the same reason that 4 doesn't match 2 x_ (even though 4 can be written as 2 * 2). In[1]:= MatchQ[5/2, b_/2] Out[1]= False The pattern matcher doesn't normally dissect atoms looking for matches. One noteworthy exception to this is that the pattern matcher does dissect atoms to match patterns like Rational[b_, 2]. In[2]:= (c^2)^(5/2)/.{(a_^2)^Rational[b_, 2]->a^b} 5 Out[2]= c MatchQ is a very useful tool for resolving problems like this. Dave Withoff Research and Development Wolfram Research ==== [MESSAGE SEPARATOR] ====