Cat::TreesClass – The category of tree-like combinatorial classes that can be described by a grammar
Cat::TreesClass represents the category of combinatorial classes of tree-like objects that can be described by a grammar.
Creating the Category
Cat::TreesClass(<specification>, <Options>)
Parameters:
specification: |
a list, or set, or table of production rules |
Options:
Labelled, Labelled = g: |
Selects whether the trees are labeled or not. b must be TRUE or FALSE. The default value is FALSE. |
Binary, Binary = b: |
Selects whether the trees are binary or not. b must be TRUE or FALSE. The default value is FALSE. |
CompleteBinary, CompleteBinary = b: |
Selects whether the trees are complete binary trees. b must be TRUE or FALSE. The default value is FALSE. |
Ordered, Ordered = b: |
Selects whether trees are ordered or not. b must be TRUE or FALSE. The default value is TRUE. |
MainNonTerminal = T: |
Specifies the main non terminal in the specification. The default value is Tree. |
Categories
Details:
A combinatorial class C of tree-like objects is most of the time decomposable; that is it can be defined using a recursive specification (or grammar) that can be fed to combinat::decomposableObjects.
The purpose of this category is mostly technical: it is a specialization of the category Cat::DecomposableClass, which defines a number of handy shortcuts for implementing such a combinatorial class C. Namely, it defines a set of natural default productions, according to the provided options:
Tree
the tree
Node
a node of the tree
NodeLabel
the label of a node
ChildList
the childs of a node
Leaf
a leaf of the tree
LeafLabel
the label of a leaf,
LeafNIL
a void leaf
Those default productions may be overwritten at will in specification.
The methods "generator", "list", and so on use the constructor "new" to build recursively the elements of this domain. This constructor must accept the same syntax as the constructor of combinat::trees (see "new" for details).
Method count is inherited from Cat::CombinatorialClass.
Method generator is inherited from Cat::CombinatorialClass.
Method list is inherited from Cat::CombinatorialClass.
Method unrank is inherited from Cat::CombinatorialClass.
Method random is inherited from Cat::CombinatorialClass.
Method specification is inherited from Cat::DecomposableClass.
Method fromGrammar is inherited from Cat::DecomposableClass.
new – create element of this domain
Cat::TreesClass::new()
Cat::TreesClass::new([label])
Cat::TreesClass::new([label, dom child1, ...])
Must return the empty tree.
Must return a new leaf with label label.
Must return a new tree whose root node has label label and childs .
Of course, this constructor may accept other arguments as well.
We create a combinatorial class for unlabelled unordered trees. To this end, we inherit the data structure from the domain combinat::trees and the counting and generating methods from the category Cat::TreesClass:
domain unorderedTrees
inherits combinat::trees;
category Cat::TreesClass(Ordered=FALSE);
end_domain:
unorderedTrees::list(5)
-- o, o , o , o , o , o , o , o , o --
| | | | | / \ / \ / \ /|\ // \\ |
| | | / \ /|\ | /\ | | | |
| | / \ | | |
-- | --
This is the most common use case, where the data structure is either inherited from combinat::trees or from combinat::binaryTrees. As a syntactic sugar, there is a wrapper domain combinat::treesGeneric that achieves concisely the same effect:
unorderedTrees := combinat::treesGeneric(Ordered = FALSE):
unorderedTrees::list(5)
-- o, o , o , o , o , o , o , o , o --
| | | | | / \ / \ / \ /|\ // \\ |
| | | / \ /|\ | /\ | | | |
| | / \ | | |
-- | --
See combinat::treesGeneric for more examples.
We now illustrate how to use Cat::TreesClass to implement combinatorial classes of tree-like objects whose data structure is not given by combinat::trees. We start with unordered trees with nodes of arity at least two and labels on the leaves only, represented using sets:
domain treesAsSets
inherits Dom::BaseDomain;
category Cat::TreesClass([Leaf = Atom(id),
NodeLabel=Epsilon,
ChildList=Powerset(Tree, MinLength=2)],
Labelled);
new := l -> { op(l,2..nops(l)) };
end_domain:
treesAsSets::list(3)
Now, we construct all the expressions that can be built from one unary predicate f, and two binary commutative predicates g and h:
domain expressions
inherits Dom::BaseDomain;
category Cat::TreesClass([Leaf = Atom(f),
NodeLabel=Union(Atom(g), Atom(h))],
CompleteBinary, Ordered=FALSE);
new := l -> op(l,1)(op(l,2..nops(l)));
end_domain:
expressions::list(5)
At this point, we are reaching the limits of this category. It is almost as simple to use directly combinat::decomposableObjects:
expressions :=
combinat::decomposableObjects
([Tree = Union(Leaf, Node),
Leaf = Atom(f),
NodeLabel = Union(Atom(g), Atom(h)),
Node = Alias(Prod(NodeLabel, Multiset(Tree, Length=2)),
x -> op(x, 1) (op(op(x, 2))))]):
expressions::list(5)
Changes in MuPAD 3.4
New Function.