Embedding phylogenetic trees in networks of low treewidth

Given a rooted, binary phylogenetic network and a rooted, binary phylogenetic tree, can the tree be embedded into the network? This problem, called \textsc{Tree Containment}, arises when validating networks constructed by phylogenetic inference methods.We present the first algorithm for (rooted) \textsc{Tree Containment} using the treewidth $t$ of the input network $N$ as parameter, showing that the problem can be solved in $2^{O(t^2)}\cdot|N|$ time and space.


Background: phylogenetic trees and networks
Phylogenetic trees and networks are graphs used to represent evolutionary relationships.In particular, a rooted phylogenetic network is a directed acyclic graph with distinctly labelled leaves, a unique root and no indegree-1 outdegree-1 vertex.Here, we will only consider rooted binary phylogenetic networks, which we will call networks for short.The labels of the leaves (indegree-1 outdegree-0 vertices) can, for example, represent a collection of studied biological species, and the network then describes how they evolved from a common ancestor (the root, a unique indegree-0 outdegree-2 vertex).Vertices with indegree 2 and outdegree 1 are called reticulations and represent events where lineages combine, for example the emergence of new hybrid species.All other vertices have indegree 1 and outdegree 2. A network without reticulations is a phylogenetic tree.

The TREE CONTAINMENT problem
The evolutionary history of a small unit of hereditary information (for example a gene, a fraction of a gene or (in linguistics) a word) can often be described by a phylogenetic tree.This is because at each reticulation, each unit is inherited from only one parent.Hence, if we trace back the evolutionary history of such a hereditary unit in the network, we see that its phylogenetic tree can be embedded in the network.This raises the fundamental question: given a phylogenetic network and a phylogenetic tree, can the tree be embedded into the network?This is called the TREE CONTAINMENT problem (see Fig. 1).To formalize this problem, we say that a network N displays a tree T if some subgraph of N is a subdivision of T .

Motivation
Apart from being a natural and perhaps one of the most fundamental questions regarding phylogenetic networks, the TREE CONTAINMENT problem has direct applications in phylogenetics.The main application is the validation of phylogenetic network inference methods.After constructing a network, one may want to verify whether it is consistent with the phylogenetic trees.For example, if a heuristic method is used to generate a network for a genomic data set, and tree inference methods are used to generate trees for each gene, then the quality of the produced network can be assessed by computing the fraction of the gene trees that can be embedded into it.In addition, one may want to find the actual embeddings for visualisation purposes and/or to assess the importance of each network arc.However, our main motivation for studying TREE CONTAINMENT is that it is a first step towards the wider application of treewidth based approaches in phylogenetics (see Sections 1.3 and 1.4).The techniques we develop are not exclusively designed for TREE CONTAINMENT but intended to be useful also for other problems such as NETWORK CONTAINMENT [JM21] and HYBRIDIZATION NUM-BER [BS07, vIKL + 16, vIKS16, vIL13].The former is the natural generalization of TREE CONTAINMENT in which we have two networks as input and want to decide whether one can be embedded into the other.It can, in particular, be used to decide whether two networks are isomorphic.In the latter problem, HY-BRIDIZATION NUMBER, the input consists of a set of phylogenetic trees, and the aim is to construct a network with at most k reticulations that embeds each of the input trees.Although this will certainly be non-trivial, we expect that at least part of the approach we introduce here can be applied to those and other problems in phylogenetics.We also believe our approach may have application to problems outside of phylogenetics, involving the reconciliation of multiple related graphs.
Embedding phylogenetic trees in networks of low treewidth 3

Treewidth
The parameters that are most heavily used for phylogenetic network problems (see eg. Section 1.5) are the reticulation number and the level.This is true not only for TREE CONTAINMENT but more generally in the phylogenetic networks literature.Although these parameters are natural, their downside is that they are not necessarily much smaller than the input size.This is why we study a different parameter here.
The treewidth of a graph measures its tree-likeness (see definition below), similarly to the reticulation number and level.In that sense, it is also a natural parameter to consider in phylogenetics, where networks are often expected to be reasonably tree-like.A major advantage of treewidth is that it is expected to be much smaller than the reticulation number and level.In particular, there exist classes of networks for which the treewidth is at most a constant factor times the square-root of the level (see [KSW18] for an example).Moreover, a broad range of advanced techniques have been developed for designing FPT algorithms for graph problems when the parameter is the treewidth [Bod88, CNP + 11, BCKN15,EGHK21].For these reasons, the treewidth has recently been studied for phylogenetics problems [JJK + 19, KvSW16, KSW18, SW21] and related width parameters have been proposed [BSW20].However, using treewidth as parameter for phylogenetic problems poses major challenges and, therefore, there are still few algorithms in phylogenetics that use treewidth as parameter (see Section 1.4).
One of the most famous results in treewidth is Courcelle's Theorem [Cou90,ALS91], which states, informally, that graph problems expressible in monadic second-order logic (MSOL) can be solved in linear time on graphs of bounded treewidth.This makes MSOL formulations a powerful tool for establishing FPT results.For practical purposes, it is often preferable to establish a concrete algorithm, since the running times derived via Courcelle's theorem are dominated by a tower of exponentials of size bounded in the treewidth.
It will be convenient to define a tree decomposition of a graph G = (V, E) as a rooted tree, where each vertex of the tree is called a bag and is assigned a partition (P, S, F ) of V , where S is a separator between P and F .We will refer to S as the present of the bag.The set P is equal to the union of the presents of all descendant bags (minus the elements of S) and we refer to it as the past of the bag.The set F = V \ (S ∪ P ) is referred to as the future of the bag.For each edge of the graph, there is at least one bag for which both endpoints of the edge are in the present of the bag.Finally, for each v ∈ V , the bags that have v in the present form a non-empty connected subtree of the tree decomposition.The width of a tree decomposition is one less than the maximum size of any bag's present and the treewidth tw(G) of a graph G is the minimum width of any tree decomposition of G.The treewidth of a phylogenetic network or other directed graph is the treewidth of the underlying undirected graph.
Our dynamic programming works with nice tree decompositions, in which the root is assigned (V, ∅, ∅) and each bag assigned (P, S, F ) has exactly one of four types: Leaf bags have P = S = ∅ (hence F = V ) and have no child, Introduce bags have a single child assigned (P, S \ {z}, F ∪ {z}) for some z ∈ S, Forget bags have a single child assigned (P \ {z}, S ∪ {z}, F ) for some z ∈ P , and Join bags have two children assigned (L, S, F ∪ R) and (R, S, F ∪ L) respectively, where (L, R) is a partition of P .When the treewidth is bounded by a constant, [Bod96] showed that a minimum-width tree decomposition can be found in linear time and [Klo94] showed that a nice tree decomposition of the same width can be obtained in linear time.Regarding approximation, it is known that, for all graphs G, tree decompositions of width O(tw(G)) can be computed in time single-exponential in tw(G) [CFK + 15, BDD + 16, Kor21] and tree decompositions of width O(tw(G) log tw(G)) can be computed in polynomial time [FHL08].

Challenges
One of the main challenges of using treewidth as parameter in phylogenetics is that the central goal in this field is to infer phylogenetic networks and, thus, the network is not known a priori so a tree decomposition cannot be constructed easily.A possible strategy to overcome this problem is to work with the display graph (see Fig. 1).Consider a problem taking as input a set of trees, such as HYBRIDIZATION NUMBER.Then, the display graph of the trees is obtained by taking all trees and identifying leaves with the same label.Now we have a graph in the input and hence we can compute a tree decomposition.Moreover, in some cases, there is a strong relation between the treewidth of the display graph and the treewidth of an optimal network [GKL15, KSW18, JJK + 19].
A few instances of exploiting (tree decompositions of) the display graph of input networks for algorithm design have been published.Famously, Bryant and Lagergren [BL06] designed MSOL formulations solving the TREE CONSISTENCY problem on display graphs, which have been improved by a concrete dynamic programming on a given tree decomposition of the display graph [BPSC17].Kelk et al. [KvSW16] also developed MSOL formulations on display graphs for multiple incongruence measures on trees, based on so-called "agreement forests".
For the TREE CONTAINMENT problem, MSOL formulations acting on the display graph have been used to prove fixed-parameter tractability with respect to the treewidth [JJK + 19].Analogously to the work of Baste et al. [BPSC17] for TREE CONSISTENCY, we develop in this manuscript a concrete dynamic programming algorithm for TREE CONTAINMENT acting on display graphs.
TREE CONTAINMENT is conceptually similar to HYBRIDIZATION NUMBER in the sense that the main challenge is to decide which tree vertices correspond to which vertices of the other trees (for HYBRIDIZA-TION NUMBER) or network vertices (for TREE CONTAINMENT).However, HYBRIDIZATION NUMBER is even more challenging since the network may contain vertices that do not correspond to any input vertex [vIKL + 16].Therefore, TREE CONTAINMENT is a natural first problem to develop techniques for, aiming at extending them to HYBRIDIZATION NUMBER and other problems in phylogenetics in the long run.
That being said, solving TREE CONTAINMENT parameterized by treewidth poses major challenges itself.Even though the general idea of dynamic programming on a tree decomposition is clear, its concrete use for TREE CONTAINMENT is severely complicated by the fact that the tree decomposition does not know the correspondence between tree vertices and network vertices.For example, when considering a certain bag of the tree decomposition, a tree vertex that is in the present of that bag may have to be embedded into a network vertex that is in the past or in the future.It may also be necessary to map vertices from the future of the tree to the past of the network and vice versa.Therefore, it will not be possible to "forget the past" and "not worry about the future".In particular, this makes it much more challenging to bound the number of possible assignments for a given bag.We will do this by bounding the number of "time-travelling" vertices by a function of the treewidth.We will describe these challenges in more detail in Section 2.2.

Previous work
TREE CONTAINMENT was shown to be NP-hard [KNTX08], even for tree-sibling, time-consistent, regular networks [ISS10].On the positive side, polynomial-time algorithms were found for other restricted classes, including tree-child networks [GGL + 15, GGL + 18, Gun18, GYZ19, ISS10, Wel18].The first non-trivial FPT algorithm for TREE CONTAINMENT on general networks had running time O(2 k/2 n 2 ), where the parameter k is the number of reticulations in the network [KNTX08].Another algorithm was proposed by [GLZ16] with the same parameter, but it is only shown to be FPT for a restricted class of networks.Since the problem can be split into independent subproblems at non-leaf cut-edges [ISS10], the parameterization can be improved to the largest number of reticulations in any biconnected component (block), also called the level of the network.Further improving the parameterization, the maximum number t * of "unstable component-roots" per biconnected component was considered and an algorithm (working also in the non-binary case) was found with running time O(3 t * |N ||T |) [Wel18].Herein, a parameterization "improves" over another if the first is provably smaller than (a function of) the second in any input network.
Several generalizations and variants of the TREE CONTAINMENT problem have been studied.The more general NETWORK CONTAINMENT problem asks to embed a network in another and has been shown to be solvable in polynomial time on a restricted network class [JM21].When allowing multifurcations and non-binary reticulations, two variants of TREE CONTAINMENT have been considered: In the FIRM version, each non-binary node ("polytomy") of the tree has to be embedded in a polytomy of the network whereas, in the SOFT version, polytomies may be "resolved" into binary subtrees in any way [BMW18].Finally, the unrooted version of TREE CONTAINMENT was also shown to be NP-hard but fixed-parameter tractable when the parameter is the reticulation number (the number of edges that need to be deleted from the network to obtain a tree) [IKS + 18].While this version of the problem is also known to be fixedparameter tractable with respect to the treewidth of the network [JJK + 19], the work does not explicitly describe an algorithm and the implied running time depends on Courcelle's theorem [Cou97] which makes practical implementation virtually impossible.
Since the notion of "display" closely resembles that of "topological minor" (with the added constraint that the embedding must respect leaf-labels), TREE CONTAINMENT can be understood as a special case of a variant of the well-known TOPOLOGICAL MINOR CONTAINMENT (TMC) problem for directed graphs.TMC is known to be NP-complete in general by reduction from HAMILTONIAN CYCLE and previous algorithmic results focus on the undirected variant, parameterized by the size h of the sought topological minor H (corresponding to the input tree for TREE CONTAINMENT).In particular, undirected TMC can be solved in f (h)n O(1) time [GKMW11, FLP + 20].However, the dependency of the function f on h makes such algorithms impractical for all but small values of h.By contrast, in TREE CONTAINMENT the input tree may be assumed to typically have a size comparable to the overall input size.In the directed case, even the definition of "topological minor" has been contested [GHK + 16] and we are aware of little to no algorithmic results.In TREE CONTAINMENT, part of the embedding of the host tree in the guest network is fixed by the leaf-labeling.If the node-mapping is fixed for all nodes of the host, then directed TMC generalizes the DISJOINT PATHS problem [FHW80], which is NP-complete for 2 paths or in case the host network is acyclic.Indeed, one can show TREE CONTAINMENT to be NP-hard in a similar fashion [KNTX08].

Our contribution
In this paper, we present an FPT-algorithm for TREE CONTAINMENT parameterized by the treewidth of the input network.Our algorithm is one of the first (constructive) FPT-algorithms for a problem in phylogenetics parameterized by treewidth.We believe that this is an important development as the treewidth can be much smaller than other parameters such as reticulation number and level which are easier to work with.We see this algorithm as an important step towards the wide application of treewidth-based methods in phylogenetics.

