MathGroup Archive 2006

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

Search the Archive

Re: ReplaceAll (/.)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69208] Re: ReplaceAll (/.)
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 1 Sep 2006 18:41:12 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <ed9491$tu$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Bruce Colletti wrote:
> Re Mathematica 5.2.0.0.
> 
> Why doesn't:
> 
>                (a b) /. x_Times -> List @@ x
> 
> return {a,b}? 

Trace[a*b /. x_Times -> List @@ x]

{{{List @@ x, x}, x_Times -> x, x_Times -> x}, a*b /. x_Times -> x, a*b}

> My (flawed) reasoning is that a b has form Times[a,b], and so x matches to Times[a,b].  List@@x replaces Times with List to yield List[a,b], or {a,b}...or so it would seem.
> 
> The explanation is somehow linked to the fact that:
> 
>                (a b) /. x_Times :> List @@ x
> 
> returns {a,b}, but I don't see why this works but not the above.  

Trace[a*b /. x_Times :> List @@ x]
{{x_Times :> List @@ x, x_Times :> List @@ x}, a*b /. x_Times :> List @@ 
x, List @@ (a*b), {a, b}}

See Section "2.5.8 Immediate and Delayed Definitions" of The Mathematica 
Book at http://documents.wolfram.com/mathematica/book/section-2.5.8

Regards,
Jean-Marc


  • Prev by Date: RE: How to identify "intersections" between to data sets?
  • Next by Date: Re: a curious answer
  • Previous by thread: Re: ReplaceAll (/.)
  • Next by thread: Re: ReplaceAll (/.)