Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: a problem applying Rule

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,

  In an earlier posting I wrote



     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__]]


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[z,f[],a]] /. {f [f[],x__] -> f[f[]], g[f[],x__] -> g[f[]]}


Allan Hayes
Mathematica Training and Consulting
Leicester, UK
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642

  • Prev by Date: Eigenvectors
  • Next by Date: Mathematica 2.2.2 in Windows 95
  • Prev by thread: Re: Eigenvectors
  • Next by thread: Re: a problem applying Rule