Universal Structures and the logic of Forbidden Patterns

Forbidden Patterns Problems (FPPs) are a proper generalisation of Constraint Satisfaction Problems (CSPs). However, we show that when the input is connected and belongs to a class which has low tree-depth decomposition (e.g. structure of bounded degree, proper minor closed class and more generally class of bounded expansion) any FPP becomes a CSP. This result can also be rephrased in terms of expressiveness of the logic MMSNP, introduced by Feder and Vardi in relation with CSPs. Our proof generalises that of a recent paper by Nesetril and Ossona de Mendez. Note that our result holds in the general setting of problems over arbitrary relational structures (not just for graphs).


Introduction
Constraint satisfaction problems have been first investigated in artificial intelligence as a generic concept covering a wide range of combinatorial problems. The input of such a problem consists of a set of variables, a set of values for these variables and a set of constraints between these variables; the question is to decide whether there is an assignment of values to the variables that satisfies all the constraints. Note that these sets (of values, variables and constraints) are usually assumed to be finite, thus in particular such problems do not cover constraints over integers or over reals. However, this framework remains general enough to cover a variety of well-known problems such as Boolean satisfiability, graph 3-colourability, 2 F. R. MADELAINE and conjunctive query evaluation; and, more importantly for us as it is the approach we shall adopt in this paper, constraint satisfaction problems can be phrased as homomorphism problems. For further details, we suggest the survey [19] which gives a detailed background on the intimate connection between constraint satisfaction problems, database theory and finite model theory. Graph homomorphisms and related problems have received considerable attention in recent years as a topic in combinatorics, and the monograph [18] serves as a good survey of the area.
The theoretical investigations of constraint satisfaction problems have been concerned mostly with computational complexity; in particular, with the dichotomy conjecture, that asserts that every constraint satisfaction problem is either tractable (polynomial time decidable) or intractable (NP-complete). This conjecture is supported by early results in the Boolean case [32] and in the case of graph homomorphism [17]; and, by later results using tools from universal algebra [5]. So, despite the fact that constraint satisfaction problems capture numerous well-known problems in NP, the dichotomy conjecture suggests a fundamental difference with the class NP (recall Ladner's Theorem [23] which states that if P is different from NP then there is an infinite number of distinct polynomial-time equivalence classes in NP).
Investigations on the fundamental properties of constraint satisfaction problems have also focused on their descriptive complexity. Based upon Fagin's logical characterisation of NP as those problems expressible in the existential fragment of second order logic, Feder and Vardi attempted to find a large (syntactically-defined) sub-class of NP which exhibits the dichotomy property [11]. What emerged from Feder and Vardi's consideration was the logic MMSNP (short for Monotone Monadic SNP without inequalities) defined by imposing syntactic restrictions upon the existential fragment of second-order logic. Though syntactically defined this logic is very combinatorial in nature, in the sense that every sentence corresponds to a finite set of coloured obstructions: this was made precise in [26], where Madelaine and Stewart introduced a new class of combinatorial problems, the so-called forbidden patterns problems, and proved that every sentence of MMSNP defines a finite union of forbidden patterns problems (since we only deal with decision problems in this paper, we equate a problem with the set of its yes-instances). Feder and Vardi were unable to prove that MMSNP has the dichotomy property, a question which remains open, but showed that this logic is "computationally" equivalent to the class of constraint satisfaction problems. This result, together with Kun's derandomisation [20] of a particular graph construction used in Feder and Vardi's reduction, implies that MMSNP has the dichotomy property if, and only, if the dichotomy conjecture holds. So, one could argue that MMSNP and the class of constraint satisfaction problems are essentially the same.
However, as was first observed by Feder and Vardi, the logic MMSNP is too strong: there are forbidden patterns problems which are not constraint satisfaction problems [11,25]. Moreover, Bodirsky and Dalmau [3] showed that forbidden patterns problems are in fact examples of well-behaved constraint satisfaction with a countable set of values (which shall be referred as infinite constraint satisfaction problems thereafter). So, in the context of descriptive complexity, the logic MMSNP and constraint satisfaction problems are rather different. In [26], Madelaine and Stewart gave an effective characterisation of forbidden patterns problems that are constraint satisfaction problems: given a forbidden patterns problem, we can decide whether it is a finite or infinite constraint satisfaction problem; and, in the former case, we can compute effectively a description of this problem as a finite constraint satisfaction problem. Since the transformation of a sentence of MMSNP into a finite union of forbidden patterns problems is also effective, as a corollary, we can decide whether a given sentence of MMSNP defines a finite union of (finite) constraint satisfaction problems, or defines a finite union of infinite constraint satisfaction problems.
The question of expressivity of the logic MMSNP with respect to the class of constraint satisfaction problems is also being studied in a different guise in structural combinatorics. For example, the above result, which delineates the border between forbidden patterns problems and constraint satisfaction problems (respectively, MMSNP and finite union of constraint satisfaction problems), subsumes the characterisation of duality pairs (respectively, finite dualities) obtained by Tardif and Nešetřil [31] (see also the sequel paper [13]). Moreover, Kun and Nešetřil give a new proof of the characterisation of forbidden patterns problems that are constraint satisfaction problems [21]. Their elegant approach involves lifting dualities to a more complex form of dualities. However, contrary to Madelaine and Stewart's result, note that this approach is not effective. The present paper is motivated by another kind of duality known as restricted duality, which corresponds to restricting the studied problems to a particular class of inputs. Contrary to the case of duality, for particular restrictions, e.g. for bounded degree [16] or planar graphs [28], it turns out that we have all restricted dualities. This provokes the following question, which is the object of this paper. For which input restrictions, do all forbidden patterns problems become constraint satisfaction problems?
Before we can discuss in more detail our contribution, let us introduce more precisely duality and restricted duality. A duality pair is a pair (F, H) of structures such that, for every structure G, there is no homomorphism from F to G (we say that G is F -mote) if, and only if, there is a homomorphism from G to H (we say that G is homomorphic to H). There are structures F , for which there is no H such that (F, H) is a duality pair (for example, choose F to be the triangle). In this sense, we do not have all dualities. However, when we turn to restricted duality, that is when G in the above definition ranges over a particular class of structures, there are examples in which we have all dualities. For example, Häggkvist and Hell [16] showed how to build a finite "universal" graph H for the class of F -mote graphs of bounded degree b. That is, any degree b graph G is F -mote if, and only if, there is a homomorphism from G to H. Note that the usual notion of universal graph, as used by Fraïssé [14] is for induced substructures, not homomorphism, and that the universal graph is usually countable. In our context, the word universal graph refers to a finite graph and is universal with respect to the existence of homomorphisms.
Nešetřil and Ossona de Mendez [30] introduced the notion of tree-depth of a graph and of low tree-depth decomposition of a class of graphs. They show a restricted duality theorem for restriction to classes of low tree-depth decomposition: this includes graphs of bounded degree, planar graphs, graphs of bounded tree-width, any proper minor closed class and, more generally, classes of bounded expansion. In Figure 1, we have depicted how these classes compare. See [28] for further details on these classes, and for the algorithmic features that the existence of such low tree-depth decomposition provides. In this paper, we generalise the approach taken in [30] and show for arbitrary relational structures, not just for graphs, that every forbidden patterns problem is a constraint satisfaction problem when restricted to a class of connected structures that has a low tree-depth decomposition. Since this case is technically much more involved than the simple case of bounded-degree inputs, as a warm-up case to illustrate the basic concepts, we first show that every forbidden patterns problems restricted to connected inputs of bounded degree becomes a constraint satisfaction problem (this result already appeared in a conference paper [9]). Next, we  extend this result and prove that every forbidden patterns problem when restricted to a class of connected structures with low tree-depth decomposition is a constraint satisfaction problem. Examples of classes of structures with this property are proper minor closed classes (this result was originally presented in this restricted case in the preliminary version of this paper [24]), classes of bounded degree and, more generally, classes of bounded expansion. A well-known extension of monadic second order logic consists of allowing monadic predicates to range over tuples of elements, rather than just elements of a structure. This extension is denoted by MSO 2 whereas the more standard logic with monadic predicates ranging over elements only is denoted by MSO 1 . In general, MSO 2 is strictly more expressive than MSO 1 . However, Courcelle [7] proved that MSO 2 collapses to MSO 1 , for some restriction of the input: for graphs of degree at most k, for graphs of tree-width at most k (for any fixed k), for planar graphs and, more generally, for graphs belonging to a proper minor closed class (a class K such that: a minor of a graph G belongs to K provided that G belongs to K; and, K does not contain all graphs). It is perhaps worth mentioning that in [9,24] and the present paper we assume a definition of forbidden patterns problems that is more general than the original one in [26] in that the new definition allows colourings not only of the elements of the input structure but also of its tuples of elements. Essentially, this means that we are now considering problems related to MMSNP 2 , the extension of MMSNP with "edge" quantification (for clarity, from now on, we denote by MMSNP 1 the original logic, i.e. without edge quantification). This means that the main result of this paper provides us with a theorem analogous to that of Courcelle but concerning equal expressivity of the logics MMSNP 1 and MMSNP 2 (they both capture the class of constraint satisfaction problems, when suitably restricted). Courcelle extended the above result to uniformly sparse graphs [8]. However, as we shall see our result fails in this case: there is a problem in MMSNP 1 which is not a constraint satisfaction problem and since this problem is very restricted, it follows in fact that uniformly k-sparse graphs do not have all restricted dualities, for any fixed k ≥ 2.
As a further motivation for the definition of MMSNP 2 we show that this logic, just like MMSNP 1 , correspond to infinite constraint satisfaction problems in the sense of Bodirsky [2,3].
UNIVERSAL STRUCTURES AND THE LOGIC OF FORBIDDEN PATTERNS. 5 The paper is organised as follows. In Section 1, we define constraint satisfaction problems, forbidden patterns problems and give some examples. We conclude this section by a brief review of results on restricted dualities and we state the main result of this paper.
In Section 2, we prove that forbidden patterns problems are constraint satisfaction problems when restricted to connected structures of bounded degree. This serves as a warm up case to illustrate the main definitions and concepts.
In Section 3, we prove our main result, that is that forbidden patterns problems are constraint satisfaction problems when restricted to a class of connected structures that have low tree-depth decomposition. In order to do so, we first introduce the notion of tree-depth for structures. Then, we show that coloured structures of bounded tree-depth have bounded cores. We conclude the proof by the construction of a finite universal coloured structure, using the existence of a low tree-depth decomposition for every input.
In Section 4, we turn to logical aspects. We define MMSNP 1 , recall some known results for this logic and extend them to MMSNP 2 . Next, we reformulate our main result in terms of expressivity of the logics MMSNP 2 and MMSNP 1 with respect to constraint satisfaction problems. We compare this result with Courcelle's result on the expressivity of MSO 1 and MSO 2 . We conclude this section by proving that problems in MMSNP 2 are also infinite constraint satisfaction problems in the sense of Bodirsky.
In the last section, we conclude and discuss related work and open questions.
1. Preliminaries 1.1. Constraint satisfaction problems and forbidden patterns problems. Let σ be a signature that consists of finitely many relation symbols. From now on, unless otherwise stated, every structure considered will be a σ-structure. Let S and T be two structures. A homomorphism h from S to T is a mapping from |S| (the domain of S) to |T | such that for every r-ary relation symbol R in σ and any elements x 1 , x 2 , . . . , x r of S, if R(x 1 , x 2 , . . . , x r ) holds in S then R(h(x 1 ), h(x 2 ), . . . , h(x r )) holds in T . If there exists a homomorphism from S to T we say that S is homomorphic to T . The constraint satisfaction problem with template T is the decision problem with, • input: a finite structure S; and, • question: does there exist a homomorphism from S to T ? We denote by CSP the class of constraint satisfaction problems with a finite template.
Example 1.1. The constraint satisfaction problem with template K 3 (the clique with three elements, i.e. a triangle) is nothing other than the 3-colourability problem from graph theory.
Let V (respectively, E) be a finite set of vertex colours (respectively, edge colours). A coloured structure is a triple (S, s V , s E ), where S is a structure, s V is a mapping from |S| to V and s E is a mapping from E(S) to E where, Let (S, s V , s E ) and (S , s V , s E ) be two coloured structures. A colour-preserving homomorphism h from S to S is a homomorphism from S to S such that s V •h = s V and for every tuple t = (R, x 1 , x 2 , . . . , x r ) in E(S), s E (t ) = s E (t), where t := R, h(x 1 ), h(x 2 ), . . . , h(x r ) .
When the colours are clear from the context, we simply write that h preserves colours. Note that the composition of two homomorphism that preserve colours is also a homomorphism that preserves colours.
A structure S is connected if it can not be partitioned into two disjoint induced substructures. A pattern is a finite coloured structure (F, f V , f E ) such that F is connected. In this paper, patterns are used to model constraints in a negative fashion and consequently, we refer to them as forbidden patterns. Let F be a finite set of forbidden patterns. We say that a coloured structure (S, s V , s E ) is valid with respect to F if, and only if, for every forbidden pattern (F, f V , f E ) in F, there does not exist any colour-preserving homomorphism h from F to S.
The problem with forbidden patterns F is the decision problem with, • input: a finite structure S • question: does there exist s V : |S| → V and s E : E(S) → E such that (S, s V , s E ) is valid with respect to F? We denote by FPP 1 the class of forbidden patterns problem with vertex colours only (that is for which E has size one) and by FPP 2 the class of forbidden patterns problems.
Examples 1.2. Let G be an undirected graph. It is usual to represent G as a relational structure with a single binary relation E that is symmetric. However, the logics considered in this paper are monotone and we can not express that E is symmetric; therefore, we use a different representation to encode graphs. We say that a structure S with one binary relation symbol E encodes G, if |S| = V (G) and for any x and y in V (G), x and y are adjacent in G if, and only if, E(x, y) or E(y, x) holds in S. Note that this encoding is not bijective. Modulo this encoding, the following graph problems are forbidden patterns problems.
(1) Vertex-No-Mono-Tri: consists of the graphs for which there exists a partition of the vertex set into two sets such that no triangle has its three vertices occurring in a single partition. It was proved in [11,25] that this problem is not in CSP and in [1] that it is NP-complete. (2) Tri-Free-Tri: consists of the graphs that are both three colourable (tripartite) and in which there is no triangle. It was proved in [25] that this problem is not in CSP. It follows from [20] that this problem is NP-complete. (3) Edge-No-Mono-Tri: consists of the graphs for which there exists a partition of the edge set in two sets such that no triangle has its three edges occurring in a single partition. It is known to be NP-complete (see [15]). The above examples can be formulated as Forbidden Patterns Problems. The corresponding sets of forbidden patterns are depicted on Figure 2. In the case of Edge-No-Mono-Tri, the two type of colours for edges are depicted with dashed and full line respectively.

Restricted
Dualities. Let C be a class of structures. We say that C has all restricted dualities if, and only if, for every finite set of connected structures F there exists a finite structure U , the so-called universal structure, such that for every structure A in C there is no homomorphism from any F in F to A if, and only if, A is homomorphic to U .
The first example of a restricted duality theorem is due to Häggvist and Hell.
Theorem 1.3. [16] Let b be an integer and C be a class of graphs. If every graph in C has bounded degree b then C has all restricted dualities.

Vertex-No-Mono-Tri
Tri-Free-Tri Edge-No-Mono-Tri  Let M be a graph and C be a class of graphs. If no graph in C admits M as a minor then C has all restricted dualities.
One of the key notions in the proof is that of a low tree-depth decomposition (see Section 3.3 for a definition). More recently, the same authors have introduced the notion of classes of graphs of bounded expansion, which encompasses both classes of graphs of bounded degree and proper minor closed classes. A class of graphs C has bounded expansion if there exists a function f : N → R such that for every graph G in C and every r > 0, ∇ r (G), the so-called grad of G of rank r is bounded by f (r), where ∇ r (G) = max |E(G|P)| |P| . Here, P is a set of disjoint sets of vertices of G, each of which induce a connected subgraph of G; and, E(G|P) denotes the edge set of the minor of G constructed by identifying the vertices inside each set into a single vertex and deleting other vertices and edges. These authors proved that classes of graphs of bounded expansions have also low tree-depth decomposition and proved the following general result. Theorem 1.5. [27] Let C be a class of graphs. If C has bounded expansion then C has all restricted dualities. Example 1.6. We can use restricted duality results, such as those presented above, and ad hoc techniques from [9] to show that two of our examples are constraint satisfaction problems when restricted to a suitable class K (e.g. class of graphs of bounded degree, proper minor closed class or, more generally, class of bounded expansion; in fact, any class for which we have a suitable restricted duality result). Let U be the universal graph for F = {K 3 }. Let U be the product of U with K 3 . Recall that this is the graph with edge set |U | × |K 3 | and with an edge E((u, x), (v, y)) if, and only if both E(u, v) in U and E(x, y) in K 3 . It is not difficult to check that Tri-Free-Tri, restricted to K is the constraint satisfaction problem with template U . Similarly Vertex-No-Mono-Tri is the constraint satisfaction problem with template U , where U is the graph that consists of two copies of U , such that every pair of elements from different copies are adjacent. Note that, technically, our problems being defined over structures with a single binary relation E, we have not really expressed them as a constraint satisfaction problem. However, according to our encoding, replacing any two adjacent vertices x and y in the above graphs by two arcs E(x, y) and E(y, x) provides us with a suitable template.

Restricted Coloured Dualities.
We say that C has all restricted coloured dualities if, and only if, for every finite set of forbidden patterns F there exists a finite structure U , the so-called universal structure, such that for every structure A in C, A is valid with respect to F 1 if, and only if, A is homomorphic to U .
We say that a structure S has bounded degree b if every element of S occurs in at most b distinct tuples. We extended the previous result to restricted coloured dualities (we provide the proof of this result for completeness in Section 2). Theorem 1.7. [9] Let b be an integer and C be a class of structures. If every structure S in C has bounded degree b then C has all restricted coloured dualities.
In the preliminary version of this paper [24], we extended Theorem 1.4 to restricted coloured dualities. We also extended the result to structures, rather than just graphs. Let us make precise what we understand by a proper minor closed class of structures. Let S be a structure. The Gaifman graph of S, which we denote by G S is the loopless graph with vertices |S| in which two distincts elements x and y of S are adjacent if, and only if, there exists a tuple in a relation of S in which they occur simultaneously. Given a class K of structures, we denote by G K the class of their Gaifman graphs. A class of graphs G is said to be a proper minor closed class if the following holds: first, for any graph G and any minor H of G, if G belongs to G then so does H; and, secondly G does not contain all graphs. Alternatively, G is proper minor closed if it excludes at least one fixed graph M as a minor, a so-called forbidden minor. We say that a class of structures K is a proper minor closed class if, and only if, G K is a proper minor closed class.
Theorem 1.8. [24] Let C be a class of structures. If C is a proper minor closed class then C has all restricted coloured dualities.
The key property we use in the proof of this result, namely that such a proper minor closed class has low tree-depth decomposition, holds also in the general case of a class of (structures) of bounded expansion defined similarly as follows. A class of structures K is of bounded expansion if, and only if, G K is of bounded expansion. Thus, a similar proof provides us in fact with the following more general result which subsumes also Theorem 1.7. Theorem 1.9. Let C be a class of structures. If C has low tree-depth decomposition (e.g. bounded degree, proper minor closed class, structure of bounded expansion) then C has all restricted coloured dualities.

Section 3 is devoted to the proof of this result.
Example 1.10. The last of our examples Edge-No-Mono-Tri is also a constraint satisfaction problem when restricted to a class K that has low tree-depth decomposition by the above result.

Bounded Degree
In this section, we give a proof of Theorem 1.7. To simplify the notation we will consider graphs only but the proof extends to relational structures without major difficulty. We shall first explain the intuition and ideas behind the proof by giving an informal outline. Let us denote the largest diameter of a forbidden pattern by m. This parameter, together with the degree-bound b, are constants, i.e. they are not part of the input of the forbidden patterns problem. The universal graph U has to contain all possible small graphs that are yes-instances of the forbidden patterns problem, "small" meaning "of diameter m + 1" here and thereafter. The intuition then is that each graph G, which is a yes-instance of the forbidden patterns problem, however big, can be homomorphically mapped to U as such a mapping should be only locally consistent. Given that the degree of G is bounded by b, we need to distinguish among no more than X vertices in a small neighbourhood, where X depends on b and m. So we can use X many different labels in constructing the vertex set of U . On the other hand, in order to define the adjacency relation of the universal graph, i.e. to correctly "glue" all the possible small neighbourhoods, any vertex of U should carry information not only about its label, but also about its neighbourhood. In other words, any such vertex will represent a small graph together with a vertex which is the "centre" (or the root) of the small graph. Thus the vertex set of the universal graph will consists of all such rooted small graphs, vertex-and edge-coloured in all possible ways, that are yes-instances of the forbidden patterns problem. Two vertices will be adjacent in U if, and only if, the graphs they represent "agree", i.e. have most of their vertices with the same labels and colours and the induced subgraphs of these vertices coincide including the edge colours; for the precise definition of what "agree" means, one should see the formal proof below. It is now intuitively clear why a yes-instance G of the forbidden patterns problem should be homomorphic to the universal graph U : the vertices of G can be labelled so that any two adjacent vertices get different labels, then one can choose a good vertex-and edge-colouring of G, and because of the construction of U now every vertex u in G can be mapped to the vertex of U that represents the small neighbourhood of u rooted at u. It is straightforward to see that the mapping preserves edges.
The universal graph U has a very useful property, namely every small neighbourhood of U rooted at a vertex v is homomorphic to the small graph represented by the vertex u (see Lemma 2.2 below). This property immediately implies that a no-instance of the forbidden patterns problem cannot be homomorphic to U . Indeed, suppose for the sake of contradiction, there is a no-instance G that is homomorphic to U . Fix the colouring induced by the homomorphism and observe that there is a homomorphism from the forbidden pattern F into G. The composition of the two homomorphisms gives a homomorphism from F into U , and by the property above, by another composition, we get a homomorphism from the forbidden pattern F to some small graph represented by a vertex of U . This gives a contradiction with our construction as we have taken small no-instances only to be represented by the vertices of the universal graph.
Example 2.1. We illustrate the construction of Theorem 1.7 for our final example Edge-No-Mono-Tri in Figure 3 for inputs of bounded degree b ≥ 3. Any input G can be labelled by elements from {1, 2, . . . , 10} such that, for every vertex x in V (G), the vertices at distance at most 2 (the diameter of a triangle plus one) of x have a different label.
The remainder of this section is devoted to the formal proof of Theorem 1.7. Let b be a positive integer and F be a set of forbidden patterns. We write δ(G) to denote the diameter of a graph G: that is, the maximum for all vertices x in V (G) of the maximum distance from x to any other vertex y in V (G).
(Edge) coloured graph S 1 (Edge) coloured graph S 2 The coloured graph induced by the vertices at distance at most one from the vertex 1 is identical in both S 1 and S 2 The coloured graph induced by the vertices at distance at most one from the vertex 2 is identical in both S 1 and S 2 The template U has the edge if, and only if, the following holds: (i) (v, v ) belongs to both E(S) and E(S ); and, (ii) the induced coloured subgraph of S induced by every vertex at distance at most m from v (respectively, v ) is identical to the induced coloured subgraph of S induced by every vertex at distance at most m from v (respectively, v ).
We shall prove shortly that U is a yes-instance witnessed by the following "universal colours" defined as follows, . We first need the following lemma.
, using (i), it follows that the vertex v belongs to V (S) and that h is a homomorphism. Similarly, using (ii) it follows that h preserves colours.
Proof. Assume for contradiction that (U, u V , u E ) is not valid and that there exists some forbidden pattern (F, f V , f E ) in F and some homomorphism f from F to U that preserves these colours. Since the diameter of F is at most m, there exists a vertex x in V (F ) such that every vertex of F is at distance at most m. Hence, it is also the case for ). Both homomorphisms are colour preserving, thus composing these two homomorphisms, we get that h • f is a colour-preserving homomorphism from F to S. However, by definition of S, the coloured graph (S, s V , s E ) is valid with respect to the forbidden patterns F. We reach a contradiction and the result follows.
Claim. Yes-Instances Are Homomorphic to U .
Proof. Let G be a graph of bounded degree b for which there exist g V : V (G) → V and g E : E(G) → E such that (G, g V , g E ) is valid w.r.t. F. Since G has bounded degree b, for every vertex x in V (G), there are at most X − 1 vertices y at distance at most m from x. Therefore, there exists a map χ from V (G) to {1, 2, . . . , X} such that every two distinct vertices within distance m or less take a different colour via χ. Thus, for every vertex x in G, the subgraph of G induced by the vertices at distance at most m of x can be identified (via the labelling χ) to a graph S x with domain {1, 2, . . . , X}. Similarly, the restriction of g V and g E to this subgraph induce colour maps s V x and s E x of S. We set a(x) := (χ(x), (S x , s V x , s E x )). It follows directly from the definition of U that a is homomorphism that preserve colours.
Claim. No-instances are not homomorphic to U .
Proof. Let G be a graph of bounded degree b that is a no instance of the forbidden patterns problem represented by F and assume for contradiction that a is a homomorphism from G to U . The homomorphism a together with the universal colouring (U, u V , u E ) induces colourings g V and g E as follows: For every vertex x in V (G), set g V (x) := u V (a(x)); and, for every edge (x, y) in E(G), set g E (x, y) := u E (a(x), a(y)). Since G is a no instance, there exists a forbidden pattern (F, f V , f E ) in F and a homomorphism f from F to G that preserve these colours. Composing the two homomorphisms, we get that a • f is a homomorphism from F to U that preserves the colours of F and U . This contradicts the fact that (U, u V , u E ) is valid w.r.t. F. This concludes the proof of Theorem 1.7.
In this section we give a proof of Theorem 1.9. Before moving to the formal proof, let us give an informal outline. Given a forbidden patterns problem, we need to build a universal structure U such that, for every input structure S (that comes from a class K that has low tree-depth decomposition), S is a yes-instance of the given forbidden patterns problem if, and only if, S is homomorphic to U . Recall that we use the word universal structure with a different meaning to that of Fraïssé, in particular U has to be finite rather than infinite and is universal w.r.t. the existence of homomorphisms rather than induced substructures (i.e. existence of embeddings). Assume for now that the forbidden patterns problem in question has a single colour. One of the key properties for building such a finite U is that of bounded tree-depth. It turns out that though the size of a structure of bounded tree-depth may be arbitrarily large, the size of its core is bounded. Recall that the core of a structure S is the smallest structure that is homomorphically equivalent to S. Let Y p be the disjoint union of all cores of structures of tree-depth at most p that are valid (w.r.t. our fixed forbidden patterns problem). Note that Y p is finite and for any structure S of treedepth at most p, S is homomorphic to Y p if, and only if, S is valid. The next key ingredient is that the inputs have low tree-depth decomposition: that is any input structure can be decomposed into a fixed number of parts, say q, so that any p ≤ q parts induce a structure of tree-depth at most p (here, q depends on p and the considered class of structures). So, given some input S together with such a decomposition, if the largest forbidden pattern has size p then it suffices to check for any choice of p parts of the input, that the structure induced by these p-parts is valid, or equivalently, that it is homomorphic to Y p . Finally, we use the key concept of pth truncated product. This concept allows us to translate the existence of homomorphisms to a structure T , for any p − 1 parts of a p partitioned input S, to the existence of a homomorphism to the pth truncated product of T . Hence, by taking a sequence of suitable truncated products of Y p , we get the desired finite universal structure U . Note that we assumed that the forbidden patterns problem had a single colour. In order to get our result in general, we adapt the above ideas and concepts to coloured structures in the same spirit as in the previous section.
3.1. Tree-depth and Elimination Tree of a Structure. Following the theory of treedepth of graphs introduced in [30], we develop elements of a theory of tree-depth for structures.
Let S be a structure. We denote by H S the hypergraph induced by S, that has the same domain as S and whose hyperedges are the sets that consists of the elements that occur in the tuples of the relations of S. . We define the closure of F clos(F, σ) to be the σ-structure with domain |F | and all tuples R i (x 1 , x 2 , . . . , x r i ) such that the elements mentioned in this tuple {x i |1 ≤ i ≤ r i } form a chain w.r.t. ≤ F , where ≤ F is the partial order induced by F , i.e. x ≤ F y if, and only if, x is an ancestor of y in F . The tree-depth of S, denoted by td(S), is the minimum height of a rooted forest F such that S is a substructure of the closure of F , clos(F, σ).
These notions are closely related.
Lemma 3.1. Let S be a connected structure. A rooted tree (r, Y ) is an elimination tree for S if, and only if, S is a substructure of clos(Y, σ). Consequently, the tree-depth of S is the minimum height of an elimination tree.
Proof. We prove this result by induction on |S|. If S has a single vertex r then the result holds trivially. Assume that the above equivalence holds for every connected structure of size at most n − 1 and assume that S has size n. Let (r, Y ) be a tree that consists of a root r adjacent to rooted subtrees (r i , Y i ). The tree (r, Y ) is an elimination tree for S if, and only if, the subtrees (r i , Y i ) are elimination trees for the components S i induced by the connected component H i of H S \ {r}. By induction S i is a substructure of clos(Y i , σ). Moreover every tuple t in a relation of S either does not mention r and occurs in a single component S i or t mentions r and apart from r only elements from a single structure S i . Hence, equivalently we have that S is a substructure of clos(Y, σ).
We will need the following lemma later. Proof. The forward implication holds since every edge between two elements x and y in the Gaifman graph is induced by at least one tuple in some relation of S in which both x and y occurs. Thus, in particular x and y occur on the same branch in an elimination tree of S.
Conversely, every tuple induces a clique in the Gaifman graph and all elements of a clique must occur on the same branch of an elimination tree. Thus, an elimination tree for G S is also an elimination tree for S.

