MATHEMATICA LISTS:
Structured data objects

List groups a collection of 
expressions of any type.

lexp  =  {a, b, c}

We have just defined a Symbol lexp to be the list with elements a, b, c, which are themselves symbols.   We can then do operations on them.

lexp^2

Sin[{a, b, c}]

Many building functions having the above property are called listable.  By default, your own function will not be listable unless you change the attributes of your function.

Attributes[Sin]

?SetAttributes

List can be used as vectors:

{a, b, c}  +  {1, 2, 3}

Head[lexp]

First[lexp]

Last[lexp]

To refer to the i-th element in a list, we use the double square brackets.

lexp[[2]]

In Mathematica, the elements in a list are refers from 1, 2, ....

Length[lexp]

lexp[[0]]

lexp[[-1]]

rexp  =  {1, 2, 3}

Join[lexp,  rexp]

Append[lexp,  1]

Prepend[lexp,  1]

Lists are used to represent 
matrices as list of lists.

m = {{1, 2}, {0.5, 3}}

MatrixForm[m]

Eigenvalues[m]

Det[m]

Transpose[m]

Inverse[m]

m  .  m

This is how a matrix multiply a vector:

m  .  {a,  b}

To access the elements an array, use [[i,j]], as

m[[1, 2]]

List can be used to represent a tree.

{ {a,  b},  {{Sin[x],  1},  2}}

List (or list of lists) v.s. associative array

To use a list or array, the elements, size etc has to be defined first.  For example, the following use of two-dimensional array is not correct:

h[[1, 2]]  =  3

Since h as a list of list does not exist yet.  We should say:

(h  =  Table[0,  {5}, {5}])  //  MatrixForm

h[[1, 2]]  =  3;  MatrixForm[h]

Associative Array

For associative array, you need not specify the size of array before head.  In fact, it is internally implemented as a hashtable.  We use single square brackets for associative array.

a[0]  =  2;  a[-2]  =  -4;  a[1000]  =  w;  
    a[7, 7]  =  7

?a

Mathematica Expressions

Mathematica expressions are internally always of the form

expr[expr1,  expr2,   ... ]

Where expr is called the Head, and expr1 is the first element of the expression, expr2 2nd element etc.   We obtain the expr by applying the Head[ ...] function, we obtain expr1 by First[...].

Head[a + b]

Why?

First[a + b]

FullForm[a + b]

Plus[a, b]

FullForm[a*b  +  c (1 + x)^3]

This data structure can be understood as a tree.

Assignment and Evaluation

a = 1

a + b

b  =  (1 + x)^2

a + b

Clear[a, b]

a + b

Remove[a, b]

This show you what variables (symbols) have been defined so far.

?Global`*

READINGS:
section on lists (1.8) section on expressions (2.1).