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.
  • LeafCount is based on FullForm representation of expressions.
  • Numbers with heads Rational and Complex are treated as composite objects, just as in FullForm.


open allclose all

Basic Examples  (1)

Find the number of "leaves" in an expression tree:

Applications  (3)

Find leaf count measures of the sizes of successive integrals:

Make Simplify pick expressions with minimum LeafCount:

Find leaf counts in combinator expressions [more info]:

Properties & Relations  (2)

LeafCount includes the head and all elements inside it:

For most expressions, LeafCount equals the count matching Blank[] at level {-1}:

LeafCount counts Rational and Complex numbers using their FullForm:

Count treats Rational and Complex as atoms:

Possible Issues  (5)

LeafCount is based on the FullForm of expressions:

LeafCount counts elements in rational and complex numbers just as in FullForm:

Integers of any size are still treated as single expression leaves:

LeafCount treats SparseArray objects as single expression leaves:

Unlike TreeForm, LeafCount takes into consideration the structure of expression 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.


Wolfram Research (1988), LeafCount, Wolfram Language function, https://reference.wolfram.com/language/ref/LeafCount.html.


@misc{reference.wolfram_2021_leafcount, author="Wolfram Research", title="{LeafCount}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/LeafCount.html}", note=[Accessed: 17-May-2021 ]}


@online{reference.wolfram_2021_leafcount, organization={Wolfram Research}, title={LeafCount}, year={1988}, url={https://reference.wolfram.com/language/ref/LeafCount.html}, note=[Accessed: 17-May-2021 ]}


Wolfram Language. 1988. "LeafCount." Wolfram Language & System Documentation Center. Wolfram Research. 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