The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: is Head[] part of the expression?
Replies: 9   Last Post: Jun 20, 2012 3:49 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Nasser Abbasi

Posts: 6,677
Registered: 2/7/05
is Head[] part of the expression?
Posted: Jun 15, 2012 3:42 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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 -----

Out[68]= {{1},{3}} (*what I expected*)

--- case 2 --------------------

Out[69]= {{0},{1},{3}}

----- case 3 ---------------------

Out[70]= {{0},{1},{3},{}}

---- case 4--------------
Position[v, x_ /; Not[SameQ[x, 0]], 2]

Out[71]= {{0},{1},{3}}



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.