Reformulating the problem
A key concept throughout this paper will be display graphs [BL06], which are the graphs formed from the union of a phylogenetic tree and a phylogenetic network by identifying leaves with the same labels.Throughout this paper we will let N IN and T IN denote the respective input network and tree in our instance of TREE CONTAINMENT.The main object of study will be the "display graph" of N IN and T IN .For the purposes of our dynamic programming algorithm, we will often consider graphs that are not exactly this display graph, but may be thought of as roughly corresponding to subgraphs of it (though they are not exactly subgraphs; see Section 3.1).In order to incorporate such graphs as well, we will define display graphs in a slightly more general way than that usually found in the literature.In particular, we allow for the two "sides" of a display graph to be disconnected, and for some leaves to belong to one side but not the other.
Definition 1 (display graph).A display graph is a directed acyclic graph D = (V, A), with specified subsets V T , V N ⊆ V such that V T ∪ V N = V , satisfying the following properties: • The graph T := D[V T ] is an out-forest; • Every vertex has in-and out-degree at most 2 and total degree at most 3; We now reformulate the TREE CONTAINMENT problem in terms of an embedding function on a display graph.Unlike the standard definition of an embedding function (see, e.g., [ISS10]), which is defined for a phylogenetic network N and tree T , our definition of an embedding function applies directly to the display graph D(N, T ).Because of our more general definition of display graphs, our definition of an embedding function will also be more general than that found in the literature.The key idea of an embedding function remains the same, however: it shows how a subdivision of T may be viewed as a subgraph of N .
Definition 2 (embedding function).Let D be a display graph with network side N and tree side T , and let P(N ) denote the set of all directed paths in N .An embedding function on D is a function (e) for any distinct p, q ∈ A(T ), φ(p) and φ(q) share a vertex z only if p and q share a vertex w with z = φ(w); Note that the standard definition of an embedding of a phylogenetic tree T into a phylogenetic network N (see e.g.[ISS10]) coincides with the definition of an embedding function on D(N, T ).Prop-erty (e) ensures that, while the embeddings of arcs uv, vw 1 , vw 2 can all meet at φ(v), the embeddings of different tree arcs cannot otherwise meet.(In particular, the path φ(uv) cannot end at a reticulation that is also an internal vertex of φ(u ′ v ′ ), something that is otherwise allowed by properties (a)-(d).)As is often the case for treewidth parameterizations, we will proceed via a dynamic programming on a tree decomposition, in this case a tree decomposition of D IN (N IN , T IN ).Recall that we view a bag (P, S, F ) in the tree decomposition as partitioning the vertices of D IN (N IN , T IN ) into past, present and future.A typical dynamic programming approach is to store, for each bag, some set of information about the present, while forgetting most information about the past, and not yet caring about what happens in the future.The resulting information is stored in a "signature", and the algorithm works by calculating which signatures are possible on each bag, in a bottom-up manner.This approach is complicated by the fact that the sought-for embedding of T IN into N IN may not map the past/present/future of T IN into the past/present/future (respectively) of N IN .Vertices from the past of T IN may be embedded in the future of N IN , or vice versa.Thus, we have to store more information than we might at first think.In particular, it is not enough to store information about which present vertices of T IN are embedded in which present vertices of N IN (indeed, depending on the bag, it may be that none of them are).As such, our notion of a "signature" has to track how vertices from the past of T IN are embedded in the present and future of N IN , and which vertices from the past of N IN contain vertices from the present or future of T IN .Vertices of the past which are mapped to vertices of the past, on the other hand, can mostly be forgotten about.

