Phylogenetic Flexibility via Hall-Type Inequalities and Submodularity

Given a collection τ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\tau $$\end{document} of subsets of a finite set X, we say that τ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\tau $$\end{document} is phylogenetically flexible if, for any collection R of rooted phylogenetic trees whose leaf sets comprise the collection τ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\tau $$\end{document}, R is compatible (i.e. there is a rooted phylogenetic X-tree that displays each tree in R). We show that τ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\tau $$\end{document} is phylogenetically flexible if and only if it satisfies a Hall-type inequality condition of being ‘slim’. Using submodularity arguments, we show that there is a polynomial-time algorithm for determining whether or not τ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\tau $$\end{document} is slim. This ‘slim’ condition reduces to a simpler inequality in the case where all of the sets in τ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\tau $$\end{document} have size 3, a property we call ‘thin’. Thin sets were recently shown to be equivalent to the existence of an (unrooted) tree for which the median function provides an injective mapping to its vertex set; we show here that the unrooted tree in this representation can always be chosen to be a caterpillar tree. We also characterise when a collection τ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\tau $$\end{document} of subsets of size 2 is thin (in terms of the flexibility of total orders rather than phylogenies) and show that this holds if and only if an associated bipartite graph is a forest. The significance of our results for phylogenetics is in providing precise and efficiently verifiable conditions under which supertree methods that require consistent inputs of trees can be applied to any input trees on given subsets of species.


Introduction
In phylogenomics, biologists often encounter the following problem: Given a collection τ of different subsets of species, the corresponding phylogenetic trees-each one reconstructed from the genomic data available for the corresponding subset-cannot be consistently combined into a single phylogenetic tree for all the species. When this occurs, various heuristic and somewhat ad hoc 'supertree' methods (such as 'matrix recoding with parsimony') are often applied to provide some estimate of a parent tree (Felsenstein 2004). However, when the collection of subsets of species has sufficiently sparse overlap (in a sense we will make precise shortly), then any phylogenetic tree assignment for τ will lead to a set of trees that can be consistently combined into a parent tree. Figure 1i provides an example of this.
In this paper, we investigate the conditions under which the existence of a consistent parent tree can be guaranteed regardless of the tree structure for each subset. Here 'parent' tree means that the leaf set of the tree is the union of the leaf sets of the input trees. For example, given a set of input trees, if there is a parent tree that displays each tree, then a simple, fast and well-known algorithm due to Aho et al. (1981) constructs such a tree in a canonical way. However, this method will fail to return any phylogenetic tree when presented with input trees that are incompatible (i.e. cannot be displayed by any parent tree). In this paper, we characterise when such a method will always be safe to use on any set of input trees, given the sets of taxa that form the leaf sets of those trees. Thus, we consider as input just subsets of species and develop mathematical characterisations and algorithms for this combinatorial question in the special case where each subset has a fixed (small) size. Later in the paper, we consider how the results extend to more general set systems. Our approach throughout is to b, c}, {a, b, d}, {b, c, e}, {d, e, f }} of four sets that is phylogenetically flexible and (ii) a collection τ = τ ∪ {{b, d, e}} that fails to be phylogenetically flexible. In (i) all of the 3 4 = 81 choices of rooted triples (one for each of the four leaf sets) give a set of rooted triples that is displayed by at least one rooted phylogenetic tree on the six leaves a, b, . . . , f . However, in (ii) this fails, for example, the set of rooted triples ab|c, bd|a, bc|e, d f |e together with be|d (for the fifth set) is not displayed by any tree on the six leaves. The set τ is thin, but τ is not, since it has a subset (namely τ itself) which has strictly negative excess (equal to −1) reduce certain combinatorial questions in phylogenetics to the study of systems of inequalities involving linear expressions and related submodularity properties.
In discussion section, we mention a further biological context where the results may be relevant. Note that there are many reasons why phylogenetic trees are constructed on different subsets of species, and a particularly topical one is that genes used to estimate a given phylogeny may only be present (or have been sequenced) in a given subset of the species, and these subsets vary from gene to gene (Sanderson et al. 2011).
Our work is motivated in part by a remarkable combinatorial result by Grünewald (2012) involving unrooted binary trees. In that paper, a set P of binary trees having leaves labelled from some set X is said to be 'slim' if for every non-empty subset P of P, the number of leaves appearing in at least one tree in P is at least the total number of interior edges of T plus 3. Theorem 1.1 of Grünewald (2012) then states that for any such thin collection P there is a tree with leaf set X that 'displays' each of the trees in P. In particular, this leads to the rather striking consequence that 'the property of being slim only depends on the involved leaf sets of the trees and not on which phylogenetic tree is chosen for a fixed leaf set' (Grünewald 2012, p. 324). In this paper, we explore this notion further, and by working with rooted trees (rather than unrooted ones) we are able to establish precise characterisations of the analogous 'slim' property.
Our work is also partly motivated by results from Dress and Steel (2009) where slim-type properties also arise in a tree-based setting, but for a quite different question involving 'median' vertices. To explain this, given a tree T = (V, E) and a subset S of V of size 3, say S = {x, y, z}, consider the path in T connecting x, y, the path connecting x, z and the path connecting y, z. There is a unique vertex that is shared by these three paths, the median vertex of S in T , denoted med T (S). In Dress and Steel (2009), the authors show that 'slim'-type properties characterise when a set of triples from X can be realised as providing an encoding of the interior vertices of a (unrooted) tree with leaf set X . (An extension of this to sets of subset of X of size greater than 3 is also described.) In this paper, we extend this result further by showing that the tree that provides this encoding can be chosen to have a particular special type of structure (a 'caterpillar').
The phylogenetic combinatorics of subsets of a species set is a topic that has also been explored recently in the setting of 'phylogenetic decisiveness' (Steel and Sanderson 2010). However, the questions that we consider here are quite different from that setting; rather than requiring a dense overlap of the species subsets in the phylogenetic decisiveness setting, here we investigate sparse overlap.
We begin with some definitions. Throughout this paper, X will denote a fixed finite set.

