MathGroup Archive 2002

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

Search the Archive

Re: Using a Named Pattern in a Rule

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36282] Re: [mg36278] Using a Named Pattern in a Rule
  • From: Andrzej Kozlowski <andrzej at lineone.net>
  • Date: Fri, 30 Aug 2002 01:19:07 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

The presence of 3* in your formula prevents the match pattern you want 
form taking place since:

In[11]:=
FullForm[3*f[x]*g[y]]

Out[11]//FullForm=
Times[3,f[x],g[y]]

use instead:


In[12]:=
expr=3*f[x]*g[y]+2+x^2;

In[13]:=
expr /. a:((p_.)*f[_]*g[_]) :> p*a^2

Out[13]=
2 + x^2 + 27*f[x]^2*g[y]^2



Andrzej Kozlowski
Toyama International University
JAPAN



On Thursday, August 29, 2002, at 06:38  AM, David Park 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]
>
> 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/
>
>
>
>



  • Prev by Date: Re: Help Window Categories Fonts
  • Next by Date: Re: Laplace Transform bug?
  • Previous by thread: Re: Using a Named Pattern in a Rule
  • Next by thread: Re: Using a Named Pattern in a Rule