Re: Using a Named Pattern in a Rule
- To: mathgroup at smc.vnet.net
- Subject: [mg36288] Re: Using a Named Pattern in a Rule
- From: Tom Burton <tburton at brahea.com>
- Date: Fri, 30 Aug 2002 01:19:13 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
David, On 8/28/02 10:53 PM, in article akkd5n$82d$1 at smc.vnet.net, you wrote: > I would like to match a named pattern in an expression and then square the > result. But my attempt fails. > > Clear[f, g, x, y, a] > expr = 3*f[x]*g[y] + 2 + x^2; > > expr /. a:(f[_]*g[_]) :> a^2 > 2 + x^2 + 3*f[x]*g[y] ... Well, I see that expr /. a:Times[f[_],g[_],h___]:> a^2 works, and I think I understand why your form above does not work (examine FullForm of expr--your form does not account for "3"), but I don't understand why eliminating "a:" from your form allows the pattern to match. Tom Burton