Thin Set Systems
Suppose τ is a non-empty subset of X r , r ≥ 2. Let L(τ ) = s∈τ s (i.e. the set of elements of X that appear in at least one set in τ ) and define the excess of τ , denoted exc(τ ), by: We say that τ is thin if, for all non-empty subsets τ of τ , we have: This notion appears in related but slightly different settings, namely for the leaf sets of unrooted trees in Grünewald (2012), in the median representation of sets of triples in Dress and Steel (2009), and as sparse triplet covers in Grünewald et al. (2017).
In the following lemma, recall that a collection of (not necessarily distinct) sets {B 1 , B 2 , . . . , B m } has a system of distinct representatives if one can select an element x i ∈ B i for each i ∈ {1, . . . , m} so that the elements x 1 , x 2 , . . . , x m are all distinct. For τ a non-empty subset of X r , r ≥ 2 with L(τ ) = X and for x ∈ X let n τ (x) be the number of elements in τ that contain x.
Lemma 1 Let τ be a non-empty subset of X r , r ≥ 2 and L(τ ) = X. If τ is thin, then the following properties hold: (iii) For any subset B of X of size r − 1, the collection of sets {S − B : S ∈ τ } has a system of distinct representatives.
Proof Part (i) follows from the defining condition for thin upon taking τ = τ . Part (ii) can be established by the following double-counting argument. Suppose that there is no element x ∈ X with n τ (x) ≤ r − 2, so that n τ (x) ≥ r − 1 for all x ∈ X . Let Ω = {(x, S) : x ∈ S ∈ τ }. We then have: where k = |{x ∈ X : n τ (x) = r − 1}|. On the other hand: where the inequality is from Part (i). Combining (1) and (2) gives k ≥ r (r − 1) and, so, k ≥ 2. By the definition of k, (ii) follows. For Part (iii), consider the union of any l sets A 1 , A 2 , . . . , A l where A i = S i − B and S i ∈ τ for i = 1, . . . , l. (Note that these sets may have different sizes and a set may occur more than once.) Since τ is thin, Hall's marriage theorem (Hall 1935) ensures that τ has a system of distinct representatives.
For the first part of this paper, we will deal with the case where r = 3. However, the main theorem in this setting (Theorem 1) will be used in Sect. 4 to derive a result for the more general case where the sets have different sizes. When r = 3, notice that if |τ | = 1, then exc(τ ) = 3 − 1 − 2 = 0; however, if |τ | = 2, then exc(τ ) ≥ 4 − 2 − 2 = 0, so it suffices, in the definition of thin, to consider subsets of τ of τ of size at least 3.
A simple way to generate a thin set is to take any ordered sequence of subsets of X of size 3, for which the ordered sequence has the property that each member contains at least one element of X that is not present in any earlier member of the sequence. However, not all thin sets can be obtained in this way. For example, consider the collection {{a, b, c}, {c, d, e}, {b, e, f }, {a, d, f }} of four subsets sets of X = {a, b, . . . , f }. This collection of subsets is thin, yet these four sets cannot be ordered so as to satisfy the property described.

