Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10491

Re: part of the expression?

From Christoph Lhotka <christoph.lhotka@fundp.ac.be>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: part of the expression?
Date 2012-06-15 19:39 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jrg31c$soj$1@smc.vnet.net> (permalink)
References <201206150741.DAA24416@smc.vnet.net>

Show all headers | View raw


Hi,

  I think that there is no general rule,

In[]:={#, #[0 @@ {0}, 0], #[0 @@ {1}, 0]} & /@ {MemberQ, FreeQ,
   Position, Count, Cases, DeleteCases, Drop, Take}

Out[]:={{MemberQ, True, False}, {FreeQ, False,
   False}, {Position, {{0}, {1}}, {{0}}}, {Count, 1,
   0}, {Cases, {0}, {}}, {DeleteCases, 0[], 0[1]}, {Drop, 0[0],
   0[1]}, {Take, 0[], 0[]}}

It actually depends on what you want, e.g. MemberQ does not
look on its head by default, but if you write

MemberQ[0[1], 0, Heads -> True]
True

it will return true.

Just some more examples.

Christoph


On 06/15/2012 09:41 AM, 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
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: part of the expression? Christoph Lhotka <christoph.lhotka@fundp.ac.be> - 2012-06-15 19:39 +0000

csiph-web