Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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,
> 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





  • 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