Phylogenetic Trees and Flexible Sets
Following Semple and Steel (2003), a rooted phylogenetic tree T is a rooted tree having a set L(T ) of labelled leaves (vertices of out-degree 0) and for which every non-leaf vertex is unlabelled and has out-degree at least 2. We let ρ T , or more briefly ρ denote the root vertex of T , which has in-degree 0. In case each non-leaf vertex has out-degree exactly 2, we say that T is binary. If L(T ) = X , we will also say that T is a rooted phylogenetic X-tree. We letV (T ) denote the set of interior (i.e. non-leaf) vertices of T . Similarly, an unrooted phylogenetic tree T is an unrooted tree having a set L(T ) of labelled leaves (vertices of degree 1) and for which every non-leaf vertex is unlabelled and has degree at least 3. In case each non-leaf vertex has degree exactly 3, we say that T is binary. If L(T ) = X , we will also say that T is a unrooted phylogenetic X-tree.
A rooted triple is a rooted binary phylogenetic tree on three leaves, and we denote such a tree as ab|c if it has leaf set {a, b, c} with leaf c adjacent to the root. A rooted phylogenetic X -tree T is said to display the rooted triple ab|c if some subdivision of the tree ab|c is a subgraph of T .
A cherry in a (rooted or unrooted) phylogenetic tree is a pair of leaves that is adjacent to the same vertex. A rooted (respectively, unrooted) caterpillar tree on X is a rooted (resp. unrooted) binary phylogenetic X -tree for which the number of cherries is at most 1 (respectively, 2).
These notions are illustrated in Fig. 2. A set R of rooted triples chosen from X is said to be compatible if there is a rooted phylogenetic X -tree T that displays each rooted triple in R (in which case, we say that T displays R). Note that if R is compatible, then T can always be chosen to be a binary tree and R can contain at most one tree for any triplet (i.e. at most one of ab|c, ac|b, and bc|a can be present in R). Suppose that we have a set R of rooted triples with leaves chosen from X . We will let ||R|| denote the subset of X 3 consisting of the leaf sets of the trees in R. We say that a non-empty subset τ of X 3 is phylogenetically flexible if every set R of rooted triples for which ||R|| = τ holds is compatible. An example to illustrate this notion is provided in Fig. 1.
The following observation that phylogenetic flexibility is hereditary is straightforward to check.
Lemma 2 Suppose τ is a non-empty subset of X 3 that is phylogenetically flexible. If τ is a non-empty subset of τ , then τ is phylogenetically flexible.

Characterisation Result
We can now state our first main result.

Theorem 1 Suppose that τ is a non-empty subset of X 3 . Then τ is phylogenetically flexible if and only if τ is thin.
The 'if' direction of Theorem 1 can be established by applying Theorem 1.1 of Grünewald (2012); however, we give a shorter and more direct proof of this direction here (as well as establishing the converse). We begin with some preliminary results, which are required for the argument.
Given a rooted phylogenetic tree T = (V, E) with leaf set X and every vertex in For a set R of rooted triples on X , put L(R) = t∈R L(t). Furthermore, for a non-empty subset S of X , let [R, S] be the graph with vertex set S and with an edge {a, b} if and only if there exists a rooted triple ab|c ∈ R for at least one element c ∈ S. By Bryant and Steel (1995, Theorem 2), R is compatible if and only if the graph [R, S] is disconnected for all subsets S of X of size at least 2.

