Using a Named Pattern in a Rule
- To: mathgroup at smc.vnet.net
- Subject: [mg36278] Using a Named Pattern in a Rule
- From: "David Park" <djmp at earthlink.net>
- Date: Thu, 29 Aug 2002 01:38:06 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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] If I drop the name on the pattern, it matches - but it doesn't do what I want. expr /. f[_]*g[_] :> a^2 2 + 3*a^2 + x^2 How can I name such a pattern and use it on the rhs of a rule? David Park djmp at earthlink.net http://home.earthlink.net/~djmp/