Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 2006

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

Search the Archive

Re: ReplaceAll (/.)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69202] Re: ReplaceAll (/.)
  • From: p-valko at tamu.edu
  • Date: Fri, 1 Sep 2006 18:40:59 -0400 (EDT)
  • References: <ed9491$tu$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I think you really want

(a b) /. Times -> List

and it does return

{a,b}


The pattern  x_Times  would pick "a part of an expression that - after
plugging into the function Times - gives True". There is no such part
of your expression so it is returned intact.



Regards, P.V.


Bruce Colletti wrote:
> Re Mathematica 5.2.0.0.
>
> Why doesn't:
>
>                (a b) /. x_Times -> List @@ x
>
> return {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.
>
> Although List@@(a,b) returns {a,b}, I want to use the above ReplaceAll function (this example here is taken from a larger problem).
> 
> Thankx.
> 
> Bruce


  • Prev by Date: RE: ReplaceAll (/.)
  • Next by Date: Re: ReplaceAll (/.)
  • Previous by thread: RE: ReplaceAll (/.)
  • Next by thread: Re: ReplaceAll (/.)