Lemma 3 Suppose that T is a rooted binary phylogenetic X -tree, that R is a set of rooted triples with L(R) = X , and that each rooted triple supports a unique (interior non-root) vertex in T . Then, the graph [R, X ] has precisely two connected components.
Proof For v ∈V (T ) − {ρ T }, let X v be the leaf set of the rooted subtree of T with root v. We claim that for every such v, the graph induced by [R, X ] on X v is connected. The lemma then follows immediately by considering the graphs induced by [R, X ] on X u , X w for u and w the children of the root of T .
To prove the claim, for u (a child of the root ρ T of T ), we consider the following set: where v is said to be below u if u lies on the path from ρ T to v. Note that since |X | ≥ 3, there must exist a child u of ρ T such that X u = ∅ and also there exists some vertex v ∈ V (T ) below or equal to u such that |X v | ≥ 2. We use induction on |X v | for X v in X u . If |X v | = 2, then both children of v are leaves and the lemma holds because if X v = {p, q}, then, by assumption, there exists a rooted triple in R of the form r | pq for some r ∈ X − {p, q} that supports v. Hence, there is an edge { p, q} in [R, X ], and therefore, the graph induced by [R, X ] on X v is connected. Now suppose that v is an internal vertex of T below or equal to u such that |X v | ≥ 3. Then at least one of the two children v 1 and v 2 of v is not a leaf of T . Without loss of generality, we may assume that v 1 is that child. Therefore, 2 ≤ |X v 1 | < |X v | and so, by induction, the graph induced by [R, X ] on X v 1 is connected. If v 2 is not a leaf of T , then the same arguments as before imply that the graph induced by [R, X ] on X v 2 is also connected. If v 2 is a leaf of T , then the graph [R, X ] on v 2 is a vertex and therefore is (trivially) connected. Since, by assumption, there exists a rooted triple in Proof of Theorem 1 We first establish the 'if' direction. Suppose that τ is thin, and let R be a set of rooted triples with leaves chosen from X with ||R|| = τ . We show that any such choice of R is compatible.
We will establish the compatibility of R via the aforementioned characterisation that R is compatible if and only if [R, S] is disconnected for all subsets S of X of size at least 2. To that end, let S be a subset of X of size at least two. Notice where R S is the subset of those rooted triples in R that have all three of their leaves in S. Let τ = ||R S ||. Since τ is thin, we have exc(τ ) ≥ 0, in other words: Now (i) the number of vertices of [R, S] is |S| and |S| ≥ |L(τ )|; (ii) the number of edges of [R, S] is at most |R S | = |τ |. Thus, by Inequality (3), the number of vertices of [R, S] minus the number of edges of this graph is at least 2. But any finite graph with this property must be disconnected. Since this holds for all subsets S of X of size at least two, it follows that R is compatible.
Now, root the tree T by inserting a root vertex ρ into an edge which separates x, y from z, when the edge is removed from T . Let R be a set of rooted triples induced by the map med T (for each element {a, b, c} in τ , med T maps to some v ∈V (T ) so that we get a rooted triple with leaf set {a, b, c} which supports v in the rooted version of T ) with ||R || = τ and L(R ) = X . Since med T is a bijection, R satisfies the conditions of Lemma 3 for the rooted version of T . Hence, the graph [R , X ] has two connected components, one that contains x, y in its vertex set and the other that contains z.
Now consider the set of rooted triples R = R ∪ {y|zx}. Then L(R) = X , [R, X ] is connected and so R is not compatible, and ||R|| = τ . But this is impossible, since τ is phylogenetically flexible.
The following corollary of Theorem 1 is now immediate from Lemma 1(i).
We end this section by considering how many trees can display a set of rooted triples R when ||R|| is phylogenetically flexible. It might be suspected that since the overlap between the leaf sets of the trees in R is sparse, the number of trees displaying R would need to be large. Indeed, this is sometimes the case; for example, suppose that the leaf sets in R are all disjoint, so the total number of leaves is given by n = 3k, where k = |R|. In this case, the number N of rooted binary trees on n leaves that display R is given by: which grows exponentially with n. The proof of Eq. (5) is to observe that each of the 3 k ways to select a rooted triple from the k triples in ||R|| provides a set of rooted triples that is displayed by at least one rooted phylogenetic tree [by the algorithm from Aho et al. (1981)] and hence by at least one rooted binary tree, and these rooted binary trees are pairwise distinct, since any two of them display a different rooted triple for at least one triple in ||R||.
At the other extreme, if R has the maximum possible size for a phylogenetically flexible set on n leaves (namely n − 2 by Corollary 1), then it is possible for there to be just a single rooted phylogenetic tree that displays R; this is stated more precisely in the next proposition.
Proposition 1 (i) For every rooted binary phylogenetic X -tree T on n ≥ 3 leaves, there exists a set R T of n − 2 rooted triples for which (a) T is the only phylogenetic X -tree that displays R T and (b) ||R T || is thin.
(ii) There exist phylogenetically flexible sets of triples of size n − 2 on n leaves (n ≥ 6) for which each assignment of a tree structure to these triples leads to a set of rooted triples that can be displayed by more than one rooted phylogenetic tree.
Proof (i) We use induction on n. For n = 3, we can write T = ab|c, in which case R T = {ab|c} satisfies Conditions (a) and (b). Suppose now that Proposition 1 holds for k ≤ n where n ≥ 3 and that T is a rooted binary phylogenetic X -tree with n + 1 leaves. Select a pair of leaves a, b that are adjacent to the same vertex (say v) of T (i.e. {a, b} is a cherry of T ), let vertex u be the parent of vertex v in T , and let c be any leaf of T present in the component of T − u (the graph obtained by deleting u from T ) that contains neither the root, nor the leaves a, b. Put X = X − {a} and let T be the rooted binary phylogenetic X -tree obtained from T by deleting leaf a and its incident edge and suppressing the resulting vertex of degree 2. Since T has n leaves, the induction hypothesis ensures that there is a set R T of n − 2 rooted triples for which T is the only phylogenetic X -tree that displays R T and that ||R T || is thin.
If we now let R T = R T ∪ {ab|c}, then R T is a set of (n + 1) − 2 rooted triples and R T satisfies Conditions (a) and (b) for the tree T . This establishes the induction step and thereby the proposition.
(ii) Let τ = {{1, 2, j} : 2 < j ≤ n}. In this case, τ is a thin (and therefore phylogenetically flexible) set of size n − 2. Now, for n ≥ 6, it can be checked that any assignment of a tree structure to these triples leads to a set of rooted triples that can be displayed by more than one rooted phylogenetic tree.

Median Characterisations
Given a phylogenetic tree T with leaf set X and a set s ∈ X 3 , let med T (s) refer to the vertex that is the unique median vertex of T for the three elements of s.
The following result was established in Dress and Steel (2009, Theorem 1.1). Suppose that τ is a subset of X 3 with L(τ ) = X . The following are equivalent: (i) τ is thin. (ii) There exists a binary unrooted phylogenetic X -tree T = (V, E) for which the function med T : τ →V (T ): s → med T (s) from the elements s of τ to the set of interior vertices of T is one to one.
When (ii) holds, we say that T provides a median representation of τ . Figure 3i illustrates how this equivalence applies. We now strengthen this result from Dress and Steel (2009) by showing that the tree T can always be chosen to be an unrooted caterpillar tree. For example, for the thin collection of sets considered in Fig. 3, we may select the caterpillar tree shown in Fig. 3ii.  b, c}, {c, d, e}, {a, e, f }, {b, e, g}, {a, d, g}} with its median vertex in the tree shown provides a one-to-one mapping. (ii) A caterpillar tree that also provides a median representation of this thin collection of sets Lemma 1(i). Let us suppose that it holds whenever 4 ≤ |X | ≤ n − 1, for some n ≥ 5. Let X be such that |X | = n. By Lemma 1(ii), we may assume that one of the following two cases hold: (A) There is an element x of X with n τ (x) = 1. (B) There is an element x of X with n τ (x) = 2.
In case (A), there is some triple {a, b, x} ∈ τ such that for τ = τ − {{a, b, x}} we have that τ is thin. Put X = L(τ ). By induction, there is an unrooted caterpillar tree T with leaf set X and the function med T : τ →V (T ) is one to one. Now we can create a tree T by inserting an edge {x, u} where u is a new vertex subdividing an interior edge of T on the path between a and b. The resulting tree T is clearly a unrooted caterpillar tree on X and med T : τ →V (T ) is one to one. This establishes the induction step in this case.
In Case (B), there is an element x in X with n τ (x) = 2. Then there exist two distinct triples t, t ∈ τ each of which contains x. We consider the following two possible cases: (i) |t ∩ t | = 2 and (ii) |t ∩ t | = 1.
Case (i): |t ∩ t | = 2. In this case, there exist a, b, b ∈ X with b = b such that t = {a, b, x} and t = {a, b , x}. Since τ is thin, it follows that is also thin. Put X = L(τ ). Then, by induction, there is a unrooted caterpillar tree T with leaf set X and med T : τ →V (T ) is one to one.
Consider the leaf b of T . Let b ∈V (T ) denote the vertex adjacent to b . As T is an unrooted caterpillar tree, it suffices to consider the following two subcases:

