>

$\mathrm{with}\left(\mathrm{combstruct}\right)\:$

For example, a labeled binary tree is a node or a node and two subtrees.
>

$\mathrm{tree}\u2254\left\{N=\mathrm{Atom}\,T=\mathrm{Union}\left(N\,\mathrm{Prod}\left(N\,T\,T\right)\right)\right\}\:$

One can use attributes to count the number of leaves.
>

$\mathrm{l\_tree}\u2254\left\{\mathrm{leaf}\left(T\right)=\mathrm{Union}\left(1\,\mathrm{Prod}\left(0\,\mathrm{leaf}\left(T\right)\,\mathrm{leaf}\left(T\right)\right)\right)\right\}\:$

>

$\mathrm{agfeqns}\left(\mathrm{tree}\,\mathrm{l\_tree}\,\mathrm{unlabeled}\,z\,\left[\left[u\,\mathrm{leaf}\right]\right]\right)$

$\left[{N}{}\left({z}{\,}{u}\right){=}{z}{}{u}{\,}{T}{}\left({z}{\,}{u}\right){=}{z}{}{u}{+}{z}{}{{T}{}\left({z}{\,}{u}\right)}^{{2}}\right]$
 (1) 
For example, the series up to order 10 indicates that there are five trees with 7 nodes and 4 leaves.
>

$\mathrm{Order}\u225410\:$$\mathrm{agfseries}\left(\mathrm{tree}\,\mathrm{l\_tree}\,\mathrm{unlabeled}\,z\,\left[\left[u\,\mathrm{leaf}\right]\right]\right)$

${table}{}\left(\left[{T}{}\left({z}{\,}{u}\right){=}{u}{}{z}{+}{{u}}^{{2}}{}{{z}}^{{3}}{+}{2}{}{{u}}^{{3}}{}{{z}}^{{5}}{+}{5}{}{{u}}^{{4}}{}{{z}}^{{7}}{+}{14}{}{{u}}^{{5}}{}{{z}}^{{9}}{+}{O}{}\left({{z}}^{{11}}\right){\,}{N}{}\left({z}{\,}{u}\right){=}{u}{}{z}\right]\right)$
 (2) 
The internal path length, or sum of distances from nodes to the root, can be defined recursively.
>

$\mathrm{pl\_tree}\u2254\left\{\mathrm{path}\left(T\right)=\mathrm{Union}\left(0\,\mathrm{Prod}\left(0\,\mathrm{size}\left(T\right)+\mathrm{path}\left(T\right)\,\mathrm{size}\left(T\right)+\mathrm{path}\left(T\right)\right)\right)\right\}\:$

>

$\mathrm{agfeqns}\left(\mathrm{tree}\,\mathrm{pl\_tree}\,\mathrm{unlabeled}\,z\,\left[\left[u\,\mathrm{path}\right]\right]\right)$

$\left[{N}{}\left({z}{\,}{u}\right){=}{z}{}{u}{\,}{T}{}\left({z}{\,}{u}\right){=}{z}{+}{z}{}{{T}{}\left({z}{}{u}{\,}{u}\right)}^{{2}}\right]$
 (3) 
This system can be solved and the average values attained.