Brauer and partition diagram models for phylogenetic trees and forests

We introduce a correspondence between phylogenetic trees and Brauer diagrams, inspired by links between binary trees and matchings described by Diaconis and Holmes (1998 Proc. Natl Acad. Sci. USA 95, 14 600–14 602. (doi:10.1073/pnas.95.25.14600)). This correspondence gives rise to a range of semigroup structures on the set of phylogenetic trees, and opens the prospect of many applications. We furthermore extend the Diaconis–Holmes correspondence from binary trees to non-binary trees and to forests, showing for instance that the set of all forests is in bijection with the set of partitions of finite sets.


Introduction
Phylogenetic trees are a fundamental and persistent idea used to represent evolutionary relationships between species for nearly two centuries. Their use extends beyond biology to the representation of language evolution, and to decision processes in algorithms. Their appeal is that they provide an extra dimension to the ways to relate the elements of a set beyond a linear order. They have been studied directly in numerous ways, through stochastic processes, combinatorics and geometry (e.g. [1,2]).
An indirect but powerful way to study tree structures is to consider correspondences, or ways to represent trees, within other mathematical objects. This is a standard approach in much of mathematics of course (representation theory is defined by this idea). And there are several known bijections between rooted binary phylogenetic trees and other structures. For instance, trees correspond to certain polynomials [3,4], to perfect matchings [5], and to more general partitions of finite sets [6]. The latter has been extended to classes of forests relevant to phylogenetics via a correspondence between forests and trees, providing a way to enumerate such forests using Stirling numbers [7]. Other frameworks for capturing the combinatorics of tree counting and tree shapes have been through the analysis of binary sequences [8], via symmetric function theory [9], and numerous others (see for example the OEIS listing A001147 [10]). The particular connection with perfect matchings has prompted the suggestion by Diaconis & Holmes [5] that there may be a relation to certain diagrams that have independently arisen within several branches of algebra, notably those given by the Brauer algebra [11].
In this paper, we take up and develop the link to Brauer algebras, and develop correspondences between the related diagram structures and phylogenetic trees, that provide an algebraic framework for their study. Each labelled, rooted binary tree will correspond to a unique element in the Brauer category, whose elements can be represented by asymmetrical Brauer diagrams. More generally, a corresponding structure for non-binary trees can be defined using the associated partition category (for partition categories see for instance [12,13]), and we are able to extend this correspondence to the set of all forests. The extension to forests is associated with a new bijective correspondence between forests and partitions of finite sets that directly extends the ideas of Erdős & Székely [6] in a direction distinct from that in Erdős [7].
The Brauer diagram framework has the potential to reveal more structure within the space of tree shapes (sometimes called topologies), and to provide new methods to randomly move about that space (something important for many tree reconstruction algorithms). In particular, the inherited structure provides numerous ways to break down tree space: for instance, through the use of Green's relations from semigroup theory, we can break the set of phylogenetic trees into L -classes, R-classes, H -classes and D-classes, each of which can be interpreted in the light of standard properties of trees (see §4 for definitions of these semigroup classes). A concomitant of this is the possibility to craft new metrics on tree space. Finally, we are able to define an operation on tree-space, effectively a multiplication of trees, relative to a fixed tree, that turns the space into a semigroup, using the 'sandwich semigroup' product. It is then possible to consider the 'regular' elements of this semigroup, that provide a subsemigroup of the set of trees with respect to the chosen fixed tree.
The paper begins in §2 with some background to the algebraic structures we will be using to describe tree space, namely the Brauer algebra and related monoids. We also recall key concepts from semigroup theory, especially Green's relations and the corresponding equivalence classes into which a semigroup decomposes. We then describe ( §3) the matching result of Diaconis & Holmes [5], and show how it extends to a correspondence with Brauer diagrams. Section 4 then explores the result of transferring the results on the analysis and properties known in the Brauer category, across to phylogenetic trees, and discusses the rich new structure for tree space that becomes available. Section 5 introduces a product on trees, relative to a given tree, derived from the definition of the sandwich semigroup on Brauer diagrams, and explores various algebraic consequences of this powerful concept, including for example the characterization of related entities such as the associated regular subsemigroup of trees. Finally, §6 sketches a further broad generalization of the correspondence, between non-binary trees, and associated partition diagrams and the partition category. A key result is a correspondence results for trees and forests with sets of partitions of finite sets (theorem 6.5). We end with a discussion of directions that this algebraic landscape for phylogenetic trees might open up for further research ( §7).