Subcase (a):
The leaves a and b are on the same side of T relative to b (i.e. they are in the same connected component of T − b as b ). Without loss of generality, assume that the distance from a to b in T is less than or equal to distance from b to b in T . Note that in this case med T (a, b, b ) is the vertex in T that is adjacent to a. Now create a tree T with leaf set X by inserting a new vertex u and a new edge {u, x} into T such that {u, b } is an edge on the path connecting b and a. The tree T is again an unrooted caterpillar tree on X . Furthermore, med T : τ →V (T ) is one to one since (i) med T is one to one, and (ii) med T (x, a, b ) = u and the median of {x, a, b} in T corresponds to the median vertex of {a, b, b } in T and therefore is a vertex of T that is different from any other median vertex of an element in τ .

Subcase (b):
The leaves a and b are on different sides of T relative to b . Note that in this case, med T (a, b, b ) = b . Now create a tree T with leaf set X by inserting a new vertex u and a new edge {x, u} into T such that {u, b } is an edge on the path connecting b and b. T is then clearly an unrooted caterpillar tree on X . Since med T (x, b , b) = u and the median of {x, a, b } in T corresponds to the median vertex of {a, b, b } in T , the same arguments as in the previous case imply that med T : τ →V (T ) is one to one.
Case (ii): |t ∩ t | = 1. In this case, there exist pairwise distinct elements a, a , b, b in X such that t = {a, b, x} and t = {a , b , x}. We may assume that τ does not contain both {a, a , b} and {a, a , b } as, otherwise, the claim follows from Case (B)(i)(a). By symmetry, we can assume without loss of generality that Then since τ is thin it follows that τ is thin. Put X = L(τ ). Then, by induction, there is an unrooted caterpillar tree T with leaf set X and med T : τ →V (T ) is one to one.
Consider the leaf a . As T is a caterpillar tree on X , we can again consider two subcases ((a) and (b)), the first of which involves two further subcases: Case (a): The leaves a and b are on the same side of T relative to b . Without loss of generality, assume that the distance from a to b in T is less than or equal to distance from b to b in T . We now have two subcases to consider for this subcase: Case (a1): The leaf a is on the same side of the caterpillar T as a and b relative to b . If a and b are on the same side of T relative a , then the same arguments as in the Case (B)(i)(a) apply with a playing the role of b . If a and b are on different sides of T relative a , then the same arguments apply as in Case (B)(i)(b) with a playing the role of b .

Case (a2):
The leaf a is on a different side of the caterpillar T from a and b relative to b . Now create a tree T on X by inserting a new vertex u and a new edge {x, u} into T such that with b ∈V (T ) the vertex adjacent with b we have that {b , u} is an edge on the path connecting a and b . Then, T is clearly a unrooted caterpillar tree with leaf set X . Since med T (x, a , b ) is u and the median of {x, a, b} in T corresponds to the median of {a, a , b} in T , the same arguments as in Case (B)(i)(a) imply that med T : τ →V (T ) is one to one.

Case (b):
The leaves a and b are on different sides of T relative to b . If a lies on the same side of T as a relative b and a and b lie on different sides of T relative a, then the same arguments as in the Case (B)(i)(a) apply with a playing the role of b . In all other cases, the same arguments as in the Case (B)(i)(b) apply with a playing the role of b

The Case r = 2
The concept of phylogenetic flexibility does not directly carry over to the case where r = 2, since in this case, there is just a single rooted phylogenetic tree. Instead, we use a stronger notion of tree structure (namely, total order) to obtain an analogue of Theorem 1.
We say that a non-empty subset τ of X 2 is total-order flexible if every choice of a total order on the set s, for each s ∈ τ , is compatible with a total order on X . More formally, for every s = {x, y} ∈ τ , if we declare that either x ≺ y or y ≺ x, then for any such selection of choices (one for each s ∈ τ ), there is a total order on X that agrees with these inequalities. For example, τ = {{a, b}, {b, c}} is total-order flexible but {{a, b}, {b, c}, {a, c}} is not, since the orderings a ≺ b, b ≺ c, c ≺ a are not compatible with any total order on a, b, c. The following result is the analogue of Theorem 1 for the case where r = 2.

