Re: substitution rules and patterns

• To: mathgroup at smc.vnet.net
• Subject: [mg3416] Re: [mg3410] substitution rules and patterns
• From: Richard Mercer <richard at seuss.math.wright.edu>
• Date: Wed, 6 Mar 1996 01:45:37 -0500
• Sender: owner-wri-mathgroup at wolfram.com

```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.

FullForm[d/2]
Times[Rational[1, 2], d]

FullForm[5/2]
Rational[5, 2]

FullForm[b_/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:

(c^2)^(5/2)/.{(a_^2)^Rational[b_,2]*u_.:>a^(b*u)}

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

==== [MESSAGE SEPARATOR] ====

```

• 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