An informal guide to (compact) signatures
Roughly speaking, a signature σ for a bag (P, S, F ) in the tree decomposition of D IN (N IN , T IN ) consists of the following items (see Fig. 3 for an example): 1. a display graph D(N, T ), some of whose vertices correspond (isomorphically ).In our dynamic programming algorithm, we build valid signatures for a bag x from valid signatures of the child bag(s) of x (in particular, validity of a signature for x is characterized by the validity of certain signatures for the child bag(s)).
Since the definition of a signature does not guarantee any bound on the number of vertices labeled PAST or FUTURE, iterating over all signatures for a bag (P, S, F ) (in order to check their validity) exceeds FPT time.Therefore we will instead consider "compact" signatures, whose number and size are bounded in the width |S| of the bag (P, S, F ).If D IN (N IN , T IN ) admits an embedding function φ * , then a compact signature corresponding to this embedding function exists.In the following, we informally describe the compaction process for this hypothetical solution φ * , thus giving a rough idea of the definition of a "compact" signature.At all times, the (tentative) signature will contain a display graph D(N, T ) (initially , and an embedding function of T into N (initially φ * ).For a more complete description of our approach, see Section 3 and, for an illustration, see Fig. 2.
Step 1 After initialization with φ * , we assign a label FUTURE to all vertices of F , and a label PAST to all vertices in P (Observe that no vertex labeled PAST will be adjacent to a vertex labeled In a similar way, we forget any vertex u ∈ V (T ) and its embedding φ(u) if they are assigned the same label, provided that all their incident arcs can also be forgotten.We will call the vertices and arcs fulfilling these conditions "redundant" and we remove them from our tentative signature.We can also safely delete the vertices and arcs of N that are labelled y ∈ {PAST, FUTURE} but are not part of the image of φ.As a result, we now have that for any remaining vertex u ∈ T , either one of {u, φ(u)} is labelled PAST and the other labelled FUTURE, or some vertex element of S must appear as either one of {u, φ(u)}, a neighbor of u, or a vertex in the path φ(a) for an incident arc a of u.Thus, we have "forgotten" all the aspects of the embedding except those that involve vertices from the present in some way, or those where the embedding "timetravels" between the past and future (see Section 3.3 for a more formal description of this process).
Step 3 Finally, we may end up with long paths of vertices with in-degree and out-degree 1 that are labelled PAST or FUTURE in N (for example, if u and v are labelled PAST, then φ(uv) may be a long path in N with all vertices labelled FUTURE).Such long paths do not contain any useful information to us, we therefore compress these by suppressing vertices with in-degree and out-degree 1 (This gives the compact signature, see Section 3.8).

Bounding the number of signatures
We now outline the main arguments for why the number of possible (compact) signatures for a given bag (P, S, F ) can be bounded in |S|.Such a bound on the number of signatures ensures that the running time of the algorithm is FPT, because the number of calculations required for each bag is bounded by a function of the treewidth.The main challenge is to bound the size of the display graph D(N, T ) in a given signature for (P, S, F ). Once such a bound is achieved, this immediately implies upper bounds (albeit quite large) for the number of possible display graphs and the number of possible embeddings, and hence on the number of possible signatures.We will focus here on bounding the size of the tree part T .Once a bound is found for |T | it is relatively straightforward to use that to give a bound on |N | (because the arcs of N that are not used by the embedding of T into N are automatically deleted, unless they are themselves incident to a vertex in S, and because isolated vertices are deleted and long paths suppressed).
It can be seen that a vertex u ∈ V (T ) is redundant (and so would be deleted from the signature) unless one of the following properties holds: (1) u ∈ S, (2) φ(u) ∈ S, (3) u is incident to an element of S (4) for some arc a incident to u, the path φ(a) contains a vertex from S or (5) u and φ(u) have different labels from {PAST, FUTURE}.Essentially if none of (1)-(4) holds, then all the vertices mentioned in those properties have the same label as either u or φ(u), using the fact that S separates the vertices labelled PAST from the vertices labelled FUTURE.If u and φ(u) have the same label, then all these vertices have the same label, which is enough to show that u is redundant.It remains to bound the number of vertices satisfying one of these properties.For the first four properties, it is straightforward to find a bound in terms of |S|.The vertices satisfying the final property are "time-travelling" (in the sense that either u is labelled PAST and φ(u) FUTURE, or u is labelled FUTURE and φ(u) PAST).Because of the bounds on the other types of vertices, it is sufficient to provide a bound on the number of lowest time-travelling vertices in T .
To see the intuition why this bound should hold: consider some full solution on the original input, i.e. an embedding function on D IN (N IN , T IN ), and suppose u ∈ V (T IN ) is a lowest tree vertex for which u ∈ P, φ(u) ∈ F (thus in the corresponding signature, u has label PAST and φ(u) has label FUTURE).Let x ∈ V (N IN ) ∩ V (T IN ) be some leaf descendant of u.Then there is path in T IN from u to x, and a path in N IN from φ(u) to φ(x) = x.Thus D IN (N IN , T IN ) has an (undirected) path from u to φ(u).As this is a path between a vertex in P and a vertex in F , some vertex on this path must be in S (since S separates P from F ).Such a path must exist for every lowest time-travelling vertex u, and these paths are distinct.The existence of these paths can then be used to bound the number of lowest time-travelling vertices.
3 Filling in the details

Tracking the identity of vertices
In the following, consider a bag (P, S, F ) and recall that the sought solution may embed parts of the past of T in the future of N or vice versa.Thus, as previously indicated, a signature for (P, S, F ) will have to track information about more vertices than those in S.This leads to the following complexities in how we talk about the identity of vertices in signatures.
For the display graph D(N, T ) in a signature for (P, S, F ), we want some vertices to correspond to specific vertices in S ⊆ V (D IN (N IN , T IN )) while, for other vertices we want to express the fact that they correspond to a vertex of P or F , without specifying which one.Moreover, as our dynamic programming proceeds up the tree decomposition and we move from one signature to another, vertices will change between these two states.When we move from a child bag (P c , S c , F c ) to a parent bag (P p , S p , F p ) and a vertex x of D IN (N IN , T IN ) "leaves the bag" (that is, x ∈ S c \ S p ) then we want to "forget" that a vertex v corresponds to x (instead labelling v PAST), while still tracking its adjacencies and embedding information.Similarly, a vertex labelled FUTURE may, at some point, come to correspond to a particular vertex in S.
In order to keep this information straight, we have to be careful in how we talk about the identity of these vertices.In particular, the vertices of the display graph D(N, T ) are different from those in the signature carries a "correspondence" function ι that, on some subgraph of D(N, T ), acts as an isomorphism into the "S-part" of D IN (N IN , T IN ) while, on other vertices, acting as a labelling that assigns some vertices the label PAST and others the label FUTURE.As such, we refer to ι as an "isolabelling".
In the next definition, we consider an arbitrary set Y of labels, rather than the set {PAST, FUTURE}.While we will often have Y = {PAST, FUTURE}, we also use isolabelings in other contexts besides signatures.
Definition 3 (isolabelling).Let Y be a set of labels and let S ⊆ V (D IN (N IN , T IN )).An (S, Y)-isolabelling on a display graph D(N, T ) is a function ι : V (D(N, T )) → S ∪ Y such that S is a subset of the image of ι (ι is "surjective onto S") (i) and, for any u, v ∈ V (D(N, T )) with ι(u), ι(v) ∈ S:

Signatures and containment structures
Before formally defining a signature for a bag (P, S, F ), let us remark that, later in the paper, we will also discuss constructs which are similar in construction to signatures, but with slightly different vertex and label sets ("partial solutions" and "reconciliations").For this reason, we define a more general structure, called an (S, Y)-containment structure, that encapsulates all these notions.In the definition that follows, a signature for a bag (P, S, F ) corresponds to an (S, Y)-containment structure, where S is the present of the bag (P, S, F ) and Y is the label set {PAST, FUTURE}.For an intuitive understanding of a containment structure, the most important features are the display graph, embedding function and isolabelling.
Definition 4 (containment structure).Let Y be a set of labels and let Through most of the paper, Y = {PAST, FUTURE} and S may be referred to as the "present" of the bag (P, S, F ).However, our setup also allows us to talk about "partial solutions", where S is replaced by P ∪S (essentially merging the past and the present) and only the label set Y = {FUTURE} (corresponding to vertices in F ) is used.In some instances, we will use additional auxiliary labels; in particular when considering Join bags in Section 3.6, we use the labels LEFT and RIGHT to distinguish between the pasts of different bags.Finally, Definition 4 also allows capturing a solution for an instance of TREE CONTAIN-MENT.Indeed, if we replace the set S with

Formally defining the restriction
While Section 2.3 describes in broad strokes how a signature for a bag (P, S, F ) could be derived from a solution for an instance of TREE CONTAINMENT, we now make this process more precise.Recall that we Embedding phylogenetic trees in networks of low treewidth 13 first relabelled the vertices in P and F by PAST and FUTURE, respectively, and then, "redundant" parts of the display graph were removed and the remaining long paths contracted.Exactly which arcs and vertices should be removed is made precise in the notion of redundancy defined below.
Definition 6 (redundant).Let χ := (D(N, T ), φ, ι) be an (S, Y)-containment structure, and let y ∈ Y.Then, we define the y-redundant arcs and vertices of D(N, T ) as follows: We say that an arc or vertex of D(N, T ) is redundant if it is y-redundant for some y ∈ Y.When it is important to specify the containment structure χ, we say an arc or vertex is y-redundant with respect to χ.
Just as we derived a signature from a solution in Section 2.3 by restricting our attention to a subset of vertices (in that case, the set S), we can restrict any (S, Y)-containment structure to an (S ′ , Y)-containment structure for any S ′ ⊆ S.This will be a useful tool for deriving signatures for one bag from signatures for another bag, as well as characterizing the "validity" of a signature.
We will sometimes write (S 1 → y 1 , . . ., S j → y j )-restriction instead of g-restriction, where y 1 , . . .y j are labels in Y and g(u) := y i for all u ∈ S i , and g(u) := u for all other u.For example, we may write (P → PAST)-restriction when g is the function that maps all vertices in P to the label PAST, and leaves other vertices unchanged.If any S i is a singleton set {z}, we permit ourselves to write z → y i instead of {z} → y i .In particular, we will see (RIGHT → FUTURE)-restrictions, where the label RIGHT is mapped to the label FUTURE.Such restrictions may sometimes be used to "merge" labels.Note that Steps 1 and 2 of the process described in Section 2.3 is (roughly analogous to) the process of constructing the Before proving results relating to g-restrictions, we make the following observations about g-restrictions and redundant arcs and vertices, which are straightforward consequences of Definition 6 and, thus, we omit their proofs.∈ {PAST, FUTURE}.Right: The g-restriction of ψ.In accordance with Definition 7, note how (a) arcs in the "PAST"-area of N that are not mapped to by φ disappear in N ′ while arcs that are mapped by φ persist, (b) many of the arcs in T are in the "PAST"-area, but embedded by φ into paths of N that live (at least partially) in the "FUTURE"-area of N and, therefore, also persist, and (c) a common leaf of T and N has been removed since all its incoming arcs have been deleted.Finally, as will be the case in the dynamic programming later on, the "PAST"-and "FUTURE"-areas never touch in D(N ′ , T ′ ).
• If a is a tree arc, then Observation 2. If a tree arc uv is y-redundant then so is every arc in φ(uv).A tree vertex u is y-redundant if and only if φ(u) is y-redundant.
Lemma 3. Let χ be an (S, Y)-containment structure, let S ′ ⊆ S, and let χ ′ be the g-restriction of χ for some restriction function g : being an (S ′ , Y)-containment structure, we verify the five conditions of Definition 4 individually.D(N ′ , T ′ ) is a display graph.As D(N ′ , T ′ ) was derived from D(N, T ) by deleting a subset of arcs and vertices, it is clear that D(N ′ , T ′ ) remains a display graph.φ ′ is an embedding function.As φ ′ is the restriction of φ to T ′ , and no arc in a path φ(uv) was deleted unless the arc uv was deleted as well (and similarly for vertices φ(u)), φ ′ is still a function that maps vertices of T ′ to vertices of N ′ and arcs of T ′ to directed paths of N ′ .The other properties of an embedding function (such as all paths being arc-disjoint) follow immediately from the fact that these properties hold for φ.Thus, φ ′ is an embedding function on D(N ′ , T ′ ).
ι ′ is an (S ′ , Y)-isolabelling.Note that the properties of an isolabelling follow immediately from construction of ι ′ , the fact that g(v) = v for all v ∈ S ′ and the fact that ι is an (S, Y)-isolabelling.
To see that the image of ι ′ in D IN (N IN , T IN ) contains S ′ , we prove that, for every z ∈ S ′ , there is some u ∈ V (D(N ′ , T ′ )) for which ι ′ (u) = z.To see this, consider the vertex u ∈ V (D(N, T )) for which ι(u) = z.Since z ∈ S ′ we then have g(ι(u)) = g(z) = z / ∈ Y and, thus, u cannot become redundant in the construction of χ ′ .Hence, u is also a vertex of D(N ′ , T ′ ), and ι no arc incident to u is deleted when constructing D(N ′ , T ′ ) and, thus, u has the same in-and outdegrees in D(N ′ , T ′ ) as it does in D(N, T ), that is, the same in-and out-degrees as Then, no arc incident to u was deleted (as for any such arc a the path φ(a) contains φ(u) by Definition 2(a)) and, so, u has the same out-degree in Lemma 4 (transitivity of restrictions).Let χ be an (S, Y)-containment structure for some S and Y, let S ′′ ⊆ S ′ ⊆ S and let g ′ : S ∪ Y → S ′ ∪ Y and g ′′ : S ′ ∪ Y → S ′′ ∪ Y be restriction functions.Let χ ′ be the g ′ -restriction of χ and let χ ′′ be the g ′′ -restriction of χ ′ .Then, χ ′′ is the (g ′′ • g ′ )-restriction of χ.
Proof: First, we show that g : In the following, let χ ′ = (D(N ′ , T ′ ), φ ′ , ι ′ ), let χ ′′ = (D(N ′′ , T ′′ ), φ ′′ , ι ′′ ) and let ι g ′ be as described in Definition 7, that is, ι g ′ (u) = g ′ (ι(u)) for all u ∈ V (D(N, T )) (and analogously for ι ′ g ′′ and ι g ).Then, by Definition 7, ι ′ = ι g ′ and ι ′′ = ι ′ g ′′ .Note that, for any u ∈ V (D(N ′ , T ′ )), Next, we show that χ ′′ equals the g-restriction χ * = (D(N * , T * ), φ * , ι * ) of χ.To this end, we first prove that D(N * , T * ) = D(N ′′ , T ′′ ).As both display graphs are subgraphs of D(N, T ), it is enough to show that any arc or vertex is deleted in the construction of D(N * , T * ) from D(N, T ) if and only if it is deleted in the construction of D(N ′ , T ′ ) from D(N, T ) or of D(N ′′ , T ′′ ) from D(N ′ , T ′ ).Arcs: Let uv be an arc of D(N, T ).If uv ∈ A(T ), then let Q uv := {u, v} ∪ V (φ(uv)) (that is, Q uv contains u, v and all vertices in the path φ(uv)).If uv is an arc of N , then let Q uv be the set containing u and v together with any u ′ and v ′ for which uv is in the path φ(u ′ v ′ ) (by Definition 2, there is at most one such arc u ′ v ′ ).By Observation 1, uv is deleted in the construction of D(N * , T * ) if and only if there is some was deleted in the construction of D(N ′ , T ′ ) and, by Observation 2, so was uv, contradicting uv being in D(N ′ , T ′ ).Thus, all vertices of Q uv are in D(N ′ , T ′ ) and, by (1), . By definition of redundant vertices, either both vertices of Q v are deleted in the construction of D(N * , T * ) or neither is.As D(N * , T * ) and D(N ′′ , T ′′ ) have the same arcs, we may assume neither element of Q v has any incident arcs.Then, v is deleted in the construction of Since φ * is the restriction of φ to T * and φ ′′ is the restriction of φ to T ′′ (via φ ′ ), we also have for any vertex u in D(N ′ , T ′ ) and, thus, ι ′′ (u) = ι * (u) for any vertex u in D(N ′′ , T ′′ ) (as ι ′′ and ι * are just restrictions of ι ′ g ′′ and ι g respectively).Therefore, ι * = ι ′′ and we have proved that χ * = χ ′′ , as required.

Well-behaved containment structures
At this point, we note some additional properties that it will be helpful to assume for (S, Y)-containment structures.These properties are summarized in the concept of "well-behavedness" and, in what follows, we will restrict our attention to such containment structures.While not directly implied by the definition of a containment structure, the properties effectively ensure that containment structures behave "as expected".In particular, our dynamic programming algorithm will work with well-behaved signatures.
Here we prove a number of properties of well-behaved containment structures, that allow us to focus on them going forward.Lemma 6.Let χ = (D(N, T ), φ, ι) be a well-behaved (S, Y)-containment structure and let g be a restriction function such that, for all arcs uv of D(N, T ) with g(ι(u)), g(ι(v)) ∈ Y, we have g(ι(u)) = g(ι(v)).Then, the g-restriction σ of χ is also well-behaved.
Essentially, this condition says that relabelling according to g does not immediately create any arcs uv for which u and v are labelled with different elements of Y.

Partial solution and valid signatures
As with any dynamic programming algorithm, we need some way to decide which signatures are "correct" before we have actually found a solution.As such, we need a notion of a "partial solution".Much as we may think of a signature for a bag (P, S, F ) as corresponding to the (P → PAST, F → FUTURE)restriction of some solution, we may think of a partial solution as the (F → FUTURE)-restriction of some solution.That is, a partial solution is a (P ∪S, {FUTURE})-containment structure that roughly corresponds to what would happen if we took a solution and "forgot" some of the details about the vertices in F .A partial solution is then a "witness" for a given signature for (P, S, F ) if that signature can in turn be derived from the partial solution by "forgetting" details about the vertices in P .In this case we call the signature "valid".This is defined precisely below.
Definition 9 (partial solution, signature, valid).Let (P, S, F ) be a bag in the tree decomposition of D IN (N IN , T IN ).Then any (P ∪ S, {FUTURE})-containment structure is called F -partial solution (or simply partial solution) for (P, S, F ).A well-behaved signature σ for (P, S, F ) is called valid if σ is the (P → PAST)-restriction of a well-behaved partial solution ψ for (P, S, F ).We call ψ a witness for σ.Proof: By Lemma 5, there is a well-behaved and note that ψ is an F -partial solution.Clearly, x, y ∈ {FUTURE} ⇒ x = y and, so, Lemma 6 applies, showing that ψ is well-behaved.Finally, let σ be the (P → PAST)-restriction of ψ which is valid since ψ is well-behaved.For the converse, consider a valid signature PAST cannot make a vertex FUTURE-redundant that was not previously FUTURE-redundant (as no new vertex gains the label FUTURE).Thus, u is FUTURE-redundant in ψ, contradicting Definition 8(a).Lemma 6, Lemma 7 and Lemma 8 show that an instance (N IN , T IN ) of TREE CONTAINMENT is a YESinstance if and only if there is a well-behaved valid signature σ := (D(N, T ), φ, ι) for the root bag Thus in order to solve an instance of TREE CON-TAINMENT, it is enough to decide for each bag (P, S, F ) in the tree decomposition of D IN (N IN , T IN ), and for each well-behaved signature σ for (P, S, F ), whether σ is valid.

Determining valid signatures
With the formal definitions of valid signatures and restrictions in place, we can now show how to determine whether a well-behaved signature for a bag (P, S, F ) is valid, assuming we know this for all signatures on the child bag(s).As is common in dynamic programming techniques, we take advantage of the structure of a nice tree decomposition.The following lemmas describe the exact conditions for Leaf, Forget and Introduce bags while the additional terminology required for Join bags is deferred to Section 3.7.Proof: Suppose first that σ is valid.By Definition 9, σ is the (P → PAST)-restriction of a well-behaved F -partial solution (that is, (P ∪ S, {FUTURE})-containment structure) ψ := D(N ′ , T ′ ), φ ′ , ι ′ ).Then ι ′ (u) = PAST for every vertex u in D(N ′ , T ′ ) and, as P = ∅, this remains true after applying P → PAST.It follows that ι(u) = PAST for every vertex u ∈ D(N, T ), as required.
Conversely, suppose ι −1 (PAST) = ∅.Since P = ∅, the (S, {PAST, FUTURE})-containment structure σ is also a (P ∪ S, {FUTURE})-containment structure, that is, σ is an F -partial solution.To show that σ is valid, we prove that σ is the (P → PAST)-restriction of itself, that is, σ is a witness for σ.To this end, observe that applying P → PAST does not change the isolabelling and, by Definition 8, σ contains no redundant arcs or vertices.Thus, applying P → PAST and removing redundant arcs and vertices does not change σ.
Lemma 10.Let (P, S, F ) correspond to a Forget bag in the tree decomposition with child bag (P ′ , S ′ , F ), i.e.P = P ′ ∪ {z} and S = S ′ \ {z} for some z ∈ S ′ .Let σ be a well-behaved signature for (P, S, F ).Then, σ is valid if and only if σ is the (z → PAST)-restriction of a valid signature σ ′ for (P ′ , S ′ , F ). Proof: Suppose first that σ is the (z → PAST)-restriction of some valid signature σ ′ for (P ′ , S ′ , F ).By Definition 9, σ ′ has a witness ψ ′ (that is, ψ ′ is a well-behaved F -partial solution for (P ′ , S ′ , F ) whose P ′ → PAST-restriction is σ ′ ).By Lemma 4, σ is the (P → PAST)-restriction of ψ ′ , and so σ is valid.
For the converse, suppose that σ is valid and let ψ be a witness of σ (that is, ψ is a well-behaved F -partial solution for (P, S, F ) and σ is the (P → PAST)-restriction of ψ).Then, the (P ′ → PAST)restriction σ ′ of ψ is a valid signature for (P ′ , S ′ , F ) and, by Lemma 4, the (z → PAST)-restriction of σ ′ is the (P → PAST)-restriction of ψ, that is, σ.
Lemma 11.Let (P, S, F ) correspond to an Introduce bag in the tree decomposition with child bag (P, S ′ , F ′ ), i.e. S ′ = S \ {z} and F ′ = F ∪ {z} for some z ∈ S. Let σ be a well-behaved signature for (P, S, F ).Then, σ is valid if and only if the (z → FUTURE)-restriction σ ′ of σ is a valid signature for (P, S ′ , F ′ ).
Proof: Suppose first that σ is a valid signature and let ψ be a witness for σ (that is, ψ is a well-behaved F -partial solution for which σ is the (P → PAST)-restriction).Let ψ ′ be the (z → FUTURE)-restriction of ψ which, by Lemma 6, is a well-behaved F ′ -partial solution.Let σ * denote the (P → PAST)-restriction of ψ ′ and note that σ * is a valid signature for (P, S ′ , F ′ ).By Lemma 4, σ * is also the (P → PAST, {z} → FUTURE)-restriction of ψ and the (z → FUTURE)-restriction σ ′ of σ is also the (P → PAST, {z} → FUTURE)-restriction of ψ.Thus, σ ′ = σ * and so σ ′ is valid, as required (see Fig. 5).
To begin the construction, let V z and A z denote the the set of vertices and arcs, respectively, that are in D(N, T ) but not in D(N ′ , T ′ ) (that is, the vertices and arcs that are deleted when deriving σ ′ from σ).Letting g be the function z → FUTURE, we may assume that g(ι(v)) = FUTURE for all vertices v in V z 0 0 ffzg futureg or V (A z ) and g(ι(V (φ(uv)))) = {FUTURE} for any tree arc uv in A z as well.Similarly, let V p and A p be the vertices and arcs, respectively, that are deleted from D(N ′ 0 , T ′ 0 ) in the construction of D(N ′ , T ′ ).Letting h be the function P → PAST, we may assume that h(ι(v)) = PAST for all vertices v in V p or V (A p ), and h(ι(V (φ(uv)))) = {PAST} for any tree arc uv in A p as well.
We now construct the F -partial solution ψ := (D(N 0 , T 0 ), φ 0 , ι 0 ) as follows.First, let D(N 0 , T 0 ) be the graph derived from D(N ′ 0 , T ′ 0 ) by adding all vertices and arcs of V z and A z .Equivalently, we may say we construct D(N 0 , T 0 ) by adding the arcs and vertices of V p and A p to D(N, T ), or by adding the arcs and vertices of V z , V p , A z , A p to D(N ′ , T ′ ).Let φ 0 be defined as the 'union' of φ and φ ′ 0 -that is, φ 0 (uv) = φ(uv) if uv is an arc in T , and φ 0 (uv) = φ ′ 0 (uv) if uv is an arc in T ′ 0 (if uv is an arc of both T and T ′ 0 , then these are the same, as uv is in T ′ and φ(uv We note here that for any vertex By construction, in all other cases ι 0 (v) = ι(v).Furthermore, for any arc a incident to v in D(N 0 , T 0 ), a is an arc in D(N, T ) (since a ∈ A p would imply ι ′ 0 (v) ∈ P and hence either v ∈ V p or ι ′ (v) = PAST), and thus φ 0 (a) = φ(a).A similar argument shows that for any , and φ 0 (a) = φ ′ 0 (a) for any arc a in D(N 0 , T 0 ) incident to v.
We will now show that ψ is indeed a well-behaved F -partial solution; afterwards we will show that σ is the {P → PAST}-restriction of ψ, from which it follows that σ is valid.(A similar argument can be used to show that ψ ′ is the {{z} → FUTURE}-restriction of ψ, but we will not need this fact so we do not prove it here.)Claim 1. ψ is a well-behaved F -partial solution.
Proof: We first show that ψ satisfies one of the properties of a well-behaved (P ∪ S, {FUTURE})containment structure Suppose for a contradiction that this is not the case, and let u, v ∈ V (D(N 0 , T 0 )) be such that ι 0 (u), ι 0 (v) ∈ P ∪ S and there is a path from u to v in D(N 0 , T 0 )), but no path from ι 0 (u) , and the existence of a path from ι(u) follows from the fact that σ or σ ′ 0 is well-behaved.Otherwise, by choice of u, v we may assume all internal vertices u ′ on the path from u to v satisfy ι 0 (u ′ ) = FUTURE.Then every arc on this path is an arc in D(N, T ) and so again, we have a path from ι 0 (u -D(N 0 , T 0 ) is acyclic: Suppose for a contradiction that D(N 0 , T 0 ) contains a directed cycle.
If ι 0 (u) ∈ P ∪ S for some vertex u in this cycle, then as shown above the existence of a path from u to u in D(N 0 , T 0 ) implies the existence of a path from ι 0 (u) It remains to consider the case that every vertex z in this cycle has ι 0 (z) = FUTURE.But in this case every arc of the cycle is also an arc in D(N, T ), and so D(N, T ) contains a cycle, a contradiction as D(N, T ) is a display graph.
-T 0 is an out-forest: We first observe that for every vertex u in D(N 0 , T 0 ), either all its incident arcs in D(N 0 , T 0 ) are also arcs of D(N, T ), or they are all arcs of D(N ′ 0 , T ′ 0 ).Indeed, suppose for a contradiction that this is not the case, then there exist arcs a ∈ A p , a ′ ∈ A z that share a vertex u.But by construction, a ∈ A p implies that u ∈ V p or ι ′ (u) = PAST and so ι 0 (u) ∈ P , while a ′ ∈ A z implies ι 0 (u) ∈ S ∪ {FUTURE}, a contradiction.Now it remains to observe that every vertex in T 0 has in-degree at most 1, as either all its incident arcs are in T or they are all in T ′ 0 .This, together with the fact that D(N 0 , T 0 ) is acyclic, implies that T 0 is an out-forest.
-Every vertex in D(N 0 , T 0 ) has in-and out-degree at most 2 and total degree at most 3: As argued above, every vertex in D(N 0 , T 0 ) has all its incident arcs in D(N, T ) or in D(N ′ 0 , T ′ 0 ), and so this property follows from the fact that it holds for D(N, T ) and D(N ′ 0 , T ′ 0 ) -Any vertex in V (N 0 ) ∩ V (T 0 ) has out-degree 0 and in-degree at most 1 in each of T 0 and N 0 : Again, this follows from the fact that all incident arcs of a vertex in D(N 0 , T 0 ) belong to one of D(N, T ), D(N ′ 0 , T ′ 0 ).
-the paths {φ 0 (uv) | uv ∈ A(T 0 )} are arc-disjoint: Observe that by construction that if a tree arc uv is in A p , then so is every arc in φ 0 (uv) = φ ′ 0 (uv).Similarly if uv is in A z then so is every arc in φ 0 (uv) = φ(uv).So consider two distinct tree arcs uv, u ′ v ′ ∈ A(T 0 ).If uv ∈ A p , u ′ v ′ ∈ A z then the arcs of the paths φ 0 (uv), φ 0 (u ′ v ′ ) are in A p , A z respectively, so φ 0 (uv), φ 0 (u ′ v ′ ) are arc-disjoint.Otherwise, we may assume both uv and u ′ v ′ are arcs in one of D(N, T ), D(N ′ 0 , T ′ 0 ), from which the claim follows by the fact that φ and φ ′ 0 are embedding functions.
-for any distinct p, q ∈ A(T 0 ), φ 0 (p) and φ 0 (q) share a vertex z ′ only if p and q share a vertex w with z ′ = φ 0 (w): Suppose φ 0 (p) and φ 0 (q) share a vertex z ′ .As argued previously, all incident arcs to z ′ must be in one of D(N, T ), D(N ′ 0 , T ′ 0 ).Thus in particular, z ′ cannot have incident arcs from both A p and A z .Then since φ 0 (p) and φ 0 (q) both contain arcs incident to z ′ , we must have that p, q / ∈ A p or p, q / ∈ A z .Then either φ 0 (p) = φ(p) and φ 0 (q) = φ(q), or φ 0 (p) = φ ′ 0 (p) and φ ′ 0 (q).Then the claim follows from the fact that φ and φ ′ 0 are embedding functions.
Follows immediately from the construction of ι 0 and the fact that ι, ι ′ 0 are isolabelings.-ι 0 is surjective onto P ∪ S: Consider any w ∈ P ∪ S. If w ∈ P , there is u ∈ V (D(N ′ 0 , T ′ 0 )) with ι ′ 0 (u) = w.For such u we have either u ∈ V p or ι ′ (u) = PAST.In either case we have , and so ι 0 (u) = ι(u) = w.
• Each vertex u with ι 0 (u) ∈ P ∪ S has the same in-and out-degree in D(N 0 , T 0 ) as ι 0 (u) in D IN (N IN , T IN ): As previously shown, all incident arcs of u in D(N 0 , T 0 ) belong to at least one of D(N, T ), D(N ′ 0 , T ′ 0 ).Moreover if ι 0 (u) = ι(u) then all incident arcs are in D(N, T ) and if ι 0 (u) = ι ′ 0 (u) then all incident arcs are in D(N ′ 0 , T ′ 0 ).Then this property follows from the fact that σ and σ ′ 0 are containment structures.
• Each vertex u of T 0 with ι 0 (u) = ι(φ 0 (u)) has 2 out-arcs in D(N 0 , T 0 ) : In the case that ι 0 (u) ∈ P ∪ S, this follows from previously-shown properties.We may assume u is an internal vertex of T 0 (as otherwise u ∈ V (T 0 ) ∩ V (N 0 ) and φ 0 (u) = u).Then ι 0 (u) is also an internal vertex of T IN , and u has the same in-and out-degree as ι 0 (u).Thus in particular u has out-degree 2, as T 0 is binary.
The above conditions show that ψ is a (P ∪ S, {FUTURE})-containment structure, i.e. an F -partial solution.Next we show that ψ is well-behaved: • D(N 0 , T 0 ) contains no redundant arcs or vertices: Suppose for a contradiction that D(N 0 , T 0 ) contains a FUTURE-redundant arc or vertex a.We will show that such an arc or vertex is also redundant w.r.t σ, a contradiction as σ is well-behaved.Consider the case that a is an arc uv Then ι 0 (u) = ι 0 (v) = FUTURE.It follows by construction that u, v are vertices of D(N, T ) and ι(u) = ι(v) = FUTURE.In addition we have that ι 0 (u ′ ) = FUTURE for any vertex u ′ on the path φ 0 (uv) = φ(uv), and hence φ(u ′ ) = FUTURE for such u ′ .It follows that uv is FUTURE-redundant w.r.t σ, the desired contradiction.Essentially the same arguments can also be made for redundant network arcs and redundant tree or network vertices.
• For any y, y ′ ∈ {FUTURE} with y = y ′ , there is no arc uv in D(N 0 , T 0 ) for which ι 0 (u) = y and ι 0 (v) = y ′ : This follows immediately from the fact that |{FUTURE}| = 1 so there are no such y, y ′ .
• For any u, v, in V (D(N 0 , T 0 )) with ι p (v), ι 0 (v) ∈ P ∪ S, if D(N 0 , T 0 ) has a path from u to v then D IN (N IN , T IN ) has a path from ι 0 (u) to ι 0 (v): This has already been shown, at the start of the proof for this claim.
Equality of D(N ′′ , T ′′ ) and D(N, T ): To show this, it is enough to show that that D(N ′′ , T ′′ ) is D(N 0 , T 0 ) with the arcs of A p and vertices of V p removed, i.e. these arcs and vertices are exactly the ones that become redundant when constructing the {P → PAST}-restriction of ψ.Since these were exactly the arcs and vertices that were added to D(N, T ) to produce D(N 0 , T 0 ), this is enough to show that D(N ′′ , T ′′ ) = D(N, T ).
Let g be the restriction function {P → PAST}.We claim that for the isolabelling ι u • g, the redundant arcs are exactly those of A p .
Indeed, consider any arc uv in A p .Since uv ∈ A p , it must have been made PAST-redundant in the construction of σ ′ from ψ ′ .So if uv is a tree arc, then ι ′ 0 (z) ∈ P for all z in {u, v} ∪ V (φ ′ 0 (uv)) (as all these vertices are labelled PAST after applying {P → PAST}).Then by construction of ψ, we have φ 0 (uv) = φ ′ 0 (uv), and also ι 0 (z) = ι ′ 0 (z) for all z in {u, v} ∪ V (φ ′ 0 (uv)) (since either z ∈ V p or ι ′ (z) = PAST).Thus ι 0 (z) ∈ P for all z in {u, v} ∪ V (φ 0 (uv)), and so uv becomes PAST-redundant after applying {P → PAST}.For a network arc uv in A p , a similar argument holds, but we need to be careful if there is a tree arc u ′ v ′ for which uv is in φ(u ′ v ′ ) (in particular, we would have a problem if u ′ v ′ is not an arc in D(N ′ , T ′ ), as u ′ v ′ could conceivably prevent uv from becoming PAST-redundant).For such an arc u ′ v ′ , note that u ′ v ′ must also be in A p (otherwise u ′ v ′ is an arc in D(N ′ , T ′ ) but φ ′ (uv) = φ 0 (uv) is not a path in D(N ′ , T ′ ), a contradiction).It follows then that ι ′ 0 (u ′ ), ι 0 (v ′ ) ∈ P .We also have that ι ′ 0 (u), ι 0 (v) ∈ P .So by a similar argument to tree arcs, we have that uv is redundant after applying {P → PAST} in ψ, as required.
Conversely consider any redundant arc uv in D(N 0 , T 0 ) after applying {P → PAST}.As ψ is wellbehaved, we may assume any such arc is PAST-redundant.Then ι 0 (u), ι 0 (v) ∈ P .This implies among other things that uv is not in A z (as that would require ι 0 (u), ι 0 (v) ∈ F ∪ {FUTURE}) so uv is also an arc in D(N ′ 0 , T ′ 0 ).Similarly if uv is a tree arc then all arcs in φ 0 (uv) as also in D(N ′ 0 , T ′ 0 ), and if uv is a network arc that is part of a path φ 0 (u ′ v ′ ), then u ′ v ′ is also an arc in D(N 0 , T ′ 0 ).Furthermore ι ′ 0 (z) = ι 0 (z) for any vertex in one of these arcs (as ι ′ (z) = FUTURE and ι ′ (z) / ∈ V z ).It is then easy to see that, just as uv is redundant in ψ after applying {P → PAST}, uv is also redundant in ψ ′ after applying {P → PAST}, and so uv is in A p .
As we have now shown that ψ is a well-behaved F -partial solution and σ is the {P → PAST}-restriction of σ, we have that σ is valid, as required.

Validity for Join bags
In order to characterize validity for Join bags, we need to introduce a third type of (S, Y)-containment structure.In our notation we may think of a Join bag as being expressed by the tuple (P, S, F ) where P can be decomposed into L ∪ R, such that the "left" child bag is (L, S, F ∪ R) and the "right" child bag is (R, S, F ∪ L).We want to characterize the validity of a signature σ for a Join bag in terms of the validity of signatures for each of the child bags.The main idea is to find two signatures σ L and σ R (for different child bags) which are 'compatible', in the sense that the two witnesses for these signatures can be combined, and such that the resulting partial solution is a witness for σ.In order to facilitate this characterization, it will be useful to define a "3-way" analogue of a signature, called a reconciliation, in which we use the labels {LEFT, RIGHT, FUTURE} instead of {PAST, FUTURE}.This is defined below.
Definition 10 (reconciliation).Let (L ∪ R, S, F ) be a Join bag in the tree decomposition of D IN (N IN , T IN ) with child bags (L, S, F ∪R) and (R, S, F ∪L).Then, we call an (S, {LEFT, RIGHT, FUTURE})-containment structure a reconciliation for (L ∪ R, S, F ).Such a reconciliation µ for (L ∪ R, S, F ) is called valid if it is the (L → LEFT, R → RIGHT)-restriction of a well-behaved F -partial solution (i.e. a (L ∪ R ∪ S, {FUTURE})-containment structure).
Lemma 12. Let (L ∪ R, S, F ) be a Join bag with child bags (L, S, F ∪ R) and (R, S, F ∪ L), and let σ be a signature for (L ∪ R, S, F ).Then, σ is valid if and only if there is a reconciliation µ for (L ∪ R, S, F ) and valid signatures σ L and σ R for (L, S, F ∪ R) and (R, S, F ∪ L), respectively, such that (a) σ is the ({LEFT, RIGHT} → PAST)-restriction of µ, (b) σ L is the (LEFT → PAST, RIGHT → FUTURE)-restriction of µ, and (c) σ R is the (RIGHT → PAST, LEFT → FUTURE)-restriction of µ.
To prove this lemma, we first show the following.
Lemma 13.Any valid reconciliation is well-behaved.
Proof: Let µ be a valid reconciliation for (L ∪ R, S, F ), and let ψ = (D(N, T ), φ, ι) be a well-behaved F -partial solution for which µ is the g-restriction, where g is the function {L → LEFT, R → RIGHT}.We first show that there is no arc uv in D(N, T ) with g(ι(u)) = y, g(ι(v)) = y ′ for any y, y ′ ∈ {LEFT, RIGHT, FUTURE} with y = y ′ .Recall that by properties of a tree decomposition, there are no arcs between F and L ∪ R in D IN (N IN , T IN ), nor between L and R.So now consider a vertex u ∈ V (D(N, T )); we will show that if g(ι(u)) ∈ {LEFT, RIGHT} then u has no neighbour v with g(ι It follows that ι(v) ∈ L ∪ S and thus g(ι(v)) ∈ S ∪ {LEFT} for any neighbour of u in D(N, T ), while g(ι(u)) = LEFT.A similar argument shows that if ι(u) ∈ R, then g(ι(v)) ∈ S ∪ {RIGHT} for any neighbour of u in D(N, T ) and g(ι(u)) = RIGHT.Finally if ι(u) ∈ S ∪ {FUTURE}, then g(ι(u)) = ι(u) / ∈ {LEFT, RIGHT}, and we are done.
As no vertex labelled LEFT or RIGHT by ι•g has a neighbour with a different label from {LEFT, RIGHT, FUTURE}, there are in fact no arcs uv in D(N, T ) with g(ι(u)) = y, g(ι(v)) = y ′ for any y, y ′ ∈ {LEFT, RIGHT, FUTURE} with y = y ′ .We can therefore apply Lemma 6 to see that σ is well-behaved.
We next motivate the definition of a reconciliation by showing that the validity of a signature for (L ∪ R, S, F ) can be characterized by the validity of reconciliations for (L ∪ R, S, F ). Lemma 14.Let (L ∪ R, S, F ) be a Join bag with child bags (L, S, F ∪ R) and (R, S, F ∪ L), and let σ be a signature for (L ∪ R, S, F ). Then σ is valid if and only if there is a valid reconciliation µ for (L ∪ R, S, F ) such that σ is the {{LEFT, RIGHT} → PAST}-restriction of µ.
Proof: Suppose first that σ is valid.Then there is a well-behaved (L ∪ R ∪ S, {FUTURE})-containment structure ψ (an F -partial solution) such that σ is the {L ∪ R → PAST}-restriction of ψ.Now let µ be the {L → LEFT, R → RIGHT}-restriction of ψ.By Lemma 3, µ is an (S, {LEFT, RIGHT, FUTURE})containment structure, and by construction µ is valid.Now let σ ′ be the {{LEFT, RIGHT} → PAST}restriction of µ.Then transitivity implies that σ ′ is also the {L ∪ R → PAST}-restriction of ψ, that is σ ′ = σ.Thus σ is the {{LEFT, RIGHT} → PAST}-restriction of µ, as required.
Conversely, suppose there is a reconciliation µ for (L ∪ R, S, F ) such that σ is the {{LEFT, RIGHT} → PAST}-restriction of µ.Then as µ is valid, there is a well-behaved F -partial solution ψ such that µ is the {L → LEFT, R → RIGHT}-restriction of ψ.Then again by transitivity, σ is also the {L ∪ R → PAST}restriction of ψ.Thus σ is valid.Now we show how the validity of a reconciliation µ for (L ∪ R, S, F ) can be characterized by the validity of signatures for the child bags.
Lemma 15.Let (L ∪ R, S, F ) be a Join bag with child bags (L, S, F ∪ R) and (R, S, F ∪ L), and let µ be a well-behaved reconciliation for (L ∪ R, S, F ). Let σ L be the {LEFT → PAST, RIGHT → FUTURE}restriction of µ, and σ R the {RIGHT → PAST, LEFT → FUTURE}-restriction of µ.If µ is valid, then σ L is a valid signature for (L, S, F ∪ R) and σ R is a valid signature for (R, S, F ∪ L).
Proof: Suppose that µ is valid.Then there is a well-behaved F -partial solution ψ such that µ is the {L → LEFT, R → RIGHT}-restriction of µ.By construction and Lemma 3, σ L is an (S, {PAST, FUTURE})containment structure, and thus a signature for (L, S, F ∪ R).By transitivity, σ L is the {L → PAST, R → FUTURE}-restriction of ψ.We will show that σ L is a valid signature for (L, S, F ∪ R).
Let ψ L be the {R → FUTURE}-restriction of ψ.By construction, ψ L is an F ∪ R-partial solution and by Lemma 6 ψ L is well-behaved.Moreover by transitivity, the {L → PAST}-restriction of ψ L is also the {L → PAST, R → FUTURE}-restriction of ψ.That is, the {L → PAST}-restriction of ψ L is σ L , and so σ L is valid for (L, S, F ∪ R). (See Fig. 7.) A similar argument shows that σ R is a valid signature for (R, S, F ∪ R).Our strategy is to combine ψ L and ψ R into an F -partial solution ψ, and then show that µ is the In what follows, for a given containment structure σ, we will write the display graph, embedding function and isolabelling of σ as D(N σ , T σ ), φ σ and ι σ .Thus we have µ = (D(N µ , T µ ), φ µ , ι µ ), σ L = (D(N σL , T σL ), φ σL , ι σL ), etc. Recall that by construction, D(N σL , T σL ) is a subgraph of both D(N µ , T µ ) and D(N ψL , T ψL ).Similarly, D(N σR , T σR ) is a subgraph of both D(N µ , T µ ) and D(N ψR , T ψR ).
Now let A L be the set of arcs, and V L the set of vertices, that become redundant and are therefore deleted from D(N ψL , T ψL ) when deriving the {L → PAST}-restriction σ L from ψ L .That is, A L = A(D(N ψL , T ψL )) \ A(D(N σL , T σL )) and V L = V (D(N ψL , T ψL )) \ V (D(N σL , T σL )).We note that by construction, ι ψL (v) ∈ L for any v ∈ V L ∪ V (A L ).Similarly, let A R , V R be the sets of arcs and vertices that are deleted from D(N ψR , T ψR ) in the construction of σ R from ψ R .Let A ′ R , V ′ R be the set of vertices that are deleted from D(N µ , T µ ) in the construction of σ L from µ, and let A ′ L , V ′ L be the set of vertices that are deleted from D(N µ , T µ ) in the construction of σ R from µ. (See Fig. 8

.)
Finally let A S be the arcs of Note that the arcs and vertices of V S , A S appear in all of Indeed, when deriving σ L the {LEFT → PAST, RIGHT → FUTURE}-restriction of µ, no arcs or vertices will become PAST-redundant, since they would previously have been LEFT-redundant in µ (here we use the fact that ι µ did not already label any vertices PAST, unlike FUTURE.)So the only vertices and arcs that are removed are ones that become FUTURE-redundant, i.e. previously had their vertices labelled RIGHT or FUTURE.By a similar argument Indeed, recall that for any arc a in D(N µ , T µ ), there is a set of vertices Q a such that a is y-redundant w.r.t (D(N µ , T µ ), φ µ , ι ′ ) if and only if ι(Q a ) = {y}, for any isolabelling ι.Note that we cannot have ι µ (Q a ) = {FUTURE}, as this implies that a is redundant w.r.t µ, a contradiction as µ is well-behaved.So if a is FUTURE-redundant after applying {L → PAST, R → FUTURE} (i.e. if a ∈ A ′ R ) then there is at least one z ∈ Q a with ι µ (z) ∈ R.But then this implies that a is not FUTURE-redundant after applying {R → PAST, L → FUTURE}, so a is not in A ′ L .A similar argument shows that V ′ L and V ′ R are disjoint.
We now describe the construction of an F -partial solution ψ = (D(N, T ), φ, ι).Let D(N, T ) be the display graph with vertex set We keep the partition of these sets into network side and tree side the same as before.)That is, Let the embedding function φ be defined as follows.For a tree vertex and so these terms are all welldefined and equal by construction).
Let the (L ∪ R ∪ S, {FUTURE})-isolabelling ι be defined as follows.For We will now show that ψ is indeed a well-behaved F -partial solution; afterwards we will show that µ is the {L → LEFT, R → RIGHT}-restriction of ψ, from which it follows that µ is valid.(A similar argument can be used to show that ψ L is the {R → FUTURE}-restriction of ψ and ψ R is the {L → FUTURE}restriction of ψ, but we will not need these fact so we do not prove them here.)Claim 3. ψ is a well-behaved F -partial solution.
Proof: We first show that ψ satisfies one of the properties of well-behaved To see this property, first consider the case that uv is an arc in D(N, T ).In this case it is sufficient to show that ι(u) = ι θ (u) and ι(v) = ι θ (v) for some θ ∈ {µ, ψ L , ψ R }, as the property then follows from the fact that µ, ψ L , ψ R are all well-behaved.
If uv ∈ A L then u ∈ V (D(N ψL , T ψL )) and either u ∈ V L or ι σL (u) = PAST and ι µ (u) = LEFT; in either case ι(u) = ι ψL (u), and similarly ι(v) = ι ψL (v), so we let θ = ψ L .Similarly if uv ∈ A R then θ = ψ R .For any arc uv in D(N µ , T µ ), we can let , so we do not need to consider this case.We also cannot have {ι µ (u), ι µ (v)} = {LEFT, RIGHT} as µ is well-behaved.It remains to consider the case that one of ι µ (u), ι µ (v) is LEFT or RIGHT and the other is in S; suppose w.l.o.g. that ι µ (u) = LEFT and ι µ (v) ∈ S. In this case both u and v are vertices of D(N σL , T σL ) and therefore D(N ψL , T ψL ); moreover ι(u) = ι ψL (u) and By the above discussion uv cannot be an arc.Moreover every internal vertex z on the shortest u − v path must have ι(z) = FUTURE (otherwise ι(z) ∈ L ∪ R ∪ S and u, z forms a shorter path).Note that any such z is also a vertex in D(N µ , T µ ) with ι µ (z) = FUTURE (no other possibility leads to ι(z) = FUTURE; in particular if ι µ (z) = LEFT then ι(z) = ι ψL (z) ∈ L).Any arc incident to z in D(N, T ) is also an arc in D(N µ , T µ ) (such arcs cannot be in A L or A R ).So it follows that the path from u to v also exists in D(N µ , T µ ).Finally, we must have ι µ (u), ι µ (v) ∈ S (they cannot be in {LEFT, RIGHT} as u, v have neighbours labelled FUTURE by ι µ and µ is well-behaved).So it then follows that there is a path from ι • D(N, T ) is a display graph: -D(N, T ) is acyclic: Suppose for a contradiction that D(N, T ) contains a cycle.If ι(u) ∈ L∪R∪S for some vertex u in this cycle, then as shown above the existence of a path from u to u in D(N, T ) implies the existence of a path from ι(u) It remains to consider the case that every vertex z in this cycle has ι(z) = FUTURE.However as argued previously, any z with ι(z) = FUTURE is also a vertex in D(N µ , T µ ), and all its incident arcs in D(N, T ) are also arcs of D(N µ , T µ ).Then we have that D(N µ , T µ ) contains a cycle, a contradiction as D(N µ , T µ ) is a display graph.
-T is an out-forest: As D(N, T ) is acyclic, it is remains to show that every vertex of T has in-degree at most 1 in T .To do this, we will show something stronger: that for any vertex v in D(N, T ), all of its incident arcs in D(N, T ) are arcs in D(N θ , T θ ), for some θ ∈ {µ, ψ L , ψ R }.
Then the desired property immediately follows, as every tree vertex has at most one incoming tree-arc in D(N θ , T θ ).So consider any vertex v ∈ D(N, T ).If v ∈ V L , then the only incident arcs of v are in A L , and therefore all these arcs in D(N ψL , T ψL ).Similarly if v ∈ V R then all incident arcs are in D(N ψR , T ψR ).So now we may assume v is a vertex of D(N µ , T µ ).If ι µ (v) = LEFT then v can have no incident arcs in A ′ R or A R (as any vertex incident to such an arc must be in V R or else have ι σR (u) = PAST and so ι µ (v) = RIGHT).Then all incident arcs of uv in D(N, T ) are also in D(N ψL , T ψL ).Similarly if ι µ (v) = LEFT then all incident arcs are in D(N ψR , T ψR ).Finally if ι µ (v) ∈ S ∪ {FUTURE}, then again none of its incident arcs are in A L or A R (as this would require ι σL (v) = PAST or ι σR (v) = PAST and so ι µ (v) ∈ {LEFT, RIGHT}), and so so all incident arcs are in D(N µ , T µ ).
-Every vertex in D(N, T ) has in-and out-degree at most 2 and total degree at most 3: This follows immediately from the previously-shown property that every vertex in D(N, T ) has all its incident arcs in one of D(N µ , T µ ), D(N ψL , T ψL ), D(N ψR , T ψR ), and the fact that this constraint holds for each of these graphs.
-Any vertex in V (N ) ∩ V (T ) has out-degree 0 and in-degree at most 1 in each of T 0 and N 0 : Again this follows from the fact that every vertex in D(N, T ) has all its incident arcs in one of D(N µ , T µ ), D(N ψL , T ψL ), D(N ψR , T ψR ).
To see that φ(uv) is a path from φ(u) to φ(v), we will show that there is The result then follows from the fact that φ θ is an embedding function.
If uv ∈ A L , then neither u nor v can be in V R , nor can they be in we have that u, v are vertices in D(N µ , T µ ), and therefore not in V L or V R .It follows by construction that φ(u) = φ µ (u), φ(v) = φ µ (u), and φ(uv) = φ µ (uv), so we let θ = µ.
Recall that V L is the set of vertices in D(N ψL , T ψL ) that become PASTredundant after applying {L → PAST}, and observe that by the definition of y-redundancy, a tree vertex u is y-redundant with respect to some containment structure -the paths {φ(uv) | uv ∈ A(T )} are arc-disjoint: Similar to the proof that φ(u) = φ(v) for u = v, we observe that if an arc uv is y-redundant with respect to some (D(N ′ , T ′ ), φ ′ , ι ′ ), then so are all the arcs of φ ′ (uv).It follows by construction that if uv ∈ A L (resp.A R , AL ′ , A ′ R , A S ) then so are all arcs of φ(uv).So now suppose for a contradiction that there exist distinct tree arcs uv, u ′ v ′ such that φ(uv), φ(u ′ v ′ ) share an arc.Then uv and u ′ v ′ are both in the same set from {A L , A R , A ′ L , A ′ R , A S }, and so in particular they are both in D(N θ , T θ ) for some θ ∈ {µ, ψ L , ψ R }, with φ(uv share an arc, a contradiction as φ θ is an embedding function. -for any distinct p, q ∈ A(T ), φ(p) and φ(q) share a vertex z only if p and q share a vertex w with z = φ(w): Here we use a couple of properties that have been proved earlier.Recall from the proof that T is an out-forest, that for any vertex v in D(N, T ), all its incident arcs in D(N, T ) are arcs in D(N θ , T θ ) for some θ ∈ {µ, ψ L , ψ R }. Recall also, from the proof that the paths {φ(uv)|uv ∈ A(T )} are arc disjoint, that a tree arc uv is in A L (resp.A R , A ′ L , A ′ R , A S ) then so are all arcs in φ(uv).So now consider distinct arcs p, q ∈ A(T ) and suppose φ(p) and φ(q) share a vertex z.Suppose all incdent arcs of z are in D(N µ , T µ ) (the cases where all incident arcs are in D(N ψL , T ψL ) or D(N ψR , T ψR ) are similar).Then all incident arcs of z from φ(p) and φ(q) are in A ′ L ∪ A ′ R ∪ A S , which implies that p, q are in A ′ L ∪ A ′ R ∪ A S as well.Thus p, q are both arcs in D(N µ , T µ ).It follows that φ(p) = φ µ (p) and φ(q) = φ µ (q) also share the vertex z, which implies that p, q share a vertex w with z = φ µ (w), as φ µ is an embedding function.
Then again as µ is well-behaved, uv is an arc in D(N µ , T µ ) and thus D(N, T ).It remains to consider the case where one of ι(u), ι(v) is in S and the other is in L or R. Suppose w.l.o.g. that ι(u) ∈ L, ι(v) ∈ S. Then ι(u) = ι ψL (u), and ι(v) = ι µ (v), seemingly a problem.However, notice that as ι µ (v) ∈ S, we also have that v is a vertex of D(N σL , T σL ) and , from which it follows that uv is an arc in D(N ψL , T ψL ) and thus D(N, T ).
, and so ψ(v) = z as required.By a similar argument, if z ∈ R then there is • Each vertex u of T with ι(u) = ι(φ(u)) has 2 out-arcs in D(N, T ) : In the case that ι(u) ∈ L ∪ R ∪ S, this follows from previously-shown properties.In particular, u is not in V (T ) ∩ V (N ), as this would imply φ(u) = u (because φ is an embedding function) and thus ι(u) = ι(φ(u)).Then u / ∈ V (N ), which implies ι(u) / ∈ V (N IN ) as ι is an isolabelling.Thus we may assume ι(u) is an internal vertex of T IN , which has out-degree 2 as T IN is binary.As we have just shown that u with ι(u) ∈ L ∪ R ∪ S has the same in-and out-degree in D(N, T ) as ι(u) in D IN (N IN , T IN ), this implies that u has out-degree 2 in D(N, T ), as required.
The above conditions show that ψ is a (L ∪ R ∪ S, {FUTURE})-containment structure, i.e. an F -partial solution.Next we show that ψ is well-behaved: • D(N, T ) contains no redundant arcs or vertices: Suppose for a contradiction that there is a redundant arc or vertex w.r.t.ψ.We will show that such an arc or vertex is also redundant w.r.t µ, a contradiction as µ is well-behaved.
Consider the case where a tree arc uv is redundant w.r.t ψ.Then uv is necessarily FUTUREredundant, which implies that ι(u) = ι(v) = FUTURE.It follows by construction of ι that u, v are vertices of D(N µ , T µ ) with ι µ (u) = ι µ (v) = FUTURE.In addition, we have that ι(z) = FUTURE for any z ∈ V (φ(uv)), which again implies ι µ (v) = FUTURE for any such edge.Finally φ(uv) = φ ψ (uv) (as the arc uv is in one of A ′ L , A ′ R , A S ) , and so ι µ (z) = FUTURE for all z ∈ {u, v, } ∪V (φ µ (uv)).It follows that uv is FUTURE-redundant w.r.t µ, the desired contradiction.
Essentially the same arguments can also be used for redundant network arcs and redundant tree or network vertices.
• For any y, y ′ ∈ {FUTURE} with y = y, there is no arc uv in D(N, T ) for which ι(u) = y and ι(v) = y ′ : This follows immediately from the fact that |{FUTURE}| = 1, so there are no such y, y ′ .
• We now have that ψ satisfies all the conditions of a well-behaved F -partial solution.Finally we need to show that µ is the {L → LEFT, R → RIGHT}-restriction of ψ.
with the arcs of A L ∪ A R and vertices of V L ∪ V R removed.To do this, we will show that after applying {L → LEFT, R → RIGHT}, the LEFT-redundant arcs (resp.vertices) are exactly A L (V L ) and the RIGHT-redundant arcs (vertices) are exactly A R (V R ).
Recall that for any arc or vertex a in D(N, T ), a is y-redundant w.r.t (D(N, T ), φ, ι ′ ) if and only if ι(Q a ) = {y}, for some set Q a of vertices that depends only on D(N, T ) and φ.Note that Q a always contains a itself, if a is a vertex, or the vertices of a, if a is an arc So now let Q a be the set of vertices that determines whether a is y-redundant for (D(N, T ), φ), and let Q ′ a denote the set of vertices that determine whether a is y-redundant for (D(N ψL , T ψL ), φ ψL ), where a is any arc or vertex that in D(N ψL , T ψL ).Note that , unless there is an arc a ′ in D(N, T ) with a ∈ A(φ(a ′ )) and a ′ not in D(N ψL , T ψL ).Note however that this requires that a ′ ∈ A ′ R ∪ A R , which as argued previously would imply that A(φ(a ′ )) ⊆ A ′ R ∪ A R , a contradiction to the fact that ι(u), ι(v) ∈ L. If a is a vertex, a similar argument applies: with Q a = Q ′ a unless D(N, T ) has arcs in A R ∪ A ′ R incident to a or a ′ (with a ′ a possible vertex such that φ(a) = a ′ or φ(a ′ ) = a).But as ι(a), ι(a ′ ) ∈ L, this cannot happen.Thus in either case we have Q ′ a = Q a ⊆ L. We can now show that an arc or vertex a in D(N, T ) is LEFT-redundant w.r.t (D(N, T ), φ, ι • g) if and only if a is in D(N ψL , T ψL ) and a is PAST-redundant w.r.t.(D(N ψL , T ψL ), φ ψL , ι ψL • g ′ ), where g is the function {L → LEFT, R → RIGHT}, g ′ is the function {L → PAST}.Indeed we may assume that all vertices in a are mapped to elements of L, as otherwise neither side holds.Then it remains to observe that a is LEFT-redundant w.r.t As such, after applying g = {L → LEFT, R → RIGHT} the LEFT-redundant arcs and vertices in D(N, T ) are exactly A L , V L .A similar argument shows that the RIGHT-redundant arcs and vertices • φ µ = φ µ ′ : Here we use the fact that D(N µ , T µ ) = D(N µ ′ , T µ ′ ).Thus every tree arc uv of from which it follows by construction that φ(uv) = φ µ (uv).Similarly as tree every vertex u of we have φ(u) = φ µ (u).Then as φ µ ′ is the restriction of µ to the tree vertices of V ′ L ∪ V ′ R ∪ V S and the tree arcs of A ′ L ∪ A ′ R ∪ A S , we have φ µ ′ = φ µ , as required.
As we have now shown that ψ is a well-behaved F -partial solution and µ is the {L → LEFT, R → RIGHT}-restriction of ψ, we have that µ is valid, as required.
From the three previous lemmas we immediately have Lemma 12.

Compressing signatures
So far, we have shown relations between valid signatures such that the validity of any signature σ for a bag (P, S, F ) in the tree decomposition of D IN (N IN , T IN ) is determined by the validity of all signatures for the child bags of (P, S, F ).The final step is to contract certain long paths that may occur in the signature.This is necessary in order to bound the size, and thus the number of possible signatures, for a given bag.This is summarized by the notion of compact signatures, described below.
All our results relating the validity of well-behaved signatures also hold for compact signatures, that is, whether a compact signature is compact-valid can be determined by looking at the compact signatures for the child bags.(See Lemmas 23 to 26.) Definition 11 (compact form).Let ψ = (D(N, T ), φ, ι) be a well-behaved (S, Y)-containment structure.Then the compact form of ψ, denoted c(ψ), is the (S, Y)-containment signature derived from ψ as follows: For y ∈ Y: • if there is a path x 1 , x 2 , x 3 in N with x 2 having in-degree 1 and out-degree 1 in N , and ι({x 1 , x 2 , x 3 }) = {y}, and φ(u) = x 2 for any vertex u in T , then delete vertex x 2 and arcs x 1 x 2 , x 2 x 3 from N , and add the arc x 1 x 3 .For the arc uv in T for which x 1 x 2 x 3 is part of the path φ(uv), replace x 1 x 2 x 3 in φ(uv) with x 1 x 3 .
That is, we suppress a vertex x in N (and adjust φ as necessary), if x has a single in-neighbour and out-neighbour, and all three are mapped to a label y ∈ Y by ι, and no vertex of T is mapped to x by φ.
We call such a path a long y-path and refer to the above process as suppressing long y-paths.
If c(ψ) = ψ then we say ψ is a compact (S, Y)-containment structure.We call a compact signature σ for (P, S, F ) compact-valid if there is a compact F -partial solution ψ such that σ = c(σ ′ ) for σ ′ is the (P → PAST)-restriction of ψ.
Note that by definition, any compact (S, Y)-containment structure is also a well-behaved (S, Y)-containment structure.
Proof: Let ψ = (D(N, T ), φ, ι) and let c(ψ) = (D ′ (N ′ , T ′ ), φ ′ , ι ′ ).It is clear from the construction of c(ψ) that D ′ (N ′ , T ′ ) is a display graph and that φ ′ is an embedding of T ′ into N ′ .Moreover ι ′ (u) = ι(u) for each vertex u in D ′ (N ′ , T ′ ), and the only vertices of D(N, T ) that were suppressed in the construction of D ′ (N, T ′ ) ′ were vertices v for which ι(v) ∈ {PAST, FUTURE}.As such ι ′ satisfies all the requirements for the isolabelling function in a (S, Y)-containment structure, and so It is also clear that c(ψ) is well-behaved, by construction and the fact that ψ is well-behaved.Finally observe that D(N ′ , T ′ ) contains no long y-paths for any y ∈ Y, a all such paths are suppressed in the construction of ψ ′ .
We will now show that for the purposes of our dynamic programming algorithm, it is enough to restrict our attention to compact signatures.This allows us to get an FPT bound on the number of signatures we have to consider.In order to do this, we define an analogue of "restriction" that allows us to derive compact (S ′ , Y)-containment structures from (S, Y)-containment structures.
Definition 12 (compact restriction).Let ψ = (D(N, T ), φ, ι) be an (S, Y)-containment structure, let S ′ ⊆ S, and let g : S ∪ Y → S ′ ∪ Y be a restriction function (i.e.such that for all v ∈ S ∪ Y, g(v) = v if v ∈ S ′ and g(v) ∈ Y otherwise).Then we define the compact-g-restriction of ψ to be the compact form of the g-restriction of ψ.
When σ is a compact signature for (P, S, F ), we say that σ is compact-valid if there is a compact F -partial solution ψ such that σ is the compact-{P → PAST}-restriction of ψ.
Similarly, when µ is a compact reconciliation for (L ∪ R, S, F ), we say µ is compact-valid if there is a compact F -partial solution ψ such that µ is the compact-{L → LEFT, R → RIGHT}-restriction of ψ.
• For any new path u 1 = u, . . ., u j = v created this way, if uv is part of the path φ(u ′ v ′ ) for a tree arc u ′ v ′ then replace uv in this path with u 1 , . . .u j .
Observe that σ = c(σ 0 ) if and only if σ is compact and σ 0 is a subdivision of σ.
Proof: It is sufficient to show that for each a ∈ A(D(N, T )), any arc or internal vertex of P a in σ 0 is y-redundant w.r.t.(D(N 0 , T 0 ), φ 0 , ι 0 • g) if and only if a is y-redundant w.r.t.(D(N, T ), φ, ι • g) This can be seen by construction of σ 0 , in particular the fact that P a is part of the path φ 0 (u ′ v ′ ) if and only if a is part of the path φ(u ′ v ′ ), and the fact that ι 0 (z) = ι(u) = ι(v) (and thus g(ι(u))) = g(ι(u)) = g(ι(v))) for every vertex in P a .
Lemma 20.Let σ be a well-behaved signature for a bag (P, S, F ).If σ is valid then c(σ) is compactvalid.
Similarly if µ is a well-behaved reconciliation for a Join bag (L ∪ R, S, F ) and µ is valid, then c(µ) is compact-valid.
Proof: Suppose a signature σ is valid and let ψ be the F -partial solution such that σ is the {P → PAST}restriction of ψ.Then c(ψ) is compact F -partial solution, and by Lemma 19, c(σ) is the compact-{P → PAST}-restriction of c(ψ).Thus c(ψ) is compact-valid, as required.
For the case that a reconciliation µ is valid, a similar argument holds, using the restriction function {L → LEFT, R → RIGHT} instead of {P → PAST}.
Lemma 21.Let σ be a compact signature for a bag (P, S, F ).If σ is compact-valid then there is a valid signature σ 0 for (P, S, F ) such that σ = c(σ 0 ) is compact-valid.
Similarly if µ is a compact reconciliation for a Join bag (L ∪ R, S, F ) and µ is compact-valid, then there is a valid reconciliation µ 0 for(L ∪ R, S, F ) such that µ = c(µ 0 ).
Proof: Suppose a compact signature σ is compact-valid and let ψ be the compact F -partial solution such that σ is the compact-{P → PAST}-restriction of ψ.Let σ 0 be the {P → PAST}-restriction of ψ.Then σ 0 is a valid signature for (P, S, F ), and by construction σ = c(σ 0 ).
For the case that a compact reconciliation µ is compact-valid, a similar argument holds.
Proof: Let σ = (D(N, T ), φ, ι) and σ ′ = D(N ′ , T ′ ), φ ′ , ι ′ ).Suppose for a contradiction that σ has a long y-path for some y / ∈ {y 1 , . . ., y j }.Thus in particular, there is a path x 1 , x 2 , x 3 in N ′ with x 2 having in-degree and out-degree 1, and ι ′ (x 1 ) = ι(x 2 ) = ι ′ (x 3 ) = y.Then by construction, x 1 , x 2 , x 3 is also a path in N , and ι(x 1 ) = ι(x 2 ) = ι(x 3 ) = y (since the restriction function (S 1 → y 1 , . . ., S j → y j ) does not assign y to any vertex that was not already labelled y by ι).Furthermore x 2 cannot have any other incident arcs beside x 1 x 2 and x 2 x 3 , as such arcs would not become redundant after applying (S 1 → y 1 , . . ., S j → y j ), and so such arcs would be in N ′ as well.It follows that σ has a long y-path, contradicting the assumption that σ is compact.
For the converse, assume σ ′ = (D(N ′ , T ), φ ′ , ι ′ ) is compact-valid, and let ψ ′ be the compact F ′partial solution such that σ ′ is the compact-{P → PAST}-restriction of ψ ′ .Let σ ′ 0 be the {P ′ → PAST}restriction of ψ ′ , so σ ′ 0 is a subdivision of σ ′ .In addition let σ ′′ be the {{z} → FUTURE}-restriction of σ, so σ ′′ is also a subdivision of σ ′ .Let A p be the subset of arcs in N ′ that are subdivided by one or more additional vertices to produce σ ′ 0 .Similarly let A f be the subset of arcs in N ′ that are subdivided by one or more additional vertices to produce σ ′′ .
By Lemma 22, σ ′′ has no long PAST-paths and σ ′ 0 has no long FUTURE-paths.Thus the sets of arcs A p and A f are disjoint (as ι ′ (u) = ι ′ (v) = PAST for any uv ∈ A p , and ι ′ (u) = ι ′ (v) = FUTURE for any uv ∈ A f ).So now for each arc uv in N ′ , define P uv to be the path corresponding to uv in σ ′ 0 if uv ∈ A p , let P uv be the path corresponding to uv in σ ′′ if uv ∈ A f , and let P uv be the single arc uv otherwise.Now define σ * to be the subdivision of σ ′ derived by replacing every arc uv in N by P uv .Now we have that σ * is also a subdivision of σ ′ 0 (by subdividing arcs of A p ) and also of σ ′′ (by subdividing arcs of A f , and also that σ ′ = c(σ * ) (as σ ′ is compact).(See Fig. 9.) We now claim that σ * is a valid signature for (P ′ , S ′ , F ′ ).To see this, Let ψ * be the subdivision of ψ ′ compact-valid signature for (L, S, F ∪ R) and σ R is a compact-valid signature for (R, S, F ∪ L), then µ is compact-valid.
The proof is along similar lines to Lemma 25, but with more containment structures.Before we can proceed, we first show that the the {LEFT → PAST, RIGHT → FUTURE}-restriction of µ is in fact compact, and therefore σ L is the {LEFT → PAST, RIGHT → FUTURE}-restriction of µ, as well as the compact-{LEFT → PAST, RIGHT → FUTURE}-restriction of µ.
Indeed, let σ ′′ L denote the {LEFT → PAST, RIGHT → FUTURE}-restriction of µ, and suppose for a contradiction that σ ′′ L contains a long y-path for some y ∈ {PAST, FUTURE}.Thus there is a path x 1 , x 2 , x 3 in N σ ′′ L where x 2 has in-degree and out-degree 1 and ι σ Otherwise y = FUTURE, and ι µ (x 1 ), ι µ (x 2 ), ι µ (x 3 ) are all in {RIGHT, FUTURE}.But note that all three of ι µ (x 1 ), ι µ (x 2 ), ι µ (x 3 ) must be the same value, otherwise µ has an arc uv with ι µ ({u, v}) = {RIGHT, FUTURE} and µ is not well-behaved.So if x 2 has in-degree and out-degree 1 in N µ , then µ has a long y-path for y = ι µ (u), a contradiction as µ is compact.Otherwise, suppose x 2 has an incident arc x 2 z for z = x 3 (the case of an incident arc zx 2 is similar).As x 2 z is not an arc in N σ ′′ L , it must hold that ι µ (z) = ι µ (x 2 ) (otherwise the arc would not become redundant or µ is not well-behaved).Then since x 2 z is not redundant w.r.t µ, there is some tree arc uv in T µ such that x 2 z is an arc of φ µ (uv).But this implies also that x 1 x 2 is also arc of φ µ (uv), as x 2 = ι µ (u).Thus x 2 z is deleted in the construction of σ ′′ L only if uv is, which would in turn imply that x 1 x 2 is deleted, again a contradiction.
So we may assume that σ ′′ L is compact and thus σ ′′ L = c(σ ′′ L ) = σ L , so σ L is the {LEFT → PAST, RIGHT → FUTURE}-restriction of µ.A similar argument shows that σ R is the {RIGHT → PAST, LEFT → FUTURE}restriction of µ.
So now assume that σ L and σ R are both compact-valid.Let ψ L denote the compact F ∪ R-partial solution for which σ L is the compact {L → PAST}-restriction, and let σ ′ L be the {L → PAST}-restriction of ψ L , so that σ L = c(σ ′ L ).Similarly let ψ R denote the compact F ∪L-partial solution for which σ R is the compact {R → PAST}-restriction, and let σ ′ R be the {R → PAST}-restriction of ψ R , so that σ R = c(σ ′ R ). (See Fig. 10) By Lemma 22, the only long-y-paths in σ ′ L are for y = PAST.So σ ′ L is a subdivision of σ L in which the only subdivided arc are those uv for which ι σL (u) = ι σL (v) = PAST.So let A L the set of these arcs, and for each uv ∈ A L let P uv be the corresponding path in N σ ′ L .Similarly let A R be the set of arcs in N σR that are subdivided to produce σ ′ R from σ R (noting that ι σR (u) = ι σR (v) = PAST for any uv ∈ A R ), and let P uv be the corresponding path in N σ ′ R for each uv ∈ A R .Observe that since ι σL (u) = PAST implies ι µ (u) = LEFT and ι σR (u) = PAST implies ι µ (u) = RIGHT, the arc sets A L and A R are disjoint.Now let σ * L be the subdivision of σ ′ L (not σ L ) by replacing uv with P uv for all uv ∈ A R ∩ A(N σ ′ L ).Equivalently, σ * L is the subdivision of σ L derived by replacing uv with P uv for all arcs uv in A L is a valid signature for (L, S, R ∪ F ).To see this, let ψ * L be the subdivision of ψ L derived by replacing uv with P uv for every uv in A L ∪ (A R ∩ A(N ψL )).Then by Lemma 18 and the fact that σ ′ L is the {L → PAST}-restriction of ψ L , we have that σ * L is the {L → PAST}-restriction of ψ * L .Thus ψ * L is valid, and a similar argument shows that L , µ * R ) be the subdivision of µ derived by replacing uv with P uv for all uv in A L ∪ A R (respectively A L , A R ).Note that µ * is also a subdivision of both µ * L and µ * R .Using a similar approach to before, by Lemma 18 and the fact that σ L is the {LEFT → PAST, RIGHT → FUTURE}-restriction of µ, we can show that σ ′ L is the {LEFT → PAST, RIGHT → FUTURE}-restriction of µ * L .Using this fact in turn together with Lemma 18, we can show that σ * L is the {LEFT → PAST, RIGHT → FUTURE}-restriction of µ * .Similarly we can show that σ * R is the {RIGHT → PAST, LEFT → FUTURE}restriction of µ * .
If σ * L is a valid signature for (L, S, F ∪R) which is the {LEFT → PAST, RIGHT → FUTURE}-restriction of µ * , and σ * R is a valid signature for (R, S, F ∪ L) which is the {RIGHT → PAST, LEFT → FUTURE}restriction of µ * , we can now apply Lemma 14 to see that µ * is a valid reconciliation for (L ∪ R, S, F ).
It remains to observe that as µ * is valid and µ = c(µ * ), Lemma 20 implies that µ * is compact-valid.
From Lemmas 26 to 28 we have the following: Corollary 2. Let (L ∪ R, S, F ) be a Join bag with child bags (L, S, F ∪ R) and (R, S, F ∪ L), and let σ be a compact signature for (L ∪ R, S, F ). Then σ is compact-valid if and only if there is a compact reconciliation µ for (L ∪ R, S, F ), and compact-valid signatures σ L for (L, S, F ∪ R) and σ R for (R, S, F ∪ L), such that σ is the compact-{{LEFT, RIGHT} → PAST}-restriction of µ, σ L is the compact-{LEFT → PAST, RIGHT → FUTURE}-restriction of µ, and σ R is the compact-{RIGHT → PAST, LEFT → FUTURE}-restriction of µ.

Algorithm and running time
Algorithm 1 gives a summary of our algorithm for TREE CONTAINMENT.To summarise: we compute for each bag x = (P, S, F ) in the tree decomposition, a set CV x of compact-valid signatures for x -that is, compact signatures for which there exists a corresponding F -partial solution.The algorithm uses compactrestrictions to convert a compact signature of one bag into a compact signature for a different bag.Recall that such a restriction works by mapping certain vertices to a label PAST or FUTURE, removing redundant parts of the display graph and collapsing long paths, similarly to the process described in Section 2.3.See Sections 3.3 and 3.8 for the formal definitions.For join bags, the algorithm uses reconciliations, 3-way analogues of signatures, using labels {LEFT, RIGHT, FUTURE} instead of {PAST, FUTURE}, see Section 3.7.The correctness of the computation of the sets CV x follows from Lemmas 23 to 25 and Corollary 2. The correctness of the last three lines, in which we return TRUE if and only if there is a compact-valid signature (D(N, T ), φ, ι) for the root bag with ι −1 (FUTURE) = ∅, is a consequence of Corollary 1.
To show that the running time is bounded in a function in the treewidth of N , the main challenge is to bound the number of compact signatures for a bag (P, S, F ) by a function of |S| (which, by Theorem 1, we may assume is at most 2tw(N ) + 1).In order to do this, we first bound the size of the display graph D(N, T ) in a signature by a function of |S|.We will then use this to bound the number of possible display graphs, embedding functions and isolabellings, and thus the number of compact signatures.Proof: Let σ = (D(N, T ), φ, ι) be a compact signature for (P, S, F ).
We first bound the number of arcs in D(N, T ).To do this, let A S denote the subset of arcs in D(N, T ) incident to a vertex in ι −1 (S).As there is only one vertex u with ι(u) = s for each s ∈ S and every vertex in D(N, T ) has total degree at most 3, we have that |A S | ≤ 3|S|.As φ(uv) and φ(u ′ v ′ ) are arc-disjoint for any distinct tree arcs uv, u ′ v ′ , it follows that there are at most |A S ∩ A(N )| arcs uv of T for which φ(uv) contains an arc from A S .There are at most |A S ∩ A(T )| arcs in T incident to a vertex from ι −1 (S).Thus there are at most |A S | arcs uv in T for which {u, v} ∪ V (φ(uv)) contains a vertex from ι −1 (S).
If ι(u) = ι(v) = PAST and ι(V (φ(uv))) = {PAST}, then uv is redundant w.r.t {PAST}, a contradiction as we may assume no valid signature has a {PAST}-redundant arc.Similarly we have a contradiction if ι(u) = ι(v) = FUTURE and ι(V (φ(uv))) = {FUTURE}.So it must be the case that for all but at most 3|S| tree arcs uv, either ι(u) = ι(v) = PAST and ι(φ(uv)) = {FUTURE}, or ι(u) = ι(v) = FUTURE and ι(φ(uv)) = {PAST}.In particular, we have that ι(φ(v)) = ι(v) and, so v has out-degree 2 It follows any lowest arc uv in T is one of the at most |A S | arcs {u, v} ∪ V (φ(uv)) that contains a vertex from ι −1 (S).There are at most |S| isolated vertices u in V (D(N, T )) for which ι(u) ∈ S. For the rest, If u ∈ V (T ) and φ(u) ∈ V (N ) are both isolated vertices then we have ι(u) = ι(φ(u) ∈ {PAST, FUTURE} (as ι(u) = ι(φ(u)) would imply u has out-degree 2 and so u and φ(u) are both redundant w.r.t σ.Similarly if v is an isolated network vertex with no u ∈ V (T ) for which φ(u) = v, then v is redundant w.r.t σ.As σ has no redundant vertices (since σ is well-behaved), it follows that every isolated vertex in D(N, T ) is either a tree vertex u with φ(u) not isolated, a network vertex v = φ(u) for which u is not isolated, or a vertex of ι −1 (S).As there are at most 30|S| non-isolated vertices, it follows that there are at most 30|S| + |S| isolated vertices.
Thus For each vertex u ∈ V (D(N, T )), there are at most (|S| − 1) + 2 ≤ k + 2 possibilities for ι(u), as ι(u) is either a vertex in S other than u or one of the labels PAST and FUTURE (LEFT, RIGHT, and FUTURE for a reconciliations).Thus, the number of possible isolabelings for a given display graph D(N, T ) is Now, to bound the number of possible embedding functions φ, observe that φ is fixed by (a) specifying φ(u) for every tree vertex u (|V (N )| |V (T )| ∈ k O(k) possibilities) and (b) the set of arcs in N that appear in some path φ(uv) (2 |A(N )| ∈ 2 O(k 2 ) possibilities) -indeed, if this set of arcs is chosen correctly, then it contains only one path from φ(u) to φ(v), which must be the path φ(uv).Thus, for any fixed display graph D(N, T ), the number of possible embedding functions is upper-bounded by 2 O(k 2 ) =: f 3 (k).Now, for any bag (P, S, F ), the number of possible choices for σ = (D(N, T ), φ, ι) is bounded by

Future work
Before implementing our dynamic programming algorithm, one should first try to reduce the constant in the bound on the number of possible signatures as much as possible.Such reductions may be possible for instance by imposing further structural constraints on the signatures that need to be considered.It would also be important to find ways of generating valid signatures for one bag directly from the valid signatures if its child bag(s), rather than generating all possible signatures and then removing the invalid ones.
From a theoretical point of view, there are many opportunities for future work.First, there are multiple variants and generalizations of TREE CONTAINMENT that deserve attention, including non-binary inputs, and inputs consisting of two networks (i.e.where the task is to decide if a network is contained in a second network).For the latter problem our approach would have to be extensively modified, since our size-bound on the signatures heavily relies on T IN being a tree.In the case of non-binary inputs, it is likely that a similar approach to the one in this paper would allow us to get a size-bound on the tree side of each signature.However, more work would be needed in order to prove a bound on the network side, and the number of possible embeddings.Note in particular that, under our current approach for deriving signatures from (partial) solutions, all neighbours of S are preserved.Without a bound on the degrees, the number of such vertices can be much larger than the treewidth of D IN (N IN , T IN )).This can lead to an explosion in the length of 'compact' paths and the number of possible embeddings that one may need to consider for a single bag.Such explosions may be avoidable through clever bookkeeping, or it may be that they are unavoidable and can be used to force a W [1]-hardness reduction.
Second, a major open problem is whether the HYBRIDIZATION NUMBER problem is FPT with respect to the treewidth of the output network.Again there are different variants: rooted and unrooted, binary and non-binary, a fixed or unbounded number of input trees.For some applications, the definition of an embedding has to be relaxed (allowing, for example, multiple tree arcs embedded into the same network arc) [HMSW16,HLM21].Other interesting candidate problems for treewidth-based algorithms include phylogenetic network drawing [KS20], orienting phylogenetic networks [HvIJ + 19] and phylogenetic tree inference with duplications [vIJJ + 19].
Finally, we believe that the approach taken in this paper (applying dynamic programming techniques on a tree decomposition of single graph representing all the input data, with careful attention given to the interaction between past and future) could potentially have applications outside of phylogenetics, in any context where the input to a problem consists of two or more distinct partially-labelled graphs that need to be reconciled.

2Figure 1 :
Figure 1: Left: a phylogenetic tree T .Middle: a phylogenetic network N displaying T (solid lines indicate an embedding of T ; black nodes indicate reticulations).Right: the display graph D(N, T ) of N and T (see Section 1.4) with the network part drawn on top and the tree part drawn on the bottom.Note that vertices of the display graph are not labelled.In the figure, the leaves (square vertices) are ordered in the same way as in N .
out-degree 0 and in-degree at most 1 in both T and N := D[V N ].Herein, we call T the tree side and N the network side of D and we will use the term D(N, T ) to denote a display graph with network side N and tree side T .Given a phylogenetic network N IN and phylogenetic tree T IN with the same leaf-label set, we define D IN (N IN , T IN ) to be the display graph formed by taking the disjoint union of N IN and T IN and identifying pairs of leaves that have the same label.We note that, while the leaves of N IN and T IN were originally labelled, this labelling does not appear in D IN (N IN , T IN ).Labels are used to construct D IN (N IN , T IN ), but in the rest of the paper we will not need to consider them.Indeed, such labels are relevant to the TREE CONTAINMENT problem only insofar as they establish a relation between the leaves of T IN and N IN , and this relation is now captured by the structure of D IN (N IN , T IN ).

Lemma 1 .
A phylogenetic network N IN displays a phylogenetic tree T IN if and only if there is an embedding function on D IN (N IN , T IN ).Proof: Suppose first that N IN displays T IN , that is, there is a subgraph T ′ IN of N IN that is a subdivision of T IN .Then, every vertex of T IN corresponds to a vertex of T ′ IN and every arc uv in T IN corresponds to a directed path in T ′ IN between the vertices corresponding to u and v. Let φ denote this correspondence relation.Then, (c) of Definition 2 follows from the definition of D IN (N IN , T IN ) while the other properties follow from φ being an isomorphism (of a subdivision of T IN into T ′ IN ).Conversely, suppose that there is an embedding function φ on D IN (N IN , T IN ) and let T ′ IN be the subgraph formed by the arcs of N IN that are part of some path φ(uv) for an arc uv in T .Then, it can be verified that T ′ IN is a subdivision of T IN .In light of Lemma 1, we may henceforth view TREE CONTAINMENT as the following problem: Input: phylogenetic network N IN and phylogenetic tree T IN with the same leaf-label set Task: Find an embedding function on D IN (N IN , T IN ).
We study TREE CONTAINMENT parameterized by the treewidth of the input network N IN .A key tool will be the following theorem from [JJK + 19].In this theorem, the display graph D IN (N u , T u ) for unrooted N u and T u is defined analogously to D IN (N IN , T IN ) for rooted N IN , T IN -that is, it is the (undirected) graph derived from the disjoint union of N u and T u by identifying leaves with the same label.Theorem 1 ([JJK + 19]).Let N u and T u be an unrooted binary phylogenetic network and tree, respectively, with the same leaf-label set.If N u displays T u then tw(D IN (N u , T u )) ≤ 2tw(N u ) + 1.By Theorem 1, we suppose that the display graph D IN (N IN , T IN ) has treewidth at most 2k + 1, where k is the treewidth of the underlying undirected graph N u of N IN , as otherwise tw(D IN (N IN , T IN )) = tw(D IN (N u , T u )) > 2k + 1 and N u does not display the unrooted version T u of T IN , implying that N IN does not display T IN .

Figure 3 :
Figure 3: Example of a signature of a bag (P, S, F ).The S-part of D(NIN, TIN) is solid while the non-S part is faded.The embedding φ (right, indicated with gray edge-highlight) maps T into N .The dotted arcs labelled ι show the isomorphism between part of D(N, T ) and S ⊆ V (D(NIN, TIN)).Note that the part of D(N, T ) that is not mapped to S is not necessarily isomorphic to anything in D(NIN, TIN).
T ), • an embedding function φ on D(N, T ), and • an (S, Y)-isolabelling ι : V (D(N, T )) → S ∪ Y.In addition, each vertex u of D(N, T ) should satisfy the following properties: (a) if ι(u) ∈ S, then u has the same in-and out-degree in D(N, T ) as ι(u) in D IN (N IN , T IN ).(b) if u ∈ T and ι(u) = ι(φ(u)), then u has 2 out-arcs in D(N, T ).See Fig. 3 for an example of an (S, {PAST, FUTURE})-containment structure (D(N, T ), φ, ι).The last two properties of Definition 4 are used for bookkeeping, and to help bound the size of the display graph.Definition 5 (signature).Let (P, S, F ) be a bag in the tree decomposition of D IN (N IN , T IN ).Then any (S, {PAST, FUTURE})-containment structure is called a signature for (P, S, F ).
Definition 4).Thus, ι is a bijective function between V (D(N, T )) and V (D IN (N IN , T IN )) and, by Definition 3(c), uv is an arc in D(N, T ) if and only if and T is isomorphic to T IN (as ι maps vertices of N to vertices of N IN and vertices of T to vertices of T IN by Definition 3(a)).As φ is an embedding function on D(N, T ), combining ι with φ yields an embedding function on D IN (N IN , T IN ).Conversely, suppose that there is an embedding function φ on D IN (N IN , T IN ).Let ι be the identity function on V (D IN (N IN , T IN )) and note that, by Definition 3, ι is a (V (D IN (N IN , T IN )), Y)-isolabelling on V (D IN (N IN , T IN )) and ι −1 (Y) = ∅.Then, (D IN (N IN , T IN ), φ, ι) satisfies the first three conditions of an (S, Y)-containment structure.The remaining properties, concerning the degrees of vertices, follow from the fact that N IN and T IN are binary.In particular, for any vertex u in T IN with ι(u) = ι(φ(u)), it holds that u = φ(u) and so u is not a leaf of T IN and, thus, has out-degree 2 in D IN (N IN , T IN ).