Theorem 3 Suppose that τ is a non-empty subset of X 2 . Then τ is thin if and only if τ is total-order flexible.
Proof We first show that if τ is not thin, then τ is not total-order flexible. Suppose that τ is not thin. Then there exists a non-empty subset τ of τ for which |L(τ )| ≤ |τ |. Let G τ be the graph (L(τ ), τ ) that has vertex set L(τ ) and edge set τ . Since G τ has at least as many edges as vertices, this graph has a connected component that contains a cycle. If the edges of this cycle are {x 1 , . , x r ≺ x 1 on these pairs are not compatible with any total order on X (since transitivity would imply that x 1 ≺ x 1 ).
We now show that the thin property implies total-order flexibility by using induction on k = |τ |. The result clearly holds for k = 1 so suppose that the result holds for subsets of X 2 of size k ≥ 1 and that τ ⊆ X 2 is a thin set of size k +1. By Lemma 1(ii), there is an element x in X that is present in precisely one set, say {x, y}, in τ . Let τ be the set obtained from τ by deleting {x, y}. Then τ is thin and, since |τ | = k, the induction hypothesis implies that τ is total-order flexible. Then any choice of a total order on the set s for each s ∈ τ is compatible with a total order ≺ on X − {x} (recall that x / ∈ L(τ ) by the choice of x). If we now introduce a total order on {x, y}, then we can extend the total order ≺ to X by placing x after y if {x, y} is ordered as x, y, and placing x after y otherwise.
We now present some characterisations for when a non-empty set τ ⊆ X 2 is thin. We begin with an analogue of Dress and Steel (2009, Theorem 1.1), which was stated in the last section.
Given a rooted tree T with leaf set X and a set s ∈ X 2 , let lca T (s) refer to the vertex that is the unique vertex of T that is the least common ancestor of the elements in the set s.

Theorem 4 Suppose that τ is a subset of X (ii) There exists a rooted binary phylogenetic X -tree T = (V, E) for which the function s → lca T (s) from the elements of τ to the set of interior vertices of T is one to one. (iii) As for (ii) but with T a rooted caterpillar tree.
Proof (iii) ⇒ (ii) is trivial.
By Lemma 1(ii), there is some x with n τ (x) = 1. Let X = X − {x}. It is then straightforward to see that there is some pair {a, x} ∈ τ with τ = τ −{{a, x}}. Clearly τ is thin as τ is thin and either Assume first that L(τ ) = X , where X = X − {x}. By induction, there is a rooted caterpillar tree T with leaf set X and root ρ for which the function lca T : τ →V (T ) is one to one. Now, we can create a new rooted tree T with root ρ by adding two new edges {ρ, ρ } and {ρ, x} to T where ρ is a new vertex that is not in T . T is then clearly a rooted caterpillar tree on X ; every vertex inV (T ) has out-degree 2 and lca T : τ →V (T ) is one to one. This establishes the induction step, and so (iii) holds.
Assume next that L(τ ) = X , where X = X − {x, a}. By induction, there exists a rooted caterpillar tree T on X . Let ρ denote the root of T . Let T be rooted caterpillar tree obtained from T via the following two-step process. First, add a new root ρ and a new edge e = {ρ, ρ } to T . In the resulting tree subdivide e by a vertex c and add the edges {c, a} and {ρ, x}. Clearly, lca T : τ →V (T ) is one to one. This establishes again the induction step, and so (iii) holds too in this case.
Suppose a rooted phylogenetic tree T on X satisfies the conditions in Part (ii) of the theorem. Add a new leaf x that is not in L(τ ) to T by adding the edge {ρ T , x} and regard the resulting tree as an unrooted phylogenetic tree T on X ∪ {x}. In T , the map med T from τ * to the internal vertices of T is then one to one. Hence, by Dress and Steel (2009, Theorem 1.1), τ * is thin, and thus, for any non-empty subset ω of τ , we have: It immediately follows that τ is thin.
Interestingly, we can give an alternative characterisation of thin subsets τ of X 2 in terms of bipartite graphs.
We first recall some results from matching theory. For a graph G and v a vertex in G, we let deg G (v) denote the degree of v in G. Given a bipartite graph G = (A∪ B, E) and a non-empty set Y ⊆ A, we let N G (Y ) denote the set of vertices in B that are adjacent to some vertex in Y , and we define the surplus σ G (Y ) of Y to be: We also define the surplus σ (G) of G, to be the minimum surplus over all non-empty sets of A. We say that a bipartite graph G = (A ∪ B, E) has positive surplus (as viewed from A) if σ (G) > 0. The following result is from Lovász and Plummer (1986, Theorem 1.3.8).

Theorem 5 A bipartite graph G = (A ∪ B, E) has positive surplus (as viewed from A) if and only if G contains a forest F such that
We now apply this result to the setting of thin sets. Let τ be a non-empty collection of non-empty subsets of X . We associate a bipartite graph G(τ ) to τ that has the vertex set τ ∪ L(τ ) and the edge set given by containment (i.e. {t, x} is an edge in G(τ ) if and only if x ∈ t with x ∈ L(τ ) and t ∈ τ ). Thus, we are representing our set τ by a bipartite graph G = (A ∪ B, E) with A = τ , B = X and E given by containment.
Since τ is thin if and only if G(τ ) has positive surplus, by Theorem 5, the following corollary is straightforward.

Corollary 2 Suppose that τ is a subset of X 2 with L(τ ) = X . Then τ is thin if and only if G(τ ) is a forest.
For r = 3, it might also be interesting to characterise those graphs G(τ ) for which τ is thin.

The General Case (Slim Set Systems)
Suppose we have a non-empty collection τ of subsets of X , each of size at least 3. Consider the modified notion of excess, denoted exc and defined as follows: Define Notice that when τ ⊆ X 3 this notion of excess agrees with the earlier one. Given a non-empty collection τ of subsets of X , each of size at least 3, we say that τ is slim if for every non-empty subset τ of τ , we have exc (τ ) ≥ 0. The next result relates slim to thin; the two notions coincide when τ ⊆ X 3 ; however, slim is a more restrictive notion than thin when τ ⊆ X r , for r > 3. Note, however, that (unlike the thin property) the slim property does not require the sets in τ to all have the same size.
Lemma 4 Suppose that τ ⊆ X r , r ≥ 3. If τ is slim, then τ is thin. Moreover, for r = 3, τ is thin if and only if τ is slim.
We can extend the notion of phylogenetic flexibility introduced in Sect. 1 to arbitrary collections of subsets of X as follows. We first need to extend the earlier definitions of 'display' and 'compatibility' from sets of rooted triples to arbitrary collections of rooted trees, as follows.
Given a rooted phylogenetic X -tree T and a binary phylogenetic tree T with leaf set Y ⊆ X, T is said to display T if T contains a subdivision of T as a (directed) subtree. [This is equivalent to the condition that each rooted triple displayed by T is also displayed by T (Bryant and Steel 1995).] A set R of rooted binary phylogenetic trees is said to be compatible if there is rooted phylogenetic tree T that displays each of the trees in R.
For a set R of rooted binary phylogenetic tree, let ||R|| denote the collection of their leaf sets. Thus, ||R|| is a set of sets. Given a non-empty collection τ of subsets of X , each of size at least 3, we say that τ is phylogenetically flexible if every set R of rooted binary phylogenetic trees for which ||R|| = τ holds is compatible.
This notion agrees with the earlier notion of phylogenetic flexibility in the case where each set in τ has size exactly 3. Moreover, as before, we can assume without loss of generality that the tree T (in the definition) is binary.
The following result is a strengthening of our earlier Theorem 1; one direction follows from that theorem, the other direction is a consequence of a result from Grünewald (2012) (which dealt with unrooted trees).

Theorem 6 Suppose that τ is a collection of sets, each of size at least 3. Then τ is phylogenetically flexible if and only if τ is slim.
Proof We first establish the 'only if' direction. Suppose that τ is phylogenetically flexible. For each set s ∈ τ , select two elements x, y ∈ s and let: A(s) = {{x, y, z} : z ∈ s, z = x, y}}, and for any non-empty subset τ of τ let Thus, A(s) is a set of |s| − 2 triples, and α(τ ) is also a set of triples.

