Re: ! operator
- To: mathgroup at smc.vnet.net
- Subject: [mg55949] Re: [mg55927] ! operator
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Tue, 12 Apr 2005 05:25:59 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: DongGook Park [mailto:dgpark6 at sunchon.ac.kr] To: mathgroup at smc.vnet.net >Sent: Sunday, April 10, 2005 12:55 PM >Subject: [mg55949] [mg55927] ! operator > > >Hi, > >Could you explain a mysterious behaviour of "! operator" as >shown below? > > >In[43]:= >MemberQ[{1,2,3},3] > >Out[43]= >True > >In[47]:= >!MemberQ[{1,2,3},3] >(* Here Mathematica does not give any response! *) > >In[48]:= >Not@MemberQ[{1,2,3},3] > >Out[48]= >False > > >Considering the description from Mathematica help: > "!expr is the logical NOT function. It gives False if >expr is True, >and True if it is False." >This behaviour seems quite suspicious? > >DongGook > [...] If you continue reading Help, you might get a suspicion, that "!" at the beginning of a line is a bit "overloaded" syntactically. Move away from that, and parsing will be directed to the right way: In[26]:= Identity[! MemberQ[{1, 2, 3}, 3]] Out[26]= False In[11]:= (! MemberQ[{1, 2, 3}, 3]) Out[11]= False Whereas In[24]:= ! (MemberQ[{1, 2, 3}, 3]) In[18]:= ! ! ! MemberQ[{1, 2, 3}, 3] Will not do. Clearly In[16]:= Hold[! ! ! MemberQ[{1, 2, 3}, 3]] // FullForm Out[16]//FullForm= Hold[Not[Not[Not[MemberQ[List[1, 2, 3], 3]]]]] is parsed right. Looking at MakeExpression reveals the problem In[22]:= MakeExpression["!MemberQ[{1,2,3},3]"] Out[22]= ErrorBox[ErrorBox["!MemberQ[{1,2,3},3]"]] In[23]:= MakeExpression["(!MemberQ[{1,2,3},3])"] Out[23]= HoldComplete[! MemberQ[{1, 2, 3}, 3]] Don't be vexed! This is not a deep-seated bug, but a vestige of mixed syntax. -- Hartmut Wolf