Observation 1 .Figure 4 :
Figure 4: Illustration of Definition 7 (except non-Y parts of ι and ι ′ ).Left: The example containment structure ψ of Fig. 3.The dashed area indicates S ′ and g: for all u in the dashed area, g(ι(u)) = PAST while ι(u) /∈ {PAST, FUTURE}.Right: The g-restriction of ψ.In accordance with Definition 7, note how (a) arcs in the "PAST"-area of N that are not mapped to by φ disappear in N ′ while arcs that are mapped by φ persist, (b) many of the arcs in T are in the "PAST"-area, but embedded by φ into paths of N that live (at least partially) in the "FUTURE"-area of N and, therefore, also persist, and (c) a common leaf of T and N has been removed since all its incoming arcs have been deleted.Finally, as will be the case in the dynamic programming later on, the "PAST"-and "FUTURE"-areas never touch in D(N ′ , T ′ ).
we know that uv is deleted in the construction of D(N * , T * ).Vertices: Since each arc of D(N, T ) is in D(N * , T * ) if and only if it is in D(N ′′ , T ′′ ), all vertices with at least one incident arc in D(N * , T * ) are in D(N ′′ , T ′′ ) and vice versa.It remains to consider the isolated vertices.To this end, let v ∈ V (D(N, T )) with no incident arcs in D(N * , T * ) and let