Algorithm 1. Internal vertex labelling algorithm (Erdős--Székely, Diaconis--Holmes).
Require: T ∈ RP bin n Require: n ≥ 1 m ← 0 The number of labelled non-leaf vertices I ← set of unlabelled vertices in T Always non-empty (includes the root) The correspondence with perfect matchings gives rise naturally to a different family of diagrams, namely those in the Brauer algebra B n−1 , which (unsurprisingly) has the same Figure 1. Diagrammatic representation of the generators s i and e i ∈ B n , for i = 1, 2, . . . , n − 1.
dimension, and the partial Brauer monoid B n,n−2 . In the next section, we introduce these algebraic structures, and describe the correspondence. A (set) partition of a finite non-empty set X is a set of pairwise disjoint subsets of X, whose union is X. If π is a set partition of X, write (π ) for the number of subsets in π , and write |π | := |X|. An (integer) partition of a positive integer n is a multiset of positive integers whose sum is n. In this paper, we will use 'partition' to refer to set partition unless otherwise noted.
A semigroup is a set with an associative operation. A simple example is the set of positive integers N >0 = {1, 2, 3, . . .} with the operation of addition. If the semigroup has an identity element with respect to its operation, it is called a monoid. An example is the non-negative integers N := N ≥0 , in which the identity with respect to addition is of course 0. Later in the paper, we will introduce the semigroup notions of Green's relations and 'eggbox diagrams' that represent these relations. For an introduction to some of these notions from semigroup theory, we recommend [17,18] 3. Connections between trees, the Brauer algebra B n−1 and Brauer diagrams B n,n−2 In the first part of this paper, we develop the correspondence between binary phylogenetic trees and perfect matchings via a further diagrammatic setting, that was already referred to in [5]: namely, by exploiting diagrams linked to the Brauer algebra. These will share a basic structure and fundamental elements (the generators of the algebra), and so we briefly introduce the Brauer algebra B n (λ) itself, before moving to the specific set of diagrams B n,n−2 that will be our focus.

(a) Introduction to Brauer diagrams
For each n = 1, 2, . . . , the Brauer algebra B n (λ) is the complex algebra generated by the elements [11] {s 1 , s 2 , . . . , s n−1 , e 1 , e 2 , . . . , e n−1 } subject to the defining relations given in appendix A. For the purposes of links to phylogenetics, we will make two significant restrictions to this generality.
First, we will restrict to λ = 1, and focus on B n = B n (1) (although the potential to extend the ideas we discuss here to the full Brauer algebra makes an interesting question that we leave to future work). Second, we will treat B n and related objects B m,n (see below) as monoids (or partial monoids), working with just the basis elements of the algebra. These have a standard diagram transcription, in which elements are associated with graphs consisting of 2n nodes: '   (b) Binary phylogenetic X-trees and their correspondence with Brauer diagrams Given a binary tree on n ≥ 2 leaves, once its internal vertices are labelled according to algorithm 1, we immediately have a matching on the set {1, . . . , 2n − 2}, obtained by pairing labels on sibling vertices [5,6]. The reverse direction-constructing a tree from a matching-begins with laying out the leaf vertices and then pairing matched vertices that are already there, in increasing order.
Informally, the relation to matchings can be seen as the result of the growth of a binary tree via successive bifurcations: starting from a simple tree with two leaves (a single 'cherry'), with matching {1, 2} = [2], one or the other edge suffers a bifurcation, giving for example {{1, 2}, {21, 22}} (a matching of [4]), whereupon 2, the parent (still paired to its original partner) becomes an internal node, with the children {21, 22} a new pair of nodes. In this way, by iteration, a correspondence is built with matchings, or indeed Brauer diagrams, provided a unique convention for internal node enumeration is given (tantamount simply to having 'unlabelled' internal nodes), as has been described above following [5]. The root location is inferred from the last matched pairing.
Through the bijection between binary trees and matchings described in §2, structural features of the Brauer monoid are induced on trees. Each binary tree on n leaves uniquely defines a matching on [2n − 2], and each such matching uniquely defines a Brauer diagram in B n−1 by connecting nodes labelled by integers paired in the matching (see example in figure 3). Write δ(T) ∈ B n−1 for the Brauer diagram corresponding to T ∈ RP bin n .   If the product of two elements α, α ∈ B n−1 is written αα using juxtaposition, then there is an induced product on trees, defined by Similarly, the * -involution in B n−1 , defined on pairings by interchanging i → i , i → i for all i, or on diagrams by reflection about the horizontal axis, induces an involution on trees, For example, the tree in figure 3 satisfies T * = T, because its diagram is symmetric about the horizontal axis.
The bijection from trees of course extends to a variety of representations of the Brauer monoid or combinatorial objects tied thereto. From the perspective of matchings of an even set, for example, it is more natural to label elements as [1, 2(n − 1)] rather than marking them as [n − 1] ∪ [(n − 1) ] (as already done in establishing bijection δ), and a diagram correspondence could simply be established via arcs between a linear arrangement of nodes {1, 2, . . . , 2(n − 1)}. A less biased arrangement is a chord diagram, with arcs linking an even number 2(n − 1) of nodes arranged in a circle, as in [5]. Relative to a fixed ordering, such a diagram represents a set of transpositions, an element of the symmetric group S 2(n−1) . Thus, the chord diagram in figure 4 corresponding to the six-leaf tree of figure 3, is obtained by bending up the ends of the lower rail of nodes {n, n + 1, . . . , 2(n − 1)} of the corresponding Brauer diagram, so that they join on to the upper rail of nodes {1, 2, . . . , (n − 1)}. Associating a labelled tree with an element of the symmetric group in this way, as a product of transpositions coming from the matching, confers yet another possible multiplicative structure (exploited in the transposition distance for trees [19]).
For manipulations on trees, in this paper, we will use a modified bijection, not between RP bin n and B n−1 , but between RP bin n and B n,n−2 , one of the equivalent diagrammatic presentations of matchings. In practice, the original δ and the modified bijection δ : RP bin n → B n,n−2 (for which we use the same symbol) are the same algorithmically, with the difference that the n nodes on the upper edge correspond to the leaves of the n-leaf trees, and the n − 2 nodes on the lower edge are those reserved for the corresponding internal tree nodes (as mentioned, with the root location being inferred from the last pairing). It is also convenient to continue the numbering from top to bottom in clockwise fashion. See figure 5 for the Brauer transcription in B 6,4 of the six-leaf tree whose presentations in B 5 , and as an element of S 10 (via a chord diagram), have been given in figures 3 and 4, respectively.
With these conventions, the setting of trees in RP bin n as a semigroup, afforded by the transcription to B n−1 , is supplanted by the categorical setting of partial monoids [20][21][22], where a multiplication on B p,q × B r,s exists only if q = r (compare [23]). In practice, we analyse B n,n−2 , and hence RP bin n , via left-and right-multiplication by B n , B n−2 , respectively, and the associated equivalence classes. Moreover, via multiplication with the help of intermediate 'sandwich' elements belonging to B n−2,n ∼ = B * n,n−2 , a semigroup structure can indeed be reimposed (see §5).  This turns out to admit a rather universal description, allowing further structural aspects among the participating trees to be distinguished.
We now briefly introduce some language for describing features of a diagram α ∈ B n,n−2 , that echoes that for functions, as follows. A block of a diagram α is a connected set of nodes in α. Note that if {i, j} is a block in α with i, j ∈ [n], then both (i, j) and (j, i) are in ker(α). An example is given in figure 5. We will occasionally want to refer to the underlying set of the kernel or cokernel. By this we mean the set of all points in [n] or [n + 1, 2n − 2] respectively that appear in relations in the sets. That is, for a set of binary relations S, U(S) := {i : (i, j) ∈ S for some j} ∪ {i : (j, i) ∈ S for some j}.

