Re: Using a Named Pattern in a Rule
- To: mathgroup at smc.vnet.net
- Subject: [mg36314] Re: Using a Named Pattern in a Rule
- From: Rainer Gruber <rainer.gruber at gmx.at>
- Date: Sat, 31 Aug 2002 01:25:58 -0400 (EDT)
- Organization: Johannes Kepler Universitaet Linz
- References: <akkd5n$82d$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
David Park wrote: > I would like to match a named pattern in an expression and then square the > result. But my attempt fails. > > [...] > > David Park > djmp at earthlink.net > > I simplified your example to see whats the problem. I only take the multiplication of three symbols a, b, c. In[1]:= Clear[a, b, c, p, x, y] If you use the "unnamed" pattern 'a c' in Replace you get In[2]:= a b c /. a c :> x Out[2]= b x the replacement will be done because all possibilites of the multiplication are tested and the right one will be found. But if you take a named pattern 'p : a c' your are searching for a multiplication of exactly two variables called 'a' and 'c' and you are not successful with the replacement: In[3]:= a b c /. p : a c :> x Out[3]= a b c In this case you have to take into account that the multiplication can consist of more than two terms, e. g. In[4]:= a b c /. p : a c z___ :> x z Out[4]= b x¨ Hope that will help you, -- Rainer Gruber