Definition 8 .
An (S, Y)-containment structure (D(N, T ), φ, ι) is called well-behaved if (a) D(N, T ) contains no redundant arcs or vertices; (b) For all arcs uv in D(N, T ) with ι we know that ι is an isomorphism between D(N, T ) and V (D IN (N IN , T IN )), implying Definition 8(c), while (a) and (b) are direct consequences of ι −1 (Y) = ∅.
(a) follows by Definition 7, as redundant arcs and vertices are deleted when constructing σ. (b): Let uv be an arc of D

Lemma 7 .
Let (N IN , T IN ) be a YES-instance of TREE CONTAINMENT and let (P, S, F ) be a bag in the tree decomposition of D IN (N IN , T IN ).Then, there is a well-behaved F -partial solution ψ, and a valid signature σ for (P, S, F ).

Figure 5 :
Figure5: Illustration of proof for Introduce bags, validity of σ implies validity of σ ′ .Solid lines are restriction relations that we may assume; the dashed line shows the construction of ψ ′ from ψ; dotted lines are relations we can infer using transitivity.

Figure 6 :
Figure 6: Illustration of proof for Introduce bags, validity of σ ′ implies validity of σ.Solid lines are restriction relations that we may assume; the dashed lines show the construction of ψ from ψ ′ or σ (we do not describe the construction of φ0 or ι0 in the figure, only the construction of D(N0, T0) by adding arcs and vertices); the dotted line shows the relation we want to prove, that σ is the {P → PAST}-restriction of ψ.

