Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Undiscovered Bug?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46875] Re: [mg46862] Undiscovered Bug?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Fri, 12 Mar 2004 23:39:21 -0500 (EST)
  • References: <200403120702.CAA25505@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 12 Mar 2004, at 08:02, Harold Noffke wrote:

> 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
>
>
>
No, no bug at all, this is perfectly all right, except for somewhat 
confusing documentation. The problem is:

In[1]:=
?Part


expr[[ {i1, i2, ... } ]] gives a list of the parts i1, i2, ...  of
expr.

which is not true unless expr is a List. However, going deeper into the 
documentation you can get the correct information:

When expr is a list, expr[[ {i1, i2, ? in} ]] gives a list of parts. In 
general, the head of expr is applied to the list of parts.

Thus:

In[8]:=
f[a, b][[{1, 2}]]

Out[8]=
f[a, b]

In words, Parts 1 and 2 of f[a,b] were extracted giving {a,b} and then 
the head f was applied giving f[a,b]. For the same reason:

In[9]:=
f[a, b][[{2, 2}]]

Out[9]=
f[b, b]

This time b was extracted twice. You can also extract part 0 to get w 
weird result:

In[10]:=
f[a, b][[{2, 0}]]

Out[10]=
f[b, f]

Now your cases ought to be clear. (Look at FullForm of your 
expressions).


Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Re: ParametricPlot2D
  • Next by Date: RE: Undiscovered Bug?
  • Previous by thread: Undiscovered Bug?
  • Next by thread: Re: Undiscovered Bug?