Claim 1 A(s) ∩ A(s ) = ∅ for each s, s ∈ τ, s = s .
To see this, suppose that a triple, say {a, b, c}, lies in A(s) and A(s ) for two distinct elements s and s of τ . Then, we can select a rooted binary phylogenetic tree T s with leaf set s that displays the rooted triple ab|c and select a rooted binary phylogenetic tree T s with leaf set s that displays the rooted triple ac|b. But no rooted binary phylogenetic tree can display both T s and T s (since such a tree would also simultaneously display two different rooted triples with leaf set {a, b, c}). This contradicts the assumption that τ is phylogenetically flexible, so such a shared triple {a, b, c} in A(s) ∩ A(s ) cannot exist. This establishes Claim 1.

Claim 2 α(τ ) is phylogenetically flexible.
To see this, suppose that for each triple t ∈ α(τ ), we have an associated rooted triple T t with leaf set t. We need to show that there is a rooted binary phylogenetic tree that displays {T t : t ∈ α(τ )}. Observe that A(s) is thin for each s ∈ τ , since if A is a non-empty subset of A(s) of size k (say), then | A| = k + 2, and so | A| = |A| + 2. Theorem 1 (the 'if' direction) then ensures that for each s in τ , there is a rooted phylogenetic tree T s with leaf set s that displays {T t : t ∈ α(τ ) ∩ A(s)}. Moreover, since τ is phylogenetically flexible, there is a rooted binary phylogenetic tree T that displays T s for each s ∈ τ . It follows that the tree T displays {T t : t ∈ α(τ )}, and so α(τ ) is phylogenetically flexible, as claimed.
Claim 2 implies that α(τ ) is thin, by Theorem 1 (the 'only if' direction). We now show that this implies that τ is slim. Let τ be a non-empty subset of τ and consider α(τ ). Since L(τ ) = L(α(τ )), we have: where the inequality holds because α(τ ) (and thereby its subset α(τ )) is thin. Now: where the first equality holds by Claim 1. Combining this last equation with Inequality (6) gives: which shows that τ is slim as claimed. This establishes the 'only if' direction. Notice in doing so that we have used both directions of Theorem 1 in different places in this proof.
We turn now to the 'if' direction. Given τ , select a new element, say x, that is not present in any of the sets in τ , and add this to each of the sets in τ to produce a set τ +x . Notice that if τ is slim, then τ +x satisfies the property that for each non-empty set τ of τ +x , we have: It follows from Theorem 1.1 of Grünewald (2012) that for any assignment of unrooted binary phylogenetic trees with leaf sets that correspond to the sets in τ +x , there is a binary phylogenetic tree T x that displays each of these unrooted trees. Suppose now that we have an assignment of rooted binary phylogenetic trees having leaf sets that correspond to the sets in τ . By attaching x as a leaf adjacent to the root of each of these trees, we obtain an assignment of unrooted binary phylogenetic trees with leaf sets that correspond to the sets in τ +x . Hence, by the result just stated, there is an unrooted binary phylogenetic tree T x that displays each of these unrooted trees. If we now let T be the rooted binary phylogenetic tree obtained from T x by deleting the leaf x and rooting the resulting tree on the vertex adjacent to x, then T displays the original assignment of rooted binary phylogenetic trees. Since this holds for all possible assignments of rooted phylogenetic trees to the sets in τ , it follows that τ is phylogenetically flexible.

