Re: a problem applying Rule
- To: mathgroup@smc.vnet.net
- Subject: [mg10269] Re: a problem applying Rule
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Sat, 3 Jan 1998 05:07:20 -0500
- References: <68csbd$a8l@smc.vnet.net>
N Monomachoff wrote: > Hi there, > I'm using 3.0. > > g[f[f[],a]] /. (n:(f | g))[f[],x__] -> n[f[]] evaluates properly as > g[f[f[]]]. > But after > SetAttributes[f,Orderless] > it no longer works. This doesn't make much sense to me. Is this a bug or > a feature? And is there a way around this? Thanks for any help, > nmonomachoff@msn.com In an earlier posting I wrote After SetAttributes[f,Orderless] The evaluation of g[f[f[],a]] /. (n:(f | g))[f[],x__] -> n[f[]] goes through g[f[a,f[]]] /. (n:(f | g))[f[],x__] -> n[f[]] hence the result. But, why , if f is orderless does not (n:(f | g))[f[],x__] imatch the pattern (n:(f | g))[x__,f[]] ? Let's look a full forms. FullForm[(n:(f | g))[f[],x__]] Pattern[n,Alternatives[f,g]][f[],Pattern[x,BlankSequence[]]] Presumably the matching works on the basis that Pattern[n,Alternatives[f,g]] is not an orderless symbol. If we follow this hint then a cumbersome, way out should be g[f[f[],a]] /. {f [f[],x__] -> f[f[]], g[f[],x__] -> g[f[]]} This does work: SetAttributes[f, Orderless] g[f[f[],a]] /. {f [f[],x__] -> f[f[]], g[f[],x__] -> g[f[]]} g[f[f[]]] g[f[z,f[],a]] /. {f [f[],x__] -> f[f[]], g[f[],x__] -> g[f[]]} g[f[f[]]] -- Allan Hayes Mathematica Training and Consulting Leicester, UK hay@haystack.demon.co.uk http://www.haystack.demon.co.uk voice: +44 (0)116 271 4198 fax: +44 (0)116 271 8642