combstruct
agfmomentsolve
solve the system of generating function equations associated with an attribute grammar
Calling Sequence
Parameters
Description
Examples
agfmomentsolve(eqns, num, neweqns)
eqns
-
set of multivariate generating function equations
num
number of times to differentiate; non-negative integer
neweqns
(optional) set of equations that Maple attempts to solve
The agfmomentsolve function accepts a set of multivariate generating functions. It attempts to solve the system of generating functions where the equations are differentiated num times with respect to each variable aside from size. It then evaluates the equations with each nonsize variable set to 1.
The functions are returned as univariate functions. Thus, it is important that the first variable marks size. The agfmomentsolve function is useful for finding averages and higher moments.
The modified equations are returned by using the third argument, neweqns. If it is specified, it is assigned to the system of equations.
If the solving computation is intensive, you can interrupt it and recover the equations. This allows you to intervene with some manual manipulation or specialized solving methods.
The agfmomentsolve function relies on solutions obtained by agfmomentsolve(eqns, num-j) where j=1..num. Thus, if these cannot be solved, fail is returned.
For information on how to write combstruct grammar specifications, see combstruct and combstruct[specification].
with⁡combstruct:
First, obtain a system of equations by using gfeqns or agfeqns.
The following two examples use the variable u to mark the number of internal nodes in a nonplane tree.
eqns0≔agfeqns⁡T=Prod⁡Z,Set⁡T,h⁡T=Prod⁡0,Set⁡h⁡T+1,labeled,z,u,h
eqns0≔T⁡z,u=z⁢ⅇT⁡z,u⁢u,Z⁡z,u=z⁢u
eqns1≔gfeqns⁡E=Ε,T=Prod⁡Z,Prod⁡E,Set⁡T,labeled,z,u,E
eqns1≔E⁡z,u=u,T⁡z,u=z⁢ⅇT⁡z,u⁢u,Z⁡z,u=z
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 u 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 u, and setting this variable to 1. That is, the value of the system that agfmomentsolve(eqns, 1) attempts to solve.
agfmomentsolve⁡eqns0,0
T⁡z=−LambertW⁡−z,Z⁡z=z
agfmomentsolve⁡eqns0,1,new
T1⁡z=−ⅇ−LambertW⁡−zz⁢ⅇ−LambertW⁡−z−1,T2⁡z=−z⁢ⅇ−LambertW⁡−zz⁢ⅇ−LambertW⁡−z−1,Z1⁡z=1,Z2⁡z=z
new
T1⁡z=ⅇ−LambertW⁡−z+z⁢T1⁡z⁢ⅇ−LambertW⁡−z,T2⁡z=z⁢T2⁡z⁢ⅇ−LambertW⁡−z+z⁢ⅇ−LambertW⁡−z,Z1⁡z=1,Z2⁡z=z
The coefficient of zn of T⁡z, coeff⁡T⁡z,z,n, is the number of trees with n nodes, and coeff⁡T2⁡z,z,n is the total sum of all trees with n nodes for the number of internal nodes. The average number of internal nodes for a tree on n nodes is coeff⁡T2⁡z,z,ncoeff⁡T⁡z,z,n.
sol≔agfmomentsolve⁡eqns0,2:
subs⁡sol,T2,2⁡z
ⅇ−LambertW⁡−z2⁢z2⁢z⁢ⅇ−LambertW⁡−z−2ⅇ−LambertW⁡−z3⁢z3−3⁢ⅇ−LambertW⁡−z2⁢z2+3⁢z⁢ⅇ−LambertW⁡−z−1
This agfmomentsolve function yields information that can be used to compute the variance.
See Also
combstruct[agfeqns]
combstruct[gfsolve]
combstruct[specification]
Download Help Document