gives the total number of indivisible subexpressions in expr.
- LeafCount gives a measure of the total "size" of an expression.
- LeafCount counts the number of subexpressions in expr that correspond to "leaves" on the expression tree.
- For ordinary expressions, LeafCount is based on FullForm representation.
- For raw and other atomic expressions, the LeafCount is 1 with the following exceptions: »
Association based on the leaf count of the values Complex based on FullForm Rational based on FullForm
- With the option setting HeadsFalse, LeafCount excludes heads of expressions and their parts.
Examplesopen allclose all
Basic Examples (1)
Properties & Relations (6)
LeafCount by default includes the head and all elements inside it:
For expressions with atomic heads, this corresponds to the number of vertices in TreeForm[expr]:
Possible Issues (3)
LeafCount by default includes leaves in heads:
This shows the expression tree whose leaves are counted by LeafCount:
Wolfram Research (1988), LeafCount, Wolfram Language function, https://reference.wolfram.com/language/ref/LeafCount.html (updated 2022).
Wolfram Language. 1988. "LeafCount." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/LeafCount.html.
Wolfram Language. (1988). LeafCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LeafCount.html