This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / The Mathematica Book / Mathematica Reference Guide / Basic Objects /

A.1.1 Expressions

Expressions are the main type of data in Mathematica.

Expressions can be written in the form h[, , ... ]. The object h is known generically as the head of the expression. The are termed the elements of the expression. Both the head and the elements may themselves be expressions.

The parts of an expression can be referred to by numerical indices. The head has index 0; element has index i. Part[expr, i] or expr[[i]] gives the part of expr with index i. Negative indices count from the end.

Part[expr, , , ... ], expr[[, , ... ]] or Extract[expr, , , ... ] gives the piece of expr found by successively extracting parts of subexpressions with indices , , ... . If you think of expressions as trees, the indices specify which branch to take at each node as you descend from the root.

The pieces of an expression that are specified by giving a sequence of exactly n indices are defined to be at level n in the expression. You can use levels to determine the domain of application of functions like Map. Level 0 corresponds to the whole expression.

The depth of an expression is defined to be the maximum number of indices needed to specify any part of the expression, plus one. A negative level number -n refers to all parts of an expression that have depth n.