Structuring tree space via Green's relations
As mentioned above, with the identification with phylogenetic trees in RP bin n as Brauer diagrams of type B n,n−2 via the bijection T → δ(T), the correspondence with the monoidal structure in B n−1 ≡ B n−1,n−1 , afforded by the bijection δ, is no longer direct. Rather, it is supplanted by the categorical setting of partial monoids [20][21][22], where a multiplication on B p,q × B r,s exists only if q = r.
In practice, we analyse B n,n−2 , and hence RP bin n , via left-and right-multiplication by elements of B n and B n−2 , respectively, and the associated equivalence classes. It is important to note here that the labels on the nodes that are matched in the product are implicitly reassigned, along the lines of the description in §3a, so that instead of bottom nodes reading 8, 7, 6 from left to right in an element of B 5,3 , we treat them as though labelled 1 , 2 , 3 . The multiplication on the bottom by an element of B 3 then matches 1 , 2 , 3 along the bottom of one diagram with 1, 2, 3 along the top of the other.
As in the previous usage, we pull the appropriate multiplications back to trees via the bijection Examples of the results of multiplication of five-leaf trees by Brauer generators are shown in table 1.
In semigroup theory, elements that can be obtained from each other by left-and/or rightmultiplication are classified according to Green's relations (see [18,24]). In the context of phylogenetic trees, we find a restricted version of these relations to be most useful, in which the actions are by elements of the symmetric group S n on the left (top of the diagram) and S n−2 on the right (bottom), as opposed to the full Brauer monoid B n or B n−2 . We define these restricted adaptions of Green's relations as follows: In other words, the L -class containing T in B n,n−2 is the set of diagrams that can be reached from T by a left multiplication (by an element of S n ). Likewise, the R-classes arise from right multiplication by elements of S n−2 . The H -classes are sets of elements that are both L and Rrelated, and these form the smallest of this family of equivalence classes. By contrast, the D classes are unions of intersecting L and R-classes.
These classes are displayed using arrays called eggbox diagrams (see ch. 2 of [18]). Each D-class can be represented as a rectangular array whose entries are H -classes. The L -classes are then given by the rows of the D-class, and the R-classes by the columns.
Note that the actions by S n and S n−2 are not faithful, because for instance the action of a transposition s i on a cup between i and i + 1 has the effect of the identity action (for example, in table 1, Because top actions cannot affect the bottom of a diagram, all diagrams in an L -class have the same bottom half. And since the action of S n on the top connects all arrangements of the top half of the diagram that have the same rank (S n is the full symmetric group), each L -class is the full set of diagrams with a particular bottom half.
Likewise, each R equivalence class is indexed by the common top half of the diagrams within it. The H -classes are then those diagrams that have the same top and bottom halves (the intersections of L and R-classes), and there will be k! of these, where k is the rank of the diagrams in the class (this counts the number of ways to join into transversals the set of half-strings that come down from the top half, with those coming up from the bottom half). The D-classes are unions of L and R-classes, namely all diagrams of the same rank.   6 , representing six-leaf trees. Upper diagram: schematic illustration of the separate eggboxes for the classes D 0 , D 2 and D 4 , of Brauer ranks k = 0, 2, 4, corresponding to trees with 3, 2 or 1 cherry, and comprising 45, 540 and 360 trees, respectively (see text for discussion). Lower diagram: a 'close-up' of the D 2 eggbox for trees with two cherries (and Brauer rank 2). Row labels show bottom halves of Brauer diagrams, representing equivalence classes by left action (on the top of a diagram), the Lclasses, whereas column labels show top-halves of diagrams, representing equivalence classes by right action, the R-classes. The inset shows two labelled trees, corresponding to the two diagrams belonging to the selected H -class (the intersection of the selected row and column).

Remark 4.2.
These equivalence classes have natural interpretations in terms of trees. The Rclasses are those trees that are the same up to permutations of leaf labels: their diagrams can be reached by multiplication by an element of S n along the top (which corresponds to the leaves). The L -classes are those that have the same cherry structure at the leaves, but whose internal vertices have been permuted. The H -classes represent trees with the same cherries but whose non-cherry leaves have been permuted. Finally, the D-classes represent all trees with the same number of cherries (namely 1 2 (n − k), where k is the rank).

Multiplicative structure: the set of phylogenetic trees as a semigroup
In using a bijection between trees and an algebraic object like a Brauer monoid, the pay-off is the algebraic structure that comes to the set of trees. In choosing to use the unbalanced diagrams of B n,n−2 , we preserve information about the tree structure (with the leaves all along the top axis of the diagram), but as noted above, we lose the capacity to multiply diagrams in the way that is possible if the top and bottom axes have the same number of nodes.

(a) The sandwich product
There is, nevertheless, still a multiplicative structure available to unbalanced diagrams such as B n,n−2 , namely the sandwich product. This requires a fixed diagram (tree) T, and then allows the product of two diagrams T 1 and T 2 to be composed by inverting T (flipping it in the horizontal axis) to obtain a diagram T ∈ B n−2,n , and sandwiching it between the two trees where · is composition of diagrams. This product then allows us to define a semigroup relative to T, which we denote B T n,n−2 . Figure 7 illustrates such a sandwich product in terms of Brauer diagrams in B 7,5 while the induced operation at the level of the corresponding trees is shown in figure 8 (as can be seen, in this case the examples show a sandwich-square, of the form T * T T := T · T · T ).
Interestingly, the sandwich semigroups relative to different trees are isomorphic if the trees have the same rank (the number of transversals in the diagram) [20,Theorem 6.4]. This means that the choice of tree T as sandwich is only important (in terms of semigroup structure) up to its rank. Note that if a diagram has rank k, then its composition with any other diagram must have rank at most k, because composing diagrams cannot generate additional transversals. In particular, the sandwich semigroup relative to tree T does not contain an identity in general, because no sandwich product with a tree T of rank greater than rank(T) can ever return a tree of the same rank as T . As a consequence, the sandwich semigroup is not a monoid.
(b) The regular subsemigroup relative to a given tree Let T ∈ B n,n−2 be an n leaf tree. Using the sandwich product defined above, the set of trees with operation relative to T is called the sandwich semigroup, denoted B T n,n−2 . The 'regular' elements of this semigroup form a subsemigroup Reg(B T n,n−2 ). A semigroup element x is said to be regular if there exists an a such that xax = x. For the sandwich semigroup, this is equivalent to the property: α is regular if and only if T · α · T has the same rank as α [20].
The regular elements in this Brauer sandwich semigroup can be characterized as follows (we extract the case relevant to this context). Here, the join of two equivalence relations is their join in the lattice of equivalences, that is, the smallest equivalence relation that contains their union. The join A ∨ B separates C if each equivalence class in A ∨ B contains at most one element of C.
The elements of Reg(B T n,n−2 ) can be enumerated according to their rank relative to that of T, as follows: ). The sum in theorem 5.2 is over j = 0, 2, 4, and can be computed as follows:  There are several interesting questions related to the regular subsemigroup with respect to a tree, that we will leave for further work. For instance, the regular subsemigroup of T constitutes a type of neighbourhood of T (noting that T can be easily checked using proposition 5.1 to be regular with respect to itself). There are many ways to define a neighbourhood of a tree, for instance using operations on trees like the nearest neighbour interchange (NNI) and subtree prune and regraft moves, or the transposition distance, also based on matchings [19,25]. It would be interesting to know the relationships among these neighbourhoods. Second, we can observe that in the case of example 5.3, all trees of rank 0 are in the regular subsemigroup. Is this a general property? Are there properties of a tree that make it regular with respect to a large proportion of other trees?

