MathGroup Archive 2012

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

Search the Archive

Re: is Head[] part of the expression?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126934] Re: is Head[] part of the expression?
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Mon, 18 Jun 2012 05:46:32 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jrep1p$nrj$1@smc.vnet.net>

Position does look at the head even when you use == or !=.  The 
difference between x==0 and x===0 is that x==0 will not evaluate to 
either True or False when x has no value while x===0 will evaluate to False.

On 2012.06.15. 9:42, Nasser M. Abbasi wrote:
> I am now in a state of little confusion about when Head[]
> of a list (the value at index 0) is 'looked' at when
> passing a list to a function to process the list.
>
> For example, below I have a list, and then Position[]
> is passed this list to find the nonzero elements in
> the list.
>
> Depending on the test for zero used, different
> results show up. Sometime the Head[] of the list
> is examined (because I get zero index) and sometime
> it is not.
>
> So, my question, what is the rule-of-thumb on this?
> I am making a cheat sheet for Mathematica, and
> wanted to make a simple rules to remember.
>
>
> -- case 1 -----
> v={1,0,3};
> Position[v,x_/;x!=0]
>
> Out[68]= {{1},{3}}   (*what I expected*)
> -----------------------
>
> --- case 2 --------------------
> Position[v,x_/;Not[PossibleZeroQ[x]]]
>
> Out[69]= {{0},{1},{3}}
> ----------------------------
>
> ----- case 3 ---------------------
> Position[v,x_/;Not[SameQ[x,0]]]
>
> Out[70]= {{0},{1},{3},{}}
> --------------------------------
>
> ---- case 4--------------
> Position[v, x_ /; Not[SameQ[x, 0]], 2]
>
> Out[71]= {{0},{1},{3}}
> ---------------------------
>
> thanks,
>
> --Nasser
>


-- 
Szabolcs Horvát
Visit Mathematica.SE:  http://mathematica.stackexchange.com/





  • Prev by Date: Re: power of logistic distribution
  • Next by Date: Re: Structure of "identical" data not equal in size
  • Previous by thread: Re: is Head[] part of the expression?
  • Next by thread: Re: is Head[] part of the expression?