combstruct
agfeqns
find the system of generating function equations associated with an attribute grammar
agfseries
find the series solution of a system of generating function equations associated with an attribute grammar
Calling Sequence
Parameters
Description
Examples
agfeqns(spec, a_spec, typ, var, att_list)
agfseries(spec, a_spec, typ, var, att_list)
spec
-
combinatorial specification
a_spec
specification of attribute grammar associated with spec
typ
labeling type; 'labeled' or 'unlabeled'
var
main (size) variable in the generating function
att_list
list of lists associating attribute names with variables
These functions, agfeqns and agfseries, form the attribute grammar analogues to combstruct[gfeqns], and combstruct[gfseries]. For details on specifications, see combstruct and combstruct[specification].
These functions involve multivariate generating function equations which count the objects, as described in the specification spec, and properties of the structures, as defined in the attribute grammar, a_spec.
Each nonterminal in the grammar is associated with a generating function which is named with the name of the structure. For example, A⁡z,u would be a generating function for A. These two functions, agfeqns and agfseries, determine the equations in terms of other nonterminals and specify the series for the generating functions, respectively.
For example, in an unlabeled system with structure A and attributes f1 and f2, the multivariate generating function is defined as A⁡z,q1,q2=∑A⁡za⁢q1f1⁡a⁢q2f2⁡a.
Any number of attributes is allowable, but no user-defined attribute can be marked by the parameter var.
If the objects are labeled, the exponential generating functions are produced. If the objects are unlabeled, ordinary generating functions are used.
The attribute, size, is used for the property pertaining to the number of atoms. It can be referenced in another attribute, but not redefined.
If no rule is defined for a given attribute structure pair, a default recursive rule is used. For example, A=Union⁡B,C,E and the attribute f imply a default attribute specification of f⁡A=Union⁡f⁡B,f⁡C,f⁡E.
Each attribute must be marked by a single, unique variable.
with⁡combstruct:
For example, a labeled binary tree is a node or a node and two subtrees.
tree≔N=Atom,T=Union⁡N,Prod⁡N,T,T:
One can use attributes to count the number of leaves.
l_tree≔leaf⁡T=Union⁡1,Prod⁡0,leaf⁡T,leaf⁡T:
agfeqns⁡tree,l_tree,unlabeled,z,u,leaf
N⁡z,u=z⁢u,T⁡z,u=z⁢u+z⁢T⁡z,u2
For example, the series up to order 10 indicates that there are five trees with 7 nodes and 4 leaves.
Order≔10:agfseries⁡tree,l_tree,unlabeled,z,u,leaf
table⁡N⁡z,u=u⁢z,T⁡z,u=u⁢z+u2⁢z3+2⁢u3⁢z5+5⁢u4⁢z7+14⁢u5⁢z9+O⁡z11
The internal path length, or sum of distances from nodes to the root, can be defined recursively.
pl_tree≔path⁡T=Union⁡0,Prod⁡0,size⁡T+path⁡T,size⁡T+path⁡T:
agfeqns⁡tree,pl_tree,unlabeled,z,u,path
N⁡z,u=z⁢u,T⁡z,u=z+z⁢T⁡z⁢u,u2
This system can be solved and the average values attained.
See Also
combstruct[agfmomentsolve]
combstruct[gfseries]
combstruct[gfsolve]
combstruct[specification]
Download Help Document