Non-binary trees and partition diagrams
In this section, we extend the results from binary trees RP bin n to all trees RP n , and to forests, taking advantage of a more general family of diagrams and an associated algebraic structure, called a partition monoid [20]. We begin with the generalization to trees where the binary constraint is lifted (so that internal vertices and the root may have out-degree greater than 2).

(a) Non-binary trees
Recall that the underlying correspondence for binary trees on n ≥ 2 leaves is that a tree corresponds to a matching on the set {1, 2, . . . , 2n − 2}: a partition of the set of non-root vertices into components of size 2. The generalization to non-binary trees maps a tree to a partition of the set of non-root vertices into subsets of size ≥ 2 (note that the number of non-root vertices will be less than n − 2 if the tree is not binary). For this reason, we will again exclude the trivial tree and require n ≥ 2.
The generalization begins by observing that algorithm 1 applies without change when the input is a tree that is not necessarily binary (as in [6]). We then obtain a partition from a tree by taking a subset to be a set of sibling vertices (having the same parent), and the correspondence for non-binary trees immediately follows the same algorithm as for binary trees (figure 10).
Let Λ t denote the set of partitions of a set of t objects, and Λ (≥2) t the set of those partitions for which all constituent subsets have at least two elements. We will also refer to Λ (2) t , the set of those partitions for which all components have size exactly two. Note that Λ (2) t is precisely the set of matchings on t elements (in this case t must be even). Write Λ = ∪ t>0 Λ t for the set of all partitions

