MathGroup Archive 2007

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

Search the Archive

Re: Re: The uses of Condition (/;)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82965] Re: [mg82947] Re: The uses of Condition (/;)
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Mon, 5 Nov 2007 05:01:02 -0500 (EST)
  • References: <fghcbl$k9n$1@smc.vnet.net> <200711041111.GAA26050@smc.vnet.net>

On 4 Nov 2007, at 20:11, magma wrote:

>
> Changing slightly topic:
>
> In the same Condition documentation page we find:
>
> {6, -7, 3, 2, -1, -2} /. x_ /; x < 0 -> w
> giving
> {6, w, 3, 2, w, w}
> and that 's ok. The x_ stand for the individual elements in the list
>
>
> But why then
> {6, -7, 3, 2, -1, -2} /. x_  -> w
> gives
> w
> instead of
> {w,w,w,w,w,w}  ?
>
> shouldn't the x_ still stand for the individual elements in the list?
>
>

This is because in the first example the entire list does not satisfy  
the condition and the second cases it does (there is no condition).  
The diffeence is essentially the same as here:

{6, -7, 3, 2, -1, -2} /. x_ /; (Head[x] == Integer) -> w
  {w, w, w, w, w, w}

{6, -7, 3, 2, -1, -2} /. x_ /; (Head[x] == List) -> w
w

If you use Trace on both you will see that the actual pattern  
matching is exactly the same.

Andr


  • Prev by Date: Re: Can you get a package back to a notebook easily?
  • Next by Date: Re: Simple equation won't plot
  • Previous by thread: Re: The uses of Condition (/;)
  • Next by thread: Crash with simple plot command