16 Chapter00.
nb
Part ([[…]]) is also used to obtain sublists. To do this, you provide a list (enclosed in braces) of the
desired indices to Part ([[…]]). Note that the order of the indices determines the order of the output.
For example, to obtain the sublist of L consisting of the third, seventh, and fifth elements, you enter the
following.
In[53]:= L@@83, 7, 5<DD
Out[53]= 88, 12, 10<
You can use the Span (;;) operator in conjunction with Part ([[…]]) in order to obtain a sublist.
Within Part ([[…]]), a ;; b refers to the sublist of elements from index a to index b. The follow-
ing produces the sublist of L from index 2 through 5.
In[54]:= L@@2 ;; 5DD
Out[54]= 87, 8, 9, 10<
You can use 1 and -1 within a Span (;;) to refer to the beginning and end of the original list. You can
also simply omit a or b and Mathematica will interpret that Span (;;) as beginning at the start or
stopping at the end of the list, respectively.
In[55]:= L@@ ;; 3DD
Out[55]= 86, 7, 8<
In[56]:= L@@5 ;;DD
Out[56]= 810, 11, 12<
We mentioned above that every expression in Mathematica is, internally, represented as a head applied
to a number of arguments. Lists are no different, as FullForm reveals.
In[57]:= FullForm@LD
Out[57]//FullForm=
List@6, 7, 8, 9, 10, 11, 12D
This recognition leads us to two observations.
First, Part ([[…]]) is not a function that applies exclusively to lists. Rather, it can be used with any
expression in Mathematica, with the index referring to the positions of the elements within the brack-
ets. For example, consider the sum below.
In[58]:= sum = a + b + c + d + e
Out[58]= a+b+c+d+e
In[59]:= FullForm@sumD
Out[59]//FullForm=
Plus@a, b, c, d, eD
We can use Part ([[…]]) to access the individual elements being summed.
In[60]:= sum@@3DD
Out[60]= c
The second observation is that this universality of Part ([[…]]) provides a natural meaning to the
index 0. Namely, index 0 refers to the head of the expression.