Polynomial-Time Algorithms for Thin and Slim
Given finite set S, a function f : 2 S → R is called submodular if for all A, B ⊆ S: Submodular functions play an important role in optimisation and matroid theory (see, e.g. Lovász and Plummer 1986;Bixby and Cunningham 1995;Welsh 1995). In this section, we exploit these connections to show that there are polynomial-time algorithms to decide whether sets are thin or slim.
Suppose that τ is a subset of 2 X . For τ ⊆ τ , we define Note that σ (∅) = γ (∅) = 0 (since the summation term is then empty). Although the following result is straightforward to show by using results concerning submodular functions in the literature, for completeness we give a direct proof.
Theorem 8 Let f be a submodular function defined on the subsets of some finite set S. A set minimising f over all non-empty subsets of S can then be found in polynomial time.
In light of this theorem and Theorem 7, it follows that we can determine σ * (τ ) and γ * (τ ) for a given set τ ⊆ 2 X in polynomial time. Therefore, by Lemma 5, we can determine whether or not a given set τ for which each element has size at least three is thin or slim in polynomial time.
Note that although this shows that polynomial-time algorithms exist for determining whether or not a set is thin or slim, these are likely to be impracticable (Lovász and Plummer 1986, pp. 417-418). However, for the case of determining whether or not a set τ is thin a more explicit algorithm can be given. More specifically, in Fritzilas et al. (2013, Theorem 2) a polynomial-time algorithm is presented for computing the surplus σ (G) of a bipartite graph G. Since for a set τ ⊆ X r , r ≥ 3, the surplus of the bipartite graph G(τ ) as defined in Sect. 3.1 is equal to σ * (τ ), we can therefore apply this algorithm to determine if τ is thin. It would be interesting to find an explicit algorithm for determining whether a set is slim.
Theorem 7 has another consequence that relates to phylogenetics. Recall that a patchwork is a non-empty collection P of sets that satisfies the property: if A, B ∈ P and A ∩ B = ∅, then A ∩ B, A ∪ B ∈ P. A combinatorial theory of patchworks, relevant to phylogenetics, was developed in Böcker and Dress (2001). Patchworks were also referred to as 'intersecting families' in earlier work by Lovász (1983, p. 240). The following is a generalisation of Dress and Steel (2009, Lemma 1.2), and the proof follows a similar argument to that result.
Corollary 3 If τ is slim, then the collection P of non-empty subsets τ of τ such that |s| ≥ 3 for all s ∈ τ and exc (τ ) = 0 forms a patchwork.

Discussion
When an evolutionary biologist compares a number of trees on different, but overlapping, leaf sets, it is typically very rare that these trees are found to be compatible, due mainly to errors in the estimation of phylogenetic trees. Thus, in cases where the trees are compatible this fact alone may provide the biologist with some heightened confidence in the accuracy of the input trees. However, such confidence should clearly depend, in part, on the pattern of taxon coverage. In the extreme case where the subsets of species on which the input trees were built from a phylogenetically flexible collection, it is clear that compatibility provides absolutely no hint of accuracy of the input trees, since any trees that had been considered for those subsets would be compatible. For applications, it might therefore be useful to quantify how close to 'phylogenetically flexible' a given pattern of taxon coverage is.
Our results also suggest a second possible future research direction. Since submodular functions are connected to matroid theory, are there relevant connections between thin/slim sets and matroids? Other matroid structures in phylogenetics have been recently been described, in different contexts, by Dress et al. (2014) and Hellmuth and Seemann (2017).