Final yr we launched Model 13.0 of the Wolfram Language. Listed below are the updates in bushes since then, together with the newest options in 13.1.
Timber Proceed to Develop 🌱🌳
In Model 12.3 we launched Tree as a brand new elementary assemble within the Wolfram Language. In Model 13.0 we added a wide range of styling choices for bushes, and in Model 13.1 we’re including extra styling in addition to a wide range of new elementary options.
An necessary replace to the elemental Tree assemble in Model 13.1 is the flexibility to call branches at every node, by giving them in an affiliation:
![]() |
All tree features now embrace assist for associations:
![]() |
In lots of makes use of of bushes the labels of nodes are essential. However significantly in additional summary functions one usually needs to take care of unlabeled bushes. In Model 13.1 the operate UnlabeledTree (roughly analogously to UndirectedGraph) takes a labeled tree, and mainly removes all seen labels. Here’s a normal labeled tree
![]() |
and right here’s the unlabeled analog:
![]() |
In Model 12.3 we launched ExpressionTree for deriving bushes from common symbolic expressions. Our plan is to have a variety of “particular bushes” applicable for representing totally different particular sorts of symbolic expressions. We’re starting this course of in Model 13.1 by, for instance, having the idea of “Dataset bushes”. Right here’s ExpressionTree changing a dataset to a tree:
![]() |
And now right here’s TreeExpression “inverting” that, and producing a dataset:
![]() |
(Bear in mind the conference that *Tree features return a tree; whereas Tree* features take a tree and return one thing else.)
Right here’s a “graph rendering” of a extra sophisticated dataset tree:
![]() |
The brand new operate TreeLeafCount enables you to rely the full variety of leaf nodes on a tree (mainly the analog of LeafCount for a common symbolic expression):
![]() |
One other new operate in Model 13.1 that’s usually helpful in getting a way of the construction of a tree with out inspecting each node is RootTree. Right here’s a random tree:
![]() |
RootTree can get a subtree that’s “near the foundation”:
![]() |
It could actually additionally get a subtree that’s “removed from the leaves”, on this case happening to parts which are at degree –2 within the tree:
![]() |
In some methods the styling of bushes is just like the styling of graphs—although there are some vital variations on account of the hierarchical nature of bushes. By default, choices inserted into a selected tree ingredient have an effect on solely that tree ingredient:
![]() |
However you may give guidelines that specify how parts within the subtree under that ingredient are affected:
![]() |
In Model 13.1 there may be now detailed management obtainable for styling each nodes and edges within the tree. Right here’s an instance that provides styling for father or mother edges of nodes:
![]() |
Choices like TreeElementStyle decide styling from the positions of parts. TreeElementStyleFunction, however, determines styling by making use of a operate to the information at every node:
![]() |
This makes use of each knowledge and place data for every node:
![]() |
In analogy with VertexShapeFunction for graphs, TreeElementShapeFunction offers a common mechanism to specify how nodes of a tree ought to be rendered. This named setting for TreeElementShapeFunction makes each node be displayed as a circle:
![]() |