Lists

Mathematica is a powerful list processing language and has a lot of commands
to manipulate and create lists. A list is an ordered collection of objects and Mathematica
has commands for inserting elements to a list, to manipulate and apply functions to
the list.

The simplest list creation function is the Table commad. The first argument of Table
is the function and the second is a range. To create a table of the first ten squares, we can
write

In[49]:=

  Table[ x^2, { x, 1, 10}]

Out[49]=

  {1, 4, 9, 16, 25, 36, 49, 64, 81, 100}

The range { x, 1, 10} specifies that x ranges from 1 through 10, increasing by 1 in
each step. If we wanted the first ten odd squares, then we can use the range { x, 1, 20, 2}.
Now x is incremented by 2 in each step. An ith element of a list L can be accessed by
L[[i]]. The first and last elements of L are obtained by First[L] and Last[L]. A list is like a
vector and a list of lists (all identical size) is like a matrix, so matrix operations
can be applied to these. Transpose exchanges the rows and the columns.

Consider the application of these in the following example.

In[50]:=

  factors= FactorInteger[ 789672]
  
  
  x= Transpose[factors]
  
  primefactors= First[x]

Out[50]=

  {{2, 3}, {3, 1}, {13, 1}, {2531, 1}}

Out[51]=

  {{2, 3, 13, 2531}, {3, 1, 1, 1}}

Out[52]=

  {2, 3, 13, 2531}

The result of these operations is to extract the prime factors of the number. FactorInteger
returns a list of lists, ( a matrix) whose rows have two elements each, a prime and its
exponent in the factorization. Transpose interchanges the rows and columns, so the first
element of the transposed list is now a list of the prime factors.

More list processing functions are discussed in a separate chapter.

Exercise: Make a list of the first fifty Fibonacci numbers. Divide them by3.
Which are divisible by 3? Make a conjecture and test it for larger Fibonacci numbers
by making a list of only those Fibonacci numbers that you think are multiples of 3.
Repeat the exercise to test divisibility by 3.

Up to Tutorial