This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / The Mathematica Book / Reference Guide / Some General Notations and Conventions  /

A.3.6 Level Specifications

Level specifications.

The level in an expression corresponding to a non-negative integer n is defined to consist of parts specified by n indices. A negative level number -n represents all parts of an expression that have depth n. The depth of an expression, Depth[expr], is the maximum number of indices needed to specify any part, plus one. Levels do not include heads of expressions, except with the option setting Heads->True. Level 0 is the whole expression. Level -1 contains all symbols and other objects that have no subparts.
Ranges of levels specified by


contain all parts that are neither above level , nor below level in the tree. The need not have the same sign. Thus, for example, {2,

-2} specifies subexpressions which occur anywhere below the top level, but above the leaves, of the expression tree.
Level specifications are used by functions such as Apply, Cases, Count, FreeQ, Level, Map, MapIndexed, Position, and Scan. Note, however, that the default level specifications are not the same for all of these functions.
Functions with level specifications visit different subexpressions in an order that corresponds to depth-first traversal of the expression tree, with leaves visited before roots. The subexpressions visited have part specifications which occur in an order which is lexicographic, except that longer sequences appear before shorter ones.