Lemma 16 .Figure 7 :
Figure7: Illustration of proof for reconciliations on Join bags, validity of µ implies validity of σL and σR.Solid lines are restriction relations that we may assume; the dashed lines shows the construction of ψL and ψR from ψ; dotted lines are relations we can infer using (multiple uses of) transitivity.

Figure 8 :
Figure 8: Illustration of proof for reconciliations on Join bags, validity of σL and σR implies validity of µ.Solid lines are restriction relations that we may assume; the dashed lines show the construction of ψ from ψL or ψR (we do not describe the construction of φ0 or ι0 in the figure, only the construction of D(N0, T0) by adding arcs and vertices); the dotted line shows the relation we want to prove, that µ is the {L → LEFT, R → RIGHT}-restriction of ψ.
the same in-and out-degree in D(N, T ) as ι(u) in D IN (N IN , T IN ): Recall, from the proof that T is an out-forest, that any vertex v in D(N, T ) has all its incident vertices contained in D(N θ , T θ ), for some θ ∈ {ψ L , ψ R , µ}.Moreover if u ∈ V L or ι µ (u) = LEFT (in which case ψ(u) = ψ L (u) by construction) then all incident arcs of u are in D(N ψL , T ψL ).Thus u has the same in-and out-degree in D(N, T ) as ι(u) = ι ψL (u) in D IN (N IN , T IN ), since ψ L is a containment structure.A similar argument holds if u ∈ V R or ι µ (u) = RIGHT.Finally if ι µ (u) ∈ S, then all incident arcs of u are in D(N µ , T µ ), and so u has the same degree in D(N, T ) as ι(u) = ι µ (u) does in D IN (N IN , T IN ).
For any u, v, in V (D(N, T )) with ι(v), ι(v) ∈ L ∪ R ∪ S, if D(N, T ) has a path from u to v then D IN (N IN , T IN ) has a path from ι(u) to ι(v): This has already been shown, at the start of the proof for this claim.

