RE: Undiscovered Bug?
- To: mathgroup at smc.vnet.net
- Subject: [mg46872] RE: [mg46862] Undiscovered Bug?
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Fri, 12 Mar 2004 23:39:14 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: Harold.Noffke at wpafb.af.mil [mailto:Harold.Noffke at wpafb.af.mil] To: mathgroup at smc.vnet.net >Sent: Friday, March 12, 2004 8:03 AM >To: mathgroup at smc.vnet.net >Subject: [mg46872] [mg46862] Undiscovered Bug? > > >MathGroup: > >In Mathematica 5.0.1 with Windows 2000, I mistakenly used the [[{}]] >operator on x/y. I was expecting an error, but I kept getting unusual >results as shown in In/Out's 2 to 5 below. > >Have I stumbled on a bug, or is there a way to make sense out of this? > > >In[1]:= TreeForm[x/y] > >Out[1]//TreeForm= Times[x, | ] > Power[y, -1] > >In[2]:= (x/y)[[{2,2}]] > > >Out[2]= -2 > y > >In[3]:= (x/y)[[{1,2,1}]] > > 2 > x >Out[3]= -- > y > >In[4]:= (x/y)[[{2, 2, 2, 2}]] > > -4 >Out[4]= y > >In[5]:= (x/y)[[{2, 1, 1, 0, 2, 2, 0}]] > > 2 2 > Times x >Out[5]= --------- > 3 > y > > >Regards, >Harold > Well, Harold, it's **never** a bug! (Of course, sometimes it's a bug, but when it is, you'll know!) To understand your results we have to look first at the FullForm of the expression: In[1]:= FullForm[x/y] Out[1]//FullForm= Times[x, Power[y, -1]] Now Help says: expr[[i]] or Part[expr, i] gives the ith part of expr. Such... In[2]:= (x/y)[[2]] Out[2]= 1/y In[3]:= % // FullForm Out[3]//FullForm= Power[y, -1] ...should be clear as daylight. For the next case again consult Help: When expr is a list, expr[[{i1, i2, ...}]] gives a list of parts. In general the head of expr is applied to the list of parts Such... In[4]:= (List @@ (x/y))[[{2, 2}]] Out[4]= {1/y, 1/y} In[5]:= Times @@ % Out[5]= 1/y^2 ...should be the same as In[6]:= (x/y)[[{2, 2}]] Out[6]= 1/y^2 The explanations for your other cases go along the same lines, if you only know that In[7]:= (x/y)[[0]] Out[7]= Times -- Hartmut