MathGroup Archive 2004

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

Search the Archive

Re: ReplaceList -- Unexpected Answer

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46815] Re: ReplaceList -- Unexpected Answer
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 9 Mar 2004 04:31:01 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <c2hdqc$aeq$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

because ReplaceAll[] or /. is different from Replace[] and Replace[]
return your expression unchanged.

In[]:=Replace[{f[h[4], h[4]], f[h[4], h[5]]}, f[x : h[_], x_] -> r[x]]
Out[]={f[h[4], h[4]], f[h[4], h[5]]}

and that's why ReplaceList[] return {}

Regards
  Jens


Harold Noffke wrote:
> 
> MathGroup:
> 
> In The Mathematica 5 Book, Section 2.3.3 Naming Pieces of Patterns, we
> find the following pattern matching exercise ...
> 
>         Now both arguments of f are constrained to be the same, and only the
>         first case matches.
> 
>         In[5]:=
>                 {f[h[4], h[4]], f[h[4], h[5]]} /. f[x:h[_], x_] -> r[x]
>         Out[5]=
>                 {r[h[4]],f[h[4],h[5]]}
> 
> Now, let's use ReplaceList to get more insight into this matching
> process ...
> 
>         In[6]:=
>                 ReplaceList[ {f[h[4],h[4]],f[h[4],h[5]]},f[x:h[_],x_] -> r[x] ]
>         Out[6]=
>                 {}
> 
> I do not understand why ReplaceList returns {} instead of { r[h[4]] }.
> 
> Regards,
> Harold


  • Prev by Date: Re: Shared variables between notebooks?
  • Next by Date: RE: ReplaceList -- Unexpected Answer
  • Previous by thread: Re: ReplaceList -- Unexpected Answer
  • Next by thread: RE: ReplaceList -- Unexpected Answer