Figure 10.
A partition corresponding to a non-binary tree. As with binary trees, non-leaf vertices in the tree are numbered in sequence using algorithm 1, choosing at each point the internal vertex whose children are all numbered and which has the lowest, numbered, child vertex.
of a finite set, and Λ (≥2) and Λ (2) for the corresponding sets when the sizes of components are at least 2 or exactly 2, respectively. We now introduce partition diagrams, which are generalizations of the Brauer diagrams defined above from partitions that are matchings to more general partitions.
Recall that Brauer diagrams in B n,n−2 have 2n − 2 nodes in two rows with n nodes along the top numbered left to right 1 to n, and n − 2 nodes along the bottom, numbered right to left n + 1 to 2n − 2. Nodes that are paired in the matching are connected by an edge. A partition diagram for a set partition of [n + m] has n nodes along the top numbered from left to right 1 to n, and m nodes along the bottom numbered right to left n + 1 to n + m. Nodes are connected by edges if their labels are in the same constituent subset of the partition. If there are k > 2 nodes in the subset, we do not draw all k 2 edges, but instead draw the minimal number to show their common membership, which will be k − 1 edges. Examples are shown in figures 11 and 12.
Write n,m , and π (δ(T)) for the corresponding set partition of [n + m]. Recall that (π ) is the number of subsets in the partition π of X, and |π | is the cardinality of X.
The following lemma is the analogue of the property for diagrams from binary trees (that all satisfy m = n − 2). Proof. The blocks in the diagram δ correspond to sets of vertices in T that have the same parent in T, therefore, they are in one-to-one correspondence with the set of non-leaf vertices in T. The non-leaf vertices in T are represented by the m numbered nodes along the bottom of the diagram, with the exception of the root of T. Therefore, m = (π (δ)) − 1.
Note, this result means that given a partition π of an integer t = n + m with blocks of size at least 2, we can compute the values of n and m that give a tree corresponding to π . Since there are four blocks, lemma 6.1 implies m = 3. The partition diagram and corresponding tree on nine leaves with three internal non-root vertices are shown in figure 11.
While it is clear that each non-binary tree may be expressed as a partition diagram, it is not the case that every partition diagram is obtained from a tree, because some will not satisfy lemma 6.1. The same observation holds, of course, for binary trees.

Theorem 6.3. There is a 1-1 correspondence between the set of partitions of finite sets into components of size ≥2, and the set of (non-trivial) rooted phylogenetic trees.
Note, the 'set of partitions of finite sets' is not self-referential because the set of such partitions is infinite.
Proof. This result is a direct corollary to theorem 6.5 below.
In each direction, a partition diagram may be constructed using the partition and the values of m and n, so we also have as a consequence the following corollary. Let L [3] (2) L [4] (2) L [5] (2) Figure 13. The correspondence between sets of phylogenetic trees and sets of partitions described in theorem 6.3, showing how the sets of partitions decompose the sets of trees. An example of this decomposition for Λ (≥2) [5] is shown in figure 14.
L [5] ( 2) Figure 14. The decomposition of Λ (≥2) [5] into sets of partitions. Examples of corresponding partition diagram shapes are in the centre column, with example corresponding tree shapes in the right-hand column. The number of trees in each category is shown on the right, for instance, in the second row, there are 6 2 + 1 particular characteristics such as this are able to be counted via the partial Bell polynomials [16] B t, (x 1 , x 2 , . . . , x t− +1 ), whose monomial coefficients count the number of set partitions π of [t], with (π ) = blocks with specific frequencies. Note that t − + 1 = |π | − + 1 = n, so that these are polynomials in n indeterminates. Thus the above sequence of trees sliced by the size of the ordered set, is given by t  =1 B t, (0, 1, . . . , 1), whose first few terms are 1, 1, 4, 11, 41, 162, . . . (sequence A000296 of the On-Line Encyclopedia of Integer Sequences [10]), so that for instance there are |Λ (≥2) 5 | = 11 partitions of a set of size 5 into partitions without singletons: 5 2 ways to split into subsets of size 3 and 2 (trees on four leaves with one internal vertex), and one way to have a subset of size 5 (the star tree on five leaves). Similarly, the total number of trees with bifurcations or trifurcations only is the sequence t =1 B t, (0, 1, 1, 0, . . . , 0), whose first few terms are 1, 1, 3, 10, 25, 105, 385, . . . (sequence A227937 of [10]).
The former decomposition together with the correspondence in corollary 6.4 can be represented in the diagram in figure 13.

