MathGroup Archive 1996

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

Search the Archive

Re: substitution rules and patterns

  • To: mathgroup at
  • Subject: [mg3416] Re: [mg3410] substitution rules and patterns
  • From: Richard Mercer <richard at>
  • Date: Wed, 6 Mar 1996 01:45:37 -0500
  • Sender: owner-wri-mathgroup at

Susan Rempe wrote:

>  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)

It's because of the way the exponents are represented internally, which  
can be discovered using the FullForm operator.

Times[Rational[1, 2], d]

Rational[5, 2]

Times[Rational[1, 2], Pattern[b, Blank[]]]

So does b_/2 match 5/2? Unfortunately not; this is definitely a  
weakness of the representation used. (This is not to say I have a  
definite improvement in mind -- this is a tricky matter.)

How do you make it work? Here's one way:


In pattern Rational[b_,2]*u_.

u_. can represent an actual multiplication or none at all  
(multiplication by 1) so that this pattern covers both of the cases you  
considered. (I don't claim it solves all problems.)

Richard Mercer


  • Prev by Date: Re: Slow ReIm
  • Next by Date: Re: substitution of functions in derivatives
  • Previous by thread: Re: substitution rules and patterns
  • Next by thread: Re: substitution rules and patterns