Figure 9 :
Figure 9: Illustration of proof for Introduce bags, compact-validity of σ ′ implies compact-validity of σ ′ .Solid lines are relations that we may assume; the dashed line shows the construction of σ * , ψ * and σ ′ 0 ; dotted lines are restriction relations we can show using Lemma 18.

Figure 10 :
Figure 10: Illustration of proof of Lemma 28.Solid lines are relations that we may assume; the dashed lines show the construction of σ * L , σ * R , ψ * L , ψ * R , µ * L , µ * R , µ * ; dotted lines are restriction relations we can show using Lemma 18.Here gL denotes the restriction function {LEFT → PAST, RIGHT → FUTURE} and gR denotes {RIGHT → PAST, LEFT → FUTURE}; labels AL or AR indicate a subdivision of those arcs
Thus in total T has at most 2|A S | ≤ 6|S| arcs.Thus in total, the number of arcs in D(N, T ) is at most |A(T )|+|A S |+|A ′ N | ≤ 2|A S |+|A S |+2|A S | = 5|A S | ≤ 15|S|.It follows that the number of non-isolated vertices in D(N, T ) is at most 30|S|.It remains to bound the number of isolated vertices.
in total, |V (D(N, T ))| ≤ 30|S| + 30|S| + |S| = 61|S| ∈ O(|S|).An identical argument holds for a reconciliation µ.Lemma 30.Let k be the width of the tree decomposition of D IN (N IN , T IN ).Then, the number of compact signatures for a bag (P, S, F ) and the number of compact reconciliations for a Join bag can be upperbounded by 2 O(k 2 ) .Proof: Let σ = (D(N, T ), φ, ι) denote a compact signature for (P, S, F ) (The arguments for a reconciliation µ are similar).By Lemma 29, |V (D(N, T ))| ∈ O(|S|) and, by the properties of a tree decomposition, |S| ≤ k + 1, implying |V (D(N, T ))| ∈ O(k).As such, an upper bound for the number of possible graphs D(N, T ) is 2 O(k 2 ) =: f 1 (k).