3.2.
Tree-depth and Cores. We show that a coloured structure K of bounded tree-depth has a core of bounded size. Recall that a retract of a structure S is an induced substructure S of S for which there exists a homomorphism from S to S . A minimal retract of a structure S is called a core of S. Since it is unique up to isomorphism, we may speak of the core of a structure [18]. This notion extends naturally to coloured structures [26].
We say that a (colour-preserving) automorphism µ of a (coloured structure) S has the fixed-point property if, for every connected substructure T of S, either µ(T ) ∩ T = ∅ or there exist an element x in T such that µ(x) = x. We say that µ is involuting if µ • µ is the identity. Theorem 3.3. There exists a function η : N × N → N such that, for any coloured structure (S, s V , s E ) such that |S| > η(N, td(S)) and any mapping g : |S| → {1, 2, . . . , N }, there exists a non-trivial involuting g-preserving automorphism µ of (S, s V , s E ) with the fixedpoint property. Proof. Let (S, s V , s E ) be a coloured structure with p ≥ 1 connected components (S i , s V i , s E i ) where 1 ≤ i ≤ p and let g : |S| → {1, 2, . . . , N }. Let F be a rooted forest that consists of rooted trees (r i , Y i ), where 1 ≤ i ≤ p, such that (r i , Y i ) is an elimination tree for S i of height at most td(S). We prove this result by induction on td(S).
If td(S) = 1 then every (r i , Y i ) has height 1 and every (S i , s V i , s E i ) is a coloured selfloop (a self-loop is a structure with a single element). Let |σ| be the number of relation symbols in σ. There are at most N × |V| × |E| × 2 |σ| g-valued coloured self-loops. Hence, we set η(N, 1) := N × |V| × |E| × 2 |σ| and for any (S, s V , s E ) satisfying |S| ≥ η(N, 1) and any mapping g from |S| to {1, 2 . . . , N }, there exists a non-trivial involuting g-preserving automorphism µ of (S, s V , s E ) that has the fixed point property (simply choose for µ an automorphism that permutes two identical coloured self-loops with the same g value). In the rest of the proof, we shall write that µ is a "good" g-preserving automorphism for short.
Assume that the result holds for every coloured structure of tree depth at most n, and let S be a structure with tree-depth n + 1. Assume first that p = 1. That is, F consists of a single rooted tree (r, Y ). Let (r j , Y j ), 1 ≤ j ≤ q be the subtrees of Y where r j is a child of r in Y . We wish to define a mapping g over S \ {r} such that g (x) describes both g(x) and the relationship of x and r in S. Let N (x, r) be the coloured structure (together with the restriction of g) that is the substructure of S induced by the following set of elements: x ∈ e and r ∈ e}.
If this set is empty, we set N (x, r) to be ∅. Let Θ be the set of such neighbourhoods N (x, r) with two constants x and r, considered up to isomorphisms. We also assume that ∅ is an element of Θ. Since σ, E and V are fixed, it follows that Θ is finite. We define g as the mapping from |S| \ {r} to N × Θ such that g (x) := (g(x),Ñ (x, r)), whereÑ (x, r) belongs to Θ and is isomorphic to N (x, r). Hence, by induction if |S \ {r}| > η(N |Θ|, n), there exists a "good" g -preserving automorphism µ of S \ {r}. Let µ be the extension of µ to S such that µ(r) := r. By construction, µ is a "good" g-preserving automorphism.
Assume now that p > 1. If one of the components (S i , s V i , s E i ) with elimination tree (r i , Y i ) has size strictly greater than η(N |Θ|, n) + 1, then from the previous case, it has a "good" g-preserving automorphism µ i which we can extend by the identity into a "good" g-preserving automorphism µ of the whole structure. Assume now that every component (S i , s V i , s E i ) has size at most η(N |Θ|, n) + 1. The number ζ(N, k) of coloured structures (together with a mapping g to a set of size N ) of size at most k considered up to isomorphism depends only on N and k (and the constants σ, V and E). Hence, if p > ζ N, η(N (|Θ|, n)+1 then there must be at least two components that are isomorphic (also w.r.t. both colours and g-values). Hence, µ is a "good" g-preserving automorphism, where µ is the automorphism that exchanges these two components and leaves the element of any other component fixed. Thus, we may set, η(N, n + 1) := η(N |Θ|, n) + 1 × ζ N, η(N |Θ|, n) + 1 .
This concludes the proof.
Theorem 3.4. Let (S, s V , s E ) be a coloured structure. If |S| > η(1, td(S)) then (S, s V , s E ) maps homomorphically into one of its proper induced substructure (S 0 , s V 0 , s E 0 ). Consequently, the core of (S, s V , s E ) has size at most η(1, td(S)).
Proof. By the previous theorem, if |S| > η(1, td(S)) then there exists a non-trivial involuting automorphism µ of (S, s V , s E ) with the fixed-point property. Let F be the set of fixed-points of µ. Let S be the substructure of S induced by |S|\|F |. Let S be a connected substructure of S . Since µ has the fixed-point property and S has no fixed point by definition, we know that µ(S ) ∩ S = ∅. Note that there can not be any tuple t in a relation of S that involves simultaneously elements of S and µ(S ) (Otherwise, the substructure S t of S induced by |S | and the element of t would be connected and µ(S t )∩S t = ∅). There could be however a tuple that involves simultaneously elements of F , S and µ(S ). We need a slightly stronger result than the previous theorem. Note that in the previous proof, given a structure S, we can fix a tree decomposition (r, Y ) of height td(S) with subtrees (r i , Y i ) that corresponds to substructures S i of S, and subsequently at the induction stage, rather than using any tree-decomposition of the structures S i , we can assume that (r i , Y i ) is used instead. With this further assumption, we ensure that the automorphism µ we build has still the required properties, and moreover that there is no tuple that involves simultaneously elements of F, S and µ(S ), for any connected substructure S of S .
Hence, starting with two empty sets A and B, we can inductively pick a connected component S of S , add S to A and µ(S ) to B until S is partitioned into A and B. By construction, there is no tuple involving elements of both A and B (and possibly some element of F ). Let h be the mapping such that h(x) := µ(x), if x ∈ B, and h(x) := x, otherwise. By construction of µ, A and B, it follows that h is a homomorphism from is a proper induced substructure of (S, s V , s E ). This proves the first claim.
For the second claim, we apply inductively the first claim until we get a proper induced substructure (S , s V , s E ) of size at most η(1, td(S)). Thus, (S , s V , s E ) is an induced substructure of (S, s V , s E ) in which (S, s V , s E ) maps homomorphically into (composing the homomorphisms, we get a homomorphism). The core of (S , s V , s E ) is also the core of (S, s V , s E ) (since the two structures are homomorphically equivalent) and its size is at most that of (S , s V , s E ), which is bounded by η(1, td(S)).
Thus, we get the following result.
Corollary 3.5. Let K be any class of coloured structures of bounded tree-depth k. Then the set K of cores of structures from K (up to isomorphism) is finite.

3.3.
Decompositions. Before we can define this concept for structures, let us briefly recall how the notion was first defined for graphs. In [10], De Vos et al. proved that for any proper minor closed class K and any integer p ≥ 1, there exists an integer q such that for every graph G in K there exists a vertex partition of G into q parts such that any subgraph of G induced by at most p parts has tree-width at most p − 1 (existence of a low tree-width decomposition). Similarly, we say speak of a low tree-depth decomposition for K whenever, for every integer p, there exists an integer q such that any graph in K has a proper q-colouring in which any p colours induce a subgraph of tree-depth at most p.
In  We say that a class K of structures has low tree-depth decomposition if, and only if, for every p ≥ 1, there exists an integer q such that for any structure S in K, there exists a partition of |S| into q sets such that any substructure of S induced by at most p of these sets has tree-depth at most p.
Proposition 3.7. Let K be a class of structures. If K has bounded expansion then K has low tree-depth decomposition.
Proof. Let S be a structure in K. We apply Theorem 3.6 to G S , the Gaifman graph of S and get a vertex partition such that every subgraph of G S induced by at most p colours has a tree-decomposition of height at most p. We use the same partition for S. For every substructure S of S induced by at most p parts, the tree-decomposition of G S is also a tree-decomposition of S (by Lemma 3.2) and the result follows.
Remark 3.8. We adopt a definition of low tree-depth decomposition of structures that seems more natural than a definition that would involve the Gaifman graph (we require only a vertex partition). We do not know whether our definition is more general or not (in other words, does the converse implication in the previous result hold?).

Truncated Product.
We extend the definition of truncated product and adapt two lemmas from [30] to coloured structures. Recall first that the usual notion of product in the context of graph homomorphism is the following. The product of two structures A and B is the structure with universe the cartesian product of the universes of A and B and such that R ((a 1 , b 1 ), (a 2 , b 2 ), . . . , (a n , b n )) holds if, and only if, both R(a 1 , a 2 , . . . , a n ) holds in A and R(b 1 , b 2 , . . . , b n ) holds in B. The truncated product resembles this "classical" product except that each component has a special "don't care" element and the domain of this special product consists only of tuples involving exactly one "don't care" element.
Let (S, s V , s E ) be a coloured structure and p ≥ 2 be an integer. We define the pth truncated product of (S, s V , s E ), to be the coloured structure (S , s V , s E ) defined as follows.
• Its domain is a subset of p i=1 W i where, ( denotes a new element, i.e. ∈ |S|). • We restrict further W i toW i that consists of elements • For every relation symbol R of arity r, and every tuple (w i 1 , w i 2 , . . . , w ir ) where for every 1 ≤ k ≤ r, w i k belongs toW i k and . , x ir i ); and, − there exists e ∈ E such that for every 1 ≤ i ≤ p, s E (t i ) = e, we set R(w i 1 , w i 2 , . . . , w ir ) to hold in S and we set s E (w i 1 , w i 2 , . . . , w ir ) := e.
We denote the pth truncated product by (S, s V , s E ) ⇑p . This product has two important properties: it preserves validity w.r.t. a forbidden patterns problem (for a suitable p); and, the existence of all "partial" colour-preserving homomorphisms is equivalent to the existence of a homomorphism to the truncated product (see Lemma 3.9 and Lemma 3.10 below). Lemma 3.9. Let p ≥ 2. Let F be a set of forbidden patterns such that for every Proof. We prove the contrapositive. Assume that (S , s V , s E ) is not valid w.r.t. F, that is for some (F, f V , f E ) in F, there exist a colour-preserving homomorphism f from F to S . Since |F | < p, by the pigeon-hole principle there exists 1 Let π i 0 be the mapping from |S | \W i 0 to |S| defined as π i 0 (w i ) = x i i 0 (with the same notation as above). It follows directly from the definition of S that π i 0 is a homomorphism from S \W i 0 to S, where S \W i 0 is the substructure of S induced by |S | \W i 0 .
Hence, by composition f := π i 0 • f is a colour-preserving homomorphism from F to S and we have proved that (S, s V , s E ) is not valid w.r.t. F. Lemma 3.10. Let (U, u V , u E ) be a coloured structure and let p be an integer greater than the arity of any symbol in σ. Let (S, s V , s E ) be a coloured structure. If there exists a partition V 1 , V 2 , . . . , V p of |S| such that for every substructure (S i ,s V ,s E ) of (S, s V , s E ) induced by |S| \ V i there exist a colour-preserving homomorphisms i from (S i ,s V ,s E ) to (U, u V , u E ) then there exists a colour-preserving homomorphisms from (S i ,s V ,s E ) to (U, u V , u E ) ⇑p .
Proof. Let (U , u V , u E ) := (U, u V , u E ) ⇑p . Let x be an element of S such that x belongs to V i . Then x is an element ofS k for every 1 ≤ k ≤ p such that k = i ands k (x) is defined and we set:s (x) := (s 1 (x),s 2 (x), . . . ,s i−1 (x), ,s i+1 (x), . . . ,s p (x)). Sinces k is colour-preserving, u V (s k (x)) =s V (x) ands(x) is indeed in |U | by the definition of the truncated product. Let x 1 , x 2 , . . . , x r be elements of S that belong to the sets V i 1 , V i 2 , . . . , V ir , respectively. Let R be a r-ary relation symbol from σ such that R(x 1 , x 2 , . . . , x r ) holds in S. Then, for every 1 ≤ k ≤ p such that k ∈ {i 1 , i 2 , . . . , i r }, we have that R(s k (x 1 ),s k (x 2 ), . . . ,s r (x r )) holds in U . Moreover, sinces k is colour-preserving, we have that u E (s k (x 1 ),s k (x 2 ), . . . ,s r (x r )) = s E (x 1 , x 2 , . . . , x r ) and it follows by the definition of the truncated product that R(s(x 1 ),s(x 2 ), . . . ,s(x r )) holds in U and thats is a colour-preserving homomorphism.
Using the two previous lemmas, an easy induction provides the following result.
Proposition 3.11. Let p be an integer greater than the arity of any symbol in σ. Let F be a set of forbidden patterns such that, for every (F, f V , f E ) in F, we have |F | < p. Let q ≥ p. Let (U , u V , u E ) be a coloured structure that is valid w.r.t F. Let (S, s V , s E ) be a coloured structure.
Assume that there exists a partition V 1 , V 2 , . . . , V q of |S|, such that for every substructure . . , V ip , there exists a colour-preserving Then there exists a colour-preserving homomorphisms from 3.5. Universal Structure. We can now conclude the proof of Theorem 1.9, whose statement we recall now.
Theorem. Let C be a class of structures. If C has low tree-depth decomposition (e.g. bounded degree, proper minor closed class, structure of bounded expansion) then C has all restricted coloured dualities.
Proof. Let (S, s V , s E ) be a coloured structure such that S belongs to K. By Corollary 3.7, there exists an integer N such that every structure S in K can be partitioned into q parts, such that every p parts induce a substructure of S of tree-depth at most p. By Theorem 3.4, the core of the coloured structure induced by p parts is bounded. Let (U , u V , u E ) be the disjoint union of all such cores that are valid w.r.t. F (there are only finitely many). Since the forbidden patterns have size at most p, it suffices to check every substructure of S of size at most p and, a fortiori, (S, s V , s E ) is valid w.r.t. F if, and only if, each of its coloured substructures induced by p parts is valid, or equivalently if every such coloured substructure maps homomorphically into (U , u V , u E ). Let (U, u V , u E ) := (U , u V , u E ) ⇑(p+1)⇑(p+2)...⇑q . By Proposition 3.11, if (S, s V , s E ) is valid w.r.t. F then it is homomorphic to (U, u V , u E ); and, since (U, u V , u E ) is valid w.r.t. F the converse holds as forbidden patterns problems are closed under inverse homomorphism.
As in the proof of Theorem 1.7 in the previous section, forgetting the colours provides us with the desired template U .

