Tree Properties & Measurements
The Wolfram Language allows testing basic properties of trees, as well as computing general properties that leverage powerful functionality from the rest of the Wolfram Language. The data and subtrees in trees can be extracted by position, level, pattern matching or with arbitrary properties. Structural measurements such as the number of children or subtrees satisfying some property can be efficiently computed. Input and output are given in a form compatible with the rest of the Wolfram Language, allowing easy interoperability.
Basic Properties
TreeQ — test whether an expression is a tree object
TreeLeafQ — test whether a tree is a leaf
Basic Measurements
TreeData — give the data in a tree
TreeChildren — give the child subtrees of a tree
RootTree — give the root of a tree
TreeSize — give the number of subtrees of a tree
TreeLeafCount — give the number of leaves of a tree
TreeDepth — give the maximum level of a tree
Subtrees
TreeLeaves — the list of leaves of a tree
TreeLevel — the list of subtrees specified by a given number of indices
TreeCases — list of subtrees matching a pattern
TreePosition — positions of subtrees matching a pattern
TreeCount — number of subtrees matching a pattern
TreeSelect — list of subtrees satisfying a criterion
Positions in Trees
TreeExtract — extract parts of a tree at the specified positions
TreeLevel, TreeCases, TreeSelect — operator forms representing positions