Strange Answer
- To: mathgroup at yoda.physics.unc.edu
- Subject: Strange Answer
- From: puglisi at settimo.italtel.it
- Date: Thu, 11 Nov 93 15:25:24 MST
--------------------------------------------- Gigi Ventura (VENTURA at pd.infn.it) noticed the following "strange behaviour" of MMA: In[1]:= g1[x_]:=+x In[2]:= g1[2,3,4] Out[2]= 9 In[3]:= g2[x_]:=-x In[4]:= g2[2,3,4] Out[4]= -24 He says: the answer, that may be unexpected, is explained by the multiplication (by-1) implicitly required in the sign change. The priority of multiplication with respect to addition makes the result. To obtain the desired result parenthesis should be used: In[5]:= g3[x_]:=-(+x) In[6]:= g3[2,3,4] Out[6]= -9 I forward this notice, since it might interest some other user. Giacomo Torzo --------------------------------------------- I think the behavior you observe is wrong and due to a faulty version of Mma. Here is what I get: In[5]:= $Version Out[5]= HP 9000 Series 300 (HP-UX) 1.2 (December 13, 1990) In[6]:= g1[x_]:=+x In[7]:= g1[2,3,4] Out[7]= g1[2, 3, 4] In[8]:= g2[x_]:=-x In[9]:= g2[2,3,4] Out[9]= g2[2, 3, 4] Alberto Puglisi ITALTEL Central Research Laboratories, DRSC-IS CLTB 20019 Castelletto di Settimo Milanese (Milano) Italy phone: (+39)(2)4388-8299 fax: (+39)(2)4388-7989 e-mail: puglisi at settimo.italtel.it