Logical aspects
4.1. MMSNP 1 and MMSNP 2 . The class of forbidden patterns problems with colours over vertices only, corresponds to the problems that can be expressed by a formula in Feder and Vardi's MMSNP (Monotone Monadic SNP without inequalities, see [11,26]). Note that allowing colours over the edges does not amount to dropping the hypothesis of monadicity altogether. Rather, it corresponds to a logic, let's call it MMSNP 2 , which is similar to MMSNP but allows first-order variables over edges (just like Courcelle's MSO (Monadic Second Order logic) and MSO 2 , see [7]).
In the following, we introduce formally MMSNP 1 and recall some known results; and, secondly, we introduce MMSNP 2 and prove that it defines finite unions of problems in FPP 2 .
Definition 4.1. Monotone Monadic SNP without inequality, MMSNP 1 , is the fragment of MSO consisting of those formulae Φ of the following form: where M is a tuple of monadic relation symbols (not in σ), t is a tuple of (first-order) variables and for every negated conjunct ¬(α i ∧ β i ): • α i consists of a conjunction of positive atoms involving relation symbols from σ and variables from t; and • β i consists of a conjunction of atoms or negated atoms involving relation symbols from M and variables from t. (Notice that the equality symbol does not occur in Φ.) The negated conjuncts ¬(α ∧ β) correspond to (partially coloured) forbidden structures (and this is the reason why we use such a notation in the definition rather than using implications or clausal form). To get forbidden patterns problems, we need to restrict sentences so that negated conjuncts correspond precisely to coloured connected structures. Such a restriction was introduced in [26] as follows. • for every first-order variable x that occurs in ¬(α ∧ β) and for every monadic symbol C in M, exactly one of C(x) and ¬C(x) occurs in β; • unless x is the only first-order variable that occurs in ¬(α ∧ β), an atom of the form R(t), where x occurs in t and R is a relation symbol from σ, must occur in α; and, • the structure induced by α is connected. Remark 4.3. We have altered slightly the definitions w.r.t. [26]. We now require a pattern to be connected. However, we have amended the notion of a primitive sentence accordingly. Thus, the following statement still holds as the connectivity requirement is enforced on both sides of the equivalence. It is only a technical exercise to relate any sentence of MMSNP 1 with its primitive fragment.
Proposition 4.5. [26] Every sentence of MMSNP 1 is logically equivalent to a finite disjunction of primitive sentences.
This paper is concerned with decision problems only and we equate a problem with the (isomorphism closed) set of its yes-instances. Thus, we may speak of the union of two problems. Consequently, we have the following characterisation.
Corollary 4.6. Every sentence Φ in MMSNP 1 defines the union of finitely many problems in FPP 1 .
The logic MMSNP 2 is the extension of the logic MMSNP 1 where in each negated conjunct ¬(α ∧ β), we allow a monadic predicate to range over a tuple of elements of the structure, that is we allow new "literals" of the form M (R(x 1 , x 2 , . . . , x n )) in β, where R is n-ary relation symbol from the signature σ. We also insists that whenever such a literal occurs in β then R(x 1 , x 2 , . . . , x n ) appears in α. The semantic of a monadic predicate M is extended and is defined as both a subset of the domain and a subset of the set of tuples that occur in some input relation: that is, for a structure S, M S ⊂ |S| ∪ E(S). We say that a sentence of MMSNP 2 is primitive if each negated conjunct ¬(α ∧ β) satisfies the same conditions as in Definition 4.2 and a further condition: • if R(x 1 , x 2 , . . . , x n ) occurs in α then for every (existentially quantified) monadic predicate C exactly one of C(R(x 1 , x 2 , . . . , x n )) or ¬C(R(x 1 , x 2 , . . . , x n )) occurs in β.
It is only a technical exercise to extend all the previous results of this section concerned with MMSNP 1 and FPP 1 to MMSNP 2 and FPP 2 . In particular, we have the following result.
Corollary 4.7. Every sentence Φ in MMSNP 2 defines the union of finitely many problems in FPP 2 .

4.2.
Edge Quantification versus Vertex Quantification. Courcelle investigated the difference in expressivity that adding edge set quantification provided to MSO: he proved that MSO 2 (with edge set quantification) is more expressive than MSO 1 (with the more usual vertex set quantification) in general. However, he also showed that under certain restriction, edge set quantification does not add to MSO's expressivity.
Theorem 4.8. [7] On each of the following classes of simple graphs: those of degree at most k, those of tree-width at most k, for each k, planar graphs, and, more generally, every proper minor closed class, every sentence in MSO 2 is logically equivalent to a sentence of MSO 1 .
Restricted coloured duality theorems can be reformulated in terms of expressivity of MMSNP 2 , MMSNP 1 and constraint satisfaction problems as the following result shows. Theorem 4.9. (Collapse to CSP). If a class K has all restricted coloured dualities then MMSNP 1 and MMSNP 2 are equally expressive when restricted to inputs from K. These logics define precisely finite unions of constraint satisfaction problems; and, in particular if K contains connected structures only then these logics define precisely constraint satisfaction problems.
Proof. By Corollary 4.6 (resp. Corollary 4.7) every problem in MMSNP 1 (resp. MMSNP 2 ) is a finite union of problems from FPP 1 (resp. FPP 2 ). When restricted to a class K that has all restricted coloured dualities, every forbidden patterns problem is a restricted CSP. Moreover, any finite union of constraint satisfaction problems can be written using a sentence in MMSNP 1 [11,26]. This proves that the logics MMSNP 1 and MMSNP 2 , when restricted to a class K that has all restricted coloured dualities, define precisely finite unions of constraint satsifaction problems. Moreover, if we assume that the input is also connected, then a finite union of constraint satisfaction problems is a single constraint satisfaction problem: indeed, its template consists of the disjoint union of the template of each constraint satisfaction problem.
Remark 4.10. An alternative proof strategy would be to use Courcelle's method from [7] to build a sentence of MSO 1 and next to transform it hopefully into an equivalent sentence of MMSNP 1 using preservation under inverse homomorphisms as in Feder and Vardi's work on preservation theorem for MMSNP in [12]. However, even if successful such a proof strategy would only provide a proof that both logics become equally expressive and would not provide the collapse to (finite union of) CSP(s) as required.
Thus, Theorem 1.7 and Theorem 1.8 reformulated using Theorem 4.9 provides us with the analogous result for MMSNP to Courcelle's result for MSO. Corollary 4.11. On each of the following classes of simple graphs: those of degree at most k, those of tree-width at most k, for each k, planar graphs, and, more generally, every proper minor closed class, every sentence in MMSNP 2 is logically equivalent to a sentence of MMSNP 1 .
Courcelle has recently extended Theorem 4.8 to hypergraphs, which can be stated as follows in the case of graphs.
Theorem 4.12. [8] Let k > 0. Every sentence of MSO 2 is logically equivalent to a sentence of MSO 1 over uniformly k-sparse graphs.
Recall that a graph G is uniformly k-sparse if, and only if, every subgraph H of G is k-sparse, that is |E(H)| ≤ k.|V (H)|. This definition is equivalent to the following condition: G has an orientation such that every vertex has in-degree at most k (see Lemma 3.1 in [8]).
Remark 4.13. It follows directly from the definitions that a class of graphs with bounded expansion is uniformly k-sparse for some fixed k. However, we know that the converse implication can not hold as 2-sparse graphs do not have all restricted dualities. Indeed, we prove in Proposition 4.14 (see below) that there exists a problem definable by a first-order sentence of MMSNP 1 that is not a CSP even when restricted to uniformly 2-sparse graphs. However, this does not exclude that MMSNP 1 and MMSNP 2 are also equally expressive when restricted to uniformly k-sparse graphs.
The following was observed independently in [29]. We provide our own proof for completeness.
Proposition 4.14. Uniformly 2-sparse graphs do not have all restricted dualities.
Proof. Consider the problem Tri-Free whose yes-instances are triangle-free graphs. Consider the graph G n with n special elements, such that every pair of distinct special elements are linked by a path of length three (using additional vertices). We give an orientation to each edge on each of the path as follows: edges with a special vertex become arcs originating from this special vertex; and other edges are oriented arbitrarily. Note that every special vertex has in-degree zero and every non-special vertex has in-degree at most 2 (since it has degree at most 2). This shows that our graph is uniformly 2-sparse.
Moreover, by construction G n is triangle-free and no homomorphic image of this graph can identify special elements. The family of graphs (G n ) n∈N provides us with proofs (socalled witness family in [26]) that the problem can not be a finite union of (finite) constraint satisfaction problems even when restricted to graphs that are uniformly 2-sparse.

4.3.
Infinite constraint satisfaction problems and MMSNP 2 . Bodirsky et al. have investigated constraint satisfaction problems where the template is infinite. They have proposed restrictions that ensure that the problems are decidable (and in NP): when the template is countable and homogeneous in [4], and more recently to a more general case when the template is ω-categorical in [2]. Recall that a countable structure Γ is ω-categorical if all countable models of the first-order theory of Γ are isomorphic to Γ. Denote by CSP the set of constraint satisfaction problems that have a ω-categorical countable template and belong to NP. Remark 4.15. In [2], the definition of CSP is more restricted than ours. A template is required to be both ω-categorical and finitely constrained (see definition below). However, the property of being finitely constrained is only used in order to enforce that the problem belongs to NP. This motivates our more general definition. A countable structure Γ is finitely constrained if there is a first-order expansion Γ of Γ over some expanded signature τ and a finite set N of finite τ -structures such that Age(Γ ) = F orb(N ), where Age(Γ), the so-called age of Γ is the set of all finite induced substructures of Γ; and, by F orb(N), we denote the set of all finite structures that do not admit any of the structures from N as an induced substructure.
We say that a problem Ω is closed under disjoint union if for every structures A and B, their disjoint union A + B is a yes-instance of Ω whenever both A and B are yes-instances of Ω. Using a recent result due to Cherlin, Shelah and Chi [6], Bodirsky and Dalmau proved the following result. It follows directly from the definition that every problem in FPP 1 is closed under disjoint union. Hence, we get the following result. Since ω-categoricity is preserved under first-order interpretation, we can prove the following.
Theorem 4.18. Every problem in FPP 2 is in CSP . Consequently, every problem in MMSNP 2 is the union of finitely many problems in CSP .
Proof. Note that the second claim follows from the first claim together with Corollary 4.7. We now prove the first claim in the case of a problem Ω in FPP 2 . To simplify the notation, we assume that Ω is a problem over digraphs encoded using a single binary relation E. For simplicity, we may also assume that there are only arc colours (vertex colours can be easily encoded using more arc colours and additional forbidden patterns). Let E be the set of arc colours and let |E| = c.
Consider the problem Ω in MMSNP 1 defined over a structure with one monadic predicate T and one ternary predicate R, given by a sentence Φ with m = log c monadic predicates. We use these monadic predicates to encode the c colours in a natural way, using a conjunction χ a of m monadic predicates for each colour a (if necessary, Φ may contain negated conjuncts forbidding certain combinations of monadic predicates if 2 m > c). Each forbidden pattern (F, f E ) of Ω is encoded as a negated conjunct as follows: for each arc E(x, y) of colour a, add the literals R(x, e, y), T (e) and χ a (e).
The following formula provides an interpretation Π of the signature E in the signature T, R : ψ E (x, y) = ∃eT (e)∧R(x, e, y). By construction of Ω , this interpretation Π is a firstorder reduction from Ω to Ω. Note also that Ω is closed under disjunction (since every forbidden pattern of Ω is connected by definition of FPP 2 ). By Theorem 4.16, there exists an ω-categorical structure Γ such that Ω = CSP (Γ ). Let Γ be Π(Γ ). By Proposition 2.7 of [2] (page 27), it follows that Γ is also ω-categorical. Moreover, it is not difficult to check that Ω = CSP (Γ). Remark 4.19. As pointed out in [2], there are problems that are in CSP but not in MMSNP 1 . For example, the problem over directed graphs with template induced by the linear order over Q. Unfortunately, this problem is not expressible in MMSNP 2 either. In fact, we do not know whether MMSNP 1 is strictly contained in MMSNP 2 . Indeed, to the best of our knowledge, none of the problems used to separate MSO 1 from MSO 2 are expressible in MMSNP 2 . We suspect that the problem Edge-No-Mono-Tri is not expressible in MMSNP 1 and that MMSNP 1 is strictly contained in MMSNP 2 .

Conclusion
Our results. In this paper, we have proved that every forbidden patterns (with colours on both edges and vertices) problem is in fact a constraint satisfaction problem, when restricted to a class of structures that have low tree-depth decomposition: e.g. bounded degree structures, a proper minor closed class of structures and more generally a class of bounded expansion. We derive from this result that the logic MMSNP 2 (and MMSNP 1 ) coincides with the class of constraint satisfaction problems on connected inputs that belong to a class that has low tree-depth decomposition. Together these results cover the restrictions considered by Courcelle in [7] under which MSO 1 and MSO 2 have the same expressive power.
Some technical questions. Note that we do not know whether for unrestricted inputs, MMSNP 2 is more expressive than MMSNP 1 . Moreover, we have seen that Courcelle's more recent generalisation to uniformly k-sparse graphs [8] does not have an analog for MMSNP 1 , MMSNP 2 and constraint satisfaction problems. By this we mean that the two logics could well be equally expressive under this restriction, but they must necessarily capture problems that are not constraint satisfaction problems even when restricted to uniformly k-sparse graphs, for any fixed k ≥ 2.
Another point concerns the notion of a proper minor closed class of structures. In the present paper, we use the Gaifman graph to define this concept. However, it would be more natural and perhaps preferable to define a notion of minor for structures. The following definition seems reasonable. A minor of a structure S is obtained from S by performing a finite sequence of the following operations: taking a (not necessarily induced) substructure; and, identifying some elements, provided that they all occur in some tuple of some relation. This new definition subsumes the definition used in this paper and provokes the following question: Do the results of this paper hold under this new definition? A similar question arises for a class of structures with bounded expansion. In particular, is there a suitable definition that would be equivalent to low tree-depth decomposition (recall that to define this notion over structures we do not use the Gaifman graph)?
Future work. Apart from the above, perhaps technical questions, there are two general questions that we plan to investigate in future work. The first question is related to CSP , the class of (well-behaved) infinite constraint satisfaction problems introduced by Bodirsky. We know that any problem in MMSNP 2 is a finite union of problems from CSP . However, there are problems in CSP that are not expressible in MMSNP 2 , which yields the following question. Which logic (necessarily, some extension of MMSNP 2 ) defines precisely CSP ?
The second one concerns restricted duality and restricted coloured duality. We have given some ad-hoc techniques to lift results of restricted duality to restricted coloured duality for some of our examples. These techniques do not need to know precisely the construction of the universal graph in the case of restricted duality they reduce to. Instead they rely on the rather restricted form of our examples. We wonder whether this is indeed an artifact of the restricted nature of our examples or whether this can be done in general. In other words, Is it the case that all restricted dualities for a class K implies all restricted coloured dualities for K? 24 F. R. MADELAINE Related work. Independently to our work, Kun and Nešetřil have initiated an elegant new approach by means of lifts and shadows in [21]. In the sequel paper [22], they state a theorem, which corresponds to our main result, but in the case of vertex colours only. The approach these authors propose relies on the fact that (restricted) coloured duality can be reduced to (restricted) duality over an extended signature, where the additional symbols are monadic and used to encode the vertex colours. Since the property of being of bounded expansion does not depends on the monadic predicates, this means that one only needs to generalise the results concerning restricted duality for bounded expansion due to Nešetřil and Ossona de Mendez to arbitrary relational signature. In other words, the consideration of vertex colouring in our proof has become unecessary. We believe that it is possible to deal similarly with edge colours by defining a suitable notion of lift and follow the lines of Kun and Nešetřil's approach. This would allow us to remove the consideration of edge-colouring in our proof, simplifying it further.