First, obtain a system of equations by using gfeqns or agfeqns.
The following two examples use the variable to mark the number of internal nodes in a nonplane tree.
>
|
|
| (1) |
>
|
|
| (2) |
Given the equations, it is possible to solve the generating function for the number of trees. This can be obtained from the univariate system which is obtained from the multivariate system with set to 1. Further, cumulative generating functions for the number of internal nodes in a binary tree is determined by differentiating the multivariate generating function with respect to , and setting this variable to 1. That is, the value of the system that agfmomentsolve(eqns, 1) attempts to solve.
>
|
|
| (3) |
>
|
|
| (4) |
| (5) |
The coefficient of of , , is the number of trees with nodes, and is the total sum of all trees with nodes for the number of internal nodes. The average number of internal nodes for a tree on nodes is .
>
|
|
| (6) |
This agfmomentsolve function yields information that can be used to compute the variance.