(b) Forests
The correspondence given in §6a between trees and partitions applies to partitions with nontrivial subsets. Recalling that subsets in a partition correspond to sibling vertices in a tree, a natural interpretation for a singleton (trivial) subset is that it corresponds to a vertex with no siblings. Given the definition of a phylogenetic tree used here (and elsewhere) excludes non-root vertices of degree 2, the natural interpretation for a singleton subset is that it corresponds to a root vertex. 2 And therefore, a diagram with singleton vertices ought to correspond to a forest. Indeed, as in theorem 6.5, forests of phylogenetic trees on n leaves provide a one-to-one correspondence with a set of partitions Λ [n] defined in equation (6.3) below.
Let F n denote the set of X-forests, that is the set of forests whose leaves are labelled by elements of the set X, with |X| = n ≥ 1. X-forests are graphs whose connected components are rooted phylogenetic trees, whose leaves partition X. Note that unlike the families of rooted trees, for forests we are allowing n = 1.
Write ≥2 (π ) for the number of non-trivial blocks of the partition π ∈ D n,m . Following the definition in equation ( Proof. (1) If F ∈ F n is trivial, so that all its trees are isolated leaves, it will map to the trivial partition of [n], that is, {{1}, . . . , {n}}. So we need to prove the correspondence between non-trivial forests and non-trivial partitions.
Each (non-trivial) forest gives a partition, by first numbering non-leaf vertices according to algorithm 1, and then forming sets of sibling vertices, with labelled root vertices forming singletons. As with trees, this algorithm leaves a single root vertex un-labelled.
We now explore the properties of the partition arising from a forest, to help in constructing the map back from partitions to forests. Suppose π = π (F) is the partition obtained from the forest F.
If F is non-trivial, we have a correspondence between non-leaf vertices in F, and non-trivial blocks, given by the children of each non-leaf vertex. It follows that the number of non-leaf vertices in F is precisely ≥2 (π ).
The number of all vertices in a non-trivial forest F is |π | + 1, because one vertex (one of the roots) is left unlabelled by algorithm 1. The vertices in F are also either leaves or non-leaves, and so this number is also equal to n + ≥2 (π ). Therefore, |π | + 1 = n + ≥2 (π ) and so n = |π | − ≥2 (π ) + 1. Now consider a non-trivial partition π ∈ Λ. We will show how a forest can be constructed from π . Set n = |π | − ≥2 (π ) + 1, and create a starting forest F 0 consisting of n vertices as leaves, labelled 1, . . . , n. We will successively add vertices and edges to the forest as follows.
Letπ 0 be the set of non-trivial subsets in π 0 contained in {1, . . . , n} (that label vertices in F 0 ), and let S 0 be the element ofπ 0 containing the least integer. This is well-defined because, as argued,π 0 is non-empty.
Add a vertex v 1 to F 0 , as a parent to the vertices labelled by the elements of S 0 , to create a new forest F 1 . Then remove S 0 from π 0 to define π 1 := π 0 \S 0 .
If π 1 has no non-trivial subsets, then end the algorithm and output F 1 . (In this case, we will have had ≥2 (π ) = 1, and so |π | = n and all integers in π are labelling vertices in F 1 .) Otherwise, label the vertex v 1 in F 1 by n + 1. F 1 has leaves labelled 1, . . . , n and one other vertex labelled n + 1, which is the parent of at least two of the leaves.
Thus, the setπ 1 of non-trivial subsets in π 1 contained in {1, . . . , n + 1} is non-empty. Choose the subset inπ 1 with the least integer, and call it S 1 . This process can continue, as described in algorithm 2, until we reach a point where π i has no non-trivial subsets and we output the resulting forest. The forest will have n leaves, and i = ≥2 (π ) additional vertices, of which i − 1 will have labels: one root vertex will remain unlabelled. Thus all elements of π will be labelling vertices, since |π | = n + ≥2 (π ) − 1.
Note that singletons in the partition π are also labelling vertices in the forest. Any singleton in π that is ≤ n is already labelling an isolated leaf from the outset, and so represents a trivial tree. Any singleton greater than n will be labelling a root vertex in a tree in the forest, because it will be assigned as a parent of vertices in a block, and will not be assigned a parent because it has no other elements in its block. See example 6.6 for an illustration of these observations.
The process deterministically defines a forest on n leaves whose vertices (except one root) are labelled by the elements of the partition π , and completes the proof of (1).
(2) immediately follows from the construction described above, which gives a correspondence between a forest with n leaves and a partition satisfying the condition to be an element of Λ [n] .
For (3), suppose F has n leaves and τ component trees, and is non-trivial. Labelling the vertices according to algorithm 1, all but one of these trees will have a labelled root, and so the corresponding partition will have τ − 1 singletons. As noted above, the number of non-leaf vertices is ≥2 (π ), because they correspond to sets of siblings, which correspond to blocks of the partition. This includes the single non-labelled root vertex, and so the number of non-leaf labels in the partition for F is ≥2 (π ) − 1, and this is the value of m in the partition diagram. But since the partition has τ − 1 singleton sets, we have (π ) = ≥2 (π ) + (τ − 1), and it follows that m = (π ) − τ as required. The reverse direction takes a diagram to a partition that then constructs a forest according to algorithm 2. The conditions in the statement follow. Require: π ∈ Λ n ← |π | − ≥2 (π ) − 1 F 0 ← the trivial forest on leaves {1, . . . , n} π 0 ← π π 0 ← the subsets of π 0 of size ≥2 whose elements are labels in F 0 S 0 ← the subset in π 0 containing the least integer Go to Output statement end if π i ← subsets in π i of size ≥ 2 labelling vertices in F i . S i ← the subset inπ i with the lowest integer end for Output F. Let F 5 be the forest obtained from F 4 by adding a vertex v 5 that is a parent of the vertices labelled 9,13. Set π 5 = π 4 \S 4 = {{5}, {11}}. Since π 5 has no non-trivial subsets we end the algorithm and output F = F 5 .
The forests generated in this example are shown in figure 15.
Note, theorem 6.3, relating to non-binary trees, is a special case of this theorem for those forests that consist of a single tree, and partitions without singletons.
The correspondence with forests given in theorem 6.5 creates a broad set of correspondences between sets of partitions and sets of phylogenetic objects, as shown in figure 16. Recall that we have defined the following sets: Λ n = Set of partitions of a set of cardinality n, whose components satisfy the size condition . Here might be empty (no restrictions), or (2) or (≥2), meaning components must be of size 2 or at least 2. But in the next two corollaries, we see correspondences for when components have size at most 2. (c) Semigroup structure The semigroup structures that we have described for binary trees in §5, also extend to nonbinary trees or forests, with some caveats. For instance, immediately we see that an action by the Temperley-Lieb generators e i will not be able to be defined for non-binary trees in general: the product of e i by a partition diagram that includes a block {i, i + 1, j}, where j is on the opposite side to i and i + 1, will result in a block of size one, namely {j}. So the action of a Temperley-Lieb generator on a non-binary tree may result in a forest. However, action by the symmetric group generators s i does preserve the restriction on the partition diagram. In fact, action by s i preserves the number and size of the blocks in the partition. Therefore, we are still able to construct the eggbox diagram decomposition of the set of non-binary trees, and indeed for forests. This decomposition will have a richer structure, however, as the Dclasses are not determined simply by rank, but by other factors (the number and size of the blocks in the partition). This is a topic we leave for further investigation.
The sandwich semigroup construction allows multiplication of non-binary trees, as it does in the binary case, although in general the product will not be closed. That is, if one of the trees involved in the sandwich product is not binary, it is possible that the product of diagrams results in an isolated node, which means the diagram may correspond to a forest of more than one tree ( figure 17). Thus, the set of diagrams for non-binary trees is not closed under the sandwich product. Whether there are subfamilies of non-binary trees for which the product is defined is an interesting further question.
Likewise, the sandwich product allows the multiplication of two forests relative to a third. As with non-binary trees, there will be some products that are not defined, because the numbers of nodes in the diagrams do not match (if the numbers of non-leaf vertices in the forest are not equal). But additionally, even if this is satisfied so that the diagram product is defined, the product may not result in a forest. And this also applies to sandwich products of non-binary trees: the product of two non-binary trees, or forests, relative to a third, may result in a diagram that does not even represent a forest, in that it violates the condition in theorem 6.5(iii). An example is shown in figure 18.

Discussion
The link between phylogenetic trees and algebraic structures such as Brauer monoids and partition monoids that we have described gives rise to a wealth of questions that need further exploration. Top: a sandwich product involving a diagram from a non-binary tree that results in a diagram that does not correspond to a tree, because it has an isolated node, but to a forest with two components. Bottom: the same sandwich product showing the trees and forest involved. = Figure 18. A sandwich product involving diagrams from two non-binary trees relative to a third, and which results in a diagram that does not define a tree or a forest, because it violates the condition in theorem 6.5(iii). This product diagram has m = 2, τ = 3 (one more than the number of singleton nodes) and (π ) = 4, so does not satisfy m = (π ) − τ .
To begin, some opportunities for further development were raised by Holmes and Diaconis in 1998 [5]. For instance, they suggest the representation of a tree as a matching that they introduced (and treating the matched pairs as 2-cycles) allows for the use of multiplication in the symmetric group to create a random walk in tree space. They also suggested the use of multiplication of matchings through use of the Brauer algebra, that we have developed further in this paper in a direction they perhaps did not anticipate (by preserving the leaves along the top of a diagram to create an unbalanced but biologically interpretable model).
The developments here, representing the matching (or partition more generally) as a Brauer or partition diagram, allow a more targeted random walk to be defined that preserves certain key structures of the trees. That is, a random step can be performed by acting on the top or bottom of a diagram by an element of S n or S m , and allow movement along an R-class or L -class, which preserves certain structural properties of the tree, as described in §4.
There are many further questions that warrant exploration, some of which we list here (a) We have defined a way to multiply two binary trees relative to a third, via the sandwich product. How do features of trees (such as their balance) behave when they are multiplied together? (b) Are some properties of trees 'closed' under multiplication? If two trees share the same property, when does their product share the same property? (c) A feature of the sandwich semigroup construction is that it creates a product relative to a fixed tree. Is there some way to exploit this feature in phylogenetics? For instance, is it possible that gene trees may be constrained to be inside some neighbourhood defined by the product relative to the species tree (see [27] for discussion of the challenges understanding this relationship)? (d) The sandwich semigroup product works naturally for binary trees, whose Brauer diagrams have predictable numbers of nodes. Given the comments in §6b and figure 18, are there subclasses of forests (other than binary trees) for which the product is defined and closed?
(ii) Questions about the regular subsemigroup (iii) Other links to tree space (a) As noted in the Introduction, Holmes and Diaconis raised the prospect of using the product of trees to randomly move around tree space or search for an optimal solution to a problem. The properties of this random walk, or one extended to nonbinary trees or forests, are unknown. (b) If we restrict attention only to Brauer diagrams that are planar, that is, for which there are no crossings of lines, then we obtain another closed algebraic structure. That is, in the sandwich semigroup corresponding to a tree with planar diagram, the product of two planar diagrams will remain planar. Any diagram can be made planar by relabelling the leaves, so would this semigroup describe some sort of canonical representatives of tree space? (c) Can operations on trees, such as edge-cutting that take a tree and produce a forest (but also even tree rearrangement operations such as NNI), be implemented by a sandwich product, or an action by an element of the partition monoid? For instance, can sandwich products such as that seen in figure 17 be controlled systematically? (d) There is an interesting correspondence between 'augmented perfect matchings of [2n − 2] containing wiggly lines' and phylogenetic trees on n leaves and n − − 1 internal and root vertices, recently described in [28]. It would be interesting to investigate how such augmented matchings link to diagrams, and the set of partitions Λ (≥2) [n] described here for such trees in theorem 6.3. (iv) Other links to semigroup theory and the Brauer algebra sandwich semigroup (which is also the number of rank 0 trees on six leaves). A characterization could be illuminating. Narrowing it down further, the mididentities (elements that are idempotents when regular but satisfying additional conditions) could have a concrete phylogenetic relationship to the original tree. (b) It would be interesting to study further the restricted Green's relations in which the action on left and right is from a subgroup or subsemigroup (like our S n action in §5). (c) The general relations in the Brauer algebra (see appendix A) contain a central generator λ that we ignore by setting it to be 1. In the algebra, it tracks loops that can occasionally be generated by diagram concatenation, as occurs in the example in figure 2. Is there phylogenetically relevant information that can be captured by loops arising in products, and that might benefit from use of the full B n (λ)?
There are several opportunities to extend the ideas in this paper in different directions. For instance, is it possible to represent phylogenetic networks within a diagram semigroup framework? And coming from the algebraic point of view, is there a role for other monoidal and categorical systems, such as those described in [20] (compare also Loday [29]) to play within phylogenetics, or other scientific and combinatorial problems? Clearly, there is opportunity for exploration and development of this approach at an algebraic, combinatorial, phylogenetic and computational level. Diagram semigroups, monoids, algebras and categories have found numerous diverse and powerful applications within mathematics and physics, and it is exciting to think that they may open new doors to phylogeneticists.
Data accessibility. This article has no additional data. Conflict of interest declaration. We declare we have no competing interests. Authors' contributions. A.F.: conceptualization, formal analysis, investigation, methodology, writing-original draft, writing-review and editing; P.D.J.: conceptualization, formal analysis, investigation, methodology, writing-original draft, writing-review and editing.
Both authors gave final approval for publication and agreed to be held accountable for the work performed therein.
Funding. The authors were both supported in this research by Australian Research Council Discovery Grant DP180102215.
Acknowledgements. When the authors began exploring the potential for modelling phylogenetic trees with Brauer diagrams, they made the fortunate decision to ask James East for advice. They are tremendously grateful for his patient explanations of ideas such as the sandwich semigroup, and for pointing them to important references. They are also grateful to the referees for their careful reading, suggestions of important additional references and instructive comments that have greatly improved the presentation of the results.

Appendix A. Presentation for the Brauer algebra
For each n = 1, 2, . . . , the Brauer algebra B n (λ) is the complex algebra generated by the elements {s 1 , s 2 , . . . , s n−1 , e 1 , e 2 , . . . , e n−1 } subject to the defining relations [11]  For the generalization of these relations arising from the connection with binary trees, to the full partition algebra underlying the extension to non-binary trees and forests, see [30,31].