       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:= (c^2)^(d/2)/.{(a_^2)^(b_ /2)->a^b}
>
> Out= c^d
>
>
>
> In:= (c^2)^(5/2)/.{(a_^2)^(b_ /2)->a^b}
>
> Out= (c^2)^(5/2)
>
>
> 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:= MatchQ[5/2, b_/2]

Out= 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:= (c^2)^(5/2)/.{(a_^2)^Rational[b_, 2]->a^b}

5
Out= c

MatchQ is a very useful tool for resolving problems like this.

Dave Withoff
Research and Development
Wolfram Research

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

```

• Prev by Date: Re: How to force ( Exp[I x]/2+Exp[-I x]/2=cos(x) ) ?
• Next by Date: Re: Mma on win95 vs. Linux
• Previous by thread: Re: substitution rules and patterns
• Next by thread: Re: Mathematica on MacOS 7.52