Level
[expr, levelspec]Level uses standard level specifications:
Infinity
{n}
{m, n}
Level 0 corresponds to the whole expression.
A negative level -n
consists of parts with depth n.
Level -1 is the set of atoms in an expression:
Level[a + b ^ 3 * f[2 x ^ 2], {-1}]
Level[{{{{a}}}}, 3]
Level[{{{{a}}}}, -4]
Level[{{{{a}}}}, -5]
Level[h0[h1[h2[h3[a]]]], {0, -1}]
Use the option Heads -> True
to include heads:
Level[{{{{a}}}}, 3, Heads -> True]
Level[x^2 + y^3, 3, Heads -> True]
Level[a ^ 2 + 2 * b, {-1}, Heads -> True]
Level[f[g[h]][x], {-1}, Heads -> True]
Level[f[g[h]][x], {-2, -1}, Heads -> True]