Lemma 31 .
Algorithm 1 is correct and runs in 2 O(k 2 ) • |A(N IN )| time, where k = tw(N IN ).Proof: First, note that, by Theorem 1, N IN does not display T IN unless tw(D IN (N IN , T IN )) ≤ 2k + 1, so we are safe to return FALSE if tw(D IN (N IN , T IN )) ≤ 2tw(N IN ) + 1 in line 2 of Algorithm 1. Otherwise, for each bag x in a nice tree decomposition of D IN (N IN , T IN ), Algorithm 1 calculates the set CV x of compactvalid signatures for x.In each case the set CV x is calculated using the previously-calculated set CV y for each child y of x.The correctness of this construction follows from Lemma 23 (for the Leaf bags), Lemma 24 (for Forget bags), Lemma 25 (for Introduce bags), and Corollary 2 (for Join bags).Finally, the algorithm returns TRUE if and only if there is a valid compact signature (D(N, T ), φ, ι) for the root bag of the tree decomposition, such that ι −1 (FUTURE) = ∅.The correctness of this follows from Corollary 1.To see the running time, first note that a nice, minimum-width tree decomposition ofD IN (N IN , T IN ) with O(|V (D IN (N IN , T IN ))|) = O(|A(N IN )|) bags can be found in 2 O(tw(DIN(NIN,TIN)) 2 ) |A(N IN )|, that is, 2 O(k 2 ) |A(N IN )| time[Bod96,Klo94].By Theorem 1, we may assume D IN (N IN , T IN ) has treewidth at most 2k + 1 and, thus, |S| ≤ 2k + 1 for every bag (P, S, F ) in the decomposition.Note that, computing any compact restriction of a signature σ can be done in polynomial time and, by Lemma 30, the number of such signatures |CV x | for a bag x is bounded by 2 O(k 2 ) .It is, thus, evident that, for any bag x = (P, S, F ), the set CV x can be computed in 2 O(k 2 ) • k O(1) =2 O(k 2 ) time (see Algorithm 1).Lemma 31 immediately implies the following theorem.Theorem 2. TREE CONTAINMENT can be solved in 2 O(tw(NIN) 2 ) • |A(N IN )| time.
and the rest of which are labeled PAST or FUTURE (which we may think of as vertices corresponding to some vertex of D IN (N IN , T IN ) in P or F , respectively).We use a function ι on V (D(N, T )) to capture both this correspondence and labelling, where ι maps each vertex to an element of S or a label from {PAST, FUTURE}.We emphasize here that D(N, T ) is distinct from the input display graph D IN (N IN , T IN ). 2. an embedding φ of T in N such that, for no arc uv of T , all of V (φ(uv)) ∪ {u, v} have the same label y ∈ {PAST, FUTURE} under ι.Signatures may be seen as "partial embedding functions" on parts of D IN (N IN , T IN ) in a straightforward way.In particular, we call σ valid for (P, S, F ) if, roughly speaking, φ corresponds (via ι) to something that can be extended to an embedding function on the subgraph of D IN (N IN , T IN ) induced by the vertices P ∪ S introduced below (P, S, F FUTURE, since S separates P from F in D IN (N IN , T IN )).Then, we "forget" which vertices of D IN (N IN , T IN ) An example of a display graph DIN(NIN, TIN) for which NIN displays TIN as witnessed by the embedding function φ that is indicated by bold edges.Highlighting with dashed border represents the sets P and F , for some bag (P, S, F ) in a tree decomposition of DIN(NIN, TIN).Right: A representation of the (compact) signature for (P, S, F ) derived from this solution.Vertices labelled PAST or FUTURE are highlighted in gray without border.whose endpoints, as well as every vertex in φ(a), are assigned the label FUTURE.Intuitively, this is because this information should have no bearing on whether a solution exists with this signature for D IN (N IN , T IN ) restricted to P ∪ S.