Introduction
Robertson and Seymour’s Graph Minor Theorem [88 ] states that in every infinite sequence of graphs, some earlier graph is a minor of a later one. In particular, every minor-closed graph class is characterized by a finite set of forbidden minors. Unfortunately, the same does not hold for the induced subgraph relation: there are simple examples of infinite sequences of graphs without any pair being an induced subgraph of another (e.g., the sequence of all cycles). However, a well-quasi-ordering under induced subgraphs can be guaranteed when we restrict our attention to graphs of bounded treedepth [40 , 78 ] —a fundamental graph parameter with ties to the theory of graph sparsity. For a graph G G G , the treedepth measures the minimum depth among all forests F F F , called elimination forests, such that G G G is a subgraph of the ancestor-descendant closure of F F F [78 ] .
The existence of the aforementioned well-quasi-ordering has a broad algorithmic consequence for problems in the complexity class Strict NP , denoted SNP [54 , 81 ] . This class consists of all problems over relational structures expressible via a second-order sentence of the form
φ = ∃ R 1 ⋯ ∃ R r ∀ x 1 ⋯ ∀ x q ψ ( R 1 , … , R r , x 1 , … , x q ) , \varphi= \exists R_1 \cdots\exists R_r \forall x_1 \cdots\forall x_q \psi(R_1,\ldots,R_r,x_1,\ldots,x_q), φ = ∃ R 1 ⋯ ∃ R r ∀ x 1 ⋯ ∀ x q ψ ( R 1 , … , R r , x 1 , … , x q ) ,
where ψ \psi ψ is quantifier-free and may use the relations E 1 , … , E b E_1,\ldots,E_b E 1 , … , E b of the input structure. The existentially quantified variables range over relations on the input domain, and the universally quantified variables range over its elements. The relations R 1 , … , R r R_1,\ldots,R_r R 1 , … , R r may have arbitrary arity; a satisfying interpretation of these relations then constitutes a witness for the property expressed by φ \varphi φ .
The fact that the arity of the relations is unbounded is a crucial difference between SNP and monadic second-order logic (MSO). For example, a witness for an SNP property may contain a linear order on the entire domain or higher-arity relations describing interactions between several vertices. Moreover, the witness relations may be dense even if the input structure is sparse.
A crucial feature of this syntax is that satisfaction is preserved under taking induced substructures. Indeed, deleting elements and restricting the witness relations to the remaining domain preserves every constraint imposed by the universal first-order part. The well-quasi-ordering result also extends to relational structures over any fixed finite signature, with treedepth measured on their Gaifman graph3 [75 , 40 ] . Consequently, for each fixed formula and treedepth bound, the negative instances have a finite set of minimal obstructions under the induced-substructure relation. These fixed obstructions can be tested for on structures of bounded treedepth in linear time [34 ] , yielding the following well-established fact:
Fact F. For every problem P P P in SNP expressed by a fixed sentence φ \varphi φ and for every fixed integer k k k , there exists a linear-time algorithm that solves P P P on all relational structures whose Gaifman graph has treedepth at most k k k .
In the setting of graphs, the well-quasi-ordering argument applies to every hereditary graph property and Fact F is often understood in those terms. Note that avoiding a given set of finitely many induced subgraph obstructions arising from the well-quasi-ordering on bounded-treedepth graphs can be easily encoded in an SNP sentence—in this sense, Fact F establishes the existence of non-uniform linear-time algorithms for testing hereditary graph properties on graphs of bounded treedepth.
However, the generality of Fact F comes at a substantial price (see also [53 ] ):
It guarantees the existence of algorithms, but does not provide a procedure for constructing any such algorithm from φ \varphi φ and k k k .
It gives no computable bound on how the running time depends on φ \varphi φ and k k k .
The promised algorithm merely tests for obstructions—it does not construct witness relations.
In the language of parameterized complexity, algorithms whose existence is guaranteed in this way are sometimes called non-uniform fixed-parameter algorithms [31 Definition 6.15] . These are not fixed-parameter algorithms in the usual sense: fixed-parameter tractability (FPT) requires an algorithm whose running-time dependence on the formula length and treedepth is bounded by a computable function; see, for example, [37 Definition 2.1.1] , [50 Definition 1.4] , and [31 Definition 1.2] .4 For a range of hereditary graph problems, fixed-parameter tractability with respect to treedepth remained open despite the non-uniform linear-time algorithms guaranteed by Fact F. Well-known examples include computing the queue number [66 , 41 , 15 ] , stack number (also known as book thickness) [19 , 94 , 14 ] , track number [45 , 42 , 8 ] , or twin-width [24 BGK+24, GR26] of a graph5 ; all four cases have been explicitly identified as open problems even in recent works [8 GR26, 38 , 15 ] .
Our Contribution
We present a single, uniform, and constructive fixed-parameter algorithm for all problems in SNP parameterized by treedepth. In particular, we establish:
Theorem A (Simplified formulation of Theorem 1). There is an Algorithm A that takes as input an SNP sentence φ \varphi φ and a relational structure R \mathcal{R} R , decides whether R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ , and runs in time
f ( ∣ φ ∣ , td ( R ) ) ⋅ ∣ R ∣ f(|\varphi|,\operatorname{td}(\mathcal{R})) \cdot|\mathcal{R}| f ( ∣ φ ∣ , td ( R )) ⋅ ∣ R ∣ for some computable function f f f . Moreover, if R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ , the algorithm can output a witness for this in time
f ( ∣ φ ∣ , td ( R ) ) ⋅ ∣ R ∣ ar ( φ ) . f(|\varphi|,\operatorname{td}(\mathcal{R})) \cdot|\mathcal{R}|^{\operatorname{ar}(\varphi)}. f ( ∣ φ ∣ , td ( R )) ⋅ ∣ R ∣ ar ( φ ) . Here, ∣ R ∣ |\mathcal{R}| ∣ R ∣ denotes the encoding size of the input structure, td ( R ) \operatorname{td}(\mathcal{R}) td ( R ) is the treedepth of its Gaifman graph, and ar ( φ ) \operatorname{ar}(\varphi) ar ( φ ) denotes the maximum arity of any relation in { R 1 , … , R r } \{R_1,\ldots,R_r\} { R 1 , … , R r } . In particular, the theorem yields a fixed-parameter decision algorithm for every fixed sentence φ \varphi φ in SNP, parameterized by treedepth; it does not require a forbidden-substructure characterization as part of the input and the polynomial degree does not depend on φ \varphi φ . Moreover, it also allows us to output an explicit interpretation of the existentially quantified relations in φ \varphi φ as a witness for positive instances—however, such a witness may have size ∣ R ∣ ar ( φ ) |\mathcal{R}|^{\operatorname{ar}(\varphi)} ∣ R ∣ ar ( φ ) , necessitating a more relaxed running time bound.
Remark R. In the full statement of our main result, Theorem 1 in § 5 , we give a more fine-grained guarantee. The algorithm can output any requested subset of the witness relations, and the polynomial exponent depends only on the maximum arity among those relations.
A concrete description of A is deferred to the technical overview in the upcoming § 3 ; the full proof of our metatheorem is deferred to § 5 . One peculiarity of the result is the function f f f itself: our proof establishes computability via a concrete non-trivial procedure which constructs the function and is guaranteed to terminate, but does not itself provide any closed-form upper bound on its growth.
Applications. Theorem A resolves the parameterized complexity w.r.t. treedepth for a number of problems for which it was previously unknown. Concretely, we use our metatheorem to provide f ( td ( G ) ) ⋅ ∣ V ( G ) ∣ f(\operatorname{td}(G)) \cdot|V(G)| f ( td ( G )) ⋅ ∣ V ( G ) ∣ -time algorithms for computing the stack number, queue number, track number, twin-width, and boxicity of a graph G G G . These applications (which include all the examples listed below Fact F) are provided in § 6 .
Barriers for Generalizing the Metatheorem. We exclude in § 7 three natural generalizations of our result unless P = NP. First, we use Fagin’s theorem [48 ] to show that SNP formulas cannot be replaced with ESO formulas (where ψ \psi ψ can quantify over first-order variables, see, e.g., [73 ] ) while maintaining tractability w.r.t. treedepth. Second, we observe that there are SNP-problems which are NP-hard on graphs of pathwidth 2, meaning that it is impossible to generalize Theorem A to pathwidth. This shows a striking contrast to Courcelle’s theorem [34 ] , and the known results for ASNP and GMSNP described below. Third, we rule out a generalization to the complexity class MaxSNP 0 \operatorname{MaxSNP}_0 MaxSNP 0 [81 , 82 ] , which is the natural optimization variant of SNP.
Related Work. Feder and Vardi Feder and Vardi [54 ] established close connections between constraint satisfaction problems (CSPs) and monotone monadic SNP without inequality (MMSNP). They also showed that every problem in NP is polynomial-time equivalent to a problem in SNP.6 Hence, assuming P ≠ \ne = NP, we obtain from Ladner’s theorem [72 ] that, unlike for finite domain CSPs with a fixed constraint language and MMSNP [28 , 96 , 70 ] , there is no complexity dichotomy for SNP. Madelaine [76 ] studies the connections between MMSNP and CSPs on classes of bounded treedepth. Other relevant fragments of SNP include guarded monotone SNP (GMSNP) [27 ] and amalgamation SNP (ASNP) [22 ] . The latter work showed that for each fixed ASNP or GMSNP sentence and treewidth bound there is a polynomial-time model checking algorithm (see also the introduction of Bodirsky and Guzmán-Pro [11 ] for further background on GMSNP). Since SNP sentences define hereditary properties, SNP satisfies a 0-1 law: each sentence is either true on all finite structures or false on almost all finite structures. Kolaitis and Vardi [71 ] showed that it is moreover decidable, given an SNP sentence, which of these two cases holds. Their proof uses Ramsey arguments on atomic types, which are core building blocks that our proof relies on as well. We provide a detailed discussion of the similarities and differences of their work compared to ours in § 5.7 .
Classical metatheorems provide FPT algorithms for monadic second-order logic M S O 2 \mathrm{MSO}_2 MSO 2 on graphs of bounded treewidth [34 , 25 ] , M S O 1 \mathrm{MSO}_1 MSO 1 on graphs of bounded clique-width [33 , 80 ] , and first-order logic (FO) on effectively nowhere dense graph classes [60 ] . The bounded-treewidth results also cover MSO on relational structures and output-sensitive query evaluation [49 ] . Gajarský and Hliněný [57 ] obtained algorithms for MSO model checking on graphs of bounded treedepth by kernelizing labeled trees of bounded height. More recently, Bergougnoux, Chekan, and Stamoulis [7 ] proposed randomized algorithms with single-exponential dependence on treedepth and polynomial space for each fixed formula of a logic extending fully existential M S O 2 \mathrm{MSO}_2 MSO 2 , assuming that an elimination forest is given in the input.
The logical scope of these results differs from ours. On the one hand, SNP can only express properties that are closed under taking induced substructures, and therefore cannot express non-hereditary properties such as Hamiltonian Cycle, which are captured by M S O 2 \mathrm{MSO}_2 MSO 2 [34 ] . On the other hand, SNP allows existential quantification over arbitrary relations on the domain, whereas M S O 1 \mathrm{MSO}_1 MSO 1 and M S O 2 \mathrm{MSO}_2 MSO 2 quantify over vertex sets and, for M S O 2 \mathrm{MSO}_2 MSO 2 , also edge sets. As mentioned above, some of our applications are already NP-hard on graphs of bounded pathwidth, so their tractability cannot follow from metatheorems that apply to classes of bounded pathwidth, assuming P ≠ N P \mathrm{P} \ne\mathrm{NP} P = NP .
Recall that our result provides a single uniform algorithm for all of SNP, parameterized by the formula length and the treedepth of the input structure. So to some extent, the distinction between uniform and non-uniform tractability is at the heart of our contribution. Due to the graph minor theorem [88 ] coupled with polynomial-time minor testing [87 ] , this question has historically been of special interest for minor-closed graph classes [51 , 52 , 53 ] . Courcelle, Downey, and Fellows [30 ] showed that the forbidden minors cannot be computed from an M S O 2 \mathrm{MSO}_2 MSO 2 description of the class alone. Under additional assumptions, Adler, Grohe, and Kreutzer [3 ] give an algorithm that computes sets of forbidden minors. For vertex deletion to a fixed minor-closed class, Sau, Stamoulis, and Thilikos bound the size of the resulting obstructions [90 ] and give parameterized algorithms [89 ] .
Technical Overview
In this section, we provide a high-level overview of the main proof ingredients used to establish Theorem A. For formal definitions and proofs, we refer to later sections. Throughout this section, let ( φ , R ) (\varphi,\mathcal{R}) ( φ , R ) be an instance of SNP Model Checking, i.e., the problem of deciding whether R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ holds, where φ = ∃ R 1 , … , R r ∀ x 1 … ∀ x k ψ \varphi= \exists R_1,\ldots,R_r \forall x_1\ldots\forall x_k \psi φ = ∃ R 1 , … , R r ∀ x 1 … ∀ x k ψ is an SNP sentence and R = ( V , E 1 , … , E b ) \mathcal{R}=(V,E_1,\ldots,E_b) R = ( V , E 1 , … , E b ) a relational structure. We call a tuple ( R 1 ′ , … , R r ′ ) (R'_1,\ldots,R'_r) ( R 1 ′ , … , R r ′ ) of relations R i ′ ⊆ V ( R ) ar ( R i ) R'_i \subseteq V(\mathcal{R})^{\operatorname{ar}(R_i)} R i ′ ⊆ V ( R ) ar ( R i ) , for i ∈ [ r ] i \in[r] i ∈ [ r ] , a solution if
( R , R 1 ′ , … , R r ′ ) ⊨ ∀ x 1 … ∀ x k ψ . (\mathcal{R},R'_1,\ldots,R'_r) \models\forall x_1\ldots\forall x_k\,\psi. ( R , R 1 ′ , … , R r ′ ) ⊨ ∀ x 1 … ∀ x k ψ .
For the purpose of this overview, we assume that the domain V V V comes with (an arbitrarily constructed) fixed total order, allowing us to speak about smaller and smallest elements. Before we discuss our main result, let us first describe a pruning-based non-uniform algorithm U \mathbb{U} U for SNP Model Checking and examine the guarantees it provides.
Extending the Non-Uniform Algorithm
Fix φ \varphi φ and a positive integer h h h . As hinted in § 1 , there is some finite obstruction set J h , φ \mathcal{J}_{h,\varphi} J h , φ , such that a relational structure R \mathcal{R} R with treedepth at most h h h satisfies φ \varphi φ if and only if it contains no structure of J h , φ \mathcal{J}_{h,\varphi} J h , φ as an induced substructure. When analyzing the structure of an elimination forest T T T of the Gaifman graph of R \mathcal{R} R , it is not hard to see that we can define some notion of types for V ( T ) V(T) V ( T ) and “prune” T T T to only keep a bounded number of siblings of the same type. Indeed, it is possible to define the types in such a way that, given an integer p p p , we can prune R \mathcal{R} R to an induced substructure R p \mathcal{R}^{p} R p of size bounded by a computable function g ( p , h ) g(p,h) g ( p , h ) , such that R \mathcal{R} R contains an induced substructure of size at most p p p if and only if R p \mathcal{R}^{p} R p contains the same induced substructure. Intuitively, we keep at most p p p sibling-leaves for each possible interaction between the ancestors of a leaf and the relational structure R \mathcal{R} R (whose number can be bounded in h h h and ∣ φ ∣ |\varphi| ∣ φ ∣ ). After this step, the substructures rooted at the parents of the leaves can only have one out of boundedly-many “isomorphism and neighborhood types”, and we can iteratively apply the above-sketched idea on our way to the root of T T T .
Thus, if an oracle provided us with the size M M M of the largest obstruction in J h , φ \mathcal{J}_{h,\varphi} J h , φ , we could set p = M p=M p = M and have R p ⊨ φ \mathcal{R}^{p} \models\varphi R p ⊨ φ if and only if R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ .7 Since the size of R p \mathcal{R}^{p} R p is bounded by g ( p , h ) g(p,h) g ( p , h ) , we can decide whether R p ⊨ φ \mathcal{R}^{p} \models\varphi R p ⊨ φ by brute force. This immediately gives rise to our pruning-based non-uniform algorithm U \mathbb{U} U : Prune R \mathcal{R} R to R p \mathcal{R}^{p} R p and check whether R p ⊨ φ \mathcal{R}^{p} \models\varphi R p ⊨ φ . This approach has one inherent catch: up front, it is not clear how we can compute the correct value of p p p as it depends on the unknown set of forbidden substructures J h , φ \mathcal{J}_{h,\varphi} J h , φ .
A natural approach to circumvent this limitation is to try increasing values of p p p . This leads to a “semi-FPT” algorithm: If we find a p p p such that R p ⊭ φ \mathcal{R}^{p} \not\models\varphi R p ⊨ φ , we face a negative instance and can terminate. In fact, since J h , φ \mathcal{J}_{h,\varphi} J h , φ is finite, this algorithm will eventually terminate for every negative instance ( φ , R ) (\varphi,\mathcal{R}) ( φ , R ) and the maximum iteration count depends only on h h h and φ \varphi φ . The crux lies with positive instances: since the correct upper bound for p p p is unknown, we cannot phrase a termination criterion for our algorithm. Hence, the issue is one-sided: for negative instances, the obstructions in J h , φ \mathcal{J}_{h,\varphi} J h , φ form a finite set of bounded-sized “negative certificates”, and we eventually uncover such a certificate when facing a negative instance. What is missing to turn this into a working FPT algorithm is a set of certificates for positive instances that give us similar guarantees.
The key step for bounded treedepth is to obtain positive certificates that can be recognized on a bounded-size pruned instance and extended to the original input. We define such certificates and show that if R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ then there exists a large enough p p p (depending only on φ \varphi φ and td ( R ) \operatorname{td}(\mathcal{R}) td ( R ) ) such that R p \mathcal{R}^{p} R p contains one. The uniform Algorithm A \mathbb{A} A is then a natural extension of the above-sketched “semi-FPT” algorithm. Starting at a certain threshold value (depending only on φ \varphi φ and td ( R ) \operatorname{td}(\mathcal{R}) td ( R ) ), we iteratively examine values for p p p in increasing order. For each such p p p , we check whether R p ⊭ φ \mathcal{R}^{p} \not\models\varphi R p ⊨ φ , in which case we can correctly output that R ⊭ φ \mathcal{R} \not\models\varphi R ⊨ φ . If R p ⊨ φ \mathcal{R}^{p} \models\varphi R p ⊨ φ , we additionally check whether R p \mathcal{R}^{p} R p admits one of our positive certificates. If this is the case, then we can correctly deduce R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ . Otherwise, we continue with p + 1 p+1 p + 1 .
What makes this approach work is that bounded-size certificates now exist for any relational structure R \mathcal{R} R , regardless of whether we are facing a positive or negative instance. Besides allowing us to show that A \mathcal{A} A terminates in time f ( φ , td ( R ) ) ⋅ ∣ R ∣ f(\varphi,\operatorname{td}(\mathcal{R}))\cdot|\mathcal{R}| f ( φ , td ( R )) ⋅ ∣ R ∣ , positive certificates will also provide us with a “recipe” to extend a witness for R p ⊨ φ \mathcal{R}^{p}\models\varphi R p ⊨ φ into a witness for R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ . Interestingly, we do not know a closed-form expression for the function f f f : it depends on the size of the largest obstruction in J H , φ \mathcal{J}_{\mathcal{H},\varphi} J H , φ , for which we have no explicit bound. However, we stress that the function f f f is computable. Next, we describe these positive certificates in greater detail.
Certificates for Positive Instances
Let T T T be a treedepth decomposition of R \mathcal{R} R of height h ≤ td ( R ) + 1 h\leq\operatorname{td}(\mathcal{R})+1 h ≤ td ( R ) + 1 , i.e., an elimination tree of the primal graph of R \mathcal{R} R . The additional + 1 +1 + 1 stems from requiring T T T to be a tree, which simplifies the upcoming discussion. Since the vertex set of T T T equals the set of elements of R \mathcal{R} R , we use the terms “element” and “vertex” to refer to the same object. As indicated in § 3.1 , it is natural to define some notion of types when working with T T T . We build our notion of types on the standard notion of an atomic type (see, for example, [73 p. 226] ). The atomic type of a tuple ( v 1 , … , v z ) ∈ V z (v_1,\ldots,v_z)\in V^z ( v 1 , … , v z ) ∈ V z , for some z ∈ N z\in\mathbb{N} z ∈ N , captures which atoms on v 1 , … , v z v_1,\ldots,v_z v 1 , … , v z are true and which are false, which we use in the following form.
Definition 1 (Atomic type). Let R = ( V , E 1 , … , E b ) \mathcal{R}=(V,E_1,\ldots,E_b) R = ( V , E 1 , … , E b ) be a relational structure and let z ∈ N z\in\mathbb{N} z ∈ N . An atomic formula over the variables x 1 , … , x z x_1,\ldots,x_z x 1 , … , x z is a formula of the form E i ( x n 1 , … , x n a ) E_i(x_{n_1},\ldots,x_{n_a}) E i ( x n 1 , … , x n a ) with i ∈ [ b ] i\in[b] i ∈ [ b ] , a = ar ( E i ) a=\operatorname{ar}(E_i) a = ar ( E i ) and ( n 1 , … , n a ) ∈ [ z ] a (n_1,\ldots,n_a)\in[z]^a ( n 1 , … , n a ) ∈ [ z ] a , or of the form x n = x n ′ x_n=x_{n'} x n = x n ′ with ( n , n ′ ) ∈ [ z ] 2 (n,n')\in[z]^2 ( n , n ′ ) ∈ [ z ] 2 . The atomic type of a tuple ( v 1 , … , v z ) ∈ V z (v_1,\ldots,v_z)\in V^z ( v 1 , … , v z ) ∈ V z in R \mathcal{R} R is
atp R ( v 1 , … , v z ) : = { α ( x 1 , … , x z ) atomic ∣ R ⊨ α ( v 1 , … , v z ) } . \operatorname{atp}_{\mathcal{R}}(v_1,\ldots,v_z):=\{\alpha(x_1,\ldots,x_z)\ \text{atomic}\mid\mathcal{R}\models\alpha(v_1,\ldots,v_z)\}. atp R ( v 1 , … , v z ) := { α ( x 1 , … , x z ) atomic ∣ R ⊨ α ( v 1 , … , v z )} .
In addition to atomic types, we need some notion of type that is defined w.r.t. T T T , which we call the vertex p p p -type for an integer p ≥ 1 p\geq1 p ≥ 1 that will play the role of the pruning threshold from § 3.1 . For simplicity, let us assume for a moment that R \mathcal{R} R encodes a graph G G G . Then, the vertex p p p -type of a leaf v v v of T T T stores which of its up to h − 1 h-1 h − 1 ancestors are neighbors. For a non-leaf v v v of T T T , we additionally store how many children v v v has of each vertex p p p -type up to the number p p p to ensure that the overall number of types remains bounded in p p p and h h h . This is a common technique when tackling graph problems parameterized by treedepth; see, e.g., [57 , 15 ] . For general relational structures, adjacency is replaced by the atomic type of the root-to-v v v path in T T T . Formally, the vertex p p p -type is defined as follows.
Definition 2 (Vertex p p p -type). Let p ∈ N p\in\mathbb{N} p ∈ N and R \mathcal{R} R be a relational structure with treedepth decomposition T T T . For any v ∈ V ( R ) v\in V(\mathcal{R}) v ∈ V ( R ) , its vertex p p p -type in ( R , T ) (\mathcal{R},T) ( R , T ) is the tuple p -type ( v ) = ( δ v , λ v ) p\text{-type}(v)=(\delta_v,\lambda_v) p -type ( v ) = ( δ v , λ v ) for an ancestor label λ v \lambda_v λ v and a subtree label δ v \delta_v δ v , defined as follows.
Let d d d be the depth of v v v in T T T and P = w 1 , w 2 , … , w d P=w_1,w_2,\ldots,w_d P = w 1 , w 2 , … , w d be the path from root w 1 w_1 w 1 of T T T to vertex v = w d v=w_d v = w d . The ancestor label λ v = atp R ( w 1 , w 2 , … , w d ) \lambda_v=\operatorname{atp}_{\mathcal{R}}(w_1,w_2,\ldots,w_d) λ v = atp R ( w 1 , w 2 , … , w d ) is the atomic type of the vertices on P P P .
The subtree label is defined recursively. All leaves in T T T have the empty subtree label ε \varepsilon ε . For a non-leaf vertex v ∈ V ( T ) v\in V(T) v ∈ V ( T ) , let C v C_v C v be the set of children of v v v in T T T , and T T T be the set { p -type ( w ) ∣ w ∈ C v } \{p\text{-type}(w)\mid w\in C_v\} { p -type ( w ) ∣ w ∈ C v } . The subtree label is then a function δ v : T → [ 0 , p − 1 ] ∪ { ⋆ } \delta_v:T\to[0,p-1]\cup\{\star\} δ v : T → [ 0 , p − 1 ] ∪ { ⋆ } , defined by
δ v ( t ) = { ∣ { w ∈ C v ∣ p -type ( w ) = t } ∣ if ∣ { w ∈ C v ∣ p -type ( w ) = t } ∣ ≤ p − 1 , ⋆ otherwise. \delta_v(t)=
\begin{cases}
\lvert\{w\in C_v\mid p\text{-type}(w)=t\}\rvert& \text{if }\lvert\{w\in C_v\mid p\text{-type}(w)=t\}\rvert\leq p-1,\\
\star& \text{otherwise.}
\end{cases} δ v ( t ) = { ∣{ w ∈ C v ∣ p -type ( w ) = t }∣ ⋆ if ∣{ w ∈ C v ∣ p -type ( w ) = t }∣ ≤ p − 1 , otherwise. Hence, λ v \lambda_v λ v stores information about the ancestors of v v v in T T T , while δ v \delta_v δ v tells us how many of each kind of child v v v has. Observe that δ v ( t ) = ⋆ \delta_v(t)=\star δ v ( t ) = ⋆ indicates that v v v has at least p p p children of vertex p p p -type t t t ,
meaning that the amount of stored information is bounded by a function of the treedepth and p p p . In the following, we say that a vertex p p p -type t t t is p-abundant in the type t ′ t' t ′ if δ v ( t ) = ⋆ \delta_v(t)=\star δ v ( t ) = ⋆ for some vertex v v v with vertex p p p -type t ′ t' t ′ . This allows us to define a crucial notion: the s s s -multiplicity structure R s \mathcal{R}^s R s of R \mathcal{R} R , T T T , and p p p , for an integer s ≥ p s \ge p s ≥ p . Intuitively, R s \mathcal{R}^s R s has precisely s s s copies of the p p p -abundant children of each vertex v v v ; non-abundant types remain unchanged. Thus, the value of p p p determines which vertex p p p -types of children of a vertex are abundant, whereas s s s specifies their multiplicity in R s \mathcal{R}^s R s —put simply, we count up to p − 1 p-1 p − 1 and then represent “p p p or more” via s s s .
We can construct R s \mathcal{R}^s R s in a two-step procedure: First, we keep the smallest s s s siblings of each p p p -abundant type and delete the remaining ones (if there are any) together with their entire subtrees. By doing so, we also have to restrict all input relations to the retained elements. Second, we process the pruned tree bottom-up. If we encounter a vertex with fewer than s s s children of a p p p -abundant type, we construct copies to bring their number up to s s s .
For s = p s=p s = p , the above construction is a formalization of the pruning operation described in § 3.1 . In particular, we can observe that R p \mathcal{R}^p R p is an induced substructure of R \mathcal{R} R and thus R p ⊭ φ \mathcal{R}^p \not\models\varphi R p ⊨ φ implies R ⊭ φ \mathcal{R} \not\models\varphi R ⊨ φ . Note that for s > p s>p s > p , R s \mathcal{R}^s R s may contain elements not present in R \mathcal{R} R . While allowing for R s ⊈ R \mathcal{R}^s \not\subseteq\mathcal{R} R s ⊆ R sounds counterintuitive at first, this is useful in § 3.4 when we show that positive certificates exist for a suitable choice of p p p .
The p p p -multiplicity structure R p \mathcal{R}^p R p is an important stepping stone towards our concept of positive certificates. Essentially, positive certificates are well-structured witnesses of R p ⊨ φ \mathcal{R}^p \models\varphi R p ⊨ φ that can be extended to a witness of R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ . Observe that an SNP formula φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ \varphi= \exists R_1,\ldots,R_r \ \forall x_1,\ldots,x_k : \psi φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ can express forbidden substructures on at most k k k elements. To detect these forbidden substructures, we cannot consider individual elements but have to consider tuples of size at most k k k . This makes an extension of vertex p p p -types to tuples natural.
Defining the correct notion of a “tuple type” is non-trivial. On the one hand, if the notion is too coarse, there is no guarantee that we can obtain a solution for R \mathcal{R} R from a positive certificate for R p \mathcal{R}^p R p . On the other hand, if the notion is too fine-grained, the number of types cannot be bounded, and we cannot hope that R p \mathcal{R}^p R p admits a positive certificate. Intuitively, we want a notion of “tuple type” such that the following implication holds:
tuples ( v 1 , … , v k ) and ( w 1 , … , w k ) have the same “tuple type” ⟹ v 1 , … , v k behave identically to w 1 , … , w k in a positive certificate. (1) \begin{aligned}
&\text{tuples }(v_1,\ldots,v_k)\text{ and }(w_1,\ldots,w_k)\text{ have the same “tuple type”}\\
&\Longrightarrow\\
&v_1,\ldots,v_k\text{ behave identically to }w_1,\ldots,w_k\text{ in a positive certificate.} \tag*{(1)}
\end{aligned} tuples ( v 1 , … , v k ) and ( w 1 , … , w k ) have the same “tuple type” ⟹ v 1 , … , v k behave identically to w 1 , … , w k in a positive certificate. (1)
One could now be tempted to define the “tuple type” of ( v 1 , … , v k ) (v_1,\ldots,v_k) ( v 1 , … , v k ) by taking the k k k -tuple of the vertex p p p -types of v 1 , … , v k v_1,\ldots,v_k v 1 , … , v k . However, this initial idea completely breaks down even for the simplest structures , as the following example shows. Let R \mathcal{R} R encode a star on n n n leaves. An SNP sentence φ \varphi φ can express the existence of a total order ≺ \prec ≺ on the elements V ( R ) V(\mathcal{R}) V ( R ) of R \mathcal{R} R . Any total order suffices, so clearly R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ . Although any two k k k -tuples of leaves would have the same “naive” tuple type, they cannot behave identically in any solution. To make this concrete, consider a total order ≺ \prec ≺ on V ( R ) V(\mathcal{R}) V ( R ) , fix k = 2 k=2 k = 2 and some leaves v 1 , v 2 , w 1 , w 2 v_1,v_2,w_1,w_2 v 1 , v 2 , w 1 , w 2 with v 1 ≺ v 2 v_1 \prec v_2 v 1 ≺ v 2 and w 2 ≺ w 1 w_2 \prec w_1 w 2 ≺ w 1 . Then, ( v 1 , v 2 ) (v_1,v_2) ( v 1 , v 2 ) and ( w 1 , w 2 ) (w_1,w_2) ( w 1 , w 2 ) would have the same type, yet ( v 1 , v 2 ) (v_1,v_2) ( v 1 , v 2 ) behaves differently than ( w 1 , w 2 ) (w_1,w_2) ( w 1 , w 2 ) in the considered solution. In a nutshell, SNP is powerful enough to distinguish between elements that seem indistinguishable in the input relational structure. This requires us to define some notion of “tuple types” which can, on the one hand, distinguish between siblings in a meaningful manner but, on the other hand, still ensure that the number of types is bounded. Towards finding the correct notion of “tuple types”, we define p p p -routes, which enrich the concept of a vertex p p p -type with a “map” of how to reach it from the root of T T T .
Definition 3 (p p p -route and p p p -route of a vertex). Consider a relational structure R \mathcal{R} R with treedepth decomposition T T T , and an integer p ≥ 1 p \ge1 p ≥ 1 . A p p p -route is a non-empty finite sequence ϱ = ( e 1 , … , e d ) \varrho= (e_1, \ldots, e_d) ϱ = ( e 1 , … , e d ) of entries e ℓ = ( t ℓ , i ℓ ) e_\ell= (t_\ell, i_\ell) e ℓ = ( t ℓ , i ℓ ) , each consisting of a vertex p p p -type t ℓ t_\ell t ℓ and an index i ℓ ∈ N i_\ell\in\mathbb{N} i ℓ ∈ N ; we call d d d the length of ϱ \varrho ϱ also denoted as ∣ ϱ ∣ |\varrho| ∣ ϱ ∣ . The entry e ℓ e_\ell e ℓ is abundant if ℓ ≥ 2 \ell\ge2 ℓ ≥ 2 and t ℓ t_\ell t ℓ is p p p -abundant in t ℓ − 1 t_{\ell-1} t ℓ − 1 .
We write rt ( v ) \operatorname{rt}(v) rt ( v ) for the p p p -route of a vertex v v v of T T T , which is defined recursively as follows. For the root u u u of T T T we set rt ( u ) = ( ( p -type ( u ) , 1 ) ) \operatorname{rt}(u) = ((p\text{-type}(u), 1)) rt ( u ) = (( p -type ( u ) , 1 )) .
Let v v v be a non-root vertex in T T T and t = p -type ( v ) t = p\text{-type}(v) t = p -type ( v ) . Let w w w be the parent of v v v and let i ∈ N i \in\mathbb{N} i ∈ N be such that v v v is the i i i -th smallest8 element among all children of w w w of type t t t . Then rt ( v ) = rt ( w ) ⋄ ( t , i ) \operatorname{rt}(v) = \operatorname{rt}(w) \mathbin{\diamond} (t, i) rt ( v ) = rt ( w ) ⋄ ( t , i ) .
Any given element of R \mathcal{R} R is uniquely identified by its p p p -route in T T T . To see this, start from the root of T T T , and then descend the tree according to the route. Each entry of the route tells us, for each vertex we encounter, which of its children we need to follow; Figure 1 visualizes such a descent. However, on its own it is not a useful definition of a “tuple type”: The indices can be arbitrarily large, giving us no hope that we can bound the number of p p p -routes.
Figure 1. A p p p -route rt ( v ) \operatorname{rt}(v) rt ( v ) (right) identifying a vertex v v v in a treedepth decomposition T T T (left).
The key idea now is that p p p -routes can be normalized in a way that achieves the desired properties. Recalling the total order example from the previous page, we already know that the vertex p p p -types do not suffice to capture behavior w.r.t. a hypothetical witness. However, we will later show that our witnesses can be assumed to be, in a carefully defined sense, uniform towards the considered “arbitrary” total order on V V V . So while ( a , b ) (a,b) ( a , b ) can behave differently than ( c , d ) (c,d) ( c , d ) w.r.t. a solution if these are the respectively 10th, 100th, 30th and 25th elements of the same vertex p p p -type, we will make sure that it is only their relative order that matters in the end. The idea is that we will not store the counting information in the p p p -route “maps” exactly, but in a way which is guaranteed to preserve the relative ordering among a set S S S of such maps. This is captured by the notion of a p p p -route pattern.
Definition 4 (Normalization and p p p -route pattern). Consider a relational structure R \mathcal{R} R with treedepth decomposition T T T and an integer p ≥ 1 p \ge1 p ≥ 1 . Let S S S be a finite set of p p p -routes. Define
I ( S ) = { i ∣ there is an abundant entry ( t , i ) in at least one route of S } , I(S) = \{i \mid\text{there is an abundant entry }(t,i)\text{ in at least one route of }S\}, I ( S ) = { i ∣ there is an abundant entry ( t , i ) in at least one route of S } , and let π S : I ( S ) → [ ∣ I ( S ) ∣ ] \pi_S: I(S) \to[|I(S)|] π S : I ( S ) → [ ∣ I ( S ) ∣ ] map each index to its rank in I ( S ) I(S) I ( S ) , that is, π S ( i ) = ∣ { i ′ ∈ I ( S ) ∣ i ′ ≤ i } ∣ \pi_S(i) = |\{i' \in I(S) \mid i' \le i\}| π S ( i ) = ∣ { i ′ ∈ I ( S ) ∣ i ′ ≤ i } ∣ .
We now replace every entry e ℓ e_\ell e ℓ in every p p p -route in S S S by
e ^ ℓ = { ( t ℓ , π S ( i ℓ ) ) if e ℓ = ( t ℓ , i ℓ ) is abundant , e ℓ otherwise . \hat{e}_\ell=
\begin{cases}
(t_\ell,\pi_S(i_\ell)) & \text{if } e_\ell=(t_\ell,i_\ell)\text{ is abundant},\\
e_\ell& \text{otherwise}.
\end{cases} e ^ ℓ = { ( t ℓ , π S ( i ℓ )) e ℓ if e ℓ = ( t ℓ , i ℓ ) is abundant , otherwise .
and call ν S ( ϱ ) = ( e ^ 1 , … , e ^ d ) \nu_S(\varrho)=(\hat{e}_1,\ldots,\hat{e}_d) ν S ( ϱ ) = ( e ^ 1 , … , e ^ d ) the normalization of ϱ \varrho ϱ with respect to S S S . We write ν S ( S ′ ) = { ν S ( ϱ ) ∣ ϱ ∈ S ′ } \nu_S(S')=\{\nu_S(\varrho)\mid\varrho\in S'\} ν S ( S ′ ) = { ν S ( ϱ ) ∣ ϱ ∈ S ′ } for S ′ ⊆ S S'\subseteq S S ′ ⊆ S .
Let ( v 1 , … , v z ) (v_1,\ldots,v_z) ( v 1 , … , v z ) be a tuple of elements of R \mathcal{R} R , (i.e., vertices of T T T ) and let S = { rt ( v 1 ) , … , rt ( v z ) } S=\{\operatorname{rt}(v_1),\ldots,\operatorname{rt}(v_z)\} S = { rt ( v 1 ) , … , rt ( v z )} be the set of their p p p -routes. The p p p -route pattern of ( v 1 , … , v z ) (v_1,\ldots,v_z) ( v 1 , … , v z ) is the tuple ( ν S ( rt ( v 1 ) ) , … , ν S ( rt ( v z ) ) ) (\nu_S(\operatorname{rt}(v_1)),\ldots,\nu_S(\operatorname{rt}(v_z))) ( ν S ( rt ( v 1 )) , … , ν S ( rt ( v z ))) .
Note that the normalization is applied to all abundant entries of a tuple of p p p -routes together, regardless of where in the route they appear. Let us give an example to illustrate the definition.
Example. Let p = 4 p=4 p = 4 , let t 1 t_1 t 1 be the vertex p p p -type of the root of T T T , and suppose the p p p -routes of v 1 , v 2 , v 3 , v 4 v_1,v_2,v_3,v_4 v 1 , v 2 , v 3 , v 4 are, respectively, displayed as column vectors below:
( ( ( t 1 , 1 ) ( t 2 , 3 ) ( t 3 , 7 ) ( t 4 , 6 ) ) , ( ( t 1 , 1 ) ( t 2 , 3 ) ( t 3 , 4 ) ) , ( ( t 1 , 1 ) ( t 2 , 7 ) ( t 3 , 3 ) ) , ( ( t 1 , 1 ) ( t 2 ′ , 2 ) ( t 3 , 3 ) ) ) . \left(
\begin{pmatrix}
(t_1,1)\\
(t_2,3)\\
(t_3,7)\\
(t_4,6)
\end{pmatrix},
\begin{pmatrix}
(t_1,1)\\
(t_2,3)\\
(t_3,4)
\end{pmatrix},
\begin{pmatrix}
(t_1,1)\\
(t_2,7)\\
(t_3,3)
\end{pmatrix},
\begin{pmatrix}
(t_1,1)\\
(t'_2,2)\\
(t_3,3)
\end{pmatrix}
\right). ( t 1 , 1 ) ( t 2 , 3 ) ( t 3 , 7 ) ( t 4 , 6 ) , ( t 1 , 1 ) ( t 2 , 3 ) ( t 3 , 4 ) , ( t 1 , 1 ) ( t 2 , 7 ) ( t 3 , 3 ) , ( t 1 , 1 ) ( t 2 ′ , 2 ) ( t 3 , 3 ) .
Suppose further that t 2 t_2 t 2 is p p p -abundant in t 1 t_1 t 1 , that t 3 t_3 t 3 is p p p -abundant in t 2 t_2 t 2 , and that t 4 t_4 t 4 is p p p -abundant in t 3 t_3 t 3 , while t 2 ′ t'_2 t 2 ′ is not p p p -abundant in t 1 t_1 t 1 and t 3 t_3 t 3 is not p p p -abundant in t 2 ′ t'_2 t 2 ′ . The abundant entries are then all entries of the first three routes except their first ones (highlighted in blue ), and the indices they contribute are I ( S ) = { 3 , 4 , 6 , 7 } I(S)=\{3,4,6,7\} I ( S ) = { 3 , 4 , 6 , 7 } , so π S \pi_S π S maps 3 , 4 , 6 , 7 3,4,6,7 3 , 4 , 6 , 7 to 1 , 2 , 3 , 4 1,2,3,4 1 , 2 , 3 , 4 , respectively. Hence the p p p -route pattern of ( v 1 , v 2 , v 3 , v 4 ) (v_1,v_2,v_3,v_4) ( v 1 , v 2 , v 3 , v 4 ) is
( ( ( t 1 , 1 ) ( t 2 , 1 ) ( t 3 , 4 ) ( t 4 , 3 ) ) , ( ( t 1 , 1 ) ( t 2 , 1 ) ( t 3 , 2 ) ) , ( ( t 1 , 1 ) ( t 2 , 4 ) ( t 3 , 1 ) ) , ( ( t 1 , 1 ) ( t 2 ′ , 2 ) ( t 3 , 3 ) ) ) . \left(
\begin{pmatrix}
(t_1,1)\\
(t_2,1)\\
(t_3,4)\\
(t_4,3)
\end{pmatrix},
\begin{pmatrix}
(t_1,1)\\
(t_2,1)\\
(t_3,2)
\end{pmatrix},
\begin{pmatrix}
(t_1,1)\\
(t_2,4)\\
(t_3,1)
\end{pmatrix},
\begin{pmatrix}
(t_1,1)\\
(t'_2,2)\\
(t_3,3)
\end{pmatrix}
\right). ( t 1 , 1 ) ( t 2 , 1 ) ( t 3 , 4 ) ( t 4 , 3 ) , ( t 1 , 1 ) ( t 2 , 1 ) ( t 3 , 2 ) , ( t 1 , 1 ) ( t 2 , 4 ) ( t 3 , 1 ) , ( t 1 , 1 ) ( t 2 ′ , 2 ) ( t 3 , 3 ) .
Note that π S \pi_S π S is applied to an index regardless of where that index occurs. The index 3 will be replaced by 1 both in the entries ( t 2 , 3 ) (t_2,3) ( t 2 , 3 ) of the first two routes and in the entry ( t 3 , 3 ) (t_3,3) ( t 3 , 3 ) of the third. Likewise, the index 7 is replaced with 4 both in ( t 3 , 7 ) (t_3,7) ( t 3 , 7 ) and in ( t 2 , 7 ) (t_2,7) ( t 2 , 7 ) . The p p p -route of v 4 v_4 v 4 is left untouched, since it consists of entries of non-p p p -abundant vertices, whose indices are at most p − 1 p-1 p − 1 to begin with. In particular, one and the same entry may be renumbered in one route and kept in another: the entry ( t 3 , 3 ) (t_3,3) ( t 3 , 3 ) becomes ( t 3 , 1 ) (t_3,1) ( t 3 , 1 ) in the third route, where it is abundant, and stays ( t 3 , 3 ) (t_3,3) ( t 3 , 3 ) in the fourth, where it is not. End of example.
The p p p -route pattern of an element tuple of R \mathcal{R} R , or equivalently a vertex tuple in T T T , now forms the sought-after notion of a “tuple type”. Note that, for a fixed tuple length z z z , the number of p p p -route patterns for tuples of length at most z z z can be bounded by a function of p p p , z z z , h h h , and φ \varphi φ .
Now that we have established our notion of “tuple type”, it is time to re-visit the intended Implication (IMPL) that we aim to achieve. There, we wanted to ensure that two tuples with the same p p p -route pattern behave identically in a positive certificate. We identify the notion of pureness as the answer to this question.
Consider a solution S \mathcal{S} S and a tuple ( v 1 , … , v z ) (v_1,\ldots,v_z) ( v 1 , … , v z ) over V ( R ) V(\mathcal{R}) V ( R ) . The solution type of ( v 1 , … , v z ) (v_1,\ldots,v_z) ( v 1 , … , v z ) is the atomic type of ( v 1 , … , v z ) (v_1,\ldots,v_z) ( v 1 , … , v z ) in S \mathcal{S} S , i.e., it describes the behavior of the tuple in S \mathcal{S} S . We are now interested in solutions that behave homogeneously on all tuples of the same p p p -route pattern.9
Definition 5 (p p p -pure solution). Let p ∈ N p \in\mathbb{N} p ∈ N and ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) be an SNP Model Checking instance with treedepth decomposition T T T and a solution S = R 1 ′ , … , R r ′ \mathcal{S}=R'_1,\ldots,R'_r S = R 1 ′ , … , R r ′ . A p p p -route pattern μ \mu μ is p p p -pure in S \mathcal{S} S if any two tuples with p p p -route pattern μ \mu μ have the same solution type in S \mathcal{S} S . We call S \mathcal{S} S p p p -pure if all p p p -route patterns of tuples of length at most ∣ φ ∣ |\varphi| ∣ φ ∣ are p p p -pure.
A consequence of this definition is that p p p -pure solutions admit a bounded-size description by assigning a solution type to each p p p -route pattern of length at most ∣ φ ∣ |\varphi| ∣ φ ∣ .
Extending Pure Solutions
For pure solutions to serve as positive certificates, they must satisfy two crucial properties: (i) a p p p -pure solution of R p \mathcal{R}^p R p must extend to a solution of R \mathcal{R} R , and (ii) if R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ , then R p \mathcal{R}^p R p admits a p p p -pure solution for sufficiently large p p p . This section describes the proof technique for Property (i) that is captured by the following theorem.
Theorem 6 (Extension theorem). Let ( R , φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ ) (\mathcal{R},\varphi=\exists R_1,\ldots,R_r\ \forall x_1,\ldots,x_k:\psi) ( R , φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ ) be an instance of SNP Model Checking with treedepth decomposition T T T of height h h h and p ≥ ∣ φ ∣ ⋅ h p\geq|\varphi|\cdot h p ≥ ∣ φ ∣ ⋅ h . If R p \mathcal{R}^p R p has a p p p -pure solution S p \mathcal{S}^p S p , then R \mathcal{R} R has a solution R 1 ′ , … , R r ′ R'_1,\ldots,R'_r R 1 ′ , … , R r ′ .
Moreover, for a computable function f f f , after spending f ( p ) ⋅ ∣ R ∣ f(p)\cdot|\mathcal{R}| f ( p ) ⋅ ∣ R ∣ time on preprocessing, for every i ∈ [ r ] i\in[r] i ∈ [ r ] and u ˉ ∈ V ( R ) a \bar{u}\in V(\mathcal{R})^a u ˉ ∈ V ( R ) a we can decide whether R i ′ ( u ˉ ) R'_i(\bar{u}) R i ′ ( u ˉ ) holds in O ( a h log ( a h ) ) O(ah\log(ah)) O ( ah log ( ah )) time, where a = ar ( R i ) a=\operatorname{ar}(R_i) a = ar ( R i ) .
Proof sketch. We focus on the existence of R 1 ′ , … , R r ′ R'_1,\ldots,R'_r R 1 ′ , … , R r ′ and defer its construction to the full proof in § 5 .
Let R 1 p , … , R r p R^p_1,\ldots,R^p_r R 1 p , … , R r p be a p p p -pure solution of R p \mathcal{R}^p R p . The overall idea is to use tuples of R p \mathcal{R}^p R p as blueprints for tuples of R \mathcal{R} R . More formally, to build a solution R 1 ′ , … , R r ′ R'_1,\ldots,R'_r R 1 ′ , … , R r ′ for R \mathcal{R} R consider, for every i ∈ [ r ] i\in[r] i ∈ [ r ] , every tuple v ˉ = ( v 1 , … , v a ) \bar{v}=(v_1,\ldots,v_a) v ˉ = ( v 1 , … , v a ) of elements of R \mathcal{R} R , where a a a is the arity of R i R_i R i . Let μ \mu μ be the p p p -route pattern of v ˉ \bar{v} v ˉ . Then, using the fact that p ≥ ∣ φ ∣ ⋅ h ≥ a ⋅ h p\geq|\varphi|\cdot h\geq a\cdot h p ≥ ∣ φ ∣ ⋅ h ≥ a ⋅ h , it can be shown that there are elements z 1 , … , z a z_1,\ldots,z_a z 1 , … , z a in R p \mathcal{R}^p R p such that z ˉ = ( z 1 , … , z a ) \bar{z}=(z_1,\ldots,z_a) z ˉ = ( z 1 , … , z a ) has p p p -route pattern μ \mu μ . Since R 1 p , … , R r p R^p_1,\ldots,R^p_r R 1 p , … , R r p is p p p -pure, the concrete choice of z ˉ \bar{z} z ˉ matters only up to the requirement on having the p p p -route pattern μ \mu μ (which forces all matching tuples to have the same behavior in the solution). We let R i ′ ( v ˉ ) R'_i(\bar{v}) R i ′ ( v ˉ ) hold if and only if R i p ( z ˉ ) R^p_i(\bar{z}) R i p ( z ˉ ) holds.
The difficult part is proving that R 1 ′ , … , R r ′ R'_1,\ldots,R'_r R 1 ′ , … , R r ′ indeed form a solution for R \mathcal{R} R . Assume that this is not the case. Then, there exist elements v 1 , … , v k v_1,\ldots,v_k v 1 , … , v k in R \mathcal{R} R such that ψ ( R 1 ′ , … , R r ′ , v 1 , … , v k ) \psi(R'_1,\ldots,R'_r,v_1,\ldots,v_k) ψ ( R 1 ′ , … , R r ′ , v 1 , … , v k ) is false on R \mathcal{R} R , that is, together with the chosen relations we find a forbidden substructure. We now argue that there are elements w 1 , … , w k w_1,\ldots,w_k w 1 , … , w k in R p \mathcal{R}^p R p that also form this forbidden substructure together with R 1 p , … , R r p R^p_1,\ldots,R^p_r R 1 p , … , R r p . Let μ \mu μ be the p p p -route pattern of ( v 1 , … , v k ) (v_1,\ldots,v_k) ( v 1 , … , v k ) . We can find a tuple ( w 1 , … , w k ) (w_1,\ldots,w_k) ( w 1 , … , w k ) in R p \mathcal{R}^p R p with the same p p p -route pattern μ \mu μ . Using the definition of p p p -route patterns, we can show that these tuples have the same atomic type, and, therefore, behave the same with respect to input relations and equality.
The remaining part of the proof is showing that both tuples also behave identically w.r.t. the solution relations. To this end, consider some relation R i R_i R i of the solution of arity a ≤ ∣ φ ∣ a\leq|\varphi| a ≤ ∣ φ ∣ and a tuple ( v n 1 , … , v n a ) (v_{n_1},\ldots,v_{n_a}) ( v n 1 , … , v n a ) of elements of R \mathcal{R} R , where n 1 , … , n a ∈ [ k ] n_1,\ldots,n_a\in[k] n 1 , … , n a ∈ [ k ] . Let μ ′ \mu' μ ′ be the p p p -route pattern of ( v n 1 , … , v n a ) (v_{n_1},\ldots,v_{n_a}) ( v n 1 , … , v n a ) in R \mathcal{R} R . Recall that R i ′ ( v n 1 , … , v n a ) R'_i(v_{n_1},\ldots,v_{n_a}) R i ′ ( v n 1 , … , v n a ) holds if and only if R i p ( z 1 , … , z a ) R^p_i(z_1,\ldots,z_a) R i p ( z 1 , … , z a ) does, where ( z 1 , … , z a ) (z_1,\ldots,z_a) ( z 1 , … , z a ) has the p p p -route pattern μ ′ \mu' μ ′ in R p \mathcal{R}^p R p . Crucially, the definition of p p p -route patterns ensures that also ( w n 1 , … , w n a ) (w_{n_1},\ldots,w_{n_a}) ( w n 1 , … , w n a ) has the p p p -route pattern μ ′ \mu' μ ′ .9 w n 1 , … , w n a w_{n_1},\ldots,w_{n_a} w n 1 , … , w n a forms the tuple ( z 1 , … , z a ) (z_1,\ldots,z_a) ( z 1 , … , z a ) that we used to define R i ′ R'_i R i ′ . Precisely for this reason we required the solution to be p p p -pure. Purity gives us the guarantee that R i p ( z ˉ ) R^p_i(\bar{z}) R i p ( z ˉ ) holds if and only if R i p ( w ˉ ′ ) R^p_i(\bar{w}') R i p ( w ˉ ′ ) does. Hence, R i p ( w ˉ ′ ) R^p_i(\bar{w}') R i p ( w ˉ ′ ) holds if and only if R i ′ ( v ˉ ′ ) R'_i(\bar{v}') R i ′ ( v ˉ ′ ) does. Put differently, this shows that v ˉ ′ \bar{v}' v ˉ ′ and w ˉ ′ \bar{w}' w ˉ ′ also behave identically with respect to the relations R i ′ R'_i R i ′ , respectively R i p R^p_i R i p . Overall, with this proof strategy we can show that the two tuples ( v 1 , … , v k ) (v_1,\ldots,v_k) ( v 1 , … , v k ) and ( w 1 , … , w k ) (w_1,\ldots,w_k) ( w 1 , … , w k ) behave identically with respect to any atom of ψ \psi ψ . Therefore, ( w 1 , … , w k ) (w_1,\ldots,w_k) ( w 1 , … , w k ) would already form the forbidden substructure with respect to R 1 p , … , R r p R^p_1,\ldots,R^p_r R 1 p , … , R r p and R p R^p R p , a contradiction.
Obtaining Pure Solutions
Theorem 6 can only shine if we can guarantee that R p R^p R p admits a p p p -pure solution for sufficiently large p p p (provided R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ ). For the following, let us assume that R \mathcal{R} R has a solution. Thus, also R p R^p R p has a solution S S S as SNP-satisfaction is closed under taking induced substructures (and R p R^p R p is an induced substructure of R \mathcal{R} R ). However, S S S might not be p p p -pure. That is, there may be two tuples v ˉ \bar{v} v ˉ and w ˉ \bar{w} w ˉ with the same p p p -route pattern μ \mu μ , but different solution types.
A naive attempt to repair S S S is to delete vertices that make S S S impure, e.g., the vertices from w ˉ \bar{w} w ˉ . However, this alters the structure R p R^p R p and, consequently, can affect the p p p -types of the remaining vertices. If we start from a larger structure R ′ \mathcal{R}' R ′ with R ′ ⊨ φ \mathcal{R}'\models\varphi R ′ ⊨ φ from which we delete vertices in such a way that we end up with a structure isomorphic to R p R^p R p , this problem would not occur. In particular, we could guarantee that the p p p -route patterns of R \mathcal{R} R and the resulting structures would remain identical.
The natural candidate for R ′ \mathcal{R}' R ′ is the s s s -multiplicity structure R s \mathcal{R}^s R s for some s ≥ p s\ge p s ≥ p (recall Section 2.2), where p p p remains fixed and defines the vertex p p p -types. However, we need to show that R s ⊨ φ \mathcal{R}^s\models\varphi R s ⊨ φ . To this end, let us recall that R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ implies that R \mathcal{R} R does not contain an obstruction from J h , φ \mathcal{J}_{h,\varphi} J h , φ . Pick for p p p a value that is at least M = max { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } M=\max\{1\}\cup\{|V(H)|:H\in\mathcal{J}_{h,\varphi}\} M = max { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } , i.e., at least the number of vertices of every obstruction in J h , φ \mathcal{J}_{h,\varphi} J h , φ . Then, R \mathcal{R} R and R s \mathcal{R}^s R s contain exactly the same induced substructures of size at most p p p . Moreover, R s \mathcal{R}^s R s still has a treedepth decomposition of height h h h , so the same obstruction set applies. Hence, R s \mathcal{R}^s R s does not contain an obstruction from J h , φ \mathcal{J}_{h,\varphi} J h , φ , and we have R s ⊨ φ \mathcal{R}^s\models\varphi R s ⊨ φ :
Lemma 7. Let ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) be an instance of SNP Model Checking and T T T a treedepth decomposition of R \mathcal{R} R of height h h h . Set M = max { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } M=\max\{1\}\cup\{|V(H)|:H\in\mathcal{J}_{h,\varphi}\} M = max { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } . Then, for all s ≥ p ≥ M s\ge p\ge M s ≥ p ≥ M we have that R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ if and only if R s ⊨ φ \mathcal{R}^s\models\varphi R s ⊨ φ , where R s \mathcal{R}^s R s is the s s s -multiplicity structure for ( R , T , p ) (\mathcal{R},T,p) ( R , T , p ) .
Lemma 7 shows that we can start from a solution of R s \mathcal{R}^s R s . Moreover, we can afford to delete many vertices and still retain an induced copy of R p R^p R p . It remains to choose our deletion strategy such that we eventually arrive at a p p p -pure solution. One way of ensuring this is finding a (sub)structure in which the solution type of a tuple depends only on its p p p -route pattern. Then, the solution will be p p p -pure “by design”. We now apply Ramsey-based arguments to find such a structure.
Theorem 8 (Existence of a p p p -pure solution). Let ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) be an instance of SNP Model Checking and T T T a treedepth decomposition of R \mathcal{R} R of height h h h . Set M = max { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } M=\max\{1\}\cup\{|V(H)|:H\in\mathcal{J}_{h,\varphi}\} M = max { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } . Then, for all p ≥ max { M , ∣ φ ∣ h } p\ge\max\{M,|\varphi|^h\} p ≥ max { M , ∣ φ ∣ h } we have that if R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ , then R p R^p R p has a p p p -pure solution, where R p R^p R p is the p p p -multiplicity structure for ( R , T , p ) (\mathcal{R},T,p) ( R , T , p ) .
Proof sketch. On a high level, we want to find some integer s ≥ p s\ge p s ≥ p , such that the following holds. Given a solution S s S^s S s for the s s s -multiplicity structure R s \mathcal{R}^s R s , we can prune R s \mathcal{R}^s R s down to a structure isomorphic to R p R^p R p such that S s S^s S s restricted and transferred to R p R^p R p is p p p -pure. We start our proof idea by illustrating how we achieve this for a single p p p -route pattern $\mu.国产自拍
Fix some p p p -route pattern μ \mu μ of length at most ∣ φ ∣ |\varphi| ∣ φ ∣ . Recall that each entry of such a pattern is a pair ( t , i ) (t,i) ( t , i ) where t t t is a vertex p p p -type, and i i i is an integer. The entry is abundant if t t t is p p p -abundant in the vertex p p p -type in the preceding entry (if such an entry exists). Let β \beta β be the number of distinct indices of abundant entries of μ \mu μ . If β = 0 \beta= 0 β = 0 , only one tuple has the p p p -route pattern μ \mu μ and is therefore pure in every solution. So we assume that β > 0 \beta> 0 β > 0 .
By normalization, the distinct indices in abundant entries are precisely 1 , … , β 1,\ldots,\beta 1 , … , β . We now establish the following crucial property: there exists a bijection π \pi π from strictly increasing integer tuples in [ s ] β [s]^\beta [ s ] β to vertex tuples of R s \mathcal{R}^s R s with p p p -route pattern μ \mu μ . Given a vertex tuple v ˉ \bar{v} v ˉ of R s \mathcal{R}^s R s with p p p -route pattern μ \mu μ , let γ \gamma γ be the tuple of the p p p -routes of v ˉ \bar{v} v ˉ (and not their p p p -route pattern). Now, let n ˉ \bar{n} n ˉ be the tuple of length β \beta β obtained by collecting the distinct indices of abundant entries of γ \gamma γ , in increasing order. This integer tuple together with μ \mu μ determines the original p p p -routes, which uniquely identify v ˉ \bar{v} v ˉ . Conversely, for any strictly increasing integer tuple n ˉ = ( n 1 , … , n β ) ∈ [ s ] β \bar{n} = (n_1,\ldots,n_\beta) \in[s]^\beta n ˉ = ( n 1 , … , n β ) ∈ [ s ] β , replace every abundant entry ( t , i ) (t,i) ( t , i ) of μ \mu μ by ( t , n i ) (t,n_i) ( t , n i ) , leaving all other entries unchanged. The resulting routes identify exactly one vertex tuple π ( n ˉ ) \pi(\bar{n}) π ( n ˉ ) , whose p p p -route pattern is μ \mu μ (see Lemma 34 ).
Recall that we want to choose some value s s s such that we can prune R s \mathcal{R}^s R s to a copy of R p \mathcal{R}^p R p and ensure that μ \mu μ is p p p -pure in the restricted solution. We now use the above-established bijection π \pi π in our Ramsey arguments as follows. Let D D D be the number of possible solution types for tuples of length ∣ μ ∣ |\mu| ∣ μ ∣ . The assumption p ≥ ∣ φ ∣ h p \geq|\varphi|h p ≥ ∣ φ ∣ h ensures that β ≤ p \beta\leq p β ≤ p . To achieve our goal, we can set s = Ram β ( p , D ) s = \operatorname{Ram}_\beta(p,D) s = Ram β ( p , D ) , where Ram β ( p , D ) \operatorname{Ram}_\beta(p,D) Ram β ( p , D ) is the finite hypergraph Ramsey number [83 ] : it is the smallest integer δ \delta δ such that any edge coloring of a complete β \beta β -uniform hypergraph on δ \delta δ vertices using D D D colors contains a monochromatic hyperclique on p p p vertices.
To see that this is indeed the correct value for s s s , consider a solution S S S for the structure R s \mathcal{R}^s R s . Note that S S S exists by Lemma 7. We create a β \beta β -uniform complete hypergraph H \mathcal{H} H whose vertex set is the integer set [ s ] [s] [ s ] . For each subset of [ s ] [s] [ s ] of size β \beta β , we color the corresponding hyperedge in H \mathcal{H} H by using the above-sketched bijection π \pi π . Concretely, for such a subset S ′ S' S ′ create the β \beta β -tuple n ˉ \bar{n} n ˉ by ordering the vertices of S ′ S' S ′ increasingly, and use this tuple to obtain the corresponding vertex tuple π ( n ˉ ) \pi(\bar{n}) π ( n ˉ ) of R s \mathcal{R}^s R s with p p p -route pattern μ \mu μ . Then, π ( n ˉ ) \pi(\bar{n}) π ( n ˉ ) has some solution type in S S S , and we color the hyperedge S ′ S' S ′ by this solution type.
By Ramsey’s theorem, there is some subset N N N of [ s ] [s] [ s ] of size exactly p p p , such that H \mathcal{H} H induced by N N N is monochromatic. By the construction of H \mathcal{H} H , the corresponding vertex tuples, or equivalently element tuples, all have the same solution type. Now, prune R s \mathcal{R}^s R s as follows. Starting from the root, let v v v be a non-pruned vertex of type t t t , and let t ′ t' t ′ be a type that is abundant in t t t . Then, v v v has exactly s s s children of type t ′ t' t ′ in R s \mathcal{R}^s R s , label them 1 1 1 to s s s . Keep exactly those children of type t ′ t' t ′ whose label belongs to N N N , and delete the others together with their subtrees. We use the same set N N N at every retained vertex and for every abundant type, and leave all children of non-abundant types untouched.
Since ∣ N ∣ = p |N| = p ∣ N ∣ = p , the resulting structure U \mathcal{U} U is isomorphic to R p \mathcal{R}^p R p . In the end, each tuple of R p \mathcal{R}^p R p with p p p -route pattern μ \mu μ corresponds to a tuple of U \mathcal{U} U whose distinct abundant indices belong to N N N (and thus have p p p -route pattern μ \mu μ ). Therefore, all such tuples have the same solution type in S S S restricted to U \mathcal{U} U . Transferring this restricted solution along the isomorphism gives a solution for R p \mathcal{R}^p R p that is pure w.r.t. μ \mu μ .
By nesting the above arguments, we can achieve the result for all relevant p p p -route patterns of R \mathcal{R} R . More concretely, s s s is obtained by nesting the hypergraph Ramsey numbers at most K K K times, where K K K is the number of p p p -route patterns of tuples of length at most ∣ φ ∣ |\varphi| ∣ φ ∣ occurring in R \mathcal{R} R . Let μ 1 , … , μ K \mu_1,\ldots,\mu_K μ 1 , … , μ K be the p p p -route patterns in R \mathcal{R} R . We fix one solution for R s \mathcal{R}^s R s and iteratively choose nested sets N i N_i N i of indices. More concretely, for i = 1 , … , K i = 1,\ldots,K i = 1 , … , K , we apply Ramsey’s theorem to the hypergraph restricted to N i − 1 N_{i-1} N i − 1 . This way, we can obtain a monochromatic set N i + 1 ⊆ N i N_{i+1} \subseteq N_i N i + 1 ⊆ N i w.r.t. μ i \mu_i μ i . Passing from μ i − 1 \mu_{i-1} μ i − 1 to μ i \mu_i μ i preserves the purity already obtained for the patterns μ j \mu_j μ j , j ≤ i − 1 j \leq i - 1 j ≤ i − 1 . Hence, the index set $N_k that we eventually obtain is pure w.r.t. all p p p -route patterns. We select the Ramsey bounds such that we can ensure that N K N_K N K has p p p indices. If we use the above-described pruning procedure for R s \mathcal{R}^{s} R s w.r.t. N K N_K N K , we obtain a p p p -pure solution.
As to be expected when applying (iterative) Ramsey arguments, the obtained value s s s is astronomical. However, note that the above arguments are purely existential. Our algorithm never constructs R s \mathcal{R}^{s} R s .
The Algorithm A
We are now ready to combine Theorems 6 and 8 to obtain our Algorithm A for SNP Model Checking. Given an instance ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) of SNP Model Checking, we first compute the primal graph G G G of R \mathcal{R} R . Then, we compute its treedepth decomposition T T T of height h ≤ td ( R ) + 1 h \leq\operatorname{td}(\mathcal{R})+1 h ≤ td ( R ) + 1 using a known algorithm [86 ] . Afterwards, we iteratively consider, for larger and larger integers p ≥ ∣ φ ∣ ⋅ h p \geq|\varphi| \cdot h p ≥ ∣ φ ∣ ⋅ h , the p p p -multiplicity structure R p \mathcal{R}^{p} R p for ( R , T , p ) (\mathcal{R},T,p) ( R , T , p ) until the following holds: Either the set of all solutions L p \mathcal{L}^{p} L p of R p \mathcal{R}^{p} R p is empty, in which case we face a no-instance since SNP-satisfaction is closed under induced substructures, or L p \mathcal{L}^{p} L p contains a p p p -pure solution S p \mathcal{S}^{p} S p . Applying Theorem 6 to S p \mathcal{S}^{p} S p then allows us to conclude that R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ .
While A is easy to state and its correctness follows almost immediately from previous arguments, its termination is not immediate. To this end, we show that A terminates in an iteration for p ≤ max { M , ∣ φ ∣ ( td ( R ) + 1 ) } p \leq\max\{M,|\varphi|(\operatorname{td}(\mathcal{R})+1)\} p ≤ max { M , ∣ φ ∣ ( td ( R ) + 1 )} , where M = max ( { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J td ( R ) + 1 , φ } ) M=\max(\{1\}\cup\{|V(H)|:H\in\mathcal{J}_{\operatorname{td}(\mathcal{R})+1,\varphi}\}) M = max ({ 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J td ( R ) + 1 , φ }) . Consider the iteration for p = max { M , ∣ φ ∣ ( td ( R ) + 1 ) } p=\max\{M,|\varphi|(\operatorname{td}(\mathcal{R})+1)\} p = max { M , ∣ φ ∣ ( td ( R ) + 1 )} , if it is reached. If R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ , then by Theorem 8, we have that R p \mathcal{R}^{p} R p has a p p p -pure solution, which is found by the algorithm and allows us to correctly detect the yes-instance. Otherwise, if R ⊭ φ \mathcal{R}\not\models\varphi R ⊨ φ , then we know that already R p \mathcal{R}^{p} R p must contain a member of J td ( R ) + 1 , φ \mathcal{J}_{\operatorname{td}(\mathcal{R})+1,\varphi} J td ( R ) + 1 , φ , and the algorithm correctly detects the no-instance. See Lemma 36 for the formal proof.
However, although Lemma 36 yields an upper bound on the number of iterations of A, on its own it is not strong enough to bound the running time of A by a computable function f f f in ∣ φ ∣ |\varphi| ∣ φ ∣ and td ( R ) \operatorname{td}(\mathcal{R}) td ( R ) —after all, Lemma 36 gives no bound on the size of M M M in terms of ∣ φ ∣ |\varphi| ∣ φ ∣ and td ( R ) \operatorname{td}(\mathcal{R}) td ( R ) . As our last missing ingredient, we show that there exists an algorithm to compute the obstruction set J td ( R ) + 1 , φ \mathcal{J}_{\operatorname{td}(\mathcal{R})+1,\varphi} J td ( R ) + 1 , φ (up to isomorphism) in time g ( ∣ φ ∣ , td ( R ) ) g(|\varphi|,\operatorname{td}(\mathcal{R})) g ( ∣ φ ∣ , td ( R )) for some computable function g g g .
The idea to show that this function is computable is now based on the following enumeration argument. For the enumeration argument, fix a formula φ \varphi φ and a treedepth bound d ≥ 1 d\geq1 d ≥ 1 , so that the elimination tree of a structure R \mathcal{R} R with td ( R ) ≤ d \operatorname{td}(\mathcal{R})\leq d td ( R ) ≤ d has height at most d + 1 d+1 d + 1 . Set M d = max ( { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J d + 1 , φ } ) M_d=\max(\{1\}\cup\{|V(H)|:H\in\mathcal{J}_{d+1,\varphi}\}) M d = max ({ 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J d + 1 , φ }) and try increasing values of p ≥ ∣ φ ∣ ( d + 1 ) p\geq|\varphi|(d+1) p ≥ ∣ φ ∣ ( d + 1 ) . For such a fixed value, we enumerate all structures of matching treedepth and signature such that R = R p \mathcal{R}=\mathcal{R}^{p} R = R p . We check if all enumerated structures either do not fulfill φ \varphi φ , or have a p p p -pure solution. If this is the case, we stop. The size of such a structure R \mathcal{R} R is bounded by p p p , d d d , ∣ φ ∣ |\varphi| ∣ φ ∣ , and hence this enumeration is possible for each fixed p p p . The arguments above guarantee that, once we have reached p = max { M d , ∣ φ ∣ ( d + 1 ) } p=\max\{M_d,|\varphi|(d+1)\} p = max { M d , ∣ φ ∣ ( d + 1 )} , all structures we enumerate either do not fulfill the formula, or have a p p p -pure solution. Hence, this enumeration algorithm can compute an upper bound on the number of iterations algorithm A requires. In fact, we can even use this idea to compute the obstruction set J d , φ \mathcal{J}_{d,\varphi} J d , φ . Formally, we obtain the following.
Theorem 9. Let h ≥ 1 h\geq1 h ≥ 1 be an integer and φ \varphi φ be an SNP formula. There is an algorithm that computes the obstruction set J h , φ \mathcal{J}_{h,\varphi} J h , φ (up to isomorphism) in time f ( h , ∣ φ ∣ ) f(h,|\varphi|) f ( h , ∣ φ ∣ ) for some computable function f f f . In particular, we have max ( { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } ) ≤ g ( h , ∣ φ ∣ ) \max(\{1\}\cup\{|V(H)|:H\in\mathcal{J}_{h,\varphi}\})\leq g(h,|\varphi|) max ({ 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ }) ≤ g ( h , ∣ φ ∣ ) for some computable function g g g .
Theorem 9 bounds the iteration count of A and thus also the maximum value of p p p by some computable function g ( ∣ φ ∣ , td ( R ) ) g(|\varphi|,\operatorname{td}(\mathcal{R})) g ( ∣ φ ∣ , td ( R )) . Combining Theorems 6, 8 and 9 with the observation that every iteration of A \mathsf{A} A and the preprocessing steps run in time g ′ ( ∣ φ ∣ , td ( R ) ) ⋅ ∣ R ∣ g'(|\varphi|,\operatorname{td}(\mathcal{R}))\cdot|\mathcal{R}| g ′ ( ∣ φ ∣ , td ( R )) ⋅ ∣ R ∣ for some computable function g ′ g' g ′ , allows us to obtain the decision variant of Theorem A. For the constructive part, we can retain a p p p -pure solution S p \mathcal{S}^{p} S p in A \mathcal{A} A . We can use Theorem 6 to extend it to a solution S \mathcal{S} S of R \mathcal{R} R by iteratively considering all ar ( φ ) \operatorname{ar}(\varphi) ar ( φ ) -tuples u ˉ \bar{u} u ˉ over V ( R ) V(\mathcal{R}) V ( R ) . Since the preprocessing step from Theorem 6 can be done once at the beginning and, as discussed above, p p p can be bounded by the computable function g g g , the second part of Theorem A follows.
Finally, let us remark that we could, in principle, turn the non-uniform algorithm U \mathsf{U} U sketched in § 3.1 into a uniform algorithm by first computing the obstruction set with Theorem 9 and then checking whether R \mathcal{R} R contains an obstruction as an induced substructure. Our Algorithm A \mathsf{A} A has the additional advantage that it also constructs a witness for positive instances.
Applications
Although we see the development of Theorem A as our main result, we also want to highlight some of its applications. In particular, with our metatheorem we can solve several open problems.
Let us sketch this for the problem of computing the stack number of a graph. Given a graph G G G , the stack number of G G G , sn ( G ) \operatorname{sn}(G) sn ( G ) , is the smallest integer k k k such that there is a total order < < < on the vertices of G G G , and an edge mapping, called page-assignment, π : E ( G ) → [ k ] \pi:E(G)\to[k] π : E ( G ) → [ k ] . The mapping and ordering must be so that there are no four vertices v 1 , v 2 , w 1 , w 2 v_1,v_2,w_1,w_2 v 1 , v 2 , w 1 , w 2 with v 1 < w 1 < v 2 < w 2 v_1<w_1<v_2<w_2 v 1 < w 1 < v 2 < w 2 with v 1 v 2 ∈ E ( G ) v_1v_2\in E(G) v 1 v 2 ∈ E ( G ) , w 1 w 2 ∈ E ( G ) w_1w_2\in E(G) w 1 w 2 ∈ E ( G ) , and π ( v 1 v 2 ) = π ( w 1 w 2 ) \pi(v_1v_2)=\pi(w_1w_2) π ( v 1 v 2 ) = π ( w 1 w 2 ) . Already deciding whether sn ( G ) ≤ 2 \operatorname{sn}(G)\le2 sn ( G ) ≤ 2 holds is NP-complete [92 , 19 ] and the problem is known to be FPT with respect to the vertex integrity of G G G [38 ] and the feedback edge number of G G G [63 ] . For the special case of sn ( G ) ≤ 2 \operatorname{sn}(G)\le2 sn ( G ) ≤ 2 , the problem is known to be FPT in the treewidth of G G G [10 , 63 ] . Whether the general problem is FPT with respect to less restrictive parameters, in particular treedepth or treewidth, has repeatedly been posed as an open question [62 , 26 , 63 , 38 ] . We answer this question in the affirmative with respect to treedepth by capturing the corresponding decision problem using SNP sentences.
For a fixed integer k k k , there is a simple formula φ k \varphi_k φ k such that G ⊨ φ k G\models\varphi_k G ⊨ φ k if and only if the stack number of G G G is at most k k k . Indeed, the following formula suffices:
φ k : = ∃ L ∃ P 1 ⋯ ∃ P k ∀ u , v , x , y ( TotalOrder ( L , u , v , x ) ∧ Assigned ( P 1 , … , P k , u , v ) ∧ ⋀ i ∈ [ k ] NoCrossing ( L , P i , u , v , x , y ) ) , \begin{aligned}
\varphi_k := {} & \exists L\exists P_1\cdots\exists P_k\ \forall u,v,x,y\ \bigl(\operatorname{TotalOrder}(L,u,v,x)\\
&\mathrel{\wedge}\operatorname{Assigned}(P_1,\ldots,P_k,u,v)\\
&\mathrel{\wedge}\bigwedge_{i\in[k]}\operatorname{NoCrossing}(L,P_i,u,v,x,y)\bigr),
\end{aligned} φ k := ∃ L ∃ P 1 ⋯ ∃ P k ∀ u , v , x , y ( TotalOrder ( L , u , v , x ) ∧ Assigned ( P 1 , … , P k , u , v ) ∧ i ∈ [ k ] ⋀ NoCrossing ( L , P i , u , v , x , y ) ) ,
where L L L and P 1 , … , P k P_1,\ldots,P_k P 1 , … , P k are binary relations, with L ( u , v ) L(u,v) L ( u , v ) representing u < v u<v u < v and P i ( u , v ) P_i(u,v) P i ( u , v ) indicating that the edge u v uv uv belongs to page i i i . The formula TotalOrder ( L , u , v , x ) \operatorname{TotalOrder}(L,u,v,x) TotalOrder ( L , u , v , x ) ensures that L L L is a strict total order, Assigned ( P 1 , … , P k , u , v ) \operatorname{Assigned}(P_1,\ldots,P_k,u,v) Assigned ( P 1 , … , P k , u , v ) ensures that each edge is assigned to some page, and NoCrossing ( L , P i , u , v , x , y ) \operatorname{NoCrossing}(L,P_i,u,v,x,y) NoCrossing ( L , P i , u , v , x , y ) checks that the obtained assignment does not have any crossings on page P i P_i P i . All of these properties are easy to guarantee with forbidden substructures on at most four elements.
Note that the length of the formula above depends on k k k . However, it is known that a graph with treedepth at most k k k has stack number at most k k k [46 ] , and hence we can use the sketched formula to compute the stack number of a graph in time f ( td ( G ) ) ⋅ ∣ V ( G ) ∣ f(\operatorname{td}(G))\cdot|V(G)| f ( td ( G )) ⋅ ∣ V ( G ) ∣ using our algorithm.
In § 6 , we demonstrate that our metatheorem can also be used to obtain FPT algorithms parameterized by treedepth for further problems where this remained open until now: deciding if the queue number of G G G is at most k k k , deciding if the track number of G G G is at most k k k , deciding if the twin-width of a graph G G G is at most k k k , and deciding if the boxicity of a graph G G G is at most k k k . In particular the formula for twin-width is significantly more involved than the one above.
Preliminaries
For an integer p ≥ 1 p \ge1 p ≥ 1 we also denote the set { 1 , 2 , … , p } \{1,2,\ldots,p\} { 1 , 2 , … , p } as [ p ] [p] [ p ] , and we let [ 0 ] = ∅ [0] = \varnothing [ 0 ] = ∅ . Similarly, for integers i , j i,j i , j with i ≤ j i \le j i ≤ j we set [ i , j ] = { i , i + 1 , … , j } [i,j] = \{i,i+1,\ldots,j\} [ i , j ] = { i , i + 1 , … , j } . We use the convention max ∅ = 0 \max\varnothing= 0 max ∅ = 0 , so that maxima over empty index sets are well defined. We allow appending another object to a tuple: for a (possibly empty) tuple ( x 1 , … , x z ) (x_1,\ldots,x_z) ( x 1 , … , x z ) and an object y y y we define ( x 1 , … , x z ) ⋄ y = ( x 1 , … , x z , y ) (x_1,\ldots,x_z) \diamond y = (x_1,\ldots,x_z,y) ( x 1 , … , x z ) ⋄ y = ( x 1 , … , x z , y ) .
Graphs and Hypergraphs. We use standard graph and hypergraph terminology, but remind the reader of some notions here. For some integer d ≥ 1 d \ge1 d ≥ 1 , a d d d -uniform hyperclique is a hypergraph on a vertex set V V V with edge set ( V d ) \binom{V}{d} ( d V ) . That is, it contains all possible hyperedges of size exactly d d d , and no further edges. Given a hypergraph H = ( V , E ) H = (V,E) H = ( V , E ) , a d d d -uniform hyperclique in H H H is a hypergraph ( V ′ , E ′ ) (V',E') ( V ′ , E ′ ) with V ′ ⊆ V V' \subseteq V V ′ ⊆ V and E ′ ⊆ E E' \subseteq E E ′ ⊆ E , such that E ′ = ( V ′ d ) E' = \binom{V'}{d} E ′ = ( d V ′ ) .
Relational Structures.
Definition 10 (Relational structures and primal graph). A relational structure R = ( V , E 1 , … , E b ) \mathcal{R} = (V,E_1,\ldots,E_b) R = ( V , E 1 , … , E b ) consists of a non-empty domain V V V , which we also denote V ( R ) V(\mathcal{R}) V ( R ) , followed by relations E 1 , … , E b E_1,\ldots,E_b E 1 , … , E b over V V V . The arity of relation E i E_i E i is denoted as ar ( E i ) \operatorname{ar}(E_i) ar ( E i ) and the arity of a relational structure is ar ( R ) : = max i ∈ [ b ] ar ( E i ) \operatorname{ar}(\mathcal{R}) := \max_{i \in[b]} \operatorname{ar}(E_i) ar ( R ) := max i ∈ [ b ] ar ( E i ) . Throughout the paper we assume that all relations have positive arity. The size of R \mathcal{R} R is ∣ R ∣ : = ∣ V ∣ + ∑ i = 1 b ∑ u ˉ ∈ E i ∣ u ˉ ∣ |\mathcal{R}| := |V| + \sum_{i=1}^{b} \sum_{\bar{u} \in E_i} |\bar{u}| ∣ R ∣ := ∣ V ∣ + ∑ i = 1 b ∑ u ˉ ∈ E i ∣ u ˉ ∣ .
The primal graph of a relational structure is the graph with vertex set V V V that contains each edge { v , w } ∈ ( V 2 ) \{v,w\} \in\binom{V}{2} { v , w } ∈ ( 2 V ) if and only if v v v and w w w appear together in at least one tuple of a relation in R \mathcal{R} R , that is, if there is i ∈ [ b ] i \in[b] i ∈ [ b ] and u ˉ ∈ E i \bar{u} \in E_i u ˉ ∈ E i such that v ∈ u ˉ v \in\bar{u} v ∈ u ˉ and w ∈ u ˉ w \in\bar{u} w ∈ u ˉ .
The primal graph of a relational structure is also often called the Gaifman graph of the structure. Since its vertex set is exactly the set V ( R ) V(\mathcal{R}) V ( R ) of elements, we use the terms “element” and “vertex” to some degree interchangeably. For convenience and without loss of generality, we assume that there is a fixed total order on V ( R ) V(\mathcal{R}) V ( R ) , which lets us speak of a smaller or larger element, and of the smallest or largest element of a set. Concretely, we let it be the order in which the elements first appear in the input encoding of R \mathcal{R} R , so that this order is available after a single scan of the input. Moreover, note that the assumption that the arities of all relations are positive is without loss of generality, in the sense that relations of arity 0 0 0 can be encoded by unary relations, and that removing relations of arity 0 0 0 and introducing unary relations does not affect the primal graph.
Two notions on relational structures that we use throughout are the following.
Definition 11 (Signature and induced substructure). The signature of a relational structure R = ( V , E 1 , … , E b ) \mathcal{R} = (V,E_1,\ldots,E_b) R = ( V , E 1 , … , E b ) is the sequence ( ar ( E 1 ) , … , ar ( E b ) ) (\operatorname{ar}(E_1),\ldots,\operatorname{ar}(E_b)) ( ar ( E 1 ) , … , ar ( E b )) of the arities of its relations. For a subset U ⊆ V U \subseteq V U ⊆ V of the domain, the substructure of R \mathcal{R} R induced by U U U is the relational structure
R [ U ] = ( U , E 1 ∩ U ar ( E 1 ) , … , E b ∩ U ar ( E b ) ) , \mathcal{R}[U] = (U, E_1 \cap U^{\operatorname{ar}(E_1)}, \ldots, E_b \cap U^{\operatorname{ar}(E_b)}), R [ U ] = ( U , E 1 ∩ U ar ( E 1 ) , … , E b ∩ U ar ( E b ) ) , that is, we keep exactly those tuples all of whose entries lie in U U U . A relational structure R ′ \mathcal{R}' R ′ is an induced substructure of R \mathcal{R} R if R ′ = R [ U ] \mathcal{R}' = \mathcal{R}[U] R ′ = R [ U ] for some U ⊆ V U \subseteq V U ⊆ V ; note that R ′ \mathcal{R}' R ′ then has the same signature as R \mathcal{R} R .
With some abuse of notation, we use the same notation for relation symbols and their interpretations, and write E ( u ˉ ) E(\bar{u}) E ( u ˉ ) interchangeably with u ˉ ∈ E \bar{u} \in E u ˉ ∈ E when the intended interpretation is clear.
We also write v ∈ u ˉ v \in\bar{u} v ∈ u ˉ when v v v occurs as an entry of u ˉ \bar{u} u ˉ ; tuples are ordered and may contain repeated entries.
To categorize tuples of elements that are indistinguishable by the relations of a structure, we use the standard model-theoretic notion of an atomic type (see, e.g., [73 p. 226] ), which we use in the following form.
Definition 1 (Atomic type). Let R = ( V , E 1 , … , E b ) \mathcal{R}=(V,E_1,\ldots,E_b) R = ( V , E 1 , … , E b ) be a relational structure and let z ∈ N z \in\mathbb{N} z ∈ N . An atomic formula over the variables x 1 , … , x z x_1,\ldots,x_z x 1 , … , x z is a formula of the form E i ( x n 1 , … , x n a ) E_i(x_{n_1},\ldots,x_{n_a}) E i ( x n 1 , … , x n a ) with i ∈ [ b ] i \in[b] i ∈ [ b ] , a = ar ( E i ) a=\operatorname{ar}(E_i) a = ar ( E i ) and ( n 1 , … , n a ) ∈ [ z ] a (n_1,\ldots,n_a) \in[z]^a ( n 1 , … , n a ) ∈ [ z ] a , or of the form x n = x n ′ x_n=x_{n'} x n = x n ′ with ( n , n ′ ) ∈ [ z ] 2 (n,n') \in[z]^2 ( n , n ′ ) ∈ [ z ] 2 . The atomic type of a tuple ( v 1 , … , v z ) ∈ V z (v_1,\ldots,v_z) \in V^z ( v 1 , … , v z ) ∈ V z in R \mathcal{R} R is
atp R ( v 1 , … , v z ) : = { α ( x 1 , … , x z ) atomic ∣ R ⊨ α ( v 1 , … , v z ) } . \operatorname{atp}_{\mathcal{R}}(v_1,\ldots,v_z):=\{\alpha(x_1,\ldots,x_z)\text{ atomic}\mid\mathcal{R}\models\alpha(v_1,\ldots,v_z)\}. atp R ( v 1 , … , v z ) := { α ( x 1 , … , x z ) atomic ∣ R ⊨ α ( v 1 , … , v z )} .
We now provide a basic bound on the number of atomic types.
Lemma 12 (Number of atomic types). Let R = ( V , E 1 , … , E b ) \mathcal{R}=(V,E_1,\ldots,E_b) R = ( V , E 1 , … , E b ) be a relational structure and let z ∈ N z \in\mathbb{N} z ∈ N . The number of possible atomic types of tuples of length z z z is bounded by 2 z 2 + ∑ i ∈ [ b ] z ar ( E i ) 2^{z^2+\sum_{i\in[b]}z^{\operatorname{ar}(E_i)}} 2 z 2 + ∑ i ∈ [ b ] z ar ( E i ) .
Proof. An atomic type of a tuple of length z z z is a set of atomic formulas over x 1 , … , x z x_1,\ldots,x_z x 1 , … , x z . For each relation E i E_i E i there are z ar ( E i ) z^{\operatorname{ar}(E_i)} z ar ( E i ) such formulas E i ( x n 1 , … , x n a ) E_i(x_{n_1},\ldots,x_{n_a}) E i ( x n 1 , … , x n a ) , one per tuple of indices, and there are z 2 z^2 z 2 equality formulas x n = x n ′ x_n=x_{n'} x n = x n ′ . Hence there are z 2 + ∑ i ∈ [ b ] z ar ( E i ) z^2+\sum_{i\in[b]}z^{\operatorname{ar}(E_i)} z 2 + ∑ i ∈ [ b ] z ar ( E i ) atomic formulas in total, and an atomic type is determined by the subset of them that holds. □
SNP. An SNP sentence φ \varphi φ on a relational structure R = ( V , E 1 , … , E b ) \mathcal{R}=(V,E_1,\ldots,E_b) R = ( V , E 1 , … , E b ) is a second-order logic formula of the form ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ ( R 1 , … , R r , x 1 , … , x k ) \exists R_1,\ldots,R_r\ \forall x_1,\ldots,x_k:\psi(R_1,\ldots,R_r,x_1,\ldots,x_k) ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ ( R 1 , … , R r , x 1 , … , x k ) , where ψ \psi ψ is a quantifier-free formula over relations R 1 , … , R r , E 1 , … , E b R_1,\ldots,R_r,E_1,\ldots,E_b R 1 , … , R r , E 1 , … , E b and elements x 1 , … , x k x_1,\ldots,x_k x 1 , … , x k , built from the atoms E i ( u ˉ ) E_i(\bar{u}) E i ( u ˉ ) for i ∈ [ b ] i \in[b] i ∈ [ b ] , R j ( u ˉ ) R_j(\bar{u}) R j ( u ˉ ) for j ∈ [ r ] j \in[r] j ∈ [ r ] , and x n = x n ′ x_n=x_{n'} x n = x n ′ for n , n ′ ∈ [ k ] n,n' \in[k] n , n ′ ∈ [ k ] . In particular, the domain of each variable R i R_i R i is the set of relations over V V V , and the domain of each variable x i x_i x i is V V V .
For v ˉ = ( v 1 , … , v k ) \bar{v}=(v_1,\ldots,v_k) v ˉ = ( v 1 , … , v k ) , we write R ⊨ ψ ( R 1 ′ , … , R r ′ , v ˉ ) \mathcal{R}\models\psi(R'_1,\ldots,R'_r,\bar{v}) R ⊨ ψ ( R 1 ′ , … , R r ′ , v ˉ ) to mean that ψ \psi ψ holds in the expansion ( R , R 1 ′ , … , R r ′ ) (\mathcal{R},R'_1,\ldots,R'_r) ( R , R 1 ′ , … , R r ′ ) , where each R i R_i R i is interpreted as R i ′ R'_i R i ′ and x j x_j x j is assigned v j v_j v j . The input relations are left implicit in the arguments of ψ \psi ψ , and we omit R ⊨ \mathcal{R}\models R ⊨ when the underlying structure is clear.
The quantifier order in φ \varphi φ that is prescribed by SNP allows for the following observation:
Observation 13. Let φ \varphi φ be an SNP sentence over a relational structure R \mathcal{R} R such that R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ . Moreover, let R ′ ⊆ R \mathcal{R}'\subseteq\mathcal{R} R ′ ⊆ R be an induced substructure of R \mathcal{R} R . Then, R ′ ⊨ φ \mathcal{R}'\models\varphi R ′ ⊨ φ .
We call ar ( φ ) = max i ∈ [ r ] ar ( R i ) \operatorname{ar}(\varphi)=\max_{i\in[r]}\operatorname{ar}(R_i) ar ( φ ) = max i ∈ [ r ] ar ( R i ) the arity of φ \varphi φ , and assume without loss of generality that each ar ( R i ) \operatorname{ar}(R_i) ar ( R i ) is positive. The length ∣ φ ∣ |\varphi| ∣ φ ∣ of a formula φ \varphi φ is the sum, over all occurrences of an atom in the inner formula ψ \psi ψ , of the number of (not necessarily distinct) element variables of that atom; that is, an occurrence of an atom x n = x n ′ x_n=x_{n'} x n = x n ′ contributes length 2, and occurrences of atoms E i ( u ˉ ) E_i(\bar{u}) E i ( u ˉ ) and R j ( u ˉ ) R_j(\bar{u}) R j ( u ˉ ) contribute length ar ( E i ) \operatorname{ar}(E_i) ar ( E i ) and ar ( R j ) \operatorname{ar}(R_j) ar ( R j ) , respectively. Without loss of generality, we assume that each variable R i R_i R i and x i x_i x i is mentioned in the inner formula ψ \psi ψ , and that negations in ψ \psi ψ occur only directly in front of atoms. The latter two conventions ensure that φ \varphi φ has an encoding of size O ( ∣ φ ∣ log ∣ φ ∣ ) O(|\varphi|\log|\varphi|) O ( ∣ φ ∣ log ∣ φ ∣ ) and that, up to logical equivalence, there are only finitely many SNP formulas of a given length. Therefore,
∣ φ ∣ ≥ ∑ i ∈ [ r ] ar ( R i ) ≥ max { r , ar ( φ ) } and ∣ φ ∣ ≥ k . |\varphi|\geq\sum_{i\in[r]}\operatorname{ar}(R_i)\geq\max\{r,\operatorname{ar}(\varphi)\}\qquad\text{and}\qquad|\varphi|\geq k. ∣ φ ∣ ≥ i ∈ [ r ] ∑ ar ( R i ) ≥ max { r , ar ( φ )} and ∣ φ ∣ ≥ k .
We now define the problem we study.
SNP Model Checking
Input: Relational structure R \mathcal{R} R , SNP sentence φ \varphi φ
Parameter: td ( R ) + ∣ φ ∣ \operatorname{td}(\mathcal{R}) + |\varphi| td ( R ) + ∣ φ ∣
Question: Does R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ ?
Since the problem is trivial otherwise, we always assume that the signatures of R \mathcal{R} R and φ \varphi φ match. We also assume that R \mathcal{R} R does not use any relations that do not appear in the formula (clearly, one could otherwise remove them from R \mathcal{R} R ), and thus ∣ φ ∣ ≥ ∑ i ∈ [ b ] ar ( E i ) ≥ max { b , ar ( R ) } |\varphi| \ge\sum_{i \in[b]} \operatorname{ar}(E_i) \ge\max\{b, \operatorname{ar}(\mathcal{R})\} ∣ φ ∣ ≥ ∑ i ∈ [ b ] ar ( E i ) ≥ max { b , ar ( R )} . We also define the natural notion of a solution, and a related solution notion that only concerns some subsets of the guessed relations.
Definition 14 (Solution and Q Q Q -solution). Let φ \varphi φ be an SNP sentence with the relation variables R 1 , … , R r R_1,\ldots,R_r R 1 , … , R r , and let R \mathcal{R} R be a relational structure. A solution is an instantiation of R 1 , … , R r R_1,\ldots,R_r R 1 , … , R r under which R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ . For Q ⊆ [ r ] Q \subseteq[r] Q ⊆ [ r ] , an instantiation of ( R i ) i ∈ Q (R_i)_{i \in Q} ( R i ) i ∈ Q is a Q Q Q -solution if there is a solution to the instance that agrees with ( R i ) i ∈ Q (R_i)_{i \in Q} ( R i ) i ∈ Q . Equivalently, a Q Q Q -solution is the projection to ( R i ) i ∈ Q (R_i)_{i \in Q} ( R i ) i ∈ Q of a solution.
Treedepth. A rooted forest F \mathcal{F} F is a disjoint union of rooted trees. For a vertex x x x in a tree T T T of F \mathcal{F} F , the depth of x x x in F \mathcal{F} F is the number of vertices on the path from the root of T T T to x x x . The height of a rooted forest is the maximum depth of a vertex of the forest. Let V ( T ) V(T) V ( T ) be the vertex set of any tree T ∈ F T \in\mathcal{F} T ∈ F . Let the closure of a rooted forest F \mathcal{F} F be the graph clos ( F ) \operatorname{clos}(\mathcal{F}) clos ( F ) with the vertex set V ( clos ( F ) ) = ⋃ T ∈ F V ( T ) V(\operatorname{clos}(\mathcal{F})) = \bigcup_{T \in\mathcal{F}} V(T) V ( clos ( F )) = ⋃ T ∈ F V ( T ) and the edge set E ( clos ( F ) ) = { x y ∣ x ≠ y and x is an ancestor of y in some T ∈ F } E(\operatorname{clos}(\mathcal{F})) = \{xy \mid x \ne y \text{ and } x \text{ is an ancestor of } y \text{ in some } T \in\mathcal{F}\} E ( clos ( F )) = { x y ∣ x = y and x is an ancestor of y in some T ∈ F } . The treedepth of a graph G G G (td ( G ) \operatorname{td}(G) td ( G ) ) is the minimum height of any rooted forest F \mathcal{F} F such that G ⊆ clos ( F ) G \subseteq\operatorname{clos}(\mathcal{F}) G ⊆ clos ( F ) .
A treedepth decomposition of a graph G G G is a rooted tree T T T such that G ⊆ clos ( T ) G \subseteq\operatorname{clos}(T) G ⊆ clos ( T ) .10 We can use the algorithm of Reidl, Rossmanith, Sánchez Villaamil, and Sikdar [86 ] to compute a treedepth decomposition of G G G of height at most td ( G ) + 1 \operatorname{td}(G) + 1 td ( G ) + 1 in time 2 O ( td ( G ) ) ⋅ ∣ V ( G ) ∣ 2^{O(\operatorname{td}(G))} \cdot|V(G)| 2 O ( td ( G )) ⋅ ∣ V ( G ) ∣ . We define the treedepth td ( R ) \operatorname{td}(\mathcal{R}) td ( R ) of a relational structure R \mathcal{R} R as the treedepth of its primal graph, and similarly define a treedepth decomposition of R \mathcal{R} R to be a treedepth decomposition of the primal graph of R \mathcal{R} R . Without loss of generality we assume that a treedepth decomposition of a relational structure contains no vertices beyond the elements of that structure.
Formally Proving the Metatheorem
We now proceed to the proof of our main theorem, that is, the full version of Theorem A. Before we state it, let us quickly explain the purpose of Q Q Q -solutions, which give the more fine-grained guarantees mentioned in Remark R. If R ⊨ ∃ R 1 , … , R r ∀ x 1 , … , x k ψ ( R 1 , … , R r , x 1 , … , x k ) \mathcal{R} \models\exists R_1,\ldots,R_r \forall x_1,\ldots,x_k \psi(R_1,\ldots,R_r,x_1,\ldots,x_k) R ⊨ ∃ R 1 , … , R r ∀ x 1 , … , x k ψ ( R 1 , … , R r , x 1 , … , x k ) our algorithm can output a solution. Naturally, the size of such a solution depends on the maximum arity of the relations R 1 , … , R r R_1,\ldots,R_r R 1 , … , R r . However, for a concrete application, it is conceivable that some of the relations R 1 , … , R r R_1,\ldots,R_r R 1 , … , R r are not of interest, in so far as they could be auxiliary relations needed to encode the problem as an SNP sentence, but do not correspond to the actual witnesses one is aiming to obtain. Hence, it is preferable to have an algorithm that can output only those relations which are of actual concern, and this is exactly what we do with the Q Q Q -solutions.
Theorem 1. There is an Algorithm A that takes an SNP sentence φ \varphi φ with relation variables R 1 , … , R r R_1,\ldots,R_r R 1 , … , R r and a relational structure R \mathcal{R} R as input, runs in time f ( ∣ φ ∣ , td ( R ) ) ⋅ ∣ R ∣ f(|\varphi|,\operatorname{td}(\mathcal{R}))\cdot|\mathcal{R}| f ( ∣ φ ∣ , td ( R )) ⋅ ∣ R ∣ for some computable function f f f , and decides whether R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ . Moreover, if R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ , then for any given non-empty Q ⊆ [ r ] Q\subseteq[r] Q ⊆ [ r ] the algorithm can output a Q Q Q -solution of R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ in time f ( ∣ φ ∣ , td ( R ) ) ⋅ ∣ R ∣ max i ∈ Q ar ( R i ) f(|\varphi|,\operatorname{td}(\mathcal{R}))\cdot|\mathcal{R}|^{\max_{i\in Q}\operatorname{ar}(R_i)} f ( ∣ φ ∣ , td ( R )) ⋅ ∣ R ∣ m a x i ∈ Q ar ( R i ) .
Types, Patterns, and Basic Properties
We begin by establishing the basic definitions and properties that will later allow us to prove the theorem. The key concept of our algorithm is that two tuples of elements which are equivalent with respect to the input relational structure are also equivalent with respect to a solution. To properly define this, we first establish equivalence classes of individual elements, named vertex types , and then use them to define equivalence classes of tuples of elements, which will be known as route patterns .
Vertex Types. We characterize the type of an individual element by two components: (i) the way it and its ancestors in the treedepth decomposition T T T interact with the input relations and (ii) the counts (up to some value p p p ) of how many children of each type it has in T T T .
Definition 2 (Vertex p p p -type). Let p ∈ N p\in\mathbb{N} p ∈ N and R \mathcal{R} R be a relational structure with treedepth decomposition T T T . For any v ∈ V ( R ) v\in V(\mathcal{R}) v ∈ V ( R ) , its vertex p p p -type in ( R , T ) (\mathcal{R},T) ( R , T ) is the tuple p p p -type( v ) = ( δ v , λ v ) (v)=(\delta_v,\lambda_v) ( v ) = ( δ v , λ v ) for an ancestor label λ v \lambda_v λ v and a subtree label δ v \delta_v δ v , defined as follows.
Let d d d be the depth of v v v in T T T and P = w 1 , w 2 , … , w d P=w_1,w_2,\ldots,w_d P = w 1 , w 2 , … , w d be the path from root w 1 w_1 w 1 of T T T to vertex v = w d v=w_d v = w d . The ancestor label λ v = atp R ( w 1 , w 2 , … , w d ) \lambda_v=\operatorname{atp}_{\mathcal{R}}(w_1,w_2,\ldots,w_d) λ v = atp R ( w 1 , w 2 , … , w d ) is the atomic type of the vertices on P P P .
The subtree label is defined recursively. All leaves in T T T have the empty subtree label ε \varepsilon ε . For a non-leaf vertex v ∈ V ( T ) v\in V(T) v ∈ V ( T ) , let C v C_v C v be the set of children of v v v in T T T , and T T T be the set { p -type ( w ) ∣ w ∈ C v } \{p\text{-type}(w)\mid w\in C_v\} { p -type ( w ) ∣ w ∈ C v } . The subtree label is then a function δ v : T → [ 0 , p − 1 ] ∪ { ⋆ } \delta_v:T\to[0,p-1]\cup\{\star\} δ v : T → [ 0 , p − 1 ] ∪ { ⋆ } , defined by
δ v ( t ) = { ∣ { w ∈ C v ∣ p -type ( w ) = t } ∣ if ∣ { w ∈ C v ∣ p -type ( w ) = t } ∣ ≤ p − 1 , ⋆ otherwise. \delta_v(t)=
\begin{cases}
\lvert\{w\in C_v\mid p\text{-type}(w)=t\}\rvert& \text{if }\lvert\{w\in C_v\mid p\text{-type}(w)=t\}\rvert\le p-1,\\
\star& \text{otherwise.}
\end{cases} δ v ( t ) = { ∣{ w ∈ C v ∣ p -type ( w ) = t }∣ ⋆ if ∣{ w ∈ C v ∣ p -type ( w ) = t }∣ ≤ p − 1 , otherwise. The value ⋆ \star ⋆ of a subtree label marks exactly those child types that appear at least p p p times. Intuitively, while a solution may treat vertices of a type differently when there are only a few of them, we will find that it does not need to distinguish between them once there are too many (say, at least p p p ). These vertices thus play an important role in defining equivalence classes, and accordingly we give them a name of their own.
Definition 15 (p p p -abundant type and p p p -abundant vertex). Let R \mathcal{R} R be a relational structure with treedepth decomposition T T T , and let p ∈ N p\in\mathbb{N} p ∈ N . A vertex p p p -type t t t is p p p -abundant in a vertex p p p -type t ′ = ( δ , λ ) t'=(\delta,\lambda) t ′ = ( δ , λ ) if t t t lies in the domain of δ \delta δ and δ ( t ) = ⋆ \delta(t)=\star δ ( t ) = ⋆ . A vertex v ∈ V ( T ) v\in V(T) v ∈ V ( T ) with parent w w w is p p p -abundant if p p p -type( v ) (v) ( v ) is p p p -abundant in p p p -type( w ) (w) ( w ) .
Unfolding the definition of δ w \delta_w δ w , a vertex v v v with parent w w w is p p p -abundant precisely if w w w has at least p p p children whose vertex p p p -type is p p p -type( v ) (v) ( v ) , that is, if v v v has at least p − 1 p-1 p − 1 siblings of its own vertex p p p -type.
One reason why the vertex types are so useful is that the ancestor label they contain already pins down, for any tuple of elements and given their pairwise ancestor-descendant relations, in which relations of the input structure R \mathcal{R} R it occurs. That is, it determines the atomic type of that tuple, even across distinct input structures.
Lemma 16 (Ancestor labels determine the relations). Let z ∈ N z \in\mathbb{N} z ∈ N , let R \mathcal{R} R and R ′ \mathcal{R}' R ′ be relational structures over the same signature with treedepth decompositions T T T and T ′ T' T ′ , and let v ˉ = ( v 1 , … , v z ) ∈ V ( R ) z \bar{v}=(v_1,\ldots,v_z)\in V(\mathcal{R})^z v ˉ = ( v 1 , … , v z ) ∈ V ( R ) z and w ˉ = ( w 1 , … , w z ) ∈ V ( R ′ ) z \bar{w}=(w_1,\ldots,w_z)\in V(\mathcal{R}')^z w ˉ = ( w 1 , … , w z ) ∈ V ( R ′ ) z be such that for all m , m ′ ∈ [ z ] m,m'\in[z] m , m ′ ∈ [ z ]
v m v_m v m has the same depth in T T T as w m w_m w m has in T ′ T' T ′ ,
v m v_m v m and w m w_m w m have the same ancestor label, and
v m v_m v m is an ancestor of v m ′ v_{m'} v m ′ in T T T if and only if w m w_m w m is an ancestor of w m ′ w_{m'} w m ′ in T ′ T' T ′ ; here and below we call a vertex an ancestor of itself.
Then atp R ( v ˉ ) = atp R ′ ( w ˉ ) \operatorname{atp}_{\mathcal{R}}(\bar{v})=\operatorname{atp}_{\mathcal{R}'}(\bar{w}) atp R ( v ˉ ) = atp R ′ ( w ˉ ) .
Proof. Since two vertices are equal exactly if each is an ancestor of the other, property (3) gives v m = v m ′ v_m=v_{m'} v m = v m ′ if and only if w m = w m ′ w_m=w_{m'} w m = w m ′ , so v ˉ \bar{v} v ˉ and w ˉ \bar{w} w ˉ agree on the equality part of the atomic type of Definition 1.
Now, fix some relation E i E_i E i of arity a a a and indices n 1 , … , n a ∈ [ z ] n_1,\ldots,n_a\in[z] n 1 , … , n a ∈ [ z ] such that E i ( v n 1 , … , v n a ) E_i(v_{n_1},\ldots,v_{n_a}) E i ( v n 1 , … , v n a ) holds, and let d j d_j d j be the depth of v n j v_{n_j} v n j . Then the distinct vertices among v n 1 , … , v n a v_{n_1},\ldots,v_{n_a} v n 1 , … , v n a form a clique in the primal graph of R \mathcal{R} R , so, as T T T is a treedepth decomposition, they lie on some path ( u 1 , … , u d ) (u_1,\ldots,u_d) ( u 1 , … , u d ) in T T T , where u 1 u_1 u 1 is the root and u d u_d u d is the deepest among them. By the definition of the ancestor label λ u d = atp R ( u 1 , … , u d ) \lambda_{u_d}=\operatorname{atp}_{\mathcal{R}}(u_1,\ldots,u_d) λ u d = atp R ( u 1 , … , u d ) in Definition 2 we thus obtain E i ( x d 1 , … , x d a ) ∈ λ u d E_i(x_{d_1},\ldots,x_{d_a})\in\lambda_{u_d} E i ( x d 1 , … , x d a ) ∈ λ u d .
By properties (1) and (3), the tuples ( v n 1 , … , v n a ) (v_{n_1},\ldots,v_{n_a}) ( v n 1 , … , v n a ) and ( w n 1 , … , w n a ) (w_{n_1},\ldots,w_{n_a}) ( w n 1 , … , w n a ) agree on the depths d 1 , … , d a d_1,\ldots,d_a d 1 , … , d a and on ancestor-descendant relationships, which shows that also w n 1 , … , w n a w_{n_1},\ldots,w_{n_a} w n 1 , … , w n a lie on a path from the root in T ′ T' T ′ , and that w n j w_{n_j} w n j is the vertex of depth d j d_j d j on it. Their deepest entries sit at the same position, say ℓ \ell ℓ ; note that v n ℓ = u d v_{n_\ell}=u_d v n ℓ = u d , and that the ancestor labels of v n ℓ v_{n_\ell} v n ℓ in ( R , T ) (\mathcal{R},T) ( R , T ) and of w n ℓ w_{n_\ell} w n ℓ in ( R ′ , T ′ ) (\mathcal{R}',T') ( R ′ , T ′ ) are atomic types over the same signature, which coincide by property (2). Hence E i ( x d 1 , … , x d a ) E_i(x_{d_1},\ldots,x_{d_a}) E i ( x d 1 , … , x d a ) also lies in the ancestor label of w n ℓ w_{n_\ell} w n ℓ , that is, R ′ \mathcal{R}' R ′ satisfies E i E_i E i on the vertices of depths d 1 , … , d a d_1,\ldots,d_a d 1 , … , d a of the root-to-w n ℓ w_{n_\ell} w n ℓ path, so
E i ( v n 1 , … , v n a ) ⟹ E i ( w n 1 , … , w n a ) . E_i(v_{n_1},\ldots,v_{n_a})\Longrightarrow E_i(w_{n_1},\ldots,w_{n_a}). E i ( v n 1 , … , v n a ) ⟹ E i ( w n 1 , … , w n a ) . As the hypotheses are symmetric in ( R , T , v ˉ ) (\mathcal{R},T,\bar{v}) ( R , T , v ˉ ) and ( R ′ , T ′ , w ˉ ) (\mathcal{R}',T',\bar{w}) ( R ′ , T ′ , w ˉ ) , the tuples agree on all relations, concluding the proof.
Coming up with this equivalence notion of vertex types is only useful if they reduce the number of distinct objects we need to speak about. This is captured by the following lemma.
Lemma 17 (Enumerating vertex p p p -types). There is a computable function g g g such that for any instance ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) of SNP Model Checking, any treedepth decomposition T T T of R \mathcal{R} R of height h h h , and any integer p ≥ 1 p\ge1 p ≥ 1 the number ∣ { p -type ( v ) ∣ v ∈ V ( R ) } ∣ \lvert\{p\text{-type}(v)\mid v\in V(\mathcal{R})\}\rvert ∣{ p -type ( v ) ∣ v ∈ V ( R )}∣ of distinct vertex p p p -types is bounded by g ( h , p , ∣ φ ∣ ) g(h,p,\lvert\varphi\rvert) g ( h , p , ∣ φ ∣) .
Proof. Consider some relational structure R = ( V , E 1 , … , E b ) \mathcal{R}=(V,E_1,\ldots,E_b) R = ( V , E 1 , … , E b ) , formula φ \varphi φ of length at most L L L , and treedepth decomposition of R \mathcal{R} R of height h h h . Since we assume that each relation E i E_i E i appears in φ \varphi φ , we have b ≤ L b\le L b ≤ L and max i ∈ [ b ] ar ( E i ) ≤ L \max_{i\in[b]}\operatorname{ar}(E_i)\le L max i ∈ [ b ] ar ( E i ) ≤ L .
By Lemma 12 the number of possible atomic types of a tuple of length z z z is bounded by 2 z 2 + ∑ i ∈ [ b ] z ar ( E i ) 2^{z^2+\sum_{i\in[b]}z^{\operatorname{ar}(E_i)}} 2 z 2 + ∑ i ∈ [ b ] z ar ( E i ) . The vertex p p p -type only records the atomic types of vertices lying on a path in T T T starting at the root, and hence the length of a considered tuple is bounded by h h h . For a vertex v v v of T T T , there are thus at most 2 h 2 + L h L 2^{h^2+Lh^L} 2 h 2 + L h L possibilities for the ancestor label of v v v .
For each i ∈ [ h ] i\in[h] i ∈ [ h ] we define a number N i N_i N i that bounds the number of different possible vertex p p p -types of vertices at depth i i i in $T.
Since a leaf of T T T records no information about its children (since it has none), we can set N h = 2 2 h + L h L N_h = 2^{2^h+Lh^L} N h = 2 2 h + L h L . For i ∈ [ 1 , h − 1 ] i \in[1,h-1] i ∈ [ 1 , h − 1 ] we set N i = N h ⋅ ( p + 1 ) N i + 1 N_i = N_h \cdot(p+1)^{N_{i+1}} N i = N h ⋅ ( p + 1 ) N i + 1 . This bound is also correct, since a non-leaf vertex again has at most N h N_h N h possible ancestor labels, and it additionally stores the number of children of each type up to p p p . The final bound on the number of possible types is then given by g ( h , p , L ) = ∑ i ∈ [ h ] N i g(h,p,L) = \sum_{i\in[h]} N_i g ( h , p , L ) = ∑ i ∈ [ h ] N i , which is computable.
Routes and Route Patterns
Having established an equivalence notion on the vertex level, we proceed to define a more complex equivalence notion concerning tuples of vertices. The motivation for this is evident, when considering SNP sentences: such a sentence asks if there is some solution such that no forbidden pattern of size at most k k k exists, where the inner formula describes this forbidden pattern. It is therefore natural to consider equivalence classes of tuples of length at most k k k . These will prove useful because we construct a solution in which a whole class behaves alike: if one tuple of a class does not witness the forbidden pattern, then no tuple of that class does.
Before formally describing this equivalence class, we define an alternative way to uniquely identify a vertex v v v of T T T , the p p p -route of v v v . The idea is that we can find a vertex v v v by describing which path from the root of T T T one must follow to reach it, where the intermediate vertices of the path are identified by their vertex p p p -type, and their relative position among siblings with the same vertex p p p -type. For the latter recall that we assume there is a fixed total order on V ( R ) V(\mathcal{R}) V ( R ) .
Definition 3 (p p p -route and p p p -route of a vertex). Consider a relational structure R \mathcal{R} R with treedepth decomposition T T T , and an integer p ≥ 1 p \ge1 p ≥ 1 . A p p p -route is a non-empty finite sequence ϱ = ( e 1 , … , e d ) \varrho= (e_1,\ldots,e_d) ϱ = ( e 1 , … , e d ) of entries e ℓ = ( t ℓ , i ℓ ) e_\ell= (t_\ell,i_\ell) e ℓ = ( t ℓ , i ℓ ) , each consisting of a vertex p p p -type t ℓ t_\ell t ℓ and an index i ℓ ∈ N i_\ell\in\mathbb{N} i ℓ ∈ N ; we call d d d the length of ϱ \varrho ϱ also denoted as ∣ ϱ ∣ |\varrho| ∣ ϱ ∣ . The entry e ℓ e_\ell e ℓ is abundant if ℓ ≥ 2 \ell\ge2 ℓ ≥ 2 and t ℓ t_\ell t ℓ is p p p -abundant in t ℓ − 1 t_{\ell-1} t ℓ − 1 .
We write rt ( v ) \operatorname{rt}(v) rt ( v ) for the p p p -route of a vertex v v v of T T T , which is defined recursively as follows. For the root u u u of T T T we set rt ( u ) = ( ( p -type ( u ) , 1 ) ) \operatorname{rt}(u) = ((p\text{-type}(u),1)) rt ( u ) = (( p -type ( u ) , 1 )) .
Let v v v be a non-root vertex in T T T and t = p -type ( v ) t = p\text{-type}(v) t = p -type ( v ) . Let w w w be the parent of v v v and let i ∈ N i \in\mathbb{N} i ∈ N be such that v v v is the i i i -th smallest11 element among all children of w w w of type t t t . Then rt ( v ) = rt ( w ) ⋄ ( t , i ) \operatorname{rt}(v) = \operatorname{rt}(w) \diamond(t,i) rt ( v ) = rt ( w ) ⋄ ( t , i ) .
Observe that a p p p -route identifies at most one vertex of T T T : two vertices with the same p p p -route have, by induction on the depth, the same parent, and then the same index among the children of that parent of their common vertex p p p -type, so they are equal. The next lemma shows that we can efficiently determine the vertex p p p -type and p p p -route of all vertices.
Lemma 18 (Computing vertex p p p -types and p p p -routes). There is a computable function f f f such that for any instance ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) of SNP Model Checking, any treedepth decomposition T T T of R \mathcal{R} R of height h h h , and any integer p ≥ 1 p \ge1 p ≥ 1 , the vertex p p p -types and the p p p -routes of all elements of R \mathcal{R} R can be computed in time f ( h , p , ∣ φ ∣ ) ⋅ ∣ R ∣ f(h,p,|\varphi|)\cdot|\mathcal{R}| f ( h , p , ∣ φ ∣ ) ⋅ ∣ R ∣ .
Proof. Traversing T T T once, we compute the parent and the depth of every element; this takes time O ( ∣ R ∣ ) O(|\mathcal{R}|) O ( ∣ R ∣ ) . Recall that a vertex p p p -type is a pair ( δ v , λ v ) (\delta_v,\lambda_v) ( δ v , λ v ) of a subtree label and an ancestor label, and that λ v \lambda_v λ v depends only on the ancestors of v v v while δ v \delta_v δ v depends only on its descendants. We may therefore compute all ancestor labels in a top-down pass and then all subtree labels in a bottom-up pass as follows.
Ancestor labels. We store an atomic type as the set of the atomic formulas it contains, representing E i ( x n 1 , … , x n a ) E_i(x_{n_1},\ldots,x_{n_a}) E i ( x n 1 , … , x n a ) by the pair ( i , ( n 1 , … , n a ) ) (i,(n_1,\ldots,n_a)) ( i , ( n 1 , … , n a )) and x n = x n ′ x_n = x_{n'} x n = x n ′ by the pair ( n , n ′ ) (n,n') ( n , n ′ ) . Every tuple of every relation of R \mathcal{R} R consists of elements that are pairwise in ancestor-descendant relation in T T T , so it has a unique deepest entry, which we find in time linear in its arity. For each relation E i E_i E i and each tuple u ˉ ∈ E i \bar{u} \in E_i u ˉ ∈ E i we record the atomic formula E i ( x d 1 , … , x d ar ( E i ) ) E_i(x_{d_1}, \ldots, x_{d_{\operatorname{ar}(E_i)}}) E i ( x d 1 , … , x d ar ( E i ) ) at that deepest entry, where d j d_j d j is the depth of the j j j -th entry of u ˉ \bar{u} u ˉ . Over all tuples this takes time O ( ∣ R ∣ ) O(|\mathcal{R}|) O ( ∣ R ∣ ) . Now a tuple of elements of the root-to-v v v path either consists of elements of the root-to-w w w path, where w w w is the parent of v v v , or contains v v v and hence has v v v as its deepest entry. The vertices w 1 , … , w d w_1,\ldots,w_d w 1 , … , w d of the root-to-v v v path are pairwise distinct and w n w_n w n has depth n n n , so by Definition 1 the equality part of λ v = atp R ( w 1 , … , w d ) \lambda_v = \operatorname{atp}_{\mathcal{R}}(w_1,\ldots,w_d) λ v = atp R ( w 1 , … , w d ) is exactly { x n = x n ∣ n ∈ [ d ] } \{x_n = x_n \mid n \in[d]\} { x n = x n ∣ n ∈ [ d ]} . By the definition of the ancestor label in Definition 2 we thus obtain λ v \lambda_v λ v from λ w \lambda_w λ w by adding the atomic formulas recorded at v v v together with the equality atom x d = x d x_d = x_d x d = x d , where d d d is the depth of v v v ; if v v v is the root, λ v \lambda_v λ v consists of the atomic formulas recorded at v v v together with the equality atom x 1 = x 1 x_1 = x_1 x 1 = x 1 . Each ancestor label is a set of at most ∑ i h ar ( E i ) + h ≤ ∣ φ ∣ ⋅ h ∣ φ ∣ + h \sum_i h^{\operatorname{ar}(E_i)} + h \leq|\varphi| \cdot h^{|\varphi|} + h ∑ i h ar ( E i ) + h ≤ ∣ φ ∣ ⋅ h ∣ φ ∣ + h atomic formulas, counting also the at most h h h formulas of the equality part of the atomic type, so each of these steps takes time f 1 ( h , ∣ φ ∣ ) f_1(h,|\varphi|) f 1 ( h , ∣ φ ∣ ) for a computable function f 1 f_1 f 1 , and the pass takes time f 1 ( h , ∣ φ ∣ ) ⋅ ∣ R ∣ f_1(h,|\varphi|) \cdot|\mathcal{R}| f 1 ( h , ∣ φ ∣ ) ⋅ ∣ R ∣ .
Subtree labels. The subtree label of a leaf is ε \varepsilon ε . For a non-leaf v v v whose children all have their vertex p p p -types computed, we group the children by their vertex p p p -type and let δ v \delta_v δ v map each occurring vertex p p p -type to the number of children carrying it, or to ⋆ \star ⋆ if that number exceeds p − 1 p-1 p − 1 . A vertex p p p -type has an encoding of size at most f 2 ( h , p , ∣ φ ∣ ) f_2(h,p,|\varphi|) f 2 ( h , p , ∣ φ ∣ ) for a computable function f 2 f_2 f 2 , so the grouping costs O ( f 2 ( h , p , ∣ φ ∣ ) ) O(f_2(h,p,|\varphi|)) O ( f 2 ( h , p , ∣ φ ∣ )) per child, and summing over all vertices gives f 2 ( h , p , ∣ φ ∣ ) ⋅ O ( ∣ R ∣ ) f_2(h,p,|\varphi|) \cdot O(|\mathcal{R}|) f 2 ( h , p , ∣ φ ∣ ) ⋅ O ( ∣ R ∣ ) for the whole pass.
p p p -routes. Recall that the p p p -route of a non-root element v v v with parent w w w is rt ( w ) ⋄ ( p -type ( v ) , i ) \operatorname{rt}(w) \diamond(p\text{-type}(v),i) rt ( w ) ⋄ ( p -type ( v ) , i ) , such that v v v is the i i i -th smallest element among the children of w w w of vertex p p p -type p -type ( v ) p\text{-type}(v) p -type ( v ) in the total order on V ( R ) V(\mathcal{R}) V ( R ) . For the indices, we scan the elements in increasing order and maintain a counter for every pair consisting of an element and a vertex p p p -type; upon reaching v v v we increment the counter of ( w , p -type ( v ) ) (w,p\text{-type}(v)) ( w , p -type ( v )) and take its new value as the index i i i of v v v . As we scan in increasing order, we meet the children of w w w of any fixed vertex p p p -type in increasing order, so this is the correct index. For the routes, we traverse T T T from the root downwards, starting with rt ( u ) = ( ( p -type ( u ) , 1 ) ) \operatorname{rt}(u) = ((p\text{-type}(u),1)) rt ( u ) = (( p -type ( u ) , 1 )) at the root u u u and setting rt ( v ) = rt ( w ) ⋄ ( p -type ( v ) , i ) \operatorname{rt}(v) = \operatorname{rt}(w) \diamond(p\text{-type}(v),i) rt ( v ) = rt ( w ) ⋄ ( p -type ( v ) , i ) at every other element v v v ; as a parent is processed before its children, rt ( w ) \operatorname{rt}(w) rt ( w ) is available when v v v is reached. Each route consists of at most h h h entries of size at most f 2 ( h , p , ∣ φ ∣ ) f_2(h,p,|\varphi|) f 2 ( h , p , ∣ φ ∣ ) . Both passes therefore take time f 3 ( h , p , ∣ φ ∣ ) ⋅ ∣ R ∣ f_3(h,p,|\varphi|) \cdot|\mathcal{R}| f 3 ( h , p , ∣ φ ∣ ) ⋅ ∣ R ∣ for a computable function f 3 f_3 f 3 , which concludes the proof.
For the equivalence classes, the idea now is to normalize these p p p -routes so that they still record the vertex p p p -types, the depths and the relative order of the entries, while the value of i i i in every entry ( t , i ) (t,i) ( t , i ) becomes bounded. With the normalized p p p -route (which exists when p p p is chosen sufficiently large), one can no longer uniquely identify vertices of T T T ; however, when following the normalized p p p -route of a vertex v v v , one reaches some natural representative v ′ v' v ′ that behaves similarly to v v v . This notion is extended in the natural way to tuples of vertices.
In a nutshell, for a vertex tuple v 1 , … , v z v_1,\ldots,v_z v 1 , … , v z , we first consider the p p p -routes of all its entries. Then, instead of storing the exact indices in the p p p -route entries, we only store their relative order among all entries of the routes considered.
Definition 4 (Normalization and p p p -route pattern). Consider a relational structure R \mathcal{R} R with treedepth decomposition T T T and an integer p ≥ 1 p \geq1 p ≥ 1 . Let S S S be a finite set of p p p -routes. Define
I ( S ) = { i ∣ there is an abundant entry ( t , i ) in at least one route of S } , I(S) = \{i \mid\text{there is an abundant entry }(t,i)\text{ in at least one route of }S\}, I ( S ) = { i ∣ there is an abundant entry ( t , i ) in at least one route of S } , and let π S : I ( S ) → [ ∣ I ( S ) ∣ ] \pi_S : I(S) \to[|I(S)|] π S : I ( S ) → [ ∣ I ( S ) ∣ ] map each index to its rank in I ( S ) I(S) I ( S ) , that is, π S ( i ) = ∣ { i ′ ∈ I ( S ) ∣ i ′ ≤ i } ∣ \pi_S(i) = |\{i' \in I(S) \mid i' \leq i\}| π S ( i ) = ∣ { i ′ ∈ I ( S ) ∣ i ′ ≤ i } ∣ .
We now replace every entry e ℓ e_\ell e ℓ in every p p p -route in S S S by
e ^ ℓ = { ( t ℓ , π S ( i ℓ ) ) if e ℓ = ( t ℓ , i ℓ ) is abundant , e ℓ otherwise , \hat{e}_\ell=
\begin{cases}
(t_\ell,\pi_S(i_\ell)) & \text{if } e_\ell=(t_\ell,i_\ell)\text{ is abundant},\\
e_\ell& \text{otherwise},
\end{cases} e ^ ℓ = { ( t ℓ , π S ( i ℓ )) e ℓ if e ℓ = ( t ℓ , i ℓ ) is abundant , otherwise ,
and call ν S ( ϱ ) = ( e ^ 1 , … , e ^ d ) \nu_S(\varrho)=(\hat{e}_1,\ldots,\hat{e}_d) ν S ( ϱ ) = ( e ^ 1 , … , e ^ d ) the normalization of ϱ \varrho ϱ with respect to S S S . We write ν S ( S ′ ) = { ν S ( ϱ ) ∣ ϱ ∈ S ′ } \nu_S(S')=\{\nu_S(\varrho)\mid\varrho\in S'\} ν S ( S ′ ) = { ν S ( ϱ ) ∣ ϱ ∈ S ′ } for S ′ ⊆ S S'\subseteq S S ′ ⊆ S .
Let ( v 1 , … , v z ) (v_1,\ldots,v_z) ( v 1 , … , v z ) be a tuple of elements of R \mathcal{R} R , (i.e., vertices of T T T ) and let S = { rt ( v 1 ) , … , rt ( v z ) } S=\{\operatorname{rt}(v_1),\ldots,\operatorname{rt}(v_z)\} S = { rt ( v 1 ) , … , rt ( v z )} be the set of their p p p -routes. The p p p -route pattern of ( v 1 , … , v z ) (v_1,\ldots,v_z) ( v 1 , … , v z ) is the tuple ( ν S ( rt ( v 1 ) ) , … , ν S ( rt ( v z ) ) ) (\nu_S(\operatorname{rt}(v_1)),\ldots,\nu_S(\operatorname{rt}(v_z))) ( ν S ( rt ( v 1 )) , … , ν S ( rt ( v z ))) .
Observe that this type of normalization is a purely syntactic operation on the p p p -routes themselves: besides the p p p -routes, the only information it uses is which of their entries are abundant, which is also (implicitly) recorded in them. All the combinatorial properties of p p p -route patterns that we use are thus properties of the normalization operator, which we collect here for later reference. The first two speak about properties preserved by the normalization, the third and fourth about consecutive application of normalization, and the last about the bounds on indices after normalization.
Lemma 19 (Properties of normalization). Let S S S be a finite set of p p p -routes and let S ′ ⊆ S S'\subseteq S S ′ ⊆ S . The following properties all hold:
ν S \nu_S ν S preserves the length of every p p p -route, the vertex p p p -type in every entry, and hence the abundance of every entry.
For all ϱ , ϱ ′ ∈ S \varrho,\varrho'\in S ϱ , ϱ ′ ∈ S and every ℓ ∈ [ 0 , min { ∣ ϱ ∣ , ∣ ϱ ′ ∣ } ] \ell\in[0,\min\{|\varrho|,|\varrho'|\}] ℓ ∈ [ 0 , min { ∣ ϱ ∣ , ∣ ϱ ′ ∣ }] , the prefixes of length ℓ \ell ℓ of ϱ \varrho ϱ and ϱ ′ \varrho' ϱ ′ coincide if and only if those of ν S ( ϱ ) \nu_S(\varrho) ν S ( ϱ ) and ν S ( ϱ ′ ) \nu_S(\varrho') ν S ( ϱ ′ ) do.
ν S ′ = ν ν S ( S ′ ) ∘ ν S \nu_{S'}=\nu_{\nu_S(S')}\circ\nu_S ν S ′ = ν ν S ( S ′ ) ∘ ν S on S ′ S' S ′ , that is, normalizing ϱ ∈ S ′ \varrho\in S' ϱ ∈ S ′ for S ′ S' S ′ yields the same as first normalizing ϱ \varrho ϱ for S S S and then normalizing for the set of normalized routes ν S ( S ′ ) \nu_S(S') ν S ( S ′ ) of S ′ S' S ′ .
ν ν S ( S ) \nu_{\nu_S(S)} ν ν S ( S ) is the identity on ν S ( S ) \nu_S(S) ν S ( S ) , that is, normalizing a normalized set of routes gives the same set.
For every ϱ ∈ S \varrho\in S ϱ ∈ S , each abundant entry of ν S ( ϱ ) \nu_S(\varrho) ν S ( ϱ ) has index at most ∣ I ( S ) ∣ |I(S)| ∣ I ( S ) ∣ , which is at most ∣ S ∣ ( h − 1 ) |S|(h-1) ∣ S ∣ ( h − 1 ) if every route in S S S has length at most h h h ; each non-abundant entry of ν S ( ϱ ) \nu_S(\varrho) ν S ( ϱ ) is equal to the corresponding entry of ϱ \varrho ϱ .
Proof. (1). The operator ν S \nu_S ν S replaces index components only, so lengths and the vertex p p p -types in all entries are preserved, and the abundance of an entry depends on nothing else.
(2). We proceed by induction on ℓ \ell ℓ , the case ℓ = 0 \ell=0 ℓ = 0 being trivial. Let ϱ = ( e 1 , … , e d ) \varrho=(e_1,\ldots,e_d) ϱ = ( e 1 , … , e d ) and ϱ ′ = ( e 1 ′ , … , e d ′ ′ ) \varrho'=(e'_1,\ldots,e'_{d'}) ϱ ′ = ( e 1 ′ , … , e d ′ ′ ) be routes in S S S of length at least ℓ ≥ 1 \ell\geq1 ℓ ≥ 1 , and write e ℓ = ( t ℓ , i ℓ ) e_\ell=(t_\ell,i_\ell) e ℓ = ( t ℓ , i ℓ ) and e ℓ ′ = ( t ℓ ′ , i ℓ ′ ) e'_\ell=(t'_\ell,i'_\ell) e ℓ ′ = ( t ℓ ′ , i ℓ ′ ) . Assume that ϱ \varrho ϱ and ϱ ′ \varrho' ϱ ′ share their prefix of length ℓ \ell ℓ . Then they also share their prefix of length ℓ − 1 \ell-1 ℓ − 1 , so ν S ( ϱ ) \nu_S(\varrho) ν S ( ϱ ) and ν S ( ϱ ′ ) \nu_S(\varrho') ν S ( ϱ ′ ) do as well by the induction hypothesis. The ℓ \ell ℓ -th entry in ν S ( ϱ ) \nu_S(\varrho) ν S ( ϱ ) and ν S ( ϱ ′ ) \nu_S(\varrho') ν S ( ϱ ′ ) depends only on e ℓ e_\ell e ℓ and e ℓ ′ e'_\ell e ℓ ′ , respectively, and whether they are abundant. Since e ℓ = e ℓ ′ e_\ell=e'_\ell e ℓ = e ℓ ′ by assumption and abundance depends only on t ℓ = t ℓ ′ t_\ell=t'_\ell t ℓ = t ℓ ′ and the vertex p p p -types in their (identical) preceding entry, this gives e ^ ℓ = e ^ ℓ ′ \hat{e}_\ell=\hat{e}'_\ell e ^ ℓ = e ^ ℓ ′ ; for ℓ = 1 \ell=1 ℓ = 1 there is no preceding entry, but then neither entry is abundant by Definition 3 and both are left unchanged.
Conversely, assume that ν S ( ϱ ) \nu_S(\varrho) ν S ( ϱ ) and ν S ( ϱ ′ ) \nu_S(\varrho') ν S ( ϱ ′ ) share their prefix of length ℓ \ell ℓ . By the induction hypothesis, ϱ \varrho ϱ and ϱ ′ \varrho' ϱ ′ share their prefix of length ℓ − 1 \ell-1 ℓ − 1 , and by property (1) their ℓ \ell ℓ -th entries carry the same vertex p p p -type and are either both abundant or neither of them is. If they are not abundant, they are left unchanged, so e ℓ = e ^ ℓ = e ^ ℓ ′ = e ℓ ′ e_\ell= \hat{e}_\ell= \hat{e}'_\ell= e'_\ell e ℓ = e ^ ℓ = e ^ ℓ ′ = e ℓ ′ . If they are abundant, then by assumption π S ( i ℓ ) = π S ( i ℓ ′ ) \pi_S(i_\ell) = \pi_S(i'_\ell) π S ( i ℓ ) = π S ( i ℓ ′ ) , and π S \pi_S π S is injective, so i ℓ = i ℓ ′ i_\ell= i'_\ell i ℓ = i ℓ ′ .
(3). By property (1), normalization preserves abundance, so I ( ν S ( S ′ ) ) = π S ( I ( S ′ ) ) I(\nu_S(S')) = \pi_S(I(S')) I ( ν S ( S ′ )) = π S ( I ( S ′ )) . Since I ( S ′ ) ⊆ I ( S ) I(S') \subseteq I(S) I ( S ′ ) ⊆ I ( S ) and π S \pi_S π S is strictly increasing, each i ∈ I ( S ′ ) i \in I(S') i ∈ I ( S ′ ) has the same rank in I ( S ′ ) I(S') I ( S ′ ) as π S ( i ) \pi_S(i) π S ( i ) has in π S ( I ( S ′ ) ) \pi_S(I(S')) π S ( I ( S ′ )) . Thus,
π ν S ( S ′ ) ( π S ( i ) ) = π S ′ ( i ) for every i ∈ I ( S ′ ) . \pi_{\nu_S(S')}(\pi_S(i)) = \pi_{S'}(i) \qquad\text{for every } i \in I(S'). π ν S ( S ′ ) ( π S ( i )) = π S ′ ( i ) for every i ∈ I ( S ′ ) .
Both normalization procedures therefore agree on abundant entries and leave all other entries unchanged, proving the identity on S ′ S' S ′ .
(4). Property (3) with S ′ = S S' = S S ′ = S gives ν S = ν ν S ( S ) ∘ ν S \nu_S = \nu_{\nu_S(S)} \circ\nu_S ν S = ν ν S ( S ) ∘ ν S on S S S . Thus, ν ν S ( S ) \nu_{\nu_S(S)} ν ν S ( S ) is the identity on ν S ( S ) \nu_S(S) ν S ( S ) . Intuitively, the first normalization assigns each index in an abundant entry its rank within the set I ( S ) I(S) I ( S ) . Ranking an already ranked set just returns the same ranks.
(5). An abundant entry receives an index in [ ∣ I ( S ) ∣ ] [|I(S)|] [ ∣ I ( S ) ∣ ] by Definition 4. Each element of I ( S ) I(S) I ( S ) is the index of an abundant entry of some route of S S S , and a route of length at most h h h has at most h − 1 h-1 h − 1 abundant entries, since its first entry is never abundant; hence ∣ I ( S ) ∣ ≤ ∣ S ∣ ( h − 1 ) |I(S)| \le|S|(h-1) ∣ I ( S ) ∣ ≤ ∣ S ∣ ( h − 1 ) . Non-abundant entries are left unchanged by definition.
Since p p p -route patterns are obtained via normalization of element tuples, the above lemma helps us in establishing some useful properties of any two element tuples sharing a p p p -route pattern: (1) they occupy corresponding positions in T T T , (2) they interact with the relations in R \mathcal{R} R in the same way, and (3) any deletion, copy, or reordering, as long as applied to both original tuples, yields two tuples which again share a p p p -route pattern.
Lemma 20 (Properties of p p p -route patterns). Let p , z ∈ N p, z \in\mathbb{N} p , z ∈ N , let R \mathcal{R} R be a relational structure with treedepth decomposition T T T , and let v ˉ = ( v 1 , … , v z ) \bar{v} = (v_1,\ldots,v_z) v ˉ = ( v 1 , … , v z ) and w ˉ = ( w 1 , … , w z ) \bar{w} = (w_1,\ldots,w_z) w ˉ = ( w 1 , … , w z ) in V ( R ) z V(\mathcal{R})^z V ( R ) z have the same p p p -route pattern. The following properties all hold:
(1) For all m , m ′ ∈ [ z ] m,m' \in[z] m , m ′ ∈ [ z ] , the vertices v m v_m v m and w m w_m w m have the same depth in T T T and the same vertex p p p -type, and v m v_m v m is an ancestor of v m ′ v_{m'} v m ′ if and only if w m w_m w m is an ancestor of w m ′ w_{m'} w m ′ (even when counting a vertex as an ancestor of itself).
(2) The two tuples have the same atomic type, that is, atp R ( v ˉ ) = atp R ( w ˉ ) \operatorname{atp}_{\mathcal{R}}(\bar{v}) = \operatorname{atp}_{\mathcal{R}}(\bar{w}) atp R ( v ˉ ) = atp R ( w ˉ ) .
(3) For every a ∈ N a \in\mathbb{N} a ∈ N and all n 1 , … , n a ∈ [ z ] n_1,\ldots,n_a \in[z] n 1 , … , n a ∈ [ z ] , which need be neither distinct nor increasing, the tuples ( v n 1 , … , v n a ) (v_{n_1},\ldots,v_{n_a}) ( v n 1 , … , v n a ) and ( w n 1 , … , w n a ) (w_{n_1},\ldots,w_{n_a}) ( w n 1 , … , w n a ) have the same p p p -route pattern.
Proof. Let S v = { rt ( v 1 ) , … , rt ( v z ) } S_v = \{\operatorname{rt}(v_1),\ldots,\operatorname{rt}(v_z)\} S v = { rt ( v 1 ) , … , rt ( v z )} and S w = { rt ( w 1 ) , … , rt ( w z ) } S_w = \{\operatorname{rt}(w_1),\ldots,\operatorname{rt}(w_z)\} S w = { rt ( w 1 ) , … , rt ( w z )} be the sets of the p p p -routes of v ˉ \bar{v} v ˉ and of w ˉ \bar{w} w ˉ . That the two tuples have the same p p p -route pattern means, by Definition 4, that
ν S v ( rt ( v m ) ) = ν S w ( rt ( w m ) ) for every m ∈ [ z ] . \nu_{S_v}(\operatorname{rt}(v_m)) = \nu_{S_w}(\operatorname{rt}(w_m)) \qquad\text{for every } m \in[z]. ν S v ( rt ( v m )) = ν S w ( rt ( w m )) for every m ∈ [ z ] .
(1). By Definition 3 the length of the p p p -route of a vertex is its depth in T T T , the last entry of the p p p -route carries its vertex p p p -type, and a vertex x x x is an ancestor of a vertex y y y if and only if rt ( x ) \operatorname{rt}(x) rt ( x ) is a prefix of rt ( y ) \operatorname{rt}(y) rt ( y ) . It remains to observe that ν S v \nu_{S_v} ν S v and ν S w \nu_{S_w} ν S w both preserve lengths and the vertex p p p -type in every entry by Lemma 19 (1), and both preserve the prefix relation by Lemma 19 (2); so these three properties may be read off the common normalized routes.
(2). The ancestor label is part of the vertex p p p -type by Definition 2, so property (1) provides the three hypotheses of Lemma 16 for R ′ = R \mathcal{R}' = \mathcal{R} R ′ = R and T ′ = T T' = T T ′ = T , which gives the claim. (3). Let S v ′ = { rt ( v n 1 ) , … , rt ( v n a ) } ⊆ S v S'_v = \{\operatorname{rt}(v_{n_1}), \ldots, \operatorname{rt}(v_{n_a})\} \subseteq S_v S v ′ = { rt ( v n 1 ) , … , rt ( v n a )} ⊆ S v and S w ′ = { rt ( w n 1 ) , … , rt ( w n a ) } ⊆ S w S'_w = \{\operatorname{rt}(w_{n_1}), \ldots, \operatorname{rt}(w_{n_a})\} \subseteq S_w S w ′ = { rt ( w n 1 ) , … , rt ( w n a )} ⊆ S w be the sets of the p p p -routes of the two subt uples. Taking the images of the positions n 1 , … , n a n_1,\ldots,n_a n 1 , … , n a on both sides of the equality above yields S ∘ : = ν S v ( S v ′ ) = ν S w ( S w ′ ) S^\circ:= \nu_{S_v}(S'_v) = \nu_{S_w}(S'_w) S ∘ := ν S v ( S v ′ ) = ν S w ( S w ′ ) . Hence, for every m ∈ [ a ] m \in[a] m ∈ [ a ] , we have
ν S v ′ ( rt ( v n m ) ) = ν S ∘ ( ν S v ( rt ( v n m ) ) ) by Lemma 19 (3) for S v ′ ⊆ S v , = ν S ∘ ( ν S w ( rt ( w n m ) ) ) by the common p -route pattern of v ˉ and w ˉ , = ν S w ′ ( rt ( w n m ) ) , by Lemma 19 (3) for S w ′ ⊆ S w , \begin{aligned}
\nu_{S'_v}(\operatorname{rt}(v_{n_m})) &= \nu_{S^\circ}(\nu_{S_v}(\operatorname{rt}(v_{n_m}))) && \text{by Lemma 19 (3) for } S'_v \subseteq S_v,\\
&= \nu_{S^\circ}(\nu_{S_w}(\operatorname{rt}(w_{n_m}))) && \text{by the common }p\text{-route pattern of }\bar v\text{ and }\bar w,\\
&= \nu_{S'_w}(\operatorname{rt}(w_{n_m})), && \text{by Lemma 19 (3) for } S'_w \subseteq S_w,
\end{aligned} ν S v ′ ( rt ( v n m )) = ν S ∘ ( ν S v ( rt ( v n m ))) = ν S ∘ ( ν S w ( rt ( w n m ))) = ν S w ′ ( rt ( w n m )) , by Lemma 19 (3) for S v ′ ⊆ S v , by the common p -route pattern of v ˉ and w ˉ , by Lemma 19 (3) for S w ′ ⊆ S w ,
which by Definition 4 precisely gives that ( v n 1 , … , v n a ) (v_{n_1},\ldots,v_{n_a}) ( v n 1 , … , v n a ) and ( w n 1 , … , w n a ) (w_{n_1},\ldots,w_{n_a}) ( w n 1 , … , w n a ) have the same p p p -route pattern. Note that the indices n 1 , … , n a n_1,\ldots,n_a n 1 , … , n a need be neither distinct nor increasing, since ν S v ′ \nu_{S'_v} ν S v ′ and ν S w ′ \nu_{S'_w} ν S w ′ are applied to each position separately.
Moreover, we record that the number of possible p p p -route patterns, and thereby the number of distinct equivalence classes to consider, is bounded by a function in our parameters.
Lemma 21 (Enumerating p p p -route patterns). There is a computable function f f f such that for any instance ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) of SNP Model Checking, any treedepth decomposition T T T of R \mathcal{R} R of height h h h , and any integers p ≥ 1 p \ge1 p ≥ 1 and z ∈ N z \in\mathbb{N} z ∈ N there are at most f ( h , p , ∣ φ ∣ , z ) f(h,p,|\varphi|,z) f ( h , p , ∣ φ ∣ , z ) distinct p p p -route patterns of z z z -tuples over V ( R ) V(\mathcal{R}) V ( R ) . Moreover, given the set of vertex p p p -types occurring in R \mathcal{R} R , one can compute in time f ( h , p , ∣ φ ∣ , z ) f(h,p,|\varphi|,z) f ( h , p , ∣ φ ∣ , z ) a list of at most f ( h , p , ∣ φ ∣ , z ) f(h,p,|\varphi|,z) f ( h , p , ∣ φ ∣ , z ) candidates that contains the p p p -route pattern of every z z z -tuple over V ( R ) V(\mathcal{R}) V ( R ) .
Proof. By definition, the p p p -route of an arbitrary element in V ( R ) V(\mathcal{R}) V ( R ) contains at most h h h entries. By Lemma 19 (1), the same holds for the normalized routes in the p p p -route pattern of any z z z -tuple. Each entry consists of a vertex p p p -type and an index. Lemma 17 bounds the number of possible vertex p p p -types by a function g g g of h h h , p p p , and ∣ φ ∣ |\varphi| ∣ φ ∣ . Moreover, the index i i i in any entry ( t , i ) (t,i) ( t , i ) in the p p p -route pattern of a z z z -tuple lies between 1 and M : = max ( z ( h − 1 ) , p − 1 , 1 ) M := \max(z(h-1),p-1,1) M := max ( z ( h − 1 ) , p − 1 , 1 ) . Indeed, the index i i i for abundant types is at most z ( h − 1 ) z(h-1) z ( h − 1 ) by Lemma 19 (5). Moreover, the index i i i for non-abundant, non-root entries is at most p − 1 p-1 p − 1 by the definition of an abundant type. The index of the root entry is always 1.
There are thus at most g ( h , p , ∣ φ ∣ ) ⋅ M g(h,p,|\varphi|) \cdot M g ( h , p , ∣ φ ∣ ) ⋅ M possible entries, hence at most
h ⋅ ( g ( h , p , ∣ φ ∣ ) ⋅ M ) h h \cdot\left(g(h,p,|\varphi|) \cdot M\right)^h h ⋅ ( g ( h , p , ∣ φ ∣ ) ⋅ M ) h
possible normalized routes, as such a route is a sequence of at most h h h entries. A p p p -route pattern of a z z z -tuple is a z z z -tuple of such routes, so there are at most
f ( h , p , ∣ φ ∣ , z ) = ( h ⋅ ( g ( h , p , ∣ φ ∣ ) ⋅ M ) h ) z f(h,p,|\varphi|,z) = \left(h \cdot\left(g(h,p,|\varphi|) \cdot M\right)^h\right)^z f ( h , p , ∣ φ ∣ , z ) = ( h ⋅ ( g ( h , p , ∣ φ ∣ ) ⋅ M ) h ) z
of them, and f f f is computable since g g g is.
For the second statement, observe that the argument above does not merely count these patterns but describes them: by Lemma 19 (1) the p p p -route pattern of a z z z -tuple over V ( R ) V(\mathcal{R}) V ( R ) is a z z z -tuple of sequences of at most h h h entries ( t , i ) (t,i) ( t , i ) in which t t t is a vertex p p p -type occurring in R \mathcal{R} R and i ∈ [ M ] i \in[M] i ∈ [ M ] . Enumerating all objects of this shape from the given set of vertex p p p -types yields the desired list, and as there are at most f ( h , p , ∣ φ ∣ , z ) f(h,p,|\varphi|,z) f ( h , p , ∣ φ ∣ , z ) of them, each with an encoding of size bounded in h , p , ∣ φ ∣ h,p,|\varphi| h , p , ∣ φ ∣ and z z z , writing them all down takes time bounded in the same parameters.
As mentioned before, the p p p -route of a vertex v v v uniquely identifies v v v . For sufficiently large p p p , the routes in a p p p -route pattern identify canonical representative vertices. We call these the realizing vertices of the p p p -route pattern.
Definition 22 (Realizing vertices). Let R \mathcal{R} R be a relational structure with treedepth decomposition T T T of height h h h , and μ = ( ϱ 1 , … , ϱ z ) \mu= (\varrho_1,\ldots,\varrho_z) μ = ( ϱ 1 , … , ϱ z ) be the p p p -route pattern of z z z elements of R \mathcal{R} R for some p ≥ z ⋅ h p \ge z \cdot h p ≥ z ⋅ h .
The realizing vertices of μ \mu μ are ( v 1 , … , v z ) (v_1,\ldots,v_z) ( v 1 , … , v z ) , where v i v_i v i is the vertex identified by the p p p -route ϱ i \varrho_i ϱ i , for all i ∈ [ z ] i \in[z] i ∈ [ z ] .
We now show that these realizing vertices indeed exist, and that their pattern is again μ \mu μ .
Lemma 23 (Unique realizing vertices exist). Let R \mathcal{R} R be a relational structure with treedepth decomposition T T T of height h h h , p p p a positive integer, and μ = ( ϱ 1 , … , ϱ z ) \mu= (\varrho_1,\ldots,\varrho_z) μ = ( ϱ 1 , … , ϱ z ) be the p p p -route pattern of z z z elements of R \mathcal{R} R with p ≥ z ⋅ h p \ge z \cdot h p ≥ z ⋅ h . Then the realizing vertices of μ \mu μ exist and are unique, and the p p p -route pattern of the realizing vertices of μ \mu μ is again μ \mu μ . Moreover, every entry ( t , i ) (t,i) ( t , i ) in the p p p -route of a realizing vertex satisfies i ≤ p i \le p i ≤ p .
Proof. Uniqueness is immediate, since distinct vertices have distinct p p p -routes, as explained right after Definition 3. Choose a tuple ( v 1 , … , v z ) (v_1,\ldots,v_z) ( v 1 , … , v z ) with p p p -route pattern μ = ( ϱ 1 , … , ϱ z ) \mu= (\varrho_1,\ldots,\varrho_z) μ = ( ϱ 1 , … , ϱ z ) . Let S = { rt ( v 1 ) , … , rt ( v z ) } S = \{\operatorname{rt}(v_1),\ldots,\operatorname{rt}(v_z)\} S = { rt ( v 1 ) , … , rt ( v z )} , so that ∣ S ∣ ≤ z |S| \le z ∣ S ∣ ≤ z and every route in S S S has length at most h h h .
For existence, fix m ∈ [ z ] m \in[z] m ∈ [ z ] , write ϱ m = ( e ^ 1 , … , e ^ d ) \varrho_m = (\hat{e}_1,\ldots,\hat{e}_d) ϱ m = ( e ^ 1 , … , e ^ d ) with e ^ ℓ = ( t ℓ , j ℓ ) \hat{e}_\ell= (t_\ell,j_\ell) e ^ ℓ = ( t ℓ , j ℓ ) , and let u 1 , … , u d u_1,\ldots,u_d u 1 , … , u d with v m = u d v_m = u_d v m = u d be the vertices on the root-to-v m v_m v m path in T T T , so that p p p -type( u ℓ ) = t ℓ (u_\ell) = t_\ell ( u ℓ ) = t ℓ by Lemma 19 (1). We show by induction on ℓ \ell ℓ that ( e ^ 1 , … , e ^ ℓ ) (\hat{e}_1,\ldots,\hat{e}_\ell) ( e ^ 1 , … , e ^ ℓ ) is the p p p -route of some vertex y ℓ y_\ell y ℓ of T T T ; note that then p p p -type( y ℓ ) = t ℓ (y_\ell) = t_\ell ( y ℓ ) = t ℓ , since the last entry of the p p p -route of a vertex carries its vertex p p p -type. For ℓ = 1 \ell= 1 ℓ = 1 we have e ^ 1 = ( p -type ( u 1 ) , 1 ) \hat{e}_1 = (p\text{-type}(u_1),1) e ^ 1 = ( p -type ( u 1 ) , 1 ) by Definition 4, which is the p p p -route of the root u 1 u_1 u 1 of T T T . For the step, let y ℓ − 1 y_{\ell-1} y ℓ − 1 be given; it suffices to show that y ℓ − 1 y_{\ell-1} y ℓ − 1 has at least j ℓ j_\ell j ℓ children of vertex p p p -type t ℓ t_\ell t ℓ , as the j ℓ j_\ell j ℓ -th smallest of them is then the desired y ℓ y_\ell y ℓ .
Suppose first that e ^ ℓ \hat{e}_\ell e ^ ℓ is not abundant, so that j ℓ j_\ell j ℓ is the index of u ℓ u_\ell u ℓ among the children of u ℓ − 1 u_{\ell-1} u ℓ − 1 of vertex p p p -type t ℓ t_\ell t ℓ by Lemma 19 (5). Write t ℓ − 1 = ( δ , λ ) t_{\ell-1} = (\delta,\lambda) t ℓ − 1 = ( δ , λ ) ; note that p-type( y ℓ − 1 ) = t ℓ − 1 = p (y_{\ell-1}) = t_{\ell-1} = p ( y ℓ − 1 ) = t ℓ − 1 = p -type( u ℓ − 1 ) (u_{\ell-1}) ( u ℓ − 1 ) , so δ \delta δ is the subtree label of both y ℓ − 1 y_{\ell-1} y ℓ − 1 and u ℓ − 1 u_{\ell-1} u ℓ − 1 . As u ℓ u_\ell u ℓ is a child of u ℓ − 1 u_{\ell-1} u ℓ − 1 of vertex p p p -type t ℓ t_\ell t ℓ , the type t ℓ t_\ell t ℓ lies in the domain of δ \delta δ , and δ ( t ℓ ) ≠ ⋆ \delta(t_\ell) \ne\star δ ( t ℓ ) = ⋆ because e ^ ℓ \hat{e}_\ell e ^ ℓ is not abundant. Hence both u ℓ − 1 u_{\ell-1} u ℓ − 1 and y ℓ − 1 y_{\ell-1} y ℓ − 1 have exactly δ ( t ℓ ) ≤ p − 1 \delta(t_\ell) \le p - 1 δ ( t ℓ ) ≤ p − 1 children of vertex p p p -type t ℓ t_\ell t ℓ , and j ℓ ≤ δ ( t ℓ ) j_\ell\le\delta(t_\ell) j ℓ ≤ δ ( t ℓ ) as u ℓ u_\ell u ℓ is one of those children of u ℓ − 1 u_{\ell-1} u ℓ − 1 .
If, on the other hand, e ^ ℓ \hat{e}_\ell e ^ ℓ is abundant, then t ℓ t_\ell t ℓ is p p p -abundant in t ℓ − 1 = p t_{\ell-1} = p t ℓ − 1 = p -type( y ℓ − 1 ) (y_{\ell-1}) ( y ℓ − 1 ) , so y ℓ − 1 y_{\ell-1} y ℓ − 1 has at least p p p children of vertex p p p -type t ℓ t_\ell t ℓ , while j ℓ ≤ ∣ I ( S ) ∣ ≤ z ( h − 1 ) ≤ p j_\ell\le|I(S)| \le z(h - 1) \le p j ℓ ≤ ∣ I ( S ) ∣ ≤ z ( h − 1 ) ≤ p by Lemma 19 (5) and the hypothesis.
This argument also gives the claimed bound on the indices: the root entry has index j 1 = 1 j_1 = 1 j 1 = 1 , a non-abundant entry has index j ℓ ≤ δ ( t ℓ ) ≤ p − 1 j_\ell\le\delta(t_\ell) \le p-1 j ℓ ≤ δ ( t ℓ ) ≤ p − 1 , and an abundant entry has index j ℓ ≤ z ( h − 1 ) ≤ p j_\ell\le z(h - 1) \le p j ℓ ≤ z ( h − 1 ) ≤ p .
It remains to show that the p p p -route pattern of the realizing vertices w 1 , … , w z w_1,\ldots,w_z w 1 , … , w z of μ \mu μ is again μ \mu μ . By Definition 4 we have ϱ m = ν S ( rt ( v m ) ) \varrho_m = \nu_S(\operatorname{rt}(v_m)) ϱ m = ν S ( rt ( v m )) for every m ∈ [ z ] m \in[z] m ∈ [ z ] , and ϱ m \varrho_m ϱ m is the p p p -route of w m w_m w m by Definition 22. So the set of the p p p -routes of w 1 , … , w z w_1,\ldots,w_z w 1 , … , w z is { ϱ 1 , … , ϱ z } = ν S ( S ) \{\varrho_1,\ldots,\varrho_z\} = \nu_S(S) { ϱ 1 , … , ϱ z } = ν S ( S ) , and applying Definition 4 to the tuple ( w 1 , … , w z ) (w_1,\ldots,w_z) ( w 1 , … , w z ) shows that its p p p -route pattern is ( ν ν S ( S ) ( ϱ 1 ) , … , ν ν S ( S ) ( ϱ z ) ) (\nu_{\nu_S(S)}(\varrho_1),\ldots,\nu_{\nu_S(S)}(\varrho_z)) ( ν ν S ( S ) ( ϱ 1 ) , … , ν ν S ( S ) ( ϱ z )) . By Lemma 19 (4), this is ( ϱ 1 , … , ϱ z ) = μ (\varrho_1,\ldots,\varrho_z) = \mu ( ϱ 1 , … , ϱ z ) = μ .
Multiplicity Structures
The purpose of p p p -route patterns is that we want to treat tuples of elements that share a pattern in an interchangeable way. In this sense, we define a notion of pruning, in which each vertex keeps at most p p p children of each vertex p p p -type. We will show that this preserves the existence of all possible p p p -route patterns, since the realizing vertices of each pattern are untouched.
Indeed, the following defines pruning in a slightly more general way: we consider some s ≥ p s \ge p s ≥ p and keep s s s children of every abundant type, and even add copies of subtrees to make that exactly s s s . That is, if there are at least p p p siblings in T T T with the same vertex p p p -type, then the resulting structure has exactly s s s siblings of this vertex p p p -type instead.
Definition 24 (s s s -multiplicity structure). Let s , p ∈ N s,p \in\mathbb{N} s , p ∈ N with s ≥ p ≥ 1 s \ge p \ge1 s ≥ p ≥ 1 , and let R \mathcal{R} R be a relational structure with treedepth decomposition T T T .
We define the s s s -multiplicity structure R s \mathcal{R}^{s} R s for ( R , T , p ) (\mathcal{R},T,p) ( R , T , p ) together with the accompanying rooted tree T s T^{s} T s on its elements as follows. First, let R ′ \mathcal{R}' R ′ be the substructure of R \mathcal{R} R induced by the set of elements for which every entry ( t , i ) (t,i) ( t , i ) in their p p p -route satisfies i ≤ s i \le s i ≤ s for every vertex p p p -type t t t .12 Let T ′ T' T ′ be the rooted tree obtained from T T T by removing all vertices which are not elements of R ′ \mathcal{R}' R ′ ; this is again a tree, as the removed vertices are removed together with their subtrees.
If s = p s=p s = p , let ( R p , T p ) = ( R ′ , T ′ ) (\mathcal{R}^{p},T^{p})=(\mathcal{R}',T') ( R p , T p ) = ( R ′ , T ′ ) . Otherwise s > p s>p s > p , and we obtain ( R s , T s ) (\mathcal{R}^{s},T^{s}) ( R s , T s ) from ( R ′ , T ′ ) (\mathcal{R}',T') ( R ′ , T ′ ) by processing the vertices of T ′ T' T ′ bottom-up, each after all of its descendants, maintaining a current structure together with a current tree on its elements. When processing w w w , consider every vertex p p p -type t t t that is p p p -abundant in p p p -type( w ) (w) ( w ) and of which w w w has c t < s c_t<s c t < s children in the current tree; here, and throughout this definition, all vertex p p p -types are the ones in ( R , T ) (\mathcal{R},T) ( R , T ) . Let u u u be the smallest child of w w w of vertex p p p -type t t t , and add another s − c t s-c_t s − c t disjoint copies of the subtree rooted at u u u in the current tree. Here a copy is given by a bijection ι \iota ι from the elements of that subtree onto fresh elements; we let ι ( x ) \iota(x) ι ( x ) be a child of ι ( y ) \iota(y) ι ( y ) whenever x x x is a child of y y y in that subtree, we make ι ( u ) \iota(u) ι ( u ) a further child of w w w , and for every tuple of every relation of the current structure we add the tuple with each entry in the subtree replaced by its ι \iota ι -image. In particular, V ( T s ) = V ( R s ) V(T^{s})=V(\mathcal{R}^{s}) V ( T s ) = V ( R s ) .
Regarding the total order on the elements of R s \mathcal{R}^{s} R s , each fresh element of R s \mathcal{R}^{s} R s is sorted after all elements of R \mathcal{R} R , for an arbitrary order among the fresh elements.
Note that since the subtree of u u u is already processed when w w w is, its copies need no further processing. We now define the natural notion of retained elements .
Definition 25 (Retained elements). Let s , p ∈ N s,p \in\mathbb{N} s , p ∈ N with s ≥ p ≥ 1 s \ge p \ge1 s ≥ p ≥ 1 , and let R \mathcal{R} R be a relational structure with treedepth decomposition T T T . An element of R s \mathcal{R}^{s} R s is retained if it is an element of R \mathcal{R} R . Write orig ( y ) \operatorname{orig}(y) orig ( y ) for the retained element that an element y y y of R s \mathcal{R}^{s} R s is a copy of, obtained by following the copying bijections backwards. In particular, orig ( y ) = y \operatorname{orig}(y)=y orig ( y ) = y for retained y y y .
The following lemma collects the properties of the s s s -multiplicity structure that we use.
Lemma 26 (Properties of the s s s -multiplicity structure). Let s , p ∈ N s,p \in\mathbb{N} s , p ∈ N with s ≥ p ≥ 1 s \ge p \ge1 s ≥ p ≥ 1 , and let R \mathcal{R} R be a relational structure with treedepth decomposition T T T of height h h h .
(1) T s T^{s} T s is a treedepth decomposition of R s \mathcal{R}^{s} R s of height h h h .
(2) A tuple of retained elements lies in a relation of R s \mathcal{R}^{s} R s if and only if it lies in that relation in R \mathcal{R} R .
(3) Every element y y y of R s \mathcal{R}^{s} R s has in ( R s , T s ) (\mathcal{R}^{s},T^{s}) ( R s , T s ) the vertex p p p -type that orig ( y ) \operatorname{orig}(y) orig ( y ) has in ( R , T ) (\mathcal{R},T) ( R , T ) ; in particular y y y is p p p -abundant in ( R s , T s ) (\mathcal{R}^{s},T^{s}) ( R s , T s ) if and only if orig ( y ) \operatorname{orig}(y) orig ( y ) is p p p -abundant in ( R , T ) (\mathcal{R},T) ( R , T ) .
(4) In T s T^{s} T s , every vertex y y y has exactly s s s children of each vertex p p p -type that is p p p -abundant in p p p -type( y ) (y) ( y ) , and as many children of every other vertex p p p -type as orig ( y ) \operatorname{orig}(y) orig ( y ) has in T T T .
(5) Every element of R p \mathcal{R}^{p} R p is retained and has the same p p p -route in T p T^{p} T p as in T T T ; in particular every tuple of elements of R p \mathcal{R}^{p} R p has the same p p p -route pattern in T p T^{p} T p as in T T T .
(6) Let z ∈ N z \in\mathbb{N} z ∈ N with p ≥ z ⋅ h p \ge z \cdot h p ≥ z ⋅ h . Then for every z z z -tuple of elements of R \mathcal{R} R , the realizing vertices of its p p p -route pattern in T T T are retained in R p \mathcal{R}^{p} R p .
(7) Let z ∈ N z \in\mathbb{N} z ∈ N with p > z ⋅ h p>z\cdot h p > z ⋅ h . Then a p p p -route pattern of a z z z -tuple occurs in ( R , T ) (\mathcal{R},T) ( R , T ) if and only if it occurs in ( R p , T p ) (\mathcal{R}^{p},T^{p}) ( R p , T p ) .
(8) If ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) is an SNP Model Checking instance with p ≥ ∣ φ ∣ p \ge|\varphi| p ≥ ∣ φ ∣ , then ∣ R s ∣ ≤ f ( h , p , s ) |\mathcal{R}^{s}| \le f(h,p,s) ∣ R s ∣ ≤ f ( h , p , s ) for a computable function f f f .
Proof. (1). We show that throughout the construction in Definition 24, every tuple of every relation of the current structure is a chain in the current tree, that is, its entries are pairwise in ancestor-descendant relation; applied to the end of the construction, this gives the claim. This holds initially as T T T is a treedepth decomposition of R \mathcal{R} R , and it is maintained by the passage to ( R ′ , T ′ ) (\mathcal{R}',T') ( R ′ , T ′ ) , which leaves the ancestor-descendant relationship among the retained elements and their membership in relation tuples unchanged. In a copy step, the new tuples arise from tuples x ˉ \bar{x} x ˉ of the current structure by replacing every entry in the subtree of u u u by its ι \iota ι -image. If x ˉ \bar{x} x ˉ meets that subtree then, being a chain, each of its remaining entries lies in the subtree as well or is a proper ancestor of u u u and hence also an ancestor of ι ( u ) \iota(u) ι ( u ) , which is a child of w w w ; the entries in the subtree keep their ancestor relation, as ι \iota ι is an isomorphism onto the attached copy. So the image is again a chain, and T s T^{s} T s is a treedepth decomposition of R s \mathcal{R}^{s} R s . Copies sit at the depth of their originals and the deletion only removes vertices, so T s T^{s} T s has height at most h h h . Conversely, let v v v be a vertex of depth h h h in T T T and write rt ( v ) = ( ( t 1 , i 1 ) , … , ( t h , i h ) ) \operatorname{rt}(v)=((t_1,i_1),\ldots,(t_h,i_h)) rt ( v ) = (( t 1 , i 1 ) , … , ( t h , i h )) . Let u 1 u_1 u 1 be the root of T T T and, for ℓ ≥ 2 \ell\ge2 ℓ ≥ 2 , let u ℓ u_\ell u ℓ be the child of u ℓ − 1 u_{\ell-1} u ℓ − 1 of vertex p p p -type t ℓ t_\ell t ℓ and index 1. This is well defined since by construction u ℓ − 1 u_{\ell-1} u ℓ − 1 has the same vertex p p p -type t ℓ − 1 t_{\ell-1} t ℓ − 1 as the ancestor of v v v at depth ℓ − 1 \ell-1 ℓ − 1 and thus as that ancestor has a child of vertex p p p -type t ℓ t_\ell t ℓ , so does u ℓ − 1 u_{\ell-1} u ℓ − 1 . Now every entry of rt ( u h ) = ( ( t 1 , 1 ) , … , ( t h , 1 ) ) \operatorname{rt}(u_h)=((t_1,1),\ldots,(t_h,1)) rt ( u h ) = (( t 1 , 1 ) , … , ( t h , 1 )) has index 1 ≤ s 1 \le s 1 ≤ s , so u h u_h u h is retained, and T s T^{s} T s has height exactly h h h .
(2). Passing to R ′ \mathcal{R}' R ′ keeps exactly those tuples all of whose entries are retained. A copy step adds the image of a tuple of the current structure under a copying bijection ι \iota ι ; such an image differs from the tuple itself only if the tuple has an entry in the subtree of u u u , in which case the image contains a fresh element and is thus not a tuple of retained elements. So neither phase changes which tuples of retained elements lie in a relation.
(3) and (4). Write p p p -type( y ) = ( δ y , λ y ) (y)=(\delta_y,\lambda_y) ( y ) = ( δ y , λ y ) as in Definition 2, that is, δ y \delta_y δ y is the subtree label of y y y and λ y \lambda_y λ y is the ancestor label of y y y ; we write δ y s \delta_y^s δ y s and λ y s \lambda_y^s λ y s for the respective labels of y y y in ( R s , T s ) (\mathcal{R}^{s},T^{s}) ( R s , T s ) . For a vertex y y y , we use c ( y ) c(y) c ( y ) to denote the copy-depth of y y y : the number of times one must follow the copying bijection backwards until a retained vertex is obtained.
Ancestor labels. We show λ y s = λ orig ( y ) \lambda_y^s=\lambda_{\operatorname{orig}(y)} λ y s = λ orig ( y ) by induction on c ( y ) c(y) c ( y ) . If y y y is retained, its root-to-y y y path is the same in T s T^{s} T s as in T T T , since the set of elements inducing R ′ \mathcal{R}' R ′ is closed under taking ancestors, and by property (2) the vertices on it lie in the same relation tuples in both structures; hence the two paths have the same atomic type. Otherwise y = ι ( y 0 ) y=\iota(y_0) y = ι ( y 0 ) for a copy step that attached a copy of the subtree rooted at u u u as a further child of the parent w w w of u u u , and we have c ( y 0 ) < c ( y ) c(y_0)<c(y) c ( y 0 ) < c ( y ) and orig ( y ) = orig ( y 0 ) \operatorname{orig}(y)=\operatorname{orig}(y_0) orig ( y ) = orig ( y 0 ) . Extending ι \iota ι by the identity maps the root-to-y 0 y_0 y 0 path onto the root-to-y y y path: it maps the part inside the subtree of u u u isomorphically onto the attached copy, whose root ι ( u ) \iota(u) ι ( u ) is again a child of w w w , and it fixes the ancestors of u u u . By the copying rule this bijection preserves membership in every relation, and later copy steps do not change relation membership among already existing elements, so the two paths have the same atomic type and λ y s = λ y 0 s = λ orig ( y ) \lambda_y^s=\lambda_{y_0}^s=\lambda_{\operatorname{orig}(y)} λ y s = λ y 0 s = λ orig ( y ) .
Subtree labels. We show δ y s = δ orig ( y ) \delta_y^s=\delta_{\operatorname{orig}(y)} δ y s = δ orig ( y ) together with property (4) for y y y , by induction bottom-up on the depth of orig ( y ) \operatorname{orig}(y) orig ( y ) in T T T and, at each depth, on c ( y ) c(y) c ( y ) ; with the ancestor labels this also gives property (3). If orig ( y ) \operatorname{orig}(y) orig ( y ) is a leaf of T T T , then y y y has no children either and both labels are ϵ \epsilon ϵ .
Let y y y be retained and let n t n_t n t be its number of children of vertex p p p -type t t t in T T T ; by induction these children keep their vertex p p p -types, and once y y y has been processed neither they nor the copies attached to y y y change again. Passing to R ′ \mathcal{R}' R ′ keeps exactly the min ( n t , s ) \min(n_t,s) min ( n t , s ) of them of smallest index. If n t < p n_t<p n t < p , then t t t is not p p p -abundant in p p p -type( y ) (y) ( y ) , all n t n_t n t children survive and none of them is copied, so δ y s ( t ) = δ y ( t ) = n t \delta_y^s(t)=\delta_y(t)=n_t δ y s ( t ) = δ y ( t ) = n t ; in particular, a vertex p p p -type absent in T T T remains absent in T s T^s T s . If n t ≥ p n_t \ge p n t ≥ p , then t t t is p p p -abundant in p p p -type( y ) (y) ( y ) and the copy step raises the number of children of vertex p p p -type t t t from min ( n t , s ) \min(n_t,s) min ( n t , s ) to exactly s s s , which it already is for s = p s=p s = p ; as s ≥ p s \ge p s ≥ p , this gives δ y s ( t ) = δ y ( t ) = ⋆ \delta_y^s(t)=\delta_y(t)=\star δ y s ( t ) = δ y ( t ) = ⋆ .
If y y y is not retained, it is the copy ι ( y 0 ) \iota(y_0) ι ( y 0 ) of some y 0 y_0 y 0 with c ( y 0 ) < c ( y ) c(y_0)<c(y) c ( y 0 ) < c ( y ) , and the copy step attaches an isomorphic copy of an already processed subtree containing y 0 y_0 y 0 , which is not modified afterwards. Corresponding children of y y y and y 0 y_0 y 0 have the same orig-images and hence, by the induction on the depth, the same vertex p p p -types, so y y y and y 0 y_0 y 0 have the same child-type counts, δ y s = δ y 0 s = δ orig ( y ) \delta_y^s=\delta_{y_0}^s=\delta_{\operatorname{orig}(y)} δ y s = δ y 0 s = δ orig ( y ) , and property (4) carries over from y 0 y_0 y 0 to y y y .
Finally, for a non-root vertex y y y of T s T^s T s with parent w w w , the parent of orig ( y ) \operatorname{orig}(y) orig ( y ) is orig ( w ) \operatorname{orig}(w) orig ( w ) , so the preservation of vertex p p p -types also yields the abundance part of property (3).
(5). Since s = p s=p s = p , we have ( R p , T p ) = ( R ′ , T ′ ) (R^p,T^p)=(R',T') ( R p , T p ) = ( R ′ , T ′ ) , so no copies are added and every element of R p R^p R p is retained, and T p T^p T p arises from T T T by removing exactly those elements that have an entry ( t , i ) (t,i) ( t , i ) with i > p i>p i > p in their p p p -route, together with their subtrees. Hence every element of R p R^p R p keeps its parent and all of its ancestors, and its vertex p p p -type is the same in R p R^p R p as in R R R by property (3). The route of the root is ( ( t , 1 ) ) ((t,1)) (( t , 1 )) for its vertex p p p -type t t t , in both T T T and T p T^p T p . For a non-root element, the surviving children of its parent w w w of a vertex p p p -type t t t are precisely the (at most p p p ) smallest elements among all children of w w w of that vertex p p p -type, so such an element is preceded by the same number of children of w w w of its own vertex p p p -type in T T T as in T p T^p T p , and thus receives the same index. By induction on the depth, every entry of the p p p -route of an element of R p R^p R p is therefore unchanged.
(6). Let μ \mu μ be the p p p -route pattern in T T T of a z z z -tuple of elements of R R R . By Lemma 23, which applies as p ≥ z ⋅ h p \ge z\cdot h p ≥ z ⋅ h , the realizing vertices of μ \mu μ exist in T T T , and every entry of their p p p -routes has index at most p p p . Since s = p s=p s = p , an element is deleted only if its p p p -route contains an entry ( t , i ) (t,i) ( t , i ) with i > p i>p i > p , so every realizing vertex is retained.
(7). Every element of R p R^p R p is retained by property (5), so every z z z -tuple of R p R^p R p has the same p p p -route pattern in T p T^p T p as in T T T and its pattern occurs in ( R , T ) (R,T) ( R , T ) . Conversely, let μ \mu μ be the p p p -route pattern in T T T of a z z z -tuple of elements of R R R . Its realizing vertices are retained in R p R^p R p by property (6), they have p p p -route pattern μ \mu μ in T T T by Lemma 23, and by property (5) their p p p -route pattern in T p T^p T p is again μ \mu μ .
(8). By property (3), every vertex p p p -type occurring in ( R s , T s ) (R^s,T^s) ( R s , T s ) also occurs in ( R , T ) (R,T) ( R , T ) , so by Lemma 17 their number is bounded by g ′ ( h , p , ∣ φ ∣ ) g'(h,p,|\varphi|) g ′ ( h , p , ∣ φ ∣ ) for a computable function g ′ g' g ′ ; as ∣ φ ∣ ≤ p |\varphi|\le p ∣ φ ∣ ≤ p , it is bounded by the computable function g ( h , p ) : = max q ≤ p g ′ ( h , p , q ) g(h,p):=\max_{q\le p}g'(h,p,q) g ( h , p ) := max q ≤ p g ′ ( h , p , q ) . By property (4), every vertex y y y of T s T^s T s has exactly s s s children of each vertex p p p -type that is p p p -abundant in p p p -type( y ) (y) ( y ) , and as many children of every other vertex p p p -type t t t as orig ( y ) \operatorname{orig}(y) orig ( y ) has in T T T , which is δ orig ( y ) ( t ) ≤ p − 1 ≤ s \delta_{\operatorname{orig}(y)}(t)\le p-1\le s δ orig ( y ) ( t ) ≤ p − 1 ≤ s by Definition 2. Hence y y y has at most B : = g ( h , p ) ⋅ s B:=g(h,p)\cdot s B := g ( h , p ) ⋅ s children in total. Since T s T^s T s has height h h h by property (1), it has at most ∑ d = 0 h B d ≤ ( B + 1 ) h \sum_{d=0}^{h}B^d\le(B+1)^h ∑ d = 0 h B d ≤ ( B + 1 ) h vertices. Finally, R s R^s R s has the same signature as R R R , as passing to R ′ R' R ′ takes an induced substructure and the copy steps add no relations, and every relation of R R R appears in φ \varphi φ by our standing assumption that R R R uses no relations outside φ \varphi φ . Hence R s R^s R s has at most ∣ φ ∣ ≤ p |\varphi|\le p ∣ φ ∣ ≤ p relations, each of arity at most ∣ φ ∣ ≤ p |\varphi|\le p ∣ φ ∣ ≤ p , and therefore at most p ⋅ ( B + 1 ) h p p\cdot(B+1)^{hp} p ⋅ ( B + 1 ) h p tuples in total. Altogether ∣ R s ∣ |R^s| ∣ R s ∣ is bounded by a computable function of h , p h,p h , p and s s s . ◊
Pure Solutions. All definitions so far concerned only the input relational structure R R R ; the formula φ \varphi φ entered only through bounds on the number and the arity of the relations considered. Now, we come to the central concept that makes the main result work, the notion of a p p p -pure solution. Intuitively, p p p -purity says that if two element tuples behave the same with respect to the input relational structure (i.e., they share a p p p -route pattern), then they should behave the same with respect to the solution. As we show later, this property of purity is extremely useful for our purposes; it is the main ingredient in the algorithm we provide.
For this, we first define the solution type , which is just the atomic type of an element tuple with respect to a solution.
Definition 27 (Solution type). Let ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) be an SNP Model Checking instance with a solution S = R 1 ′ , … , R r ′ S = R'_1,\ldots,R'_r S = R 1 ′ , … , R r ′ . For any q ∈ N q \in\mathbb{N} q ∈ N , the solution type of a tuple v ˉ ∈ V ( R ) q \bar{v} \in V(\mathcal{R})^q v ˉ ∈ V ( R ) q in S S S is the atomic type of v ˉ \bar{v} v ˉ in the relational structure of the solution, sol-type S ( v ˉ ) = atp ( V ( R ) , R 1 ′ , … , R r ′ ) ( v ˉ ) \operatorname{sol\text{-}type}_S(\bar{v}) = \operatorname{atp}_{(V(\mathcal{R}),R'_1,\ldots,R'_r)}(\bar{v}) sol - type S ( v ˉ ) = atp ( V ( R ) , R 1 ′ , … , R r ′ ) ( v ˉ ) .
Now p p p -purity simply says that the same p p p -route pattern implies the same solution type.
Definition 5 (p p p -pure solution). Let p ∈ N p \in\mathbb{N} p ∈ N and ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) be an SNP Model Checking instance with treedepth decomposition T T T and a solution S = R 1 ′ , … , R r ′ S = R'_1,\ldots,R'_r S = R 1 ′ , … , R r ′ . A p p p -route pattern μ \mu μ is p p p -pure in S S S if any two tuples with p p p -route pattern μ \mu μ have the same solution type in S S S . We call S S S p p p -pure if all p p p -route patterns of tuples of length at most ∣ φ ∣ |\varphi| ∣ φ ∣ are p p p -pure.
Extending Pure Solutions
The crucial feature of this notion of purity is that, for sufficiently large p p p , a p p p -pure solution for R p \mathcal{R}^p R p yields a solution for R \mathcal{R} R . This is captured in Theorem 6.
Theorem 6 (Extension theorem). Let ( R , φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ ) (\mathcal{R},\varphi= \exists R_1,\ldots,R_r\ \forall x_1,\ldots,x_k : \psi) ( R , φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ ) be an instance of SNP Model Checking with treedepth decomposition T T T of height h h h and p ≥ ∣ φ ∣ ⋅ h p \ge|\varphi| \cdot h p ≥ ∣ φ ∣ ⋅ h . If R p \mathcal{R}^p R p has a p p p -pure solution S p S^p S p , then R \mathcal{R} R has a solution R 1 ′ , … , R r ′ R'_1,\ldots,R'_r R 1 ′ , … , R r ′ .
Moreover, for a computable function f f f , after spending f ( p ) ⋅ ∣ R ∣ f(p)\cdot|\mathcal{R}| f ( p ) ⋅ ∣ R ∣ time on preprocessing, for every i ∈ [ r ] i \in[r] i ∈ [ r ] and u ˉ ∈ V ( R ) a \bar{u} \in V(\mathcal{R})^{a} u ˉ ∈ V ( R ) a we can decide whether R i ′ ( u ˉ ) R'_i(\bar{u}) R i ′ ( u ˉ ) holds in O ( a h log ( a h ) ) O(ah\log(ah)) O ( ah log ( ah )) time, where a = ar ( R i ) a = \operatorname{ar}(R_i) a = ar ( R i ) .
Proof. Let S p = R 1 p , … , R r p S^p = R^p_1,\ldots,R^p_r S p = R 1 p , … , R r p be a p p p -pure solution for R p \mathcal{R}^p R p .
We first record that Lemma 26 (6) applies to z z z -tuples of elements for every z ≤ ∣ φ ∣ z \le|\varphi| z ≤ ∣ φ ∣ , since then z h ≤ ∣ φ ∣ ⋅ h ≤ p zh \le|\varphi| \cdot h \le p z h ≤ ∣ φ ∣ ⋅ h ≤ p . As k ≤ ∣ φ ∣ k \le|\varphi| k ≤ ∣ φ ∣ and ar ( R j ) ≤ ∣ φ ∣ \operatorname{ar}(R_j) \le|\varphi| ar ( R j ) ≤ ∣ φ ∣ for every j ∈ [ r ] j \in[r] j ∈ [ r ] , the realizing vertices of the p p p -route pattern of any tuple of at most ∣ φ ∣ |\varphi| ∣ φ ∣ elements are retained in R p \mathcal{R}^p R p ; this covers every k k k -tuple and every ar ( R j ) \operatorname{ar}(R_j) ar ( R j ) -tuple of elements.
We define relations R 1 ′ , … , R r ′ R'_1,\ldots,R'_r R 1 ′ , … , R r ′ , which will be a solution for R \mathcal{R} R , as follows. Consider any i ∈ [ r ] i \in[r] i ∈ [ r ] and v ˉ ∈ V ( R ) ar ( R i ) \bar{v} \in V(\mathcal{R})^{\operatorname{ar}(R_i)} v ˉ ∈ V ( R ) ar ( R i ) . Let μ \mu μ be the p p p -route pattern of v ˉ \bar{v} v ˉ in T T T and let w ˉ \bar{w} w ˉ be the realizing vertices of μ \mu μ , which exist in R p \mathcal{R}^p R p by the arguments above. We let R i ′ ( v ˉ ) R'_i(\bar{v}) R i ′ ( v ˉ ) hold if and only if R i p ( w ˉ ) R^p_i(\bar{w}) R i p ( w ˉ ) holds.
For the sake of contradiction, assume that R 1 ′ , … , R r ′ R'_1,\ldots,R'_r R 1 ′ , … , R r ′ do not form a solution for R \mathcal{R} R . Then, there exists a k k k -tuple v ˉ ∈ V ( R ) k \bar{v} \in V(\mathcal{R})^k v ˉ ∈ V ( R ) k such that R ⊭ ψ ( R 1 ′ , … , R r ′ , v ˉ ) \mathcal{R} \not\models\psi(R'_1,\ldots,R'_r,\bar{v}) R ⊨ ψ ( R 1 ′ , … , R r ′ , v ˉ ) . Let μ \mu μ be the p p p -route pattern of v ˉ \bar{v} v ˉ in T T T for R \mathcal{R} R , and w ˉ \bar{w} w ˉ be the realizing vertices of μ \mu μ in T T T . We show that R p ⊭ ψ ( R 1 p , … , R r p , w ˉ ) \mathcal{R}^p \not\models\psi(R^p_1,\ldots,R^p_r,\bar{w}) R p ⊨ ψ ( R 1 p , … , R r p , w ˉ ) , contradicting S p S^p S p being a solution for R p \mathcal{R}^p R p .
To this end, since ψ \psi ψ is a quantifier-free boolean formula, it suffices to show that each atom of ψ \psi ψ evaluates to the same truth value under the assignment v ˉ \bar{v} v ˉ in R \mathcal{R} R with R 1 ′ , … , R r ′ R'_1,\ldots,R'_r R 1 ′ , … , R r ′ as under the assignment w ˉ \bar{w} w ˉ in R p \mathcal{R}^p R p with R 1 p , … , R r p R^p_1,\ldots,R^p_r R 1 p , … , R r p . Any atom in the formula ψ \psi ψ asks, for a tuple of variables over { x 1 , … , x k } \{x_1,\ldots,x_k\} { x 1 , … , x k } , whether the elements assigned to them lie in some relation of R \mathcal{R} R or of the solution, or whether two of them are equal. Formally, every atom has one of the following three shapes:
E i ( u ˉ ) E_i(\bar{u}) E i ( u ˉ ) for some relation E i E_i E i of R \mathcal{R} R , where u ˉ = ( x n 1 , … , x n a ) \bar{u} = (x_{n_1},\ldots,x_{n_a}) u ˉ = ( x n 1 , … , x n a ) with a = ar ( E i ) a = \operatorname{ar}(E_i) a = ar ( E i ) and n m ∈ [ k ] n_m \in[k] n m ∈ [ k ] for all m ∈ [ a ] m \in[a] m ∈ [ a ] , or
R j ( u ˉ ) R_j(\bar{u}) R j ( u ˉ ) for some j ∈ [ r ] j \in[r] j ∈ [ r ] , where u ˉ = ( x n 1 , … , x n a ) \bar{u} = (x_{n_1},\ldots,x_{n_a}) u ˉ = ( x n 1 , … , x n a ) with a = ar ( R j ) a = \operatorname{ar}(R_j) a = ar ( R j ) and n m ∈ [ k ] n_m \in[k] n m ∈ [ k ] for all m ∈ [ a ] m \in[a] m ∈ [ a ] , or
x n = x n ′ x_n = x_{n'} x n = x n ′ with n , n ′ ∈ [ k ] n,n' \in[k] n , n ′ ∈ [ k ] .
Under the assignment v ˉ \bar{v} v ˉ such an atom evaluates at ( v n 1 , … , v n a ) (v_{n_1},\ldots,v_{n_a}) ( v n 1 , … , v n a ) , and under w ˉ \bar{w} w ˉ at ( w n 1 , … , w n a ) (w_{n_1},\ldots,w_{n_a}) ( w n 1 , … , w n a ) .
Consider the first case, an atom of the form E i ( u ˉ ) E_i(\bar{u}) E i ( u ˉ ) . Recall from Lemma 23 that μ \mu μ is also the p p p -route pattern of w ˉ \bar{w} w ˉ . Using Lemma 20 (2), we obtain that the tuples v ˉ \bar{v} v ˉ and w ˉ \bar{w} w ˉ have the same atomic type in R \mathcal{R} R . By the definition of the atomic type, we have that E i ( v n 1 , … , v n a ) ⇔ E i ( w n 1 , … , w n a ) E_i(v_{n_1},\ldots,v_{n_a}) \Leftrightarrow E_i(w_{n_1},\ldots,w_{n_a}) E i ( v n 1 , … , v n a ) ⇔ E i ( w n 1 , … , w n a ) , for every relation E i E_i E i of R \mathcal{R} R and all indices n 1 , … , n a ∈ [ k ] n_1,\ldots,n_a \in[k] n 1 , … , n a ∈ [ k ] , where a = ar ( E i ) a=\operatorname{ar}(E_i) a = ar ( E i ) . By Lemma 26 (2), and since all elements of w ˉ \bar{w} w ˉ persist in R p \mathcal{R}^p R p , E i ( w n 1 , … , w n a ) E_i(w_{n_1},\ldots,w_{n_a}) E i ( w n 1 , … , w n a ) holds in R p \mathcal{R}^p R p if and only if it holds in R \mathcal{R} R . Thus E i ( u ˉ ) E_i(\bar{u}) E i ( u ˉ ) holds under v ˉ \bar{v} v ˉ in R \mathcal{R} R if and only if it holds under w ˉ \bar{w} w ˉ in R p \mathcal{R}^p R p .
Now consider the second case, R j ( u ˉ ) R_j(\bar{u}) R j ( u ˉ ) , for any j ∈ [ r ] j \in[r] j ∈ [ r ] . Let μ ′ \mu' μ ′ be the p p p -route pattern of ( v n 1 , … , v n a ) (v_{n_1},\ldots,v_{n_a}) ( v n 1 , … , v n a ) in T T T and let ( y 1 , … , y a ) (y_1,\ldots,y_a) ( y 1 , … , y a ) be the realizing vertices of μ ′ \mu' μ ′ in T T T ; note that these need not be the elements ( w n 1 , … , w n a ) (w_{n_1},\ldots,w_{n_a}) ( w n 1 , … , w n a ) , which is precisely why the p p p -purity of S p \mathcal{S}^p S p is needed below. By the above definition of R j ′ R'_j R j ′ , we have that R j ′ ( v n 1 , … , v n a ) R'_j(v_{n_1},\ldots,v_{n_a}) R j ′ ( v n 1 , … , v n a ) holds if and only if R j p ( y 1 , … , y a ) R^p_j(y_1,\ldots,y_a) R j p ( y 1 , … , y a ) holds. By Lemma 20 (3), and since v ˉ \bar{v} v ˉ and w ˉ \bar{w} w ˉ have the same p p p -route pattern μ \mu μ , we have that μ ′ \mu' μ ′ is also the p p p -route pattern of ( w n 1 , … , w n a ) (w_{n_1},\ldots,w_{n_a}) ( w n 1 , … , w n a ) .
By the construction of R j ′ R'_j R j ′ , this gives that
R j ′ ( v n 1 , … , v n a ) ⇔ R j ′ ( w n 1 , … , w n a ) ⇔ R j p ( y 1 , … , y a ) . R'_j(v_{n_1},\ldots,v_{n_a}) \Leftrightarrow R'_j(w_{n_1},\ldots,w_{n_a}) \Leftrightarrow R^p_j(y_1,\ldots,y_a). R j ′ ( v n 1 , … , v n a ) ⇔ R j ′ ( w n 1 , … , w n a ) ⇔ R j p ( y 1 , … , y a ) .
However, this on its own does not suffice to show our claim since without further reasoning we cannot assume that R j ′ ( w n 1 , … , w n a ) R'_j(w_{n_1},\ldots,w_{n_a}) R j ′ ( w n 1 , … , w n a ) if and only if R j p ( w n 1 , … , w n a ) R^p_j(w_{n_1},\ldots,w_{n_a}) R j p ( w n 1 , … , w n a ) , for that step we require the p p p -purity of S p \mathcal{S}^p S p .
By the arguments above, the elements of ( y 1 , … , y a ) (y_1,\ldots,y_a) ( y 1 , … , y a ) are retained in R p \mathcal{R}^p R p , and so are those of ( w n 1 , … , w n a ) (w_{n_1},\ldots,w_{n_a}) ( w n 1 , … , w n a ) , as the latter occur in w ˉ \bar{w} w ˉ . Moreover, by Lemma 26 (5), elements that are retained in R p \mathcal{R}^p R p have identical p p p -routes in T T T and T p T^p T p , and tuples of such elements have the same p p p -route pattern in T T T and in T p T^p T p . Thus, ( y 1 , … , y a ) (y_1,\ldots,y_a) ( y 1 , … , y a ) and ( w n 1 , … , w n a ) (w_{n_1},\ldots,w_{n_a}) ( w n 1 , … , w n a ) share a p p p -route pattern in T p T^p T p . By the p p p -purity of S p \mathcal{S}^p S p , these two tuples of size a = ar ( R j ) ≤ ∣ φ ∣ a=\operatorname{ar}(R_j)\leq|\varphi| a = ar ( R j ) ≤ ∣ φ ∣ have the same solution type in S p \mathcal{S}^p S p . In particular, we have R j p ( y 1 , … , y a ) ⇔ R j p ( w n 1 , … , w n a ) R^p_j(y_1,\ldots,y_a) \Leftrightarrow R^p_j(w_{n_1},\ldots,w_{n_a}) R j p ( y 1 , … , y a ) ⇔ R j p ( w n 1 , … , w n a ) . In combination with the above equivalence, this establishes R j ′ ( v n 1 , … , v n a ) ⇔ R j p ( w n 1 , … , w n a ) R'_j(v_{n_1},\ldots,v_{n_a}) \Leftrightarrow R^p_j(w_{n_1},\ldots,w_{n_a}) R j ′ ( v n 1 , … , v n a ) ⇔ R j p ( w n 1 , … , w n a ) as desired, concluding the second case.
Finally, consider the third case, an atom x n = x n ′ x_n=x_{n'} x n = x n ′ with n , n ′ ∈ [ k ] n,n'\in[k] n , n ′ ∈ [ k ] . It holds under the assignment v ˉ \bar{v} v ˉ if and only if v n = v n ′ v_n=v_{n'} v n = v n ′ , and under w ˉ \bar{w} w ˉ if and only if w n = w n ′ w_n=w_{n'} w n = w n ′ . As noted in the first case, v ˉ \bar{v} v ˉ and w ˉ \bar{w} w ˉ have the same atomic type in R \mathcal{R} R by Lemma 20 (2), so its equality part in Definition 1 gives v n = v n ′ v_n=v_{n'} v n = v n ′ if and only if w n = w n ′ w_n=w_{n'} w n = w n ′ . Moreover, the elements of w ˉ \bar{w} w ˉ are retained in R p \mathcal{R}^p R p and hence elements of R \mathcal{R} R by Definition 25, so equality among them means the same in R \mathcal{R} R and in R p \mathcal{R}^p R p . Thus x n = x n ′ x_n=x_{n'} x n = x n ′ holds under v ˉ \bar{v} v ˉ in R \mathcal{R} R if and only if it holds under w ˉ \bar{w} w ˉ in R p \mathcal{R}^p R p , concluding the third case.
Hence, every atom of ψ \psi ψ evaluates the same under the assignment v ˉ \bar{v} v ˉ in R \mathcal{R} R as under the assignment w ˉ \bar{w} w ˉ in R p \mathcal{R}^p R p . Thus, if R ⊭ ψ ( R 1 ′ , … , R r ′ , v ˉ ) \mathcal{R}\not\models\psi(R'_1,\ldots,R'_r,\bar{v}) R ⊨ ψ ( R 1 ′ , … , R r ′ , v ˉ ) then R p ⊭ ψ ( R 1 p , … , R r p , w ˉ ) \mathcal{R}^p\not\models\psi(R^p_1,\ldots,R^p_r,\bar{w}) R p ⊨ ψ ( R 1 p , … , R r p , w ˉ ) , a contradiction to S p \mathcal{S}^p S p being a solution for R p \mathcal{R}^p R p .
It remains to prove the second claim. By Lemma 18 we can precompute the vertex p p p -types and the p p p -routes of all elements of R \mathcal{R} R in the allowed time; in particular we obtain the set of vertex p p p -types occurring in R \mathcal{R} R . As there are boundedly many of them by Lemma 17, we may at the same time give each an integer identifier, store all entries of all routes as pairs of such an identifier and an index, and tabulate for which pairs ( t , t ′ ) (t,t') ( t , t ′ ) of vertex p p p -types t ′ t' t ′ is p p p -abundant in t t t . The size of each entry and its lookup time in the table is then bounded by a computable function in h h h , p p p , and ∣ φ ∣ |\varphi| ∣ φ ∣ , that is, in a function of p p p by p ≥ ∣ φ ∣ ⋅ h p\geq|\varphi|\cdot h p ≥ ∣ φ ∣ ⋅ h . Applying Lemma 21 to it for every z ≤ ∣ φ ∣ z\leq|\varphi| z ≤ ∣ φ ∣ , we obtain in time f ( p ) f(p) f ( p ) a list of at most f ( p ) f(p) f ( p ) candidates that contains the p p p -route pattern of every tuple of at most ∣ φ ∣ |\varphi| ∣ φ ∣ elements of R \mathcal{R} R .
Consider one candidate μ \mu μ and follow each of its p p p -routes ϱ = ( e 1 , … , e d ) \varrho=(e_1,\ldots,e_d) ϱ = ( e 1 , … , e d ) in T p T^p T p as follows. By Definition 3 the first entry e 1 = ( t 1 , i 1 ) e_1=(t_1,i_1) e 1 = ( t 1 , i 1 ) denotes the root of T p T^p T p itself and is never abundant, so we check that t 1 t_1 t 1 is the vertex p p p -type of that root and that i 1 = 1 i_1=1 i 1 = 1 ; we then descend, for ℓ = 2 , … , d \ell=2,\ldots,d ℓ = 2 , … , d in turn, at the entry e ℓ = ( t ℓ , i ℓ ) e_\ell=(t_\ell,i_\ell) e ℓ = ( t ℓ , i ℓ ) to the i ℓ i_\ell i ℓ -th child of the current vertex of vertex p p p -type t ℓ t_\ell t ℓ . If some route fails this check or gets stuck, we discard μ \mu μ ; this loses nothing, because no tuple of elements of R R R has p p p -route pattern μ \mu μ in that case. Indeed, if some z z z -tuple with z ≤ ∣ φ ∣ z \le|\varphi| z ≤ ∣ φ ∣ had p p p -route pattern μ \mu μ , then by Lemma 26 (7) some tuple of R p R^p R p has p p p -route pattern μ \mu μ in T p T^p T p , so the routes of μ \mu μ identify vertices of T p T^p T p and both the check and the descent would have succeeded. Moreover, a traversal which passes the check and does not get stuck ends in the realizing vertices of μ \mu μ , as these are by Definition 22 precisely the elements identified by the p p p -routes of μ \mu μ , which by Lemma 26 (5) are the same in T p T^p T p as in T T T . For each candidate μ \mu μ that survives, say a pattern of z z z routes, and each i ∈ [ r ] i \in[r] i ∈ [ r ] with ar ( R i ) = z \operatorname{ar}(R_i)=z ar ( R i ) = z , we record whether R i p R_i^p R i p holds at its tuple of realizing vertices. For ar ( R i ) ≠ z \operatorname{ar}(R_i)\ne z ar ( R i ) = z no entry is stored, as R i p R_i^p R i p contains no z z z -tuples. By Lemma 26 (8), which applies as p ≥ ∣ φ ∣ ⋅ h ≥ ∣ φ ∣ p \ge|\varphi|\cdot h \ge|\varphi| p ≥ ∣ φ ∣ ⋅ h ≥ ∣ φ ∣ , the size of R p R^p R p and hence that of S p S^p S p are bounded by a computable function of h h h and p p p , so this preprocessing step is feasible in the stated time.
Now consider any i ∈ [ r ] i \in[r] i ∈ [ r ] and any element tuple u ˉ \bar{u} u ˉ of arity a = ar ( R i ) a=\operatorname{ar}(R_i) a = ar ( R i ) . Using the pre-computed p p p -routes of its elements, we can determine the p p p -route pattern of u ˉ \bar{u} u ˉ in O ( a h log ( a h ) ) O(ah\log(ah)) O ( ah log ( ah )) time, by identifying the at most a h ah ah indices to be ranked and sorting them. Looking that pattern up in the table computed above, say in a trie over its entries, takes another O ( a h ) O(ah) O ( ah ) time and tells us whether R i p R_i^p R i p holds at the realizing vertices of the pattern, which by the construction of R i ′ R'_i R i ′ is the case if and only if R i ′ ( u ˉ ) R'_i(\bar{u}) R i ′ ( u ˉ ) holds.
Though we do not use this property in what follows, we remark that the constructed solution is itself p p p -pure, since whether a tuple is in some solution relation depends only on the p p p -route pattern of that tuple.
Pure Solutions Exist
Now, we proceed to the key property that makes our algorithm terminate. Concretely, we show that, for large enough p p p (depending only on the treedepth and the formula), we can guarantee that if R ⊨ φ R \models\varphi R ⊨ φ , then ( R p , φ ) (R^p,\varphi) ( R p , φ ) has a p p p -pure solution. Therefore, not only do p p p -pure solutions certify that we have a yes-instance by Theorem 6, but also such a certificate is guaranteed to exist.
First, we establish what we mean by “sufficiently large p p p ”. The concrete value depends on the size of forbidden induced substructures, and relies on well-quasi-orderings. For this, we define the appropriate notion of obstruction sets.
Definition 28 (Obstruction set). Let h ≥ 0 h \ge0 h ≥ 0 be an integer and φ \varphi φ an SNP sentence. Let S h S_h S h be the set of all relational structures (with a signature that matches φ \varphi φ ) with treedepth at most h h h .
Set J h , φ = { R ∗ ∈ S h ∣ R ∗ ⊭ φ } \mathcal{J}_{h,\varphi}=\{R^* \in S_h \mid R^* \not\models\varphi\} J h , φ = { R ∗ ∈ S h ∣ R ∗ ⊨ φ } , that is, the set of relational structures that have treedepth at most h h h and are not models of φ \varphi φ . Create J h , φ \mathcal{J}_{h,\varphi} J h , φ by taking one representative of each isomorphism class of the members of J h , φ \mathcal{J}_{h,\varphi} J h , φ that are minimal under taking induced substructures. Then, J h , φ \mathcal{J}_{h,\varphi} J h , φ is the obstruction set of h , φ h,\varphi h , φ .
By [75 Fact 3.3.9] , which records a consequence of the work of Ding [40 ] , we have that any class of finite relational structures over a fixed finite signature that has bounded treedepth is well-quasi-ordered by the induced-substructure relation (see also Lopez [74 ] ). As a consequence, the set J h , φ \mathcal{J}_{h,\varphi} J h , φ is finite.
Lemma 29. For any integer h ≥ 0 h \ge0 h ≥ 0 and any SNP sentence φ \varphi φ the obstruction set J h , φ \mathcal{J}_{h,\varphi} J h , φ is finite.
Proof. By their minimality in Definition 28, the members of J h , φ \mathcal{J}_{h,\varphi} J h , φ are pairwise non-isomorphic and none of them is an induced substructure of another, so they form an antichain under the induced-substructure relation. They all have treedepth at most h h h and a signature matching φ \varphi φ , and a well-quasi-order admits no infinite antichain, so J h , φ \mathcal{J}_{h,\varphi} J h , φ is finite.
Now, we show that for large enough p p p , if R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ , then for all s ≥ p s \ge p s ≥ p we have that R s ⊨ φ \mathcal{R}^{s} \models\varphi R s ⊨ φ . This means that we can “blow up” the structure R \mathcal{R} R by adding unboundedly many copies of vertices with an abundant vertex p p p -type, and the resulting structure still satisfies φ \varphi φ . We give a formal proof of this fact, but note that this is easy to see intuitively because if p p p is larger than all obstructions, then adding further copies of such abundant vertices cannot make a new obstruction appear. Towards proving this, we show that the set of small induced substructures of R \mathcal{R} R and R s \mathcal{R}^{s} R s is identical.
Lemma 30. Let R \mathcal{R} R be a relational structure with treedepth decomposition T T T , and s ≥ p ≥ 1 s \ge p \ge1 s ≥ p ≥ 1 integers. Then, for any relational structure W W W on at most p p p elements, we have that R \mathcal{R} R contains an induced substructure isomorphic to W W W if and only if R s \mathcal{R}^{s} R s contains an induced substructure isomorphic to W W W .
Proof. We prove both directions of the lemma in two separate claims.
Claim 31. Let W W W be an induced substructure of R \mathcal{R} R on at most p p p elements. Then there is an induced substructure in R s \mathcal{R}^{s} R s that is isomorphic to W W W .
Proof of claim. For empty W W W the claim is trivial, so we assume W W W contains at least one element. Let W ^ \widehat{W} W be the substructure of R \mathcal{R} R induced by the ancestor-closure of the elements of W W W in the tree T T T . We show that R s \mathcal{R}^{s} R s contains an induced substructure isomorphic to W ^ \widehat{W} W too, which yields the claim since W ⊆ W ^ W \subseteq\widehat{W} W ⊆ W .
This is proven by an explicit mapping π \pi π of elements of W ^ \widehat{W} W to elements of R s \mathcal{R}^{s} R s . The root of R \mathcal{R} R , which is part of W ^ \widehat{W} W , is mapped to the root of R s \mathcal{R}^{s} R s by π \pi π . By Lemma 26 (3) the vertex p p p -type of the root of R s \mathcal{R}^{s} R s and R \mathcal{R} R is the same.
The mapping of non-root elements of W ^ \widehat{W} W is obtained recursively as follows. Let w w w be an element of W ^ \widehat{W} W with vertex p p p -type t w t_w t w already mapped to some element w ′ w' w ′ of R s \mathcal{R}^{s} R s with the same vertex p p p -type t w t_w t w . Then, let T \mathcal{T} T be the set of vertex p p p -types of all children of w w w in W ^ \widehat{W} W . For each t ∈ T t \in\mathcal{T} t ∈ T , let C t C_t C t be the set of children of w w w in W ^ \widehat{W} W with type t t t , and let C t s C_t^{s} C t s be the set of children of w ′ w' w ′ in T s T^{s} T s with type t t t . We map the elements of C t C_t C t to C t s C_t^{s} C t s injectively, which concludes the description of the mapping π \pi π .
It remains to argue that there is an injective mapping from C t C_t C t to C t s C_t^{s} C t s . Because w w w and w ′ w' w ′ have vertex p p p -type t w t_w t w , we know that w ′ w' w ′ has children of type t t t too. If t t t is not abundant in t w t_w t w , then, by Lemma 26 (4), w w w and w ′ w' w ′ have the same number of children of vertex p p p -type t t t , and therefore the injective mapping exists. Otherwise, w ′ w' w ′ has exactly s ≥ p ≥ 1 s \ge p \ge1 s ≥ p ≥ 1 children of vertex p p p -type t t t . Moreover, since W W W has at most p p p elements, we have that W ^ \widehat{W} W contains at most p p p siblings: each child of w w w in W ^ \widehat{W} W has a descendant in W W W (potentially itself). Since distinct children have distinct descendants, w w w can have at most p p p children. Hence, the injective mapping exists.
Now, we show that the mapping is an isomorphism from W ^ \widehat{W} W to the substructure W ^ s \widehat{W}^{s} W s of R s \mathcal{R}^{s} R s induced by the image of π \pi π . It is clear from the description that π \pi π is a bijection onto its image, and that it preserves depths and vertex p p p -types. Moreover, π \pi π maps the children of a vertex injectively to children of its image, so vertices in distinct child subtrees have their images in distinct child subtrees; hence v v v is an ancestor of v ′ v' v ′ in T T T if and only if π ( v ) \pi(v) π ( v ) is an ancestor of π ( v ′ ) \pi(v') π ( v ′ ) in T s T^{s} T s . Since the ancestor label is part of the vertex p p p -type, Lemma 16 applies to every tuple of elements of W ^ \widehat{W} W together with its image and shows that the two have the same atomic type. As W ^ \widehat{W} W and W ^ s \widehat{W}^{s} W s are induced substructures of R \mathcal{R} R and R s \mathcal{R}^{s} R s , respectively, this means that π \pi π is an isomorphism between them, concluding the proof.
A similar proof yields the other direction.
Claim 32. Let W W W be an induced substructure of R s \mathcal{R}^{s} R s on at most p p p elements. Then there is an induced substructure in R \mathcal{R} R that is isomorphic to W W W .
Proof of claim. The proof is largely analogous to the previous case. Use the same construction with the roles of R \mathcal{R} R and R s \mathcal{R}^{s} R s flipped. Suppose that w w w of R s \mathcal{R}^{s} R s is already mapped to w ′ w' w ′ of R \mathcal{R} R with the same vertex p p p -type t w t_w t w . Then, for each vertex p p p -type t t t that children of w w w have, note that w ′ w' w ′ has the same number of children of vertex p p p -type t t t if t t t is not abundant in t w t_w t w . Otherwise, from the definition of abundant p p p -types, we obtain that w ′ w' w ′ has at least p p p children of vertex p p p -type t t t , which again suffices.
Combining both claims completes the proof.
Now, we can use this lemma to show that R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ if and only if R s ⊨ φ \mathcal{R}^{s} \models\varphi R s ⊨ φ , for appropriate values of p p p and s s s .
Lemma 7. Let ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) be an instance of SNP Model Checking and T T T a treedepth decomposition of R \mathcal{R} R of height h h h . Set M = max { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } M=\max\{1\}\cup\{|V(H)|:H\in\mathcal{J}_{h,\varphi}\} M = max { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } . Then, for all s ≥ p ≥ M s\ge p\ge M s ≥ p ≥ M we have that R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ if and only if R s ⊨ φ \mathcal{R}^{s}\models\varphi R s ⊨ φ , where R s \mathcal{R}^{s} R s is the s s s -multiplicity structure for ( R , T , p ) (\mathcal{R},T,p) ( R , T , p ) .
Proof. First, consider that R ⊭ φ \mathcal{R}\not\models\varphi R ⊨ φ . Then, R \mathcal{R} R is isomorphic to some structure of J h , φ \mathcal{J}_{h,\varphi} J h , φ . By the definition of J h , φ \mathcal{J}_{h,\varphi} J h , φ , there is some structure R ⋆ ∈ J h , φ \mathcal{R}^{\star}\in\mathcal{J}_{h,\varphi} R ⋆ ∈ J h , φ such that R ⋆ ⊭ φ \mathcal{R}^{\star}\not\models\varphi R ⋆ ⊨ φ , and R ⋆ \mathcal{R}^{\star} R ⋆ has an induced copy in R \mathcal{R} R . Because ∣ V ( R ⋆ ) ∣ ≤ M ≤ p |V(\mathcal{R}^{\star})|\le M\le p ∣ V ( R ⋆ ) ∣ ≤ M ≤ p , Lemma 30 gives an induced copy of R ⋆ \mathcal{R}^{\star} R ⋆ in R s \mathcal{R}^{s} R s . Since SNP satisfaction is closed under taking induced substructures (recall Observation 13), we obtain R s ⊭ φ \mathcal{R}^{s}\not\models\varphi R s ⊨ φ .
Now, assume that R s ⊭ φ \mathcal{R}^{s}\not\models\varphi R s ⊨ φ . We have td ( R s ) ≤ h \operatorname{td}(\mathcal{R}^{s})\le h td ( R s ) ≤ h by Lemma 26 (1). Therefore, there is some R ⋆ ∈ J h , φ \mathcal{R}^{\star}\in\mathcal{J}_{h,\varphi} R ⋆ ∈ J h , φ such that R ⋆ \mathcal{R}^{\star} R ⋆ has an induced copy in R s \mathcal{R}^{s} R s . Since ∣ V ( R ⋆ ) ∣ ≤ M ≤ p |V(\mathcal{R}^{\star})|\le M\le p ∣ V ( R ⋆ ) ∣ ≤ M ≤ p , Lemma 30 gives an induced copy in R \mathcal{R} R , proving R ⊭ φ \mathcal{R}\not\models\varphi R ⊨ φ .
We use this lemma in our upcoming proof about the existence of p p p -pure solutions. Before providing this proof, we need to define the notion of realizations of p p p -route patterns using integer tuples , as they play a crucial role in the proof. Intuitively, such a realization using an integer tuple just takes a p p p -route pattern μ \mu μ , and replaces the indices of abundant entries with those provided by the integer tuple. For technical reasons, we define this notion for the s s s -multiplicity structure.
Definition 33 (Realization of a p p p -route pattern using an integer tuple). Let R \mathcal{R} R be a relational structure with treedepth decomposition T T T , and let s ≥ p ≥ 1 s\ge p\ge1 s ≥ p ≥ 1 be integers. Consider the s s s -multiplicity structure R s \mathcal{R}^{s} R s for ( R , T , p ) (\mathcal{R},T,p) ( R , T , p ) with its accompanying tree T s T^{s} T s . Let μ = ( ϱ 1 , … , ϱ z ) \mu=(\varrho_1,\ldots,\varrho_z) μ = ( ϱ 1 , … , ϱ z ) be a p p p -route pattern occurring in ( R , T ) (\mathcal{R},T) ( R , T ) or in ( R s , T s ) (\mathcal{R}^{s},T^{s}) ( R s , T s ) , with β \beta β distinct indices in its p p p -abundant entries. By normalization, these indices are precisely 1 , … , β 1,\ldots,\beta 1 , … , β .
For a strictly increasing tuple n ˉ = ( n 1 , … , n β ) \bar{n}=(n_1,\ldots,n_\beta) n ˉ = ( n 1 , … , n β ) of integers in [ s ] [s] [ s ] , the realization of μ \mu μ using n ˉ \bar{n} n ˉ is the element tuple in R s \mathcal{R}^{s} R s whose p p p -routes in T s T^{s} T s are obtained from μ \mu μ by replacing every p p p -abundant entry ( t , j ) (t,j) ( t , j ) by ( t , n j ) (t,n_j) ( t , n j ) , leaving all other entries unchanged. When β = 0 \beta=0 β = 0 , we use the empty integer tuple and make no replacements.
Now, similarly to Lemma 23, we show that such a realization exists.
Lemma 34. Let R \mathcal{R} R be a relational structure with treedepth decomposition T T T , and let s ≥ p ≥ 1 s\ge p\ge1 s ≥ p ≥ 1 be integers. Let μ = ( ϱ 1 , … , ϱ z ) \mu=(\varrho_1,\ldots,\varrho_z) μ = ( ϱ 1 , … , ϱ z ) be a p p p -route pattern appearing in ( R , T ) (\mathcal{R},T) ( R , T ) or in ( R s , T s ) (\mathcal{R}^{s},T^{s}) ( R s , T s ) with β ≤ s \beta\le s β ≤ s distinct indices in its p p p -abundant entries. Moreover, let n ˉ ∈ [ s ] β \bar{n}\in[s]^\beta n ˉ ∈ [ s ] β be a vector with strictly increasing entries. The realization of μ \mu μ using n ˉ \bar{n} n ˉ exists and its p p p -route pattern is μ \mu μ . Conversely, every element tuple in R s \mathcal{R}^{s} R s with p p p -route pattern μ \mu μ is the realization of μ \mu μ using a unique strictly increasing β \beta β -tuple in [ s ] [s] [ s ] .
Proof. For the first assertion, replace each abundant index j j j in μ \mu μ by n j n_j n j and follow the resulting routes in T s T^s T s . The root entry remains unchanged and identifies the root of T s T^s T s , whose vertex p p p -type agrees with that of the root of T T T by Lemma 26 (3). At each subsequent step, the current parent vertex has the vertex p p p -type specified by the preceding entry. If the current entry has an abundant vertex p p p -type, the parent vertex has exactly s s s children of the required vertex p p p -type, and the substituted index is at most s s s . For a non-abundant vertex p p p -type, the parent vertex p p p -type records the exact number of children of the required type, and the unchanged index remains valid. This constructs a unique vertex for each route. Therefore, the realization is unique.
Normalizing the resulting tuple again replaces n j n_j n j by j j j in every abundant entry, since n ˉ \bar{n} n ˉ is strictly increasing, and hence recovers μ \mu μ . Thus the realizing vertex tuple has p p p -route pattern μ \mu μ .
Conversely, the increasing list of distinct abundant indices in any element tuple with pattern μ \mu μ has length β \beta β and is its unique substitution tuple. Each index of an abundant entry is at most s s s by the definition of s s s -multiplicity structures.
Since later arguments build on it, we now define the standard notion of the finite hypergraph Ramsey number.
Definition 35 (Hypergraph ramsey number). For any integers x , y , c ≥ 1 x,y,c \ge1 x , y , c ≥ 1 , with x ≥ y x \ge y x ≥ y , let Ram y ( x , c ) \operatorname{Ram}_y(x,c) Ram y ( x , c ) be the smallest integer N N N such that, for any y y y -uniform hyperclique H H H on at least N N N vertices, where the edges are colored using at most c c c colors, there exists a y y y -uniform hyperclique in H H H on x x x vertices whose edges all have the same color.
The Ramsey theorem for finite hypergraphs guarantees that this number Ram y ( x , c ) \operatorname{Ram}_y(x,c) Ram y ( x , c ) indeed exists [83 Theorem B] . Finally, we have all ingredients to prove the existence of a p p p -pure solution.
Theorem 8 (Existence of a p p p -pure solution). Let ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) be an instance of SNP Model Checking and T T T a treedepth decomposition of R \mathcal{R} R of height h h h . Set M = max ( { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } ) M = \max(\{1\} \cup\{|V(H)| : H \in\mathcal{J}_{h,\varphi}\}) M = max ({ 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ }) . Then, for all p ≥ max { M , ∣ φ ∣ h } p \ge\max\{M,|\varphi|h\} p ≥ max { M , ∣ φ ∣ h } we have that if R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ , then R p ∗ h a s a ∗ \mathcal{R}^p *has a* R p ∗ ha s a ∗ p− ∗ p u r e s o l u t i o n , w h e r e ∗ -*pure solution, where* − ∗ p u r eso l u t i o n , w h er e ∗ \mathcal{R}^p is the p p p -multiplicity structure for ( R , T , p ) (\mathcal{R},T,p) ( R , T , p ) .
Proof. We begin by sketching the idea of the proof.
Proof idea. By assumption, we have that R \mathcal{R} R has a solution. Then, from Lemma 7 we obtain that R p \mathcal{R}^p R p has a solution too. Our aim is showing that indeed R p \mathcal{R}^p R p has a p p p -pure solution. Recall that the main property of such a solution is that, for p p p -route patterns of bounded length, all element tuples with that p p p -route pattern have the same solution type.
For a single p p p -route pattern, say μ \mu μ , we seek a set of indices on which all realizations of μ \mu μ have the same solution type. Keeping only these indices in every abundant child-type class gives a structure R ~ \widetilde{\mathcal{R}} R . Then, we could project our solution down to R ~ \widetilde{\mathcal{R}} R , and would find that p p p -route pattern μ \mu μ is always mapped to the same solution type, as desired. Of course, R ~ \widetilde{\mathcal{R}} R might not contain the same p p p -route patterns as R \mathcal{R} R : taking substructures can change which vertices are p p p -abundant, completely changing the picture. However, if every abundant child-type class still has at least p p p children, the vertex p p p -types remain unchanged. Ramsey theory will provide such a common set of indices while retaining sufficiently many children in every abundant class. We use nested Ramsey arguments on the structure R p α \mathcal{R}^{p_\alpha} R p α for a large p α p_\alpha p α to ensure this works for many patterns.
The blowup structure. First, we determine the value of integer p α p_\alpha p α . Let μ 1 , … , μ α \mu_1,\ldots,\mu_\alpha μ 1 , … , μ α be the list of all p p p -route patterns of size up to ∣ φ ∣ |\varphi| ∣ φ ∣ appearing in R \mathcal{R} R , in an arbitrary order. Moreover, let φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ \varphi= \exists R_1,\ldots,R_r\,\forall x_1,\ldots,x_k:\psi φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ . A p p p -route pattern of length z ≤ ∣ φ ∣ z \le|\varphi| z ≤ ∣ φ ∣ uses at most z ( h − 1 ) ≤ p z(h-1) \le p z ( h − 1 ) ≤ p distinct indices in abundant entries. By definition, every index of an abundant entry in a p p p -route pattern is therefore at most p p p . Moreover, by Lemma 26 (7), which applies as p ≥ ∣ φ ∣ ⋅ h ≥ z h p \ge|\varphi| \cdot h \ge zh p ≥ ∣ φ ∣ ⋅ h ≥ z h for every z ≤ ∣ φ ∣ z \le|\varphi| z ≤ ∣ φ ∣ , the sets of p p p -route patterns of tuples of length at most ∣ φ ∣ |\varphi| ∣ φ ∣ appearing in ( R , T ) (R,T) ( R , T ) and in ( R p , T p ) (R^p,T^p) ( R p , T p ) are identical.
For each μ i \mu_i μ i , let β i \beta_i β i be the number of distinct indices of abundant entries of μ i \mu_i μ i (such that a realization of μ i \mu_i μ i requires an integer tuple of length β i \beta_i β i ). Moreover, set D = 2 ∣ φ ∣ 2 + ∑ j = 1 ∣ φ ∣ a r ( R j ) D=2^{|\varphi|^2+\sum_{j=1}^{|\varphi|} ar(R_j)} D = 2 ∣ φ ∣ 2 + ∑ j = 1 ∣ φ ∣ a r ( R j ) . By Lemma 12 and Definition 27 the number of possible solution types for tuples realizing μ i \mu_i μ i is bounded by D D D in any possible solution.
Define p 0 = p p_0=p p 0 = p . Inductively define
p i = { Ram β i ( p i − 1 , D ) if β i > 0 , p i − 1 otherwise , p_i =
\begin{cases}
\operatorname{Ram}_{\beta_i}(p_{i-1},D) & \text{if } \beta_i>0,\\
p_{i-1} & \text{otherwise},
\end{cases} p i = { Ram β i ( p i − 1 , D ) p i − 1 if β i > 0 , otherwise ,
for each i ∈ [ α ] i \in[\alpha] i ∈ [ α ] , where Ram β i ( p i − 1 , D ) \operatorname{Ram}_{\beta_i}(p_{i-1},D) Ram β i ( p i − 1 , D ) denotes the finite hypergraph Ramsey number of Definition 35. Since β i ≤ p ≤ p i − 1 \beta_i \le p \le p_{i-1} β i ≤ p ≤ p i − 1 , the recurrence is well-defined and p i ≥ p i − 1 ≥ p p_i \ge p_{i-1} \ge p p i ≥ p i − 1 ≥ p .
Obtaining the p p p -pure solution. Since β i ≤ p ≤ p α \beta_i \le p \le p_\alpha β i ≤ p ≤ p α for every i ∈ [ α ] i \in[\alpha] i ∈ [ α ] , Lemma 34 gives that each p p p -route pattern μ i \mu_i μ i also occurs in ( R p α , T p α ) (R^{p_\alpha},T^{p_\alpha}) ( R p α , T p α ) . Fix a solution S S S for the structure R p α R^{p_\alpha} R p α , which exists by Lemma 7. We prove by induction that for each i ∈ [ 0 , α ] i \in[0,\alpha] i ∈ [ 0 , α ] there exists a set N i ⊆ [ p α ] N_i \subseteq[p_\alpha] N i ⊆ [ p α ] of size p i p_i p i , such that all realizations of each of the p p p -route patterns μ α , … , μ i + 1 \mu_\alpha,\ldots,\mu_{i+1} μ α , … , μ i + 1 using integers in N i N_i N i have the same solution type in S S S .
In the base case i = α i=\alpha i = α , the conditions are vacuous, and we set N α = [ p α ] N_\alpha=[p_\alpha] N α = [ p α ] .
For the induction step, we assume the statement holds for index i ≥ 1 i \ge1 i ≥ 1 , and we show it holds for i − 1 i-1 i − 1 too. Let N i N_i N i be the set provided by the induction hypothesis.
If β i = 0 \beta_i=0 β i = 0 , then there is only a single element tuple with p p p -route pattern μ i \mu_i μ i in R p α R^{p_\alpha} R p α , and therefore μ i \mu_i μ i is vacuously p p p -pure in S S S . In this case, we additionally have p i = p i − 1 p_i=p_{i-1} p i = p i − 1 , and setting N i − 1 = N i N_{i-1}=N_i N i − 1 = N i suffices.
Otherwise, we have β i > 0 \beta_i>0 β i > 0 . We now build an edge-colored β i \beta_i β i -uniform hyperclique H i H_i H i for our application of Ramsey theory. The vertex set of the hypergraph is the integer set N i N_i N i . For each tuple n ˉ = n 1 , … , n β i \bar n=n_1,\ldots,n_{\beta_i} n ˉ = n 1 , … , n β i of β i \beta_i β i distinct vertices of the graph, ordered increasingly, we color the corresponding hyperedge (that is, the hyperedge whose elements are those of n ˉ \bar n n ˉ ) as follows. Let v ˉ \bar v v ˉ be the realization of μ i \mu_i μ i using n ˉ \bar n n ˉ in R p α R^{p_\alpha} R p α , as given by Lemma 34 with s = p α s=p_\alpha s = p α . Then, the tuple v ˉ \bar v v ˉ has some solution type t t t in S S S . We color the hyperedge on n ˉ \bar n n ˉ with color t t t .
Hypergraph Ramsey yields that there is a β i \beta_i β i -uniform hyperclique on exactly p i − 1 p_{i-1} p i − 1 vertices in H i H_i H i whose edges all have the same color. Let N i − 1 N_{i-1} N i − 1 be the vertex set of this β i \beta_i β i -uniform hyperclique in H i H_i H i . We claim that all realizations of each of μ α , … , μ i \mu_\alpha,\ldots,\mu_i μ α , … , μ i using integers in N i − 1 N_{i-1} N i − 1 have the same solution type.
That this holds for μ α , … , μ i + 1 \mu_\alpha,\ldots,\mu_{i+1} μ α , … , μ i + 1 follows from the induction hypothesis, since N i − 1 ⊆ N i N_{i-1} \subseteq N_i N i − 1 ⊆ N i . For μ i \mu_i μ i , note the following: by Lemma 34, each considered vertex tuple with p p p -route pattern μ i \mu_i μ i is uniquely identified by the increasing list n ˉ \bar n n ˉ of its distinct abundant indices. This list is a β i \beta_i β i -tuple of N i − 1 N_{i-1} N i − 1 . Therefore, from the fact that we have a monochromatic hyperclique on N i − 1 N_{i-1} N i − 1 , we obtain that these all have the same solution type.
At i = 0 i=0 i = 0 , we obtain a set N 0 N_0 N 0 of size p p p ; write N 0 = { n 1 < ⋯ < n p } N_0=\{n_1<\cdots<n_p\} N 0 = { n 1 < ⋯ < n p } . Recall that in R p α R^{p_\alpha} R p α , for each vertex p p p -type t t t that is abundant in the vertex p p p -type of its parent, the parent vertex has exactly p α p_\alpha p α children of type t t t . In R p R^p R p , every such class has exactly p p p children; non-abundant child-type classes at parents of the same vertex p p p -type have the same size in both structures.
We now define an induced embedding π \pi π from R p R^p R p to R p α R^{p_\alpha} R p α . Concretely, π \pi π maps the root of R p R^p R p to the root of R p α \mathcal{R}^{p\alpha} R p α , and for each vertex w w w already mapped to π ( w ) \pi(w) π ( w ) , we map its children as follows. If t t t is abundant in the vertex p p p -type of w w w , we map the j j j th smallest child of w w w with vertex p p p -type t t t to the n j n_j n j th smallest child of π ( w ) \pi(w) π ( w ) with vertex p p p -type t t t . Otherwise, we map the j j j th smallest child of w w w with vertex p p p -type t t t to the j j j th smallest child of π ( w ) \pi(w) π ( w ) with vertex p p p -type t t t . The roots have the same vertex p p p -type by Lemma 26 (3), and the child counts above make π \pi π a well-defined injection preserving depths, vertex p p p -types, and the ancestor relation in both directions. Since the ancestor label is part of the vertex p p p -type, Lemma 16 then gives that every tuple of elements of R p \mathcal{R}^{p} R p has the same atomic type as its image, that is, π \pi π is an induced embedding.
Write S = R 1 ′ , … , R r ′ \mathcal{S}=R'_1,\ldots,R'_r S = R 1 ′ , … , R r ′ . Create S p = R 1 p , … , R r p \mathcal{S}^{p}=R^p_1,\ldots,R^p_r S p = R 1 p , … , R r p by setting
R j p ( v 1 , … , v a ) ⟺ R j ′ ( π ( v 1 ) , … , π ( v a ) ) R^p_j(v_1,\ldots,v_a)\Longleftrightarrow R'_j(\pi(v_1),\ldots,\pi(v_a)) R j p ( v 1 , … , v a ) ⟺ R j ′ ( π ( v 1 ) , … , π ( v a ))
for each j ∈ [ r ] j\in[r] j ∈ [ r ] , with a = ar ( R j ) a=\operatorname{ar}(R_j) a = ar ( R j ) , and each tuple ( v 1 , … , v a ) ∈ V ( R p ) a (v_1,\ldots,v_a)\in V(\mathcal{R}^{p})^a ( v 1 , … , v a ) ∈ V ( R p ) a .
Consider any assignment of vertices v 1 , … , v k v_1,\ldots,v_k v 1 , … , v k of R p \mathcal{R}^{p} R p to the variables x 1 , … , x k x_1,\ldots,x_k x 1 , … , x k , and compare it with the assignment π ( v 1 ) , … , π ( v k ) \pi(v_1),\ldots,\pi(v_k) π ( v 1 ) , … , π ( v k ) in R p α \mathcal{R}^{p\alpha} R p α . For any relation E i E_i E i of the input relational structures, we have that E i ( v 1 , … , v z ) E_i(v_1,\ldots,v_z) E i ( v 1 , … , v z ) holds in R p \mathcal{R}^{p} R p if and only if E i ( π ( v 1 ) , … , π ( v z ) ) E_i(\pi(v_1),\ldots,\pi(v_z)) E i ( π ( v 1 ) , … , π ( v z )) holds in R p α \mathcal{R}^{p\alpha} R p α , since π \pi π is an induced embedding. The same holds for the equality relation: v 1 v_1 v 1 and v 2 v_2 v 2 are identical if and only if π ( v 1 ) \pi(v_1) π ( v 1 ) and π ( v 2 ) \pi(v_2) π ( v 2 ) are. Finally, for any relation R j p R^p_j R j p of the solution, by construction R j p ( v 1 , … , v a ) ⟺ R j ′ ( π ( v 1 ) , … , π ( v a ) ) R^p_j(v_1,\ldots,v_a)\Longleftrightarrow R'_j(\pi(v_1),\ldots,\pi(v_a)) R j p ( v 1 , … , v a ) ⟺ R j ′ ( π ( v 1 ) , … , π ( v a )) . Therefore, the assignment v 1 , … , v k v_1,\ldots,v_k v 1 , … , v k fulfills ψ \psi ψ if and only if the assignment π ( v 1 ) , … , π ( v k ) \pi(v_1),\ldots,\pi(v_k) π ( v 1 ) , … , π ( v k ) does. Hence, we have that S p \mathcal{S}^{p} S p is a solution for R p \mathcal{R}^{p} R p .
We claim that S p \mathcal{S}^{p} S p is a p p p -pure solution for R p \mathcal{R}^{p} R p . Consider any element v v v of R p \mathcal{R}^{p} R p . By construction, the p p p -route of π ( v ) \pi(v) π ( v ) is obtained from that of v v v by replacing each abundant entry ( t , j ) (t,j) ( t , j ) by ( t , n j ) (t,n_j) ( t , n j ) , leaving all other entries unchanged.
Now, consider any element tuple v 1 , … , v z v_1,\ldots,v_z v 1 , … , v z in R p \mathcal{R}^{p} R p of length at most ∣ φ ∣ |\varphi| ∣ φ ∣ . By the argument above, π ( v 1 ) , … , π ( v z ) \pi(v_1),\ldots,\pi(v_z) π ( v 1 ) , … , π ( v z ) have the same atomic type as v 1 , … , v z v_1,\ldots,v_z v 1 , … , v z . Since mapping j j j to n j n_j n j is a strictly increasing mapping, and this mapping is used in every abundant entry, the p p p -route pattern of v 1 , … , v z v_1,\ldots,v_z v 1 , … , v z is the same as the p p p -route pattern of π ( v 1 ) , … , π ( v z ) \pi(v_1),\ldots,\pi(v_z) π ( v 1 ) , … , π ( v z ) . Moreover, all abundant indices of the p p p -routes of the image tuple lie in N 0 N_0 N 0 .
For any μ i \mu_i μ i , by the Ramsey argument above, all element tuples of R p α \mathcal{R}^{p\alpha} R p α with p p p -route pattern μ i \mu_i μ i where all abundant indices lie in N 0 N_0 N 0 have the same solution type in S \mathcal{S} S . By our arguments earlier, all element tuples v 1 , … , v z v_1,\ldots,v_z v 1 , … , v z with p p p -route pattern μ i \mu_i μ i in R p \mathcal{R}^{p} R p have image tuples π ( v 1 ) , … , π ( v z ) \pi(v_1),\ldots,\pi(v_z) π ( v 1 ) , … , π ( v z ) with the same p p p -route pattern, such that all abundant indices of their p p p -routes lie in N 0 N_0 N 0 . Hence, all these image tuples have the same solution type in S \mathcal{S} S . Now, observe that the solution type of v 1 , … , v z v_1,\ldots,v_z v 1 , … , v z in S p \mathcal{S}^{p} S p and of π ( v 1 ) , … , π ( v z ) \pi(v_1),\ldots,\pi(v_z) π ( v 1 ) , … , π ( v z ) in S \mathcal{S} S is also the same by construction of S p \mathcal{S}^{p} S p and injectivity of π \pi π . Therefore, we have that S p \mathcal{S}^{p} S p is p p p -pure.
Combining Everything: The Algorithm
With Theorems 6 and 8 at hand, we now have two main ingredients for establishing our main theorem.
Theorem 1. There is an Algorithm A \mathsf{A} A that takes an SNP sentence φ \varphi φ with relation variables R 1 , … , R r R_1,\ldots,R_r R 1 , … , R r and a relational structure R \mathcal{R} R as input, runs in time f ( ∣ φ ∣ , td ( R ) ) ⋅ ∣ R ∣ f(|\varphi|,\operatorname{td}(\mathcal{R}))\cdot|\mathcal{R}| f ( ∣ φ ∣ , td ( R )) ⋅ ∣ R ∣ for some computable function f f f , and decides whether R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ . Moreover, if R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ , then for any given non-empty Q ⊆ [ r ] Q\subseteq[r] Q ⊆ [ r ] the algorithm can output a Q Q Q -solution of R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ in time f ( ∣ φ ∣ , td ( R ) ) ⋅ ∣ R ∣ max i ∈ Q ar ( R i ) f(|\varphi|,\operatorname{td}(\mathcal{R}))\cdot|\mathcal{R}|^{\max_{i\in Q}\operatorname{ar}(R_i)} f ( ∣ φ ∣ , td ( R )) ⋅ ∣ R ∣ m a x i ∈ Q ar ( R i ) .
We proceed by describing (the decision variant of) the algorithm and establishing its properties. These properties then culminate in the proof of the main theorem.
Algorithm A. Let ( R , φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ ) (\mathcal{R}, \varphi= \exists R_1, \ldots, R_r \ \forall x_1, \ldots, x_k : \psi) ( R , φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ ) be an instance of SNP Model Checking. Compute the primal graph of R \mathcal{R} R and a treedepth decomposition T T T of it of height h ≤ td ( R ) + 1 h \le\operatorname{td}(\mathcal{R})+1 h ≤ td ( R ) + 1 using the algorithm by Reidl, Rossmanith, Sánchez Villaamil and Sikdar [86 ] . Consider iteratively j = 0 , 1 , 2 , … j = 0, 1, 2, \ldots j = 0 , 1 , 2 , … and let p = j + ∣ φ ∣ ⋅ h p = j + |\varphi| \cdot h p = j + ∣ φ ∣ ⋅ h . In each iteration, compute the p p p -multiplicity structure R p \mathcal{R}^{p} R p for ( R , T , p ) (\mathcal{R}, T, p) ( R , T , p ) as well as the set L p \mathcal{L}^{p} L p of all solutions of R p \mathcal{R}^{p} R p . Consider the following cases in order:
if L p = ∅ \mathcal{L}^{p} = \emptyset L p = ∅ , we output R ⊭ φ \mathcal{R} \not\models\varphi R ⊨ φ , i.e., we face a negative instance,
if L p \mathcal{L}^{p} L p contains a p p p -pure solution S p \mathcal{S}^{p} S p for R p \mathcal{R}^{p} R p and T p T^{p} T p , we retain S p \mathcal{S}^{p} S p and output R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ , i.e., we face a positive instance,
otherwise, proceed to the next iteration.
End of Algorithm.
While Algorithm A is easy to state, it is a priori not clear that it even terminates. Thus, we first show in Lemma 36 that it does so and establish its correctness.
Lemma 36. Let ( R , φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ ) (\mathcal{R}, \varphi= \exists R_1, \ldots, R_r \ \forall x_1, \ldots, x_k : \psi) ( R , φ = ∃ R 1 , … , R r ∀ x 1 , … , x k : ψ ) be an instance of SNP Model Checking. Moreover, let M = max { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J td ( R ) + 1 , φ } M = \max\{1\} \cup\{|V(H)| : H \in\mathcal{J}_{\operatorname{td}(\mathcal{R})+1,\varphi}\} M = max { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J td ( R ) + 1 , φ } , where J td ( R ) + 1 , φ \mathcal{J}_{\operatorname{td}(\mathcal{R})+1,\varphi} J td ( R ) + 1 , φ is the obstruction set from Definition 28. Then, Algorithm A has the following properties:
If it enters Case 1, then R ⊭ φ \mathcal{R} \not\models\varphi R ⊨ φ .
If it enters Case 2, then R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ .
In the iteration for p = max { M , ∣ φ ∣ ( td ( R ) + 1 ) } p = \max\{M, |\varphi|(\operatorname{td}(\mathcal{R}) + 1)\} p = max { M , ∣ φ ∣ ( td ( R ) + 1 )} (if reached), it does not enter Case 3.
In particular, Algorithm A terminates in an iteration with p ≤ max { M , ∣ φ ∣ ( td ( R ) + 1 ) } p \le\max\{M, |\varphi|(\operatorname{td}(\mathcal{R})+1)\} p ≤ max { M , ∣ φ ∣ ( td ( R ) + 1 )} and correctly determines whether R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ .
Proof. Let T T T be the treedepth decomposition of R \mathcal{R} R of height h ≤ td ( R ) + 1 h \le\operatorname{td}(\mathcal{R})+1 h ≤ td ( R ) + 1 computed in Algorithm A. We show the three properties separately.
First, assume that Algorithm A enters Case 1. This means that for the p p p that we consider in that iteration, the p p p -multiplicity structure R p \mathcal{R}^{p} R p for ( R , T , p ) (\mathcal{R}, T, p) ( R , T , p ) has no solution. To see that this implies R ⊭ φ \mathcal{R} \not\models\varphi R ⊨ φ , assume otherwise. Since R p \mathcal{R}^{p} R p is an induced substructure of R \mathcal{R} R and SNP-satisfaction is closed under taking induced substructures (recall Observation 13 ), we get R p ⊨ φ \mathcal{R}^{p} \models\varphi R p ⊨ φ . However, this contradicts the precondition of Case 1, i.e., that the set of solutions L p \mathcal{L}^{p} L p is empty. Hence, R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ cannot hold.
Second, assume that Algorithm A enters Case 2. This means that the solution set L p \mathcal{L}^{p} L p contains a p p p -pure solution S p \mathcal{S}^{p} S p for R p \mathcal{R}^{p} R p and T p T^{p} T p . Theorem 6 together with p ≥ ∣ φ ∣ ⋅ h p \ge|\varphi| \cdot h p ≥ ∣ φ ∣ ⋅ h guarantees that we can extend the p p p -pure solution S p \mathcal{S}^{p} S p to a solution for R \mathcal{R} R , which implies R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ .
Third, consider the iteration for p = max { M , ∣ φ ∣ ( td ( R ) + 1 ) } p = \max\{M, |\varphi|(\operatorname{td}(\mathcal{R}) + 1)\} p = max { M , ∣ φ ∣ ( td ( R ) + 1 )} . We now argue that Algorithm A either enters Case 1 or Case 2. If R ⊭ φ \mathcal{R} \not\models\varphi R ⊨ φ , by Lemma 7, we have that R p ⊭ φ \mathcal{R}^{p} \not\models\varphi R p ⊨ φ since p ≥ M p \ge M p ≥ M . Hence, L p = ∅ \mathcal{L}^{p} = \emptyset L p = ∅ and Algorithm A enters Case 1. If R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ , since we have p = max { M , ∣ φ ∣ ( td ( R ) + 1 ) } ≥ max { M , ∣ φ ∣ h } p = \max\{M, |\varphi|(\operatorname{td}(\mathcal{R}) + 1)\} \ge\max\{M, |\varphi|h\} p = max { M , ∣ φ ∣ ( td ( R ) + 1 )} ≥ max { M , ∣ φ ∣ h } , Theorem 8 ensures that R p \mathcal{R}^{p} R p has a p p p -pure solution S p \mathcal{S}^{p} S p and Algorithm A enters Case 2. In both cases Algorithm A does not enter Case 3.
To combine everything, observe that Algorithm A iteratively considers every p ≥ ∣ φ ∣ ⋅ ( td ( R ) + 1 ) p \ge|\varphi| \cdot(\operatorname{td}(\mathcal{R})+1) p ≥ ∣ φ ∣ ⋅ ( td ( R ) + 1 ) . Since max { M , ∣ φ ∣ ( td ( R ) + 1 ) } ≥ ∣ φ ∣ ⋅ ( td ( R ) + 1 ) \max\{M, |\varphi|(\operatorname{td}(\mathcal{R})+1)\} \ge|\varphi| \cdot(\operatorname{td}(\mathcal{R})+1) max { M , ∣ φ ∣ ( td ( R ) + 1 )} ≥ ∣ φ ∣ ⋅ ( td ( R ) + 1 ) , the algorithm terminates at the latest for p = max { M , ∣ φ ∣ ( td ( R ) + 1 ) } p = \max\{M, |\varphi|(\operatorname{td}(\mathcal{R})+1)\} p = max { M , ∣ φ ∣ ( td ( R ) + 1 )} by entering either Case 1 or Case 2. Moreover, R p \mathcal{R}^{p} R p has bounded size by Lemma 26 and thus we can brute-force candidate solutions. By the first two properties, we obtain correctness of Algorithm A. ∎
While Lemma 36 guarantees correctness and termination of Algorithm A, it alone does not yet show that the running time of our algorithm can be bounded by a computable function in the parameters td ( R ) \operatorname{td}(\mathcal{R}) td ( R ) and ∣ φ ∣ |\varphi| ∣ φ ∣ . Indeed, the termination property in Lemma 36 relies on the size M M M of the largest element in the obstruction set J td ( R ) + 1 , φ \mathcal{J}_{\operatorname{td}(\mathcal{R})+1,\varphi} J td ( R ) + 1 , φ . We only know that J td ( R ) + 1 , φ \mathcal{J}_{\operatorname{td}(\mathcal{R})+1,\varphi} J td ( R ) + 1 , φ is finite; recall Lemma 29 . Moreover, the well-quasi-ordering argument only implies that M M M exists but provides no bound on M M M in terms of td ( R ) \operatorname{td}(\mathcal{R}) td ( R ) and ∣ φ ∣ |\varphi| ∣ φ ∣ . We now show that we can actually bound M M M by a computable function in the parameters.
Theorem 9. Let h ≥ 1 h \ge1 h ≥ 1 be an integer and φ \varphi φ be an SNP formula. There is an algorithm that computes the obstruction set J h , φ \mathcal{J}_{h,\varphi} J h , φ (up to isomorphism) in time f ( h , ∣ φ ∣ ) f(h,|\varphi|) f ( h , ∣ φ ∣ ) for some computable function f f f . In particular, we have max ( { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ } ) ≤ g ( h , ∣ φ ∣ ) \max(\{1\} \cup\{|V(H)| : H \in\mathcal{J}_{h,\varphi}\}) \le g(h,|\varphi|) max ({ 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J h , φ }) ≤ g ( h , ∣ φ ∣ ) for some computable function g g g .
Proof. We present a procedure P φ P_{\varphi} P φ to compute J h , φ \mathcal{J}_{h,\varphi} J h , φ . On a high level, P φ P_{\varphi} P φ emulates the behavior of Algorithm A when given a relational structure R \mathcal{R} R with td ( R ) ≤ h \operatorname{td}(\mathcal{R}) \le h td ( R ) ≤ h and φ \varphi φ . We then aim to find a value p φ p_{\varphi} p φ for p p p such that we enter Case 1 or Case 2 for every structure that can arise in the corresponding iteration of Algorithm A. The negative instances witnessed at p φ p_{\varphi} p φ can then be used to construct J h , φ \mathcal{J}_{h,\varphi} J h , φ .
We now describe the procedure P φ P_{\varphi} P φ . We start with p = ∣ φ ∣ ⋅ ( h + 1 ) p = |\varphi| \cdot(h+1) p = ∣ φ ∣ ⋅ ( h + 1 ) and enumerate every pair ( X , T X ) (\mathcal{X},T_{\mathcal{X}}) ( X , T X ) of a relational structure X \mathcal{X} X with an accompanying treedepth decomposition T X T_{\mathcal{X}} T X where X \mathcal{X} X matches the signature of φ \varphi φ such that X p = X \mathcal{X}^{p} = \mathcal{X} X p = X , td ( X ) ≤ h \operatorname{td}(\mathcal{X}) \le h td ( X ) ≤ h , and T X T_{\mathcal{X}} T X has height at most h + 1 h+1 h + 1 . Recall that the number of distinct vertex p p p -types can be bounded by some computable function in h h h , p p p , and ∣ φ ∣ |\varphi| ∣ φ ∣ (Lemma 17 ). Since X p = X \mathcal{X}^{p} = \mathcal{X} X p = X , every vertex in T X T_{\mathcal{X}} T X has at most p p p children of every possible vertex p p p -type, which allows us to bound the degree of every vertex in T X T_{\mathcal{X}} T X by some computable function in these values. Since the height of T X T_{\mathcal{X}} T X is at most h + 1 h+1 h + 1 , this ensures that ∣ T X ∣ |T_{\mathcal{X}}| ∣ T X ∣ can be bounded by a computable function in h h h , p p p , and ∣ φ ∣ |\varphi| ∣ φ ∣ . Requiring X p = X \mathcal{X}^{p} = \mathcal{X} X p = X bounds not only its size by a computable function g ′ ( h , p ) g'(h,p) g ′ ( h , p ) (recall Lemma 26) but also the number of candidate relational structures X \mathcal{X} X by a computable function in h h h , p p p , ∣ φ ∣ |\varphi| ∣ φ ∣ . Thus, we can enumerate all pairs (where the domain of X \mathcal{X} X is a subset of [ g ′ ( h , p ) ] [g'(h,p)] [ g ′ ( h , p )] ). Consider one of these pairs ( X , T X ) (\mathcal{X},T_{\mathcal{X}}) ( X , T X ) . Since ∣ X p ∣ = ∣ X ∣ ≤ g ′ ( h , p ) |\mathcal{X}^{p}| = |\mathcal{X}| \le g'(h,p) ∣ X p ∣ = ∣ X ∣ ≤ g ′ ( h , p ) , we can brute force all solutions L X \mathcal{L}_{\mathcal{X}} L X of X \mathcal{X} X . If L X ≠ ∅ \mathcal{L}_{\mathcal{X}} \ne\varnothing L X = ∅ but contains no p p p -pure solution, we increase p p p by one and restart the enumeration with the larger p p p . Otherwise, if for every pair ( X , T X ) (\mathcal{X},T_{\mathcal{X}}) ( X , T X ) we have that either L X = ∅ \mathcal{L}_{\mathcal{X}} = \varnothing L X = ∅ or L X \mathcal{L}_{\mathcal{X}} L X contains a p p p -pure solution, we terminate.
We now argue that P φ P_{\varphi} P φ terminates. To this end, observe that the obstruction set J h + 1 , φ \mathcal{J}_{h+1,\varphi} J h + 1 , φ only depends on h h h and φ \varphi φ , but not on X \mathcal{X} X ; recall Definition 28 . Moreover, J h + 1 , φ \mathcal{J}_{h+1,\varphi} J h + 1 , φ is finite by Lemma 29 . Furthermore, note that J h ′ , φ ⊆ J h + 1 , φ \mathcal{J}_{h',\varphi} \subseteq\mathcal{J}_{h+1,\varphi} J h ′ , φ ⊆ J h + 1 , φ holds for all h ′ ≤ h + 1 h' \le h+1 h ′ ≤ h + 1 (up to isomorphism) by the definition of the obstruction set. Hence, there exists some (unknown) value for p p p such that every relational structure X = X p \mathcal{X} = \mathcal{X}^{p} X = X p with X ⊨ φ \mathcal{X} \models\varphi X ⊨ φ that we consider in this iteration has a p p p -pure solution (for any p p p that satisfies the bound from Theorem 8 each considered pair ( X , T X ) (\mathcal{X},T_{\mathcal{X}}) ( X , T X ) with X ⊨ φ \mathcal{X} \models\varphi X ⊨ φ has a p p p -pure solution). All the other relational structures are no-instances, i.e., L X = ∅ \mathcal{L}_{\mathcal{X}} = \varnothing L X = ∅ . Consequently, P φ P_{\varphi} P φ terminates eventually. We let p φ p_{\varphi} p φ denote the value of p p p when P φ P_{\varphi} P φ terminates.
We now use p φ p_{\varphi} p φ to construct J h , φ \mathcal{J}_{h,\varphi} J h , φ . To this end, we consider every pair ( X , T X ) (\mathcal{X},T_{\mathcal{X}}) ( X , T X ) with td ( X ) ≤ h \operatorname{td}(\mathcal{X}) \le h td ( X ) ≤ h , where T X T_{\mathcal{X}} T X has height at most h + 1 h+1 h + 1 such that X p φ = X \mathcal{X}^{p_{\varphi}} = \mathcal{X} X p φ = X and X ⊭ φ \mathcal{X} \not\models\varphi X ⊨ φ . Let Q ′ \mathcal{Q}' Q ′ be the set of these structures. Consider only the members of Q ′ \mathcal{Q}' Q ′ for which every proper induced substructure is a model of φ \varphi φ (which can be checked since elements of Q ′ \mathcal{Q}' Q ′ have bounded size), choose one representative from each such isomorphism class and call the set of these representatives Q \mathcal{Q} Q . We claim that Q = J h , φ \mathcal{Q} = \mathcal{J}_{h,\varphi} Q = J h , φ (up to isomorphism).
Note that Q ⊆ J h , φ \mathcal{Q} \subseteq\mathcal{J}_{h,\varphi} Q ⊆ J h , φ holds by the definition of Q \mathcal{Q} Q . To see that also J h , φ ⊆ Q \mathcal{J}_{h,\varphi} \subseteq\mathcal{Q} J h , φ ⊆ Q holds, take an arbitrary obstruction Y ∈ J h , φ \mathcal{Y} \in\mathcal{J}_{h,\varphi} Y ∈ J h , φ and fix a corresponding treedepth decomposition T Y T_{\mathcal{Y}} T Y of height at most h + 1 h+1 h + 1 . By Definition 28 we have td ( Y ) ≤ h \operatorname{td}(\mathcal{Y}) \le h td ( Y ) ≤ h and Y ⊭ φ \mathcal{Y} \not\models\varphi Y ⊨ φ , and Y \mathcal{Y} Y is minimal under taking induced substructures; as induced substructures do not increase the treedepth, the latter means that every proper induced substructure of Y \mathcal{Y} Y is a model of φ \varphi φ . Assume Y p φ ≠ Y \mathcal{Y}^{p_{\varphi}} \ne\mathcal{Y} Y p φ = Y . Thus, Y p φ \mathcal{Y}^{p_{\varphi}} Y p φ is a proper induced substructure and by the minimality-definition of J h , φ \mathcal{J}_{h,\varphi} J h , φ , we have Y p φ ⊨ φ \mathcal{Y}^{p_{\varphi}} \models\varphi Y p φ ⊨ φ . Since P φ P_{\varphi} P φ enumerates every pair ( X , T X ) (\mathcal{X}, T_{\mathcal{X}}) ( X , T X ) as described above, it also enumerates a pair containing the structure Y p φ \mathcal{Y}^{p_{\varphi}} Y p φ . Indeed, Y p φ \mathcal{Y}^{p_{\varphi}} Y p φ matches the signature of φ \varphi φ and satisfies td ( Y p φ ) ≤ h \operatorname{td}(\mathcal{Y}^{p_{\varphi}}) \le h td ( Y p φ ) ≤ h , both because it is an induced substructure of Y \mathcal{Y} Y ; its decomposition T Y p φ T_{\mathcal{Y}^{p_{\varphi}}} T Y p φ has height at most h + 1 h+1 h + 1 by Lemma 26 (1); and ( Y p φ ) p φ = Y p φ (\mathcal{Y}^{p_{\varphi}})^{p_{\varphi}} = \mathcal{Y}^{p_{\varphi}} ( Y p φ ) p φ = Y p φ , as for s = p s=p s = p the construction in Definition 24 adds no copies and, by Lemma 26 (5), its deletion step removes no element of Y p φ \mathcal{Y}^{p_{\varphi}} Y p φ . As Y p φ ⊨ φ \mathcal{Y}^{p_{\varphi}} \models\varphi Y p φ ⊨ φ , it must have a p φ p_{\varphi} p φ -pure solution (since P φ P_{\varphi} P φ terminated) whose existence is preserved under (order- and decomposition-preserving) isomorphisms. By Theorem 6, we can use the p φ p_{\varphi} p φ -pure solution of Y p φ \mathcal{Y}^{p_{\varphi}} Y p φ together with p φ ≥ ∣ φ ∣ ( h + 1 ) p_{\varphi} \ge|\varphi|(h+1) p φ ≥ ∣ φ ∣ ( h + 1 ) to derive Y ⊨ φ \mathcal{Y} \models\varphi Y ⊨ φ , a contradiction to Y ∈ J h , φ \mathcal{Y} \in\mathcal{J}_{h,\varphi} Y ∈ J h , φ . Thus, Y p φ = Y \mathcal{Y}^{p_{\varphi}} = \mathcal{Y} Y p φ = Y and hence Y ∈ Q \mathcal{Y} \in Q Y ∈ Q up to isomorphism, since Y \mathcal{Y} Y is a minimal obstruction. Both directions allow us to conclude Q = J h , φ Q = \mathcal{J}_{h,\varphi} Q = J h , φ . Since P φ P_{\varphi} P φ terminates, we can bound its number of iterations, and thus also running time, by a computable function t φ ( h ) t_{\varphi}(h) t φ ( h ) . We can run the above procedure for every possible formula φ ′ \varphi' φ ′ of length ∣ φ ′ ∣ = ∣ φ ∣ |\varphi'| = |\varphi| ∣ φ ′ ∣ = ∣ φ ∣ . Up to logical equivalence and renaming of variables and relation symbols, the number of such formulas can be bounded by a computable function q ( ∣ φ ∣ ) q(|\varphi|) q ( ∣ φ ∣ ) and all of them can be enumerated. Thus, the function f ( h , ∣ φ ∣ ) = max φ ′ , ∣ φ ′ ∣ = ∣ φ ∣ t φ ′ ( h ) f(h,|\varphi|) = \max_{\varphi',\,|\varphi'|=|\varphi|} t_{\varphi'}(h) f ( h , ∣ φ ∣ ) = max φ ′ , ∣ φ ′ ∣ = ∣ φ ∣ t φ ′ ( h ) is computable and an upper bound on the running time of P φ P_{\varphi} P φ in terms of h h h and ∣ φ ∣ |\varphi| ∣ φ ∣ . Since ∣ X p φ ∣ ≤ g ′ ( h , p φ ) |\mathcal{X}^{p_{\varphi}}| \le g'(h,p_{\varphi}) ∣ X p φ ∣ ≤ g ′ ( h , p φ ) for some computable g ′ g' g ′ (recall Lemma 26), every obstruction has also bounded size. The value of g ( h , ∣ φ ∣ ) g(h,|\varphi|) g ( h , ∣ φ ∣ ) can be obtained by taking the maximum value of g ′ ( h , p φ ′ ) g'(h,p_{\varphi'}) g ′ ( h , p φ ′ ) over all formulas φ ′ \varphi' φ ′ of length ∣ φ ′ ∣ = ∣ φ ∣ |\varphi'|=|\varphi| ∣ φ ′ ∣ = ∣ φ ∣ , which is computable.
Observe that in terms of the elements of the obstruction set J h , φ \mathcal{J}_{h,\varphi} J h , φ , Theorem 9 only shows that their size can be bounded by a computable function in h h h and ∣ φ ∣ |\varphi| ∣ φ ∣ , but does not give an explicit bound on the value of g ( h , ∣ φ ∣ ) g(h,|\varphi|) g ( h , ∣ φ ∣ ) . Still, Theorem 9 is the last missing ingredient to establish our main theorem.
Proof of Main Theorem. We first focus on the decision variant of the main theorem and then discuss how to make the algorithm constructive and the impact this has on the running time. To this end, we use Algorithm A to solve an instance ( R , φ ) (\mathcal{R},\varphi) ( R , φ ) of SNP Model Checking. Correctness of the algorithm follows from Lemma 36, and it remains to argue its running time.
Decision Variant. For bounding the running time of the decision algorithm, we start by noting that Algorithm A has two preprocessing steps. First, it has to compute the primal graph G G G of R \mathcal{R} R ; recall Definition 10. Let R = ( V , E 1 , … , E b ) \mathcal{R} = (V,E_1,\ldots,E_b) R = ( V , E 1 , … , E b ) . The vertex set of G G G is V V V and to compute the edge set of G G G , we consider every relation E i E_i E i , i ∈ [ b ] i \in[b] i ∈ [ b ] , and its tuples u ˉ ∈ E i \bar{u} \in E_i u ˉ ∈ E i . We introduce in G G G a clique on the (distinct) elements in u ˉ \bar{u} u ˉ . It is well-known that the treedepth of K η K_\eta K η is η \eta η and treedepth does not increase when taking subgraphs. Thus, u ˉ \bar{u} u ˉ consists of at most td ( R ) \operatorname{td}(\mathcal{R}) td ( R ) distinct elements. Hence, we can scan all tuples of R \mathcal{R} R once to identify their set of pairwise distinct elements. Afterwards, introducing a clique for u ˉ \bar{u} u ˉ takes O ( td ( R ) 2 ) O(\operatorname{td}(\mathcal{R})^2) O ( td ( R ) 2 ) time. Overall, this takes O ( td ( R ) 2 ⋅ ∣ R ∣ ) O(\operatorname{td}(\mathcal{R})^2 \cdot|\mathcal{R}|) O ( td ( R ) 2 ⋅ ∣ R ∣ ) time, which is also an upper bound on the number of edges of the created primal graph G G G . In the same time, we can once more iterate over all edges of G G G and remove any multi-edges to ensure that G G G is simple.
Once we have the primal graph G G G , Algorithm A computes a treedepth decomposition T T T of G G G of height h ≤ td ( R ) + 1 h \le\operatorname{td}(\mathcal{R})+1 h ≤ td ( R ) + 1 . Using the algorithm by Reidl, Rossmanith, Sánchez Villaamil and Sikdar [86 ] , this can be done in 2 O ( td ( R ) 2 ) ⋅ ∣ V ( G ) ∣ ≤ 2 O ( td ( R ) 2 ) ⋅ ∣ R ∣ 2^{O(\operatorname{td}(\mathcal{R})^2)} \cdot|V(G)| \le2^{O(\operatorname{td}(\mathcal{R})^2)} \cdot|\mathcal{R}| 2 O ( td ( R ) 2 ) ⋅ ∣ V ( G ) ∣ ≤ 2 O ( td ( R ) 2 ) ⋅ ∣ R ∣ time. The latter upper bound is also an upper bound on the preprocessing steps of Algorithm A. Next, we analyze the running time of the iteration for one fixed p p p . First, we have to compute the p p p -multiplicity structure R p \mathcal{R}^{p} R p for p p p , T T T , and R \mathcal{R} R . To this end, we compute the vertex p p p -types and the p p p -routes of all elements of R \mathcal{R} R . By Lemma 18 , this can be done in time g 1 ( h , p , ∣ φ ∣ ) ⋅ ∣ R ∣ g_1(h,p,|\varphi|) \cdot|\mathcal{R}| g 1 ( h , p , ∣ φ ∣ ) ⋅ ∣ R ∣ for some computable function g 1 g_1 g 1 . Once we have the p p p -routes, we can compute the p p p -multiplicity structure R p \mathcal{R}^p R p by iterating once over the elements and once over the relations in R \mathcal{R} R ; recall Definition 24 . Thus, we can compute R p \mathcal{R}^p R p in time g 2 ( h , p , ∣ φ ∣ ) ⋅ ∣ R ∣ g_2(h,p,|\varphi|)\cdot|\mathcal{R}| g 2 ( h , p , ∣ φ ∣ ) ⋅ ∣ R ∣ for some computable function g 2 g_2 g 2 . The remaining steps in the iteration for p p p consist of obtaining the solution set L p \mathcal{L}^p L p and checking whether it is empty or contains a p p p -pure solution S p S^p S p . Since Lemma 26 bounds the size of R p \mathcal{R}^p R p by a computable function in h h h and p p p , we can upper bound the running time for the entire iteration by some computable function g 3 ( td ( R ) + 1 , ∣ φ ∣ , p ) ⋅ ∣ R ∣ g_3(\operatorname{td}(\mathcal{R})+1,|\varphi|,p)\cdot|\mathcal{R}| g 3 ( td ( R ) + 1 , ∣ φ ∣ , p ) ⋅ ∣ R ∣ .
By Lemma 36, Algorithm A terminates after at most max { M , ∣ φ ∣ ( td ( R ) + 1 ) } \max\{M,|\varphi|(\operatorname{td}(\mathcal{R})+1)\} max { M , ∣ φ ∣ ( td ( R ) + 1 )} iterations, where M = max ( { 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J td ( R ) + 1 , φ } ) M=\max(\{1\}\cup\{|V(H)|:H\in\mathcal{J}_{\operatorname{td}(\mathcal{R})+1,\varphi}\}) M = max ({ 1 } ∪ { ∣ V ( H ) ∣ : H ∈ J td ( R ) + 1 , φ }) is the size of the largest element in the obstruction set J td ( R ) + 1 , φ \mathcal{J}_{\operatorname{td}(\mathcal{R})+1,\varphi} J td ( R ) + 1 , φ . By Theorem 9, we can bound M M M by a computable function g 4 ( td ( R ) + 1 , ∣ φ ∣ ) g_4(\operatorname{td}(\mathcal{R})+1,|\varphi|) g 4 ( td ( R ) + 1 , ∣ φ ∣ ) . Define I = max { g 4 ( td ( R ) + 1 , ∣ φ ∣ ) , ∣ φ ∣ ( td ( R ) + 1 ) } I=\max\{g_4(\operatorname{td}(\mathcal{R})+1,|\varphi|),|\varphi|(\operatorname{td}(\mathcal{R})+1)\} I = max { g 4 ( td ( R ) + 1 , ∣ φ ∣ ) , ∣ φ ∣ ( td ( R ) + 1 )} , which is computable. Since g 3 ( td ( R ) + 1 , ∣ φ ∣ , p ) g_3(\operatorname{td}(\mathcal{R})+1,|\varphi|,p) g 3 ( td ( R ) + 1 , ∣ φ ∣ , p ) can be assumed without loss of generality to be monotonically increasing in p p p , all iterations together take at most I ⋅ g 3 ( td ( R ) + 1 , ∣ φ ∣ , I ) ⋅ ∣ R ∣ I\cdot g_3(\operatorname{td}(\mathcal{R})+1,|\varphi|,I)\cdot|\mathcal{R}| I ⋅ g 3 ( td ( R ) + 1 , ∣ φ ∣ , I ) ⋅ ∣ R ∣ time. Together with the preprocessing steps and h ≤ td ( R ) + 1 h\leq\operatorname{td}(\mathcal{R})+1 h ≤ td ( R ) + 1 , we can bound the running time of Algorithm A by f 1 ( ∣ φ ∣ , td ( R ) ) ⋅ ∣ R ∣ f_1(|\varphi|,\operatorname{td}(\mathcal{R}))\cdot|\mathcal{R}| f 1 ( ∣ φ ∣ , td ( R )) ⋅ ∣ R ∣ , where f 1 ( ∣ φ ∣ , td ( R ) ) = 2 O ( td ( R ) 2 ) + I ⋅ g 3 ( td ( R ) + 1 , ∣ φ ∣ , I ) f_1(|\varphi|,\operatorname{td}(\mathcal{R}))=2^{O(\operatorname{td}(\mathcal{R})^2)}+I\cdot g_3(\operatorname{td}(\mathcal{R})+1,|\varphi|,I) f 1 ( ∣ φ ∣ , td ( R )) = 2 O ( td ( R ) 2 ) + I ⋅ g 3 ( td ( R ) + 1 , ∣ φ ∣ , I ) is a computable function.
Constructing a Q Q Q -Solution. For the constructive part of the statement assume that R ⊨ φ \mathcal{R}\models\varphi R ⊨ φ (otherwise there is nothing to show). Algorithm A retains in this case a p p p -pure solution S p S^p S p for some p p p ; recall Case 2. Recall that Theorem 6 not only guarantees the existence of a solution R 1 ′ , … , R r ′ R'_1,\ldots,R'_r R 1 ′ , … , R r ′ for R \mathcal{R} R , but also gives us the means to compute one. To this end, for every i ∈ Q i\in Q i ∈ Q , we consider every a i a_i a i -tuple u ⃗ ∈ V ( R ) a i \vec{u}\in V(\mathcal{R})^{a_i} u ∈ V ( R ) a i , where a i = ar ( R i ) a_i=\operatorname{ar}(R_i) a i = ar ( R i ) is the arity of the relation R i R_i R i . By Theorem 6, we can decide, after an f ′ ( p ) ⋅ ∣ R ∣ f'(p)\cdot|\mathcal{R}| f ′ ( p ) ⋅ ∣ R ∣ preprocessing step, whether R i ′ ( u ⃗ ) R'_i(\vec{u}) R i ′ ( u ) holds in O ( a i h log ( a i h ) ) O(a_i h\log(a_i h)) O ( a i h log ( a i h )) time. If this is the case, we output u ⃗ \vec{u} u . Since Theorem 6 guarantees that R 1 ′ , … , R r ′ R'_1,\ldots,R'_r R 1 ′ , … , R r ′ is a solution, our output ( R i ′ ) i ∈ Q (R'_i)_{i\in Q} ( R i ′ ) i ∈ Q is a Q Q Q -solution. It remains to argue the running time. For a single i ∈ Q i\in Q i ∈ Q , this takes overall f ′ ( p ) ⋅ ∣ R ∣ + O ( ∣ R ∣ a i ⋅ a i h log ( a i h ) ) f'(p)\cdot|\mathcal{R}|+O(|\mathcal{R}|^{a_i}\cdot a_i h\log(a_i h)) f ′ ( p ) ⋅ ∣ R ∣ + O ( ∣ R ∣ a i ⋅ a i h log ( a i h )) time. Note that the preprocessing step can be done once globally instead of for every i ∈ Q i\in Q i ∈ Q individually. Let a = max i ∈ Q a i a=\max_{i\in Q}a_i a = max i ∈ Q a i be the maximum arity over all relations whose index is in Q Q Q . By the above arguments, we can upper bound the running time for the entire set Q Q Q , whose size is at most r ≤ ∣ φ ∣ r\leq|\varphi| r ≤ ∣ φ ∣ , with f ′ ( p ) ⋅ ∣ R ∣ + O ( ∣ φ ∣ ⋅ ∣ R ∣ a ⋅ a h log ( a h ) ) f'(p)\cdot|\mathcal{R}|+O(|\varphi|\cdot|\mathcal{R}|^a\cdot ah\log(ah)) f ′ ( p ) ⋅ ∣ R ∣ + O ( ∣ φ ∣ ⋅ ∣ R ∣ a ⋅ ah log ( ah )) . Recall that ∣ φ ∣ ≥ ∑ i ∈ [ r ] ar ( R i ) |\varphi|\geq\sum_{i\in[r]}\operatorname{ar}(R_i) ∣ φ ∣ ≥ ∑ i ∈ [ r ] ar ( R i ) . Thus, the above-stated running time can be upper bounded by f ′ ( p ) ⋅ ∣ R ∣ + O ( ∣ φ ∣ ⋅ ∣ R ∣ a ⋅ ∣ φ ∣ h log ( ∣ φ ∣ h ) ) f'(p)\cdot|\mathcal{R}|+O(|\varphi|\cdot|\mathcal{R}|^a\cdot|\varphi|h\log(|\varphi|h)) f ′ ( p ) ⋅ ∣ R ∣ + O ( ∣ φ ∣ ⋅ ∣ R ∣ a ⋅ ∣ φ ∣ h log ( ∣ φ ∣ h )) . As shown above, we can bound p p p by a computable function in td ( R ) + 1 \operatorname{td}(\mathcal{R})+1 td ( R ) + 1 and ∣ φ ∣ |\varphi| ∣ φ ∣ . Therefore, we can rewrite the running time bound as f 2 ( ∣ φ ∣ , td ( R ) ) ⋅ ∣ R ∣ max i ∈ Q ar ( R i ) f_2(|\varphi|,\operatorname{td}(\mathcal{R}))\cdot|\mathcal{R}|^{\max_{i\in Q}\operatorname{ar}(R_i)} f 2 ( ∣ φ ∣ , td ( R )) ⋅ ∣ R ∣ m a x i ∈ Q ar ( R i ) , where the function f 2 f_2 f 2 is a computable function that incorporates the computable functions f ′ f' f ′ and f 1 f_1 f 1 (the running time of the decision variant of Algorithm A) and the hidden constants in the O O O -notation.
We can use f = f 2 f=f_2 f = f 2 (since f 2 f_2 f 2 incorporates f 1 f_1 f 1 ) as the computable function from the theorem statement to cover both cases. □ \square □
Comparison with Kolaitis and Vardi
Let us now elaborate on the aforementioned connections to Kolaitis and Vardi [71 Section 5] . Call a solution relation canonical if its truth on a tuple depends only on the atomic type of that tuple in the input structure expanded by an auxiliary total order. A solution is canonical if each of its witness relations is canonical.
Writing k k k for the number of universally quantified variables in φ \varphi φ , [71 Theorem 11] states that if the countable random structure A \mathcal{A} A satisfies φ \varphi φ , then there is a finite ordered structure B \mathcal{B} B that realizes every ordered input type on at most k k k elements and admits a canonical solution. To show this, fix a finite structure B \mathcal{B} B (also equipped with a total order) such that each ordered atomic type on at most k k k elements appears in it. Then, Ramsey theory is used to show that there exists a large finite structure C \mathcal{C} C , such that if C ⊨ φ \mathcal{C}\models\varphi C ⊨ φ , then C \mathcal{C} C contains a copy of B \mathcal{B} B with a canonical solution. Since A \mathcal{A} A is the infinite countable random structure, A \mathcal{A} A contains a copy of C \mathcal{C} C . 13 From A ⊨ φ \mathcal{A} \models\varphi A ⊨ φ one can then deduce C ⊨ φ \mathcal{C} \models\varphi C ⊨ φ , and hence obtains that B \mathcal{B} B has a canonical solution. Conversely, equip A \mathcal{A} A with an auxiliary total order. For each k k k -tuple v ˉ \bar{v} v ˉ of A \mathcal{A} A , choose a k k k -tuple w ˉ \bar{w} w ˉ of B \mathcal{B} B with the same ordered atomic input type, and prescribe the solution type of v ˉ \bar{v} v ˉ to match that of w ˉ \bar{w} w ˉ . Canonicity ensures that these prescriptions are independent of the chosen representatives and consistent on shared subtuples, yielding a solution on A \mathcal{A} A . Decidability follows from the fact that B \mathcal{B} B can be constructed effectively, and that it can be checked if B \mathcal{B} B has a canonical solution.
Recall that in the problem studied by Kolaitis and Vardi, they are only given an SNP sentence φ \varphi φ and want to decide whether φ \varphi φ holds on every relational structure. The problem we are dealing with asks whether R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ holds for a given relational structure R \mathcal{R} R . In particular, we cannot construct an arbitrary structure B \mathcal{B} B with a canonical solution but have to take R \mathcal{R} R into account.
Consequently, a first key difference of their approach compared to ours concerns the information recorded by types. Ordered atomic input types suffice in the argument of Kolaitis and Vardi, but they are completely insufficient in our setting. For example, consider K 2 K_2 K 2 on { u , v } \{u,v\} { u , v } with φ 2 \varphi_2 φ 2 being the standard SNP encoding of 2-colorability using two unary relations. Obviously K 2 ⊨ φ 2 K_2 \models\varphi_2 K 2 ⊨ φ 2 . The singleton tuples ( u ) (u) ( u ) and ( v ) (v) ( v ) have the same atomic input type even after adding a linear order. A canonical solution would therefore assign them the same color, so no such solution exists for this encoding. Hence, even in this simple case, the existence theorem (Theorem 8) cannot hold when using canonical solutions instead of pure solutions.
A second difference concerns the availability of a suitable structure on which to apply Ramsey arguments. In their setting, A \mathcal{A} A contains C \mathcal{C} C simply because A \mathcal{A} A contains every finite input structure. Hence, a solution on A \mathcal{A} A restricts to one on C \mathcal{C} C . In our setting, we must establish that R s ⊨ φ \mathcal{R}^s \models\varphi R s ⊨ φ whenever R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ . For s ≥ p ≥ M s \ge p \ge M s ≥ p ≥ M , this follows from Lemma 7 and relies on the well-quasi-ordering of structures of bounded treedepth. Moreover, we implement the Ramsey step on a common integer index set and not on the relational structure R s \mathcal{R}^s R s directly. There, tuples of vertices of R \mathcal{R} R having a fixed p p p -route pattern are encoded by integer subsets of specific sizes. This encoding allows us to use ordinary hypergraph Ramsey while retaining the prescribed structure.
Finally, our algorithm must decide R ⊨ φ \mathcal{R} \models\varphi R ⊨ φ uniformly over pairs ( φ , R ) (\varphi,\mathcal{R}) ( φ , R ) , with a computable parameter dependence on the formula length and treedepth. It searches for a negative certificate or a p p p -pure solution without constructing the large Ramsey structure or knowing M M M in advance. Theorem 9 supplies the computable bound on this search, and Theorem 6 reconstructs witnesses on the input domain.
Applying the Metatheorem
In this section we illustrate the reach of Theorem 1 by applying it to several graph parameters whose exact computation is NP-hard already for small fixed values: stack number, queue number, track number, twin-width, and boxicity. For each we show that the property “the parameter is at most k k k ” is definable by an SNP sentence whose length is bounded by a function of k k k . Since all five parameters are bounded in terms of treewidth, a well-studied width parameter that is in turn bounded by treedepth [77 ] , the meta-theorem yields fixed-parameter algorithms for their exact computation with respect to treedepth; we first record this reduction once, in a generic form, and then instantiate it after each encoding. The tractability with respect to treedepth was, to our knowledge, previously unknown for all five problems.
Lemma 37. Let π \pi π be a graph parameter and let g 1 , g 2 g_1,g_2 g 1 , g 2 be computable, non-decreasing functions. Suppose that for every k ∈ N k \in\mathbb{N} k ∈ N there is an SNP sentence Φ k \Phi_k Φ k of arity at most a a a , computable from k k k ,
with ∣ Φ k ∣ ≤ g 1 ( k ) |\Phi_k| \le g_1(k) ∣ Φ k ∣ ≤ g 1 ( k ) and G ⊨ Φ k ⟺ π ( G ) ≤ k G \models\Phi_k \Longleftrightarrow\pi(G) \le k G ⊨ Φ k ⟺ π ( G ) ≤ k for every graph G G G , and that π ( G ) ≤ g 2 ( td ( G ) ) \pi(G) \le g_2(\operatorname{td}(G)) π ( G ) ≤ g 2 ( td ( G )) for every graph G G G . Then, given G G G and k k k , deciding π ( G ) ≤ k \pi(G) \le k π ( G ) ≤ k takes time f ′ ( td ( G ) ) ⋅ ∣ G ∣ f'(\operatorname{td}(G)) \cdot|G| f ′ ( td ( G )) ⋅ ∣ G ∣ for a computable function f ′ f' f ′ ; π ( G ) \pi(G) π ( G ) can be computed within the same time bound.
Proof. We regard G G G as the relational structure ( V , E ) (V,E) ( V , E ) ; its Gaifman graph is G G G , so its treedepth is td ( G ) \operatorname{td}(G) td ( G ) . We compute t : = td ( G ) t := \operatorname{td}(G) t := td ( G ) in FPT time [86 ] . If k ≥ g 2 ( t ) k \ge g_2(t) k ≥ g 2 ( t ) , then π ( G ) ≤ g 2 ( t ) ≤ k \pi(G) \le g_2(t) \le k π ( G ) ≤ g 2 ( t ) ≤ k by assumption, and we answer yes. Otherwise k < g 2 ( t ) k < g_2(t) k < g 2 ( t ) , so ∣ Φ k ∣ ≤ g 1 ( k ) ≤ g 1 ( g 2 ( t ) ) |\Phi_k| \le g_1(k) \le g_1(g_2(t)) ∣ Φ k ∣ ≤ g 1 ( k ) ≤ g 1 ( g 2 ( t )) , and running A from Theorem 1 on Φ k \Phi_k Φ k and G G G decides π ( G ) ≤ k \pi(G) \le k π ( G ) ≤ k in time f ( g 1 ( g 2 ( t ) ) , t ) ⋅ ∣ G ∣ f(g_1(g_2(t)),t) \cdot|G| f ( g 1 ( g 2 ( t )) , t ) ⋅ ∣ G ∣ . Since k ↦ Φ k k \mapsto\Phi_k k ↦ Φ k is computable, the number of steps needed to compute Φ k \Phi_k Φ k is a computable function T ( k ) T(k) T ( k ) , and T ( k ) ≤ max k ′ ≤ g 2 ( t ) T ( k ′ ) T(k) \le\max_{k' \le g_2(t)} T(k') T ( k ) ≤ max k ′ ≤ g 2 ( t ) T ( k ′ ) is bounded by a computable function of t t t because k < g 2 ( t ) k < g_2(t) k < g 2 ( t ) . To compute π ( G ) \pi(G) π ( G ) , run the above for the smallest value that π ( G ) \pi(G) π ( G ) can possibly take and iterate with increasingly bigger k k k until g 2 ( t ) g_2(t) g 2 ( t ) is reached; return the least k k k that is accepted.
The brief complexity-theoretic overviews that complement the following subsections use standard notions of classical and parameterized complexity as well as standard structural graph parameters that play no role in our proofs; we do not define them here and refer the reader to the textbooks [39 ] , [31 ] and [37 ] instead.
Stack and Queue Layouts
A linear layout of a graph G = ( V , E ) G = (V,E) G = ( V , E ) consists of a total order < < < on V V V together with a partition of E E E into k k k pages E 1 , … , E k E_1,\ldots,E_k E 1 , … , E k , for some k ∈ N k \in\mathbb{N} k ∈ N , and one typically requires that the edges on each page satisfy a certain condition. The two classical and by-far most studied linear layouts are stack and queue layouts [19 , 66 , 44 ] ; see also Figure 2 for an illustration.
Figure 2. (a) A graph G G G , (b) a 2-page stack layout, and (c) a 2-page queue layout of G G G , both on the same linear order < < < . The two pages are colored blue and purple, respectively.
Definition 38 (Stack and queue layout). Let G = ( V , E ) G = (V,E) G = ( V , E ) be a graph and let ( < , E 1 , … , E k ) (<,E_1,\ldots,E_k) ( < , E 1 , … , E k ) be a k k k -page linear layout of G G G for some k ∈ N k \in\mathbb{N} k ∈ N . Let a b , c d ∈ E ab,cd \in E ab , c d ∈ E be two edges with a < b a < b a < b and c < d c < d c < d , and assume by symmetry that a < c a < c a < c . They cross if c < b < d c < b < d c < b < d , and they nest if c < d < b c < d < b c < d < b . We call ( < , E 1 , … , E k ) (<,E_1,\ldots,E_k) ( < , E 1 , … , E k ) a k k k -page stack layout if no two edges on the same page cross and a k k k -page queue layout if no two edges on the same page nest.
Stack and queue layouts give rise to the notions of stack and queue number of a graph:
Definition 39 (Stack and queue number). Let G = ( V , E ) G = (V,E) G = ( V , E ) be a graph. The stack number sn ( G ) \operatorname{sn}(G) sn ( G ) of G G G is the least k k k such that G G G admits a k k k -page stack layout, and the queue number qn ( G ) \operatorname{qn}(G) qn ( G ) of G G G is the least k k k such that G G G admits a k k k -page queue layout.
The relation between structural properties of a graph G G G and its stack or queue number has been studied extensively in the past, and we refer to the survey of Dujmović and Wood [44 ] for an overview. Most notably, planar graphs have stack number at most 4 [94 ] and queue number at most 49 [41 ] , and the upper bound for the stack number is tight [20 ] . Moreover, sn ( G ) ≤ tw ( G ) + 1 \operatorname{sn}(G) \le\operatorname{tw}(G) + 1 sn ( G ) ≤ tw ( G ) + 1 [46 ] and qn ( G ) ≤ 2 tw ( G ) − 1 \operatorname{qn}(G) \le2^{\operatorname{tw}(G)} - 1 qn ( G ) ≤ 2 tw ( G ) − 1 [91 ] hold for every graph G G G , where tw ( G ) \operatorname{tw}(G) tw ( G ) denotes the treewidth of $G.`
Already deciding whether sn ( G ) ≤ 2 \operatorname{sn}(G) \le2 sn ( G ) ≤ 2 or qn ( G ) ≤ 1 \operatorname{qn}(G) \le1 qn ( G ) ≤ 1 is NP-complete [92 , 19 , 66 ] , which has motivated studying the complexity of deciding whether sn ( G ) ≤ k \operatorname{sn}(G) \le k sn ( G ) ≤ k or qn ( G ) ≤ k \operatorname{qn}(G) \le k qn ( G ) ≤ k with respect to structural parameters of G G G . When k k k is part of the input, both problems were shown to be FPT with respect to the vertex cover number of G G G [14 , 15 ] . More recently, this was extended to vertex integrity [38 ] . For stack number, Ganian, Müller, Ordyniak, Paesani, and Rychlicki [63 ] also obtain an FPT algorithm parameterized by the feedback edge number. For treedepth and treewidth, earlier fixed-parameter algorithms only handle special cases. In particular, deciding qn ( G ) ≤ 1 \operatorname{qn}(G) \le1 qn ( G ) ≤ 1 is FPT in td ( G ) \operatorname{td}(G) td ( G ) [15 ] . Bannister and Eppstein [10 ] showed that deciding sn ( G ) ≤ 2 \operatorname{sn}(G) \le2 sn ( G ) ≤ 2 is FPT in tw ( G ) \operatorname{tw}(G) tw ( G ) using Courcelle’s theorem, which was later improved to an algorithm with single-exponential dependence on tw ( G ) \operatorname{tw}(G) tw ( G ) [63 ] . Whether the general problems are FPT with respect to less restrictive parameters, in particular treedepth or treewidth, has repeatedly been posed as an open question [62 , 26 , 63 , 38 ] . Recently, it was shown that deciding qn ( G ) ≤ 1 \operatorname{qn}(G) \le1 qn ( G ) ≤ 1 is paraNP-hard with respect to the pathwidth of G G G [9 ] , ruling out the existence of an FPT and even XP algorithm with respect to the pathwidth (and thus treewidth) of G G G (unless P = NP). For treedepth, we answer this open question in the affirmative for both stack and queue number. To this end, we provide SNP sentences for both problems:
Theorem 40. For every k ≥ 1 k \ge1 k ≥ 1 there are SNP sentences Φ k s t \Phi^{\mathrm{st}}_k Φ k st and Φ k q u \Phi^{\mathrm{qu}}_k Φ k qu such that for every finite graph G G G ,
G ⊨ Φ k s t ⟺ sn ( G ) ≤ k and G ⊨ Φ k q u ⟺ qn ( G ) ≤ k . G \models\Phi^{\mathrm{st}}_k \Longleftrightarrow\operatorname{sn}(G) \le k \qquad\text{and}\qquad G \models\Phi^{\mathrm{qu}}_k \Longleftrightarrow\operatorname{qn}(G) \le k. G ⊨ Φ k st ⟺ sn ( G ) ≤ k and G ⊨ Φ k qu ⟺ qn ( G ) ≤ k . Moreover, Φ k s t \Phi^{\mathrm{st}}_k Φ k st (Φ k q u \Phi^{\mathrm{qu}}_k Φ k qu , respectively) has k + 1 k+1 k + 1 existentially quantified relation symbols, all of arity 2 2 2 , four first-order variables, and length O ( k ) O(k) O ( k ) ; the map k ↦ Φ k s t k \mapsto\Phi^{\mathrm{st}}_k k ↦ Φ k st (k ↦ Φ k q u k \mapsto\Phi^{\mathrm{qu}}_k k ↦ Φ k qu , respectively) is computable in time polynomial in k k k .
Proof. The SNP sentences. Both sentences existentially quantify over a binary relation L L L and k k k binary relations P 1 , … , P k P_1,\ldots,P_k P 1 , … , P k . The intended interpretation is that L L L is the total order, written u < v u < v u < v for L ( u , v ) L(u,v) L ( u , v ) , and P j ( u , v ) P_j(u,v) P j ( u , v ) says that the edge u v uv uv lies on page j j j . First, we ensure that L L L is a total order via
(O1) ¬ L ( u , u ) , (O2) L ( u , v ) ∧ L ( v , x ) → L ( u , x ) , and (O3) L ( u , v ) ∨ L ( v , u ) ∨ u = v . \text{(O1) }\neg L(u,u), \qquad\text{(O2) }L(u,v) \land L(v,x) \to L(u,x), \qquad\text{and}\qquad\text{(O3) }L(u,v) \lor L(v,u) \lor u=v. (O1) ¬ L ( u , u ) , (O2) L ( u , v ) ∧ L ( v , x ) → L ( u , x ) , and (O3) L ( u , v ) ∨ L ( v , u ) ∨ u = v .
The next set of conditions ensures that pages cover exactly the edges of G G G . For all j ∈ { 1 , … , k } j \in\{1,\ldots,k\} j ∈ { 1 , … , k } ,
(P1) P j ( u , v ) → E ( u , v ) and P j ( u , v ) → P j ( v , u ) , \text{(P1) }\ P_j(u,v) \to E(u,v) \qquad\text{and}\qquad P_j(u,v) \to P_j(v,u), (P1) P j ( u , v ) → E ( u , v ) and P j ( u , v ) → P j ( v , u ) ,
(P2) E ( u , v ) → P 1 ( u , v ) ∨ ⋯ ∨ P k ( u , v ) . \text{(P2) }\ E(u,v) \to P_1(u,v) \lor\cdots\lor P_k(u,v). (P2) E ( u , v ) → P 1 ( u , v ) ∨ ⋯ ∨ P k ( u , v ) .
Note that the latter does not require the pages to be disjoint: an edge may lie on several pages. Although this deviates from the definition of layouts given above, it is harmless in terms of determining the stack and queue number of a graph. With our last set of constraints, we enforce a stack or queue layout, respectively by adding the following constraints for each j ∈ { 1 , … , k } j \in\{1,\ldots,k\} j ∈ { 1 , … , k } . Observe that in both cases, the layout condition is expressed via a simple forbidden pattern characterization on four vertices.
(S1) ¬ ( L ( u , x ) ∧ L ( x , v ) ∧ L ( v , y ) ∧ P j ( u , v ) ∧ P j ( x , y ) ) (no crossing within a page) \text{(S1) }\neg\bigl(L(u,x) \land L(x,v) \land L(v,y) \land P_j(u,v) \land P_j(x,y)\bigr)\quad\text{(no crossing within a page)} (S1) ¬ ( L ( u , x ) ∧ L ( x , v ) ∧ L ( v , y ) ∧ P j ( u , v ) ∧ P j ( x , y ) ) (no crossing within a page)
(Q1) ¬ ( L ( u , x ) ∧ L ( x , y ) ∧ L ( y , v ) ∧ P j ( u , v ) ∧ P j ( x , y ) ) (no nesting within a page) \text{(Q1) }\neg\bigl(L(u,x) \land L(x,y) \land L(y,v) \land P_j(u,v) \land P_j(x,y)\bigr)\quad\text{(no nesting within a page)} (Q1) ¬ ( L ( u , x ) ∧ L ( x , y ) ∧ L ( y , v ) ∧ P j ( u , v ) ∧ P j ( x , y ) ) (no nesting within a page)
Let ∀ z ⃗ ψ k s t \forall\vec{z}\,\psi^{\mathrm{st}}_k ∀ z ψ k st be the conjunction of the universal closures of (O1)–(P2) and (S1), and ∀ z ⃗ ψ k q u \forall\vec{z}\,\psi^{\mathrm{qu}}_k ∀ z ψ k qu that of (O1)–(P2) and (Q1), for all j j j and with z ⃗ = ( u , v , x , y ) \vec{z}=(u,v,x,y) z = ( u , v , x , y ) . Then
Φ k s t = ∃ L ∃ P 1 ⋯ ∃ P k ∀ z ⃗ ψ k s t and Φ k q u = ∃ L ∃ P 1 ⋯ ∃ P k ∀ z ⃗ ψ k q u . \Phi^{\mathrm{st}}_k = \exists L\,\exists P_1\cdots\exists P_k\,\forall\vec{z}\,\psi^{\mathrm{st}}_k
\qquad\text{and}\qquad
\Phi^{\mathrm{qu}}_k = \exists L\,\exists P_1\cdots\exists P_k\,\forall\vec{z}\,\psi^{\mathrm{qu}}_k. Φ k st = ∃ L ∃ P 1 ⋯ ∃ P k ∀ z ψ k st and Φ k qu = ∃ L ∃ P 1 ⋯ ∃ P k ∀ z ψ k qu .
For each j j j , the conditions (O1)–(P1) and (S1) (respectively (Q1)) have constant length and (P2) consists of k + 1 k+1 k + 1 atoms; hence Φ k s t \Phi_k^{\mathrm{st}} Φ k st and Φ k q u \Phi_k^{\mathrm{qu}} Φ k qu have length O ( k ) O(k) O ( k ) and four first-order variables, and each can be written down in time polynomial in k k k .
Correctness. We demonstrate the correctness w.r.t. the stack number; the argument for the queue number is identical with “cross” replaced by “nest” and (S1) by (Q1).
( ⇐ ) (\Leftarrow) ( ⇐ ) Let sn ( G ) ≤ k \operatorname{sn}(G) \le k sn ( G ) ≤ k and fix a k k k -page stack layout ( < , E 1 , … , E k ) (<, E_1,\ldots,E_k) ( < , E 1 , … , E k ) of G G G . Interpret L L L as < < < and P j P_j P j as { ( u , v ) : u v ∈ E j } \{(u,v):uv \in E_j\} {( u , v ) : uv ∈ E j } . Clauses (O1)–(O3) hold because < < < is a total order; (P1) because E j ⊆ E E_j \subseteq E E j ⊆ E and edges are unordered pairs; (P2) because E 1 ∪ ⋯ ∪ E k = E E_1 \cup\cdots\cup E_k = E E 1 ∪ ⋯ ∪ E k = E . For (S1), suppose u < x < v < y u < x < v < y u < x < v < y with P j ( u , v ) P_j(u,v) P j ( u , v ) and P j ( x , y ) P_j(x,y) P j ( x , y ) . Then u v , x y ∈ E j uv,xy \in E_j uv , x y ∈ E j and they cross in < < < , contradicting the definition of a stack layout. Hence, G ⊨ Φ k s t G \models\Phi_k^{\mathrm{st}} G ⊨ Φ k st .
( ⇒ ) (\Rightarrow) ( ⇒ ) Let ( V , E , L , P 1 , … , P k ) ⊨ ∀ z ⃗ ψ k s t (V,E,L,P_1,\ldots,P_k) \models\forall\vec{z}\,\psi^{\mathrm{st}}_k ( V , E , L , P 1 , … , P k ) ⊨ ∀ z ψ k st . By (O1)–(O3), L L L is a strict linear order on V V V . By (P1), each P j P_j P j is a symmetric relation contained in E E E , so F j : = { u v : P j ( u , v ) } F_j := \{uv:P_j(u,v)\} F j := { uv : P j ( u , v )} is a set of edges of G G G , and by (P2) every edge of G G G lies in some F j F_j F j . Choose for every edge e e e an index j ( e ) j(e) j ( e ) with e ∈ F j ( e ) e \in F_{j(e)} e ∈ F j ( e ) and put E j : = { e : j ( e ) = j } E_j := \{e:j(e)=j\} E j := { e : j ( e ) = j } ; then E 1 , … , E k E_1,\ldots,E_k E 1 , … , E k is a partition of E E E with E j ⊆ F j E_j \subseteq F_j E j ⊆ F j . It remains to check that no two edges on a common page E j E_j E j cross. Suppose there exist u v , x y ∈ E j uv,xy \in E_j uv , x y ∈ E j with u < v u < v u < v and x < y x < y x < y that cross in < < < . Then, by Definition 38, w.l.o.g. u < x < v < y u < x < v < y u < x < v < y . Since u < x < v < y u < x < v < y u < x < v < y means L ( u , x ) L(u,x) L ( u , x ) , L ( x , v ) L(x,v) L ( x , v ) , and L ( v , y ) L(v,y) L ( v , y ) , and since E j ⊆ F j E_j \subseteq F_j E j ⊆ F j yields P j ( u , v ) P_j(u,v) P j ( u , v ) and P j ( x , y ) P_j(x,y) P j ( x , y ) , condition (S1) is falsified by ( u , v , x , y ) (u,v,x,y) ( u , v , x , y ) —a contradiction. Thus ( < , E 1 , … , E k ) (<,E_1,\ldots,E_k) ( < , E 1 , … , E k ) is a k k k -page stack layout and sn ( G ) ≤ k \operatorname{sn}(G) \le k sn ( G ) ≤ k .
Corollary 41. Given a graph G G G and k ∈ N k \in\mathbb{N} k ∈ N , deciding sn ( G ) ≤ k \operatorname{sn}(G) \le k sn ( G ) ≤ k (qn ( G ) ≤ k \operatorname{qn}(G) \le k qn ( G ) ≤ k , respectively) is fixed-parameter tractable with respect to td ( G ) \operatorname{td}(G) td ( G ) . Moreover, sn ( G ) \operatorname{sn}(G) sn ( G ) and qn ( G ) \operatorname{qn}(G) qn ( G ) can be computed in time f ( td ( G ) ) ⋅ ∣ G ∣ f(\operatorname{td}(G)) \cdot|G| f ( td ( G )) ⋅ ∣ G ∣ for a computable function f f f .
Proof. By Theorem 40, Φ k \Phi_k Φ k has length O ( k ) O(k) O ( k ) and is computable from k k k ; moreover, it is known that sn ( G ) ≤ tw ( G ) + 1 \operatorname{sn}(G) \le\operatorname{tw}(G)+1 sn ( G ) ≤ tw ( G ) + 1 [56 ] , hence sn ( G ) ≤ td ( G ) \operatorname{sn}(G) \le\operatorname{td}(G) sn ( G ) ≤ td ( G ) and that qn ( G ) ≤ 2 tw ( G ) − 1 \operatorname{qn}(G) \le2^{\operatorname{tw}(G)}-1 qn ( G ) ≤ 2 tw ( G ) − 1 [91 ] , hence qn ( G ) ≤ 2 td ( G ) − 1 − 1 \operatorname{qn}(G) \le2^{\operatorname{td}(G)-1}-1 qn ( G ) ≤ 2 td ( G ) − 1 − 1 . The statement then immediately follows from Lemma 37.
Track Layouts
Track layouts were introduced by Dujmović, Morin, and Wood [42 ] , building on the notion of a layered drawing : the vertices are arranged on a bounded number of parallel lines, the tracks , each carrying a linear order, and one asks how many tracks are needed so that the edges between any two tracks can be drawn without crossings. See also [43 ] for a systematic study of track layouts.
Definition 42 (Track layouts, track number). Let t ≥ 1 t \ge1 t ≥ 1 . A t t t -track layout of G G G consists of a partition V = T 1 ∪ ⋯ ∪ T t V = T_1 \cup\cdots\cup T_t V = T 1 ∪ ⋯ ∪ T t of the vertex set into independent sets, the tracks, together with a strict linear order < i <_{i} < i on each track T i T_i T i , such that no two edges form an X-crossing, that is, there are no i ≠ j i \ne j i = j and edges u v , x y uv, xy uv , x y with u , x ∈ T i u, x \in T_i u , x ∈ T i , v , y ∈ T j v, y \in T_j v , y ∈ T j , u < i x u <_{i} x u < i x and y < j v y <_{j} v y < j v . The track number tn ( G ) \operatorname{tn}(G) tn ( G ) is the least t t t such that G G G has a t t t -track layout.
Equivalently, draw the tracks as parallel horizontal lines with the vertices placed along them in the given orders; then the layout condition says that the edges between any two tracks, drawn as straight segments, are pairwise non-crossing. Since tracks are independent sets, every edge runs between two different tracks; see Figure 3 for a small example.
Figure 3. (a) A graph G G G with track number 4. (b) A 4-track layout of G G G : the vertices are partitioned into four tracks T 1 , … , T 4 T_1,\ldots,T_4 T 1 , … , T 4 , each drawn as a horizontal band and ordered from left to right. No two edges u v uv uv and x y xy x y between the same pair of tracks form an X-crossing, i.e., there are no such edges with u < x u < x u < x on one track and y < v y < v y < v on the other.
Deciding whether tn ( G ) ≤ 2 \operatorname{tn}(G) \le2 tn ( G ) ≤ 2 is easy, since the graphs of track number at most 2 are exactly the caterpillar forests [43 ] . However, already the next value is hard: Bannister, Devanny, Dujmović, Eppstein, and Wood [8 ] show that a graph is leveled planar if and only if it is bipartite and admits a 3-track layout; since recognizing the former is NP-complete [66 ] , so is deciding tn ( G ) ≤ 3 \operatorname{tn}(G) \le3 tn ( G ) ≤ 3 , which settles a question left open by Dujmović, Pór, and Wood [43 ] .
On the parameterized side, the same authors show by a Myhill–Nerode-type argument that leveled planarity is not finite-state with respect to treewidth, so that Courcelle’s theorem and, more generally, dynamic programming over tree decompositions with a bounded number of states are not applicable [8 Sect. 5.1] ; as finite-state properties are closed under intersection and bipartiteness is finite-state, the same holds for deciding tn ( G ) ≤ 3 \operatorname{tn}(G) \le3 tn ( G ) ≤ 3 . Whether track number is fixed-parameter tractable with respect to treewidth by other means remains open. With respect to treedepth they obtain fixed-parameter tractability only non-uniformly, via the well-quasi-ordering of graphs of bounded treedepth under induced subgraphs [40 ] : for each value of the treedepth an algorithm exists, but it is not known how to compute it. Corollary 44 below replaces this existential statement by a single, explicitly given algorithm that also outputs a track layout.
Theorem 43. For every t ≥ 1 t \ge1 t ≥ 1 there is an SNP sentence Φ t t r \Phi^{\mathrm{tr}}_{t} Φ t tr such that for every finite graph G G G ,
G ⊨ Φ t r t ⟺ tn ( G ) ≤ t . G \models\Phi^{\mathrm{tr}_{t}} \Longleftrightarrow\operatorname{tn}(G) \le t. G ⊨ Φ tr t ⟺ tn ( G ) ≤ t . Moreover, Φ t t r \Phi^{\mathrm{tr}}_{t} Φ t tr has t + 1 t+1 t + 1 existentially quantified relation symbols, of arity at most 2, four first-order variables, and length O ( t 2 ) O(t^2) O ( t 2 ) ; the map t ↦ Φ t t r t \mapsto\Phi^{\mathrm{tr}}_{t} t ↦ Φ t tr is computable in time polynomial in t t t .
Proof. We treat a t t t -track layout as a coloring of the vertices with t t t colors together with a linear order on each color class. As for stack and queue layouts, the layout condition is a forbidden pattern on four vertices.
The SNP sentence. Φ t t r \Phi^{\mathrm{tr}}_{t} Φ t tr existentially quantifies over unary relations T 1 , … , T t T_1,\ldots,T_t T 1 , … , T t and a binary relation L L L . The intended interpretation is that T i T_i T i is the i i i -th track and that L ( u , v ) L(u,v) L ( u , v ) holds if u u u and v v v lie on a common track and u u u precedes v v v on it. We impose the following conditions, for all i , j ∈ { 1 , … , t } i,j \in\{1,\ldots,t\} i , j ∈ { 1 , … , t } with i ≠ j i \ne j i = j .
The first set of conditions ensures that the tracks partition V V V into independent sets.
(T1) T 1 ( u ) ∨ ⋯ ∨ T t ( u ) T_1(u) \lor\cdots\lor T_t(u) T 1 ( u ) ∨ ⋯ ∨ T t ( u ) , (T2) ¬ ( T i ( u ) ∧ T j ( u ) ) \neg(T_i(u) \land T_j(u)) ¬ ( T i ( u ) ∧ T j ( u )) , (T3) ¬ ( T i ( u ) ∧ T i ( v ) ∧ E ( u , v ) ) \neg(T_i(u) \land T_i(v) \land E(u,v)) ¬ ( T i ( u ) ∧ T i ( v ) ∧ E ( u , v ))
Next, we enforce L L L to be a strict linear order on each track.
(O1) ¬ L ( u , u ) \neg L(u,u) ¬ L ( u , u ) .
(O2) L ( u , v ) ∧ L ( v , w ) → L ( u , w ) L(u,v) \land L(v,w) \to L(u,w) L ( u , v ) ∧ L ( v , w ) → L ( u , w ) .
(O3) T i ( u ) ∧ T i ( v ) → u = v ∨ L ( u , v ) ∨ L ( v , u ) T_i(u) \land T_i(v) \to u = v \lor L(u,v) \lor L(v,u) T i ( u ) ∧ T i ( v ) → u = v ∨ L ( u , v ) ∨ L ( v , u ) . Finally, we forbid X-crossings between two distinct tracks.
(X1) ¬ ( T i ( u ) ∧ T i ( x ) ∧ T j ( v ) ∧ T j ( y ) ∧ E ( u , v ) ∧ E ( x , y ) ∧ L ( u , x ) ∧ L ( y , v ) ) \neg(T_i(u) \land T_i(x) \land T_j(v) \land T_j(y) \land E(u,v) \land E(x,y) \land L(u,x) \land L(y,v)) ¬ ( T i ( u ) ∧ T i ( x ) ∧ T j ( v ) ∧ T j ( y ) ∧ E ( u , v ) ∧ E ( x , y ) ∧ L ( u , x ) ∧ L ( y , v )) .
Let ∀ z ψ t t r \forall z\ \psi_t^{\mathrm{tr}} ∀ z ψ t tr be the conjunction of the universal closures of (T1)–(X1) over all admissible i , j i,j i , j . We define Φ t t r : = ∃ T 1 ⋯ ∃ T t ∃ L ∀ z ψ t t r \Phi_t^{\mathrm{tr}} := \exists T_1 \cdots\exists T_t \exists L\ \forall z\ \psi_t^{\mathrm{tr}} Φ t tr := ∃ T 1 ⋯ ∃ T t ∃ L ∀ z ψ t tr . Condition (T1) has t t t atoms and there are O ( t 2 ) O(t^2) O ( t 2 ) conditions of type (T2) and (X1), each of constant length; hence ∣ Φ t t r ∣ = O ( t 2 ) |\Phi_t^{\mathrm{tr}}| = O(t^2) ∣ Φ t tr ∣ = O ( t 2 ) , every condition has at most four variables, and Φ t t r \Phi_t^{\mathrm{tr}} Φ t tr can be written down in time polynomial in t t t .
Note that L L L is only constrained on pairs of vertices from a common track; its behavior on other pairs is irrelevant, as (X1) only inspects L L L on such pairs. In (X1), the atoms T i ( u ) T_i(u) T i ( u ) , T i ( x ) T_i(x) T i ( x ) , T j ( v ) T_j(v) T j ( v ) , and T j ( y ) T_j(y) T j ( y ) with i ≠ j i \ne j i = j , together with (T2) and (O1), force u , x u,x u , x to be distinct vertices of track i i i and v , y v,y v , y distinct vertices of track j j j , so the negated conjunction describes exactly an X-crossing of u v uv uv and x y xy x y in the sense of Definition 42.
Correctness. ( ⇐ ) (\Leftarrow) ( ⇐ ) Let tn ( G ) ≤ t \operatorname{tn}(G) \le t tn ( G ) ≤ t and fix a t t t -track layout ( T 1 , … , T t ; < 1 , … , < t ) (T_1,\ldots,T_t; <_1,\ldots,<_{t}) ( T 1 , … , T t ; < 1 , … , < t ) . Interpret T i T_i T i as T i T_i T i and L L L as ⋃ i < i \bigcup_i <_i ⋃ i < i , i.e. L ( u , v ) L(u,v) L ( u , v ) iff u , v ∈ T i u,v \in T_i u , v ∈ T i and u < i v u <_i v u < i v for some i i i . Then (T1) and (T2) hold because the tracks partition V V V , and (T3) because they are independent sets. (O1) holds because each < i <_i < i is irreflexive; (O2) because L ( u , v ) ∧ L ( v , w ) L(u,v) \land L(v,w) L ( u , v ) ∧ L ( v , w ) places u , v , w u,v,w u , v , w on one track T i T_i T i (tracks are disjoint), where < i <_i < i is transitive; and (O3) because < i <_i < i is total on T i T_i T i . Finally, if the conjunction in (X1) held for some u , x ∈ T i u,x \in T_i u , x ∈ T i , v , y ∈ T j v,y \in T_j v , y ∈ T j , then u v , x y ∈ E uv,xy \in E uv , x y ∈ E with u < i x u <_i x u < i x and y < j v y <_j v y < j v would be an X-crossing, contradicting the definition of a track layout. Hence G ⊨ Φ t t r G \models\Phi_t^{\mathrm{tr}} G ⊨ Φ t tr .
( ⇒ ) (\Rightarrow) ( ⇒ ) Let ( V , E , T 1 , … , T t , L ) ⊨ ∀ z ψ t t r (V,E,T_1,\ldots,T_t,L) \models\forall z\ \psi_t^{\mathrm{tr}} ( V , E , T 1 , … , T t , L ) ⊨ ∀ z ψ t tr . By (T1) and (T2), T i : = { u : T i ( u ) } T_i := \{u : T_i(u)\} T i := { u : T i ( u )} for i = 1 , … , t i = 1,\ldots,t i = 1 , … , t is a partition of V V V , and by (T3), each T i T_i T i is an independent set. Let < i <_i < i be the restriction of L L L to T i T_i T i . By (O1) and (O2), it is irreflexive and transitive, and by (O3) it is total on T i T_i T i ; hence < i <_i < i is a strict linear order on T i T_i T i . It remains to exclude X-crossings. Suppose i ≠ j i \ne j i = j and edges u v , x y uv,xy uv , x y with u , x ∈ T i u,x \in T_i u , x ∈ T i , v , y ∈ T j v,y \in T_j v , y ∈ T j , u < i x u <_i x u < i x and y < j v y <_j v y < j v existed. Then T i ( u ) T_i(u) T i ( u ) , T i ( x ) T_i(x) T i ( x ) , T j ( v ) T_j(v) T j ( v ) , T j ( y ) T_j(y) T j ( y ) , E ( u , v ) E(u,v) E ( u , v ) , E ( x , y ) E(x,y) E ( x , y ) , L ( u , x ) L(u,x) L ( u , x ) and L ( y , v ) L(y,v) L ( y , v ) all hold, so the conjunction negated in (X1) is satisfied—a contradiction. Thus ( T 1 , … , T t ; < 1 , … , < t ) (T_1,\ldots,T_t; <_1,\ldots,<_{t}) ( T 1 , … , T t ; < 1 , … , < t ) is a t t t -track layout of G G G and tn ( G ) ≤ t \operatorname{tn}(G) \le t tn ( G ) ≤ t .
Corollary 44. Given a graph G G G and t ∈ N t \in\mathbb{N} t ∈ N , deciding tn ( G ) ≤ t \operatorname{tn}(G) \le t tn ( G ) ≤ t is fixed-parameter tractable with respect to td ( G ) \operatorname{td}(G) td ( G ) . Moreover, tn ( G ) \operatorname{tn}(G) tn ( G ) can be computed in time f ( td ( G ) ) ⋅ ∣ G ∣ f(\operatorname{td}(G)) \cdot|G| f ( td ( G )) ⋅ ∣ G ∣ for a computable function f f f .
Proof. By Theorem 43, Φ t t r \Phi_t^{\mathrm{tr}} Φ t tr is computable from t t t and has length O ( t 2 ) O(t^2) O ( t 2 ) . By Dujmović, Morin and Wood [42 ] , tn ( G ) ≤ g 0 ( tw ( G ) ) \operatorname{tn}(G) \le g_0(\operatorname{tw}(G)) tn ( G ) ≤ g 0 ( tw ( G )) for a computable, nondecreasing function g 0 g_0 g 0 , hence tn ( G ) ≤ g 2 ( td ( G ) ) \operatorname{tn}(G) \le g_2(\operatorname{td}(G)) tn ( G ) ≤ g 2 ( td ( G )) with g 2 ( s ) : = g 0 ( s − 1 ) g_2(s) := g_0(s-1) g 2 ( s ) := g 0 ( s − 1 ) . The statement then immediately follows from Lemma 37.
Twin-Width
Twin-width was introduced by Bonnet, Kim, Thomassé, and Watrigant [24 , 23 ] in 2020. Its definition turns the mechanism behind the algorithm of Guillemet and Marx [61 ] for permutation pattern matching into a graph parameter: there, pairs of vertices that are “almost twins” are iteratively contracted while errors are charged in a red graph. The parameter proved remarkably general: classes of bounded twin-width include bounded treewidth and clique-width, proper minor-closed classes, unit interval graphs, posets of bounded width and pattern-avoiding permutation graphs [24 ] ; they are closed under first-order transductions. Moreover, first-order model checking is fixed-parameter tractable on every class of bounded twin-width, provided a contraction sequence is given [24 ] . Twin-width has since become a central concept in the structural theory of dense graphs [12 , 16 ] .
Twin-width is usually defined through trigraphs, in which a contracted pair inherits a red edge whenever the two merged vertices disagree, and red edges persist; see Figure 4 for a small example. We use the partition definition by Bonnet, Kim, Thomassé, and Watrigant [24 ] . Throughout, we let ∣ V ∣ = n |V|=n ∣ V ∣ = n .
Figure 4. (a) A graph G G G with tww ( G ) = 2 \operatorname{tww}(G)=2 tww ( G ) = 2 , (b) a contraction sequence of width 2, shown as the trigraphs G 5 , … , G 2 G_5,\ldots,G_2 G 5 , … , G 2 with red edges drawn in red, and (c) the corresponding dendrogram: two vertices are joined at height i i i if they first lie in a common part after the i i i -th contraction.
Let P \mathcal{P} P be a partition of V V V and u , v ∈ V u,v\in V u , v ∈ V . We write [ v ] P [v]_{\mathcal{P}} [ v ] P for the part of the partition that contains v v v , and u ∼ P v u\sim_{\mathcal{P}}v u ∼ P v for [ u ] P = [ v ] P [u]_{\mathcal{P}}=[v]_{\mathcal{P}} [ u ] P = [ v ] P . Two distinct parts A , B ∈ P A,B\in\mathcal{P} A , B ∈ P are homogeneous if either A × B ⊆ E A\times B\subseteq E A × B ⊆ E or ( A × B ) ∩ E = ∅ (A\times B)\cap E=\varnothing ( A × B ) ∩ E = ∅ , and red-adjacent otherwise, i.e. if there are a , a ′ ∈ A a,a'\in A a , a ′ ∈ A and b , b ′ ∈ B b,b'\in B b , b ′ ∈ B with E ( a , b ) E(a,b) E ( a , b ) and ¬ E ( a , b ′ ) \neg E(a,b') ¬ E ( a , b ′ ) . The red degree rdeg ( P ) \operatorname{rdeg}(\mathcal{P}) rdeg ( P ) is the maximum, over all A ∈ P A\in\mathcal{P} A ∈ P , of the number of parts red-adjacent to A A A . For a contraction sequence P n , … , P 1 \mathcal{P}_n,\ldots,\mathcal{P}_1 P n , … , P 1 we call the passage from P i + 1 \mathcal{P}_{i+1} P i + 1 to P i \mathcal{P}_i P i step n − i n-i n − i ; thus step j ∈ { 1 , … , n − 1 } j\in\{1,\ldots,n-1\} j ∈ { 1 , … , n − 1 } produces P n − j \mathcal{P}_{n-j} P n − j .
Definition 45 (Twin-width). A contraction sequence of a graph G G G is a sequence of partitions P n , P n − 1 , … , P 1 \mathcal{P}_n,\mathcal{P}_{n-1},\ldots,\mathcal{P}_1 P n , P n − 1 , … , P 1 of V V V such that P n \mathcal{P}_n P n is the discrete partition { { v } : v ∈ V } \{\{v\}:v\in V\} {{ v } : v ∈ V } , we have P 1 = { V } \mathcal{P}_1=\{V\} P 1 = { V } , and for each 1 ≤ i < n 1\le i<n 1 ≤ i < n the partition P i \mathcal{P}_i P i is obtained from P i + 1 \mathcal{P}_{i+1} P i + 1 by replacing two distinct parts A , B ∈ P i + 1 A,B\in\mathcal{P}_{i+1} A , B ∈ P i + 1 by their union A ∪ B A\cup B A ∪ B . Its width is max i rdeg ( P i ) \max_i\operatorname{rdeg}(\mathcal{P}_i) max i rdeg ( P i ) , and the twin-width tww ( G ) \operatorname{tww}(G) tww ( G ) is the least width of any contraction sequence of G G G .
Computing twin-width is hard. Bergé, Bonnet, and Déprés [5 ] showed that deciding tww ( G ) ≤ k \operatorname{tww}(G)\le k tww ( G ) ≤ k is already NP-complete for k = 4 k=4 k = 4 , ruling out fixed-parameter tractability w.r.t. k k k . Graphs of twin-width at most one can be recognized in polynomial time [21 ] , and the cases k = 2 , 3 k=2,3 k = 2 , 3 are open. No fixed-parameter approximation with respect to twin-width itself is known [GR26]. Instead, all known algorithms resort to stronger parameters: An FPT approximation of twin-width can be computed in FPT time with respect to the feedback edge number and the vertex integrity [17 ] . Recently, Ganian and Rocton [GR26] obtained such an approximation also with respect to treedepth; this is the first tractability result for a parameter that is not a deletion distance to a simple graph class. The same work also proposes an exact FPT algorithm, parameterized by vertex integrity [GR26]. Whether twin-width can be computed exactly in FPT time with respect to treedepth, or even whether tww ( G ) ≤ k \operatorname{tww}(G)\le k tww ( G ) ≤ k can be decided in FPT time with respect to treedepth for a fixed k ≥ 4 k\ge4 k ≥ 4 , is currently open. Below, we answer this question in the positive.
Theorem 46. For every k ∈ N k\in\mathbb{N} k ∈ N there is an SNP sentence Φ k \Phi_k Φ k such that for every finite graph G G G ,
G ⊨ Φ k ⟺ tww ( G ) ≤ k . G\models\Phi_k \quad\Longleftrightarrow\quad\operatorname{tww}(G)\le k. G ⊨ Φ k ⟺ tww ( G ) ≤ k . Moreover, Φ k \Phi_k Φ k has two existentially quantified relation symbols, both of arity 4, at most O ( k ) O(k) O ( k ) first-order variables, and length O ( k 2 ) O(k^2) O ( k 2 ) ; the map k ↦ Φ k k\mapsto\Phi_k k ↦ Φ k is computable in time polynomial in k k k .
Proof. Intuition. A natural way to represent a contraction sequence is to index its steps by vertices and to point from each step to the next one; but the sequence must not stop early, so every step would need a successor until everything is merged, and “every step has a successor” is inherently a ∀ ∃ \forall\exists ∀∃ statement that SNP does not allow. We therefore describe the sequence the way a dendrogram in hierarchical clustering does: not by listing the merges in order, but by recording for any two pairs of vertices which of them is joined first. This is a relation on pairs of pairs, and it determines the sequence completely—the partition after a given merge consists of all pairs joined no later than it, and the partition before it of all pairs joined strictly earlier. In this representation the sequence cannot stop early, because a total order on pairs assigns every pair a moment at which it is joined, and totality of an order is expressible with universal quantifiers only.
The SNP sentence. We define Φ k \Phi_k Φ k as follows: Let Φ k \Phi_k Φ k existentially quantify over two relations, C and Red, both of arity 4. C ( u , v , x , y ) C(u,v,x,y) C ( u , v , x , y ) is meant to say that whenever x x x and y y y lie in a common part of the contraction sequence, so do u u u and v v v . The desired interpretation of Red ( x , y , a , b ) \operatorname{Red}(x,y,a,b) Red ( x , y , a , b ) is that the parts containing a a a and b b b are red-adjacent in the partition obtained at the step that merges x x x and y y y . Below, we force all necessary properties of the intended interpretations. In doing so, we make use of the following shorthand notation
u v ⪯ x y : = C ( u , v , x , y ) , uv \preceq xy := C(u,v,x,y), uv ⪯ x y := C ( u , v , x , y ) ,
u v ≺ x y : = C ( u , v , x , y ) ∧ ¬ C ( x , y , u , v ) , uv \prec xy := C(u,v,x,y) \land\neg C(x,y,u,v), uv ≺ x y := C ( u , v , x , y ) ∧ ¬ C ( x , y , u , v ) ,
u v ≡ x y : = C ( u , v , x , y ) ∧ C ( x , y , u , v ) , uv \equiv xy := C(u,v,x,y) \land C(x,y,u,v), uv ≡ x y := C ( u , v , x , y ) ∧ C ( x , y , u , v ) ,
and let u v ⪯̸ x y uv \not\preceq xy uv ⪯ x y denote ¬ ( u v ⪯ x y ) \neg(uv \preceq xy) ¬ ( uv ⪯ x y ) .
First, we enforce the merge order to be a total preorder (i.e., an order that is total, reflexive, and transitive) on pairs of elements. We also ensure that within this order, pairs behave reflexively, symmetrically, and transitively.
(C1) u v ⪯ x y ∨ x y ⪯ u v uv \preceq xy \lor xy \preceq uv uv ⪯ x y ∨ x y ⪯ uv (merge order is total and reflexive)
(C2) u v ⪯ x y ∧ x y ⪯ s t → u v ⪯ s t uv \preceq xy \land xy \preceq st \to uv \preceq st uv ⪯ x y ∧ x y ⪯ s t → uv ⪯ s t (merge order is transitive)
(C3) u v ⪯ x y → v u ⪯ x y uv \preceq xy \to vu \preceq xy uv ⪯ x y → v u ⪯ x y and u v ⪯ x y → u v ⪯ y x uv \preceq xy \to uv \preceq yx uv ⪯ x y → uv ⪯ y x (merge elements are symmetric)
(C4) u u ⪯ x y uu \preceq xy uu ⪯ x y (merge elements are reflexive) and x ≠ y → x y ⪯̸ u u x \ne y \to xy \not\preceq uu x = y → x y ⪯ uu (in the initial partition, no distinct elements are merged)
(C5) u v ⪯ x y ∧ v w ⪯ x y → u w ⪯ x y uv \preceq xy \land vw \preceq xy \to uw \preceq xy uv ⪯ x y ∧ v w ⪯ x y → u w ⪯ x y (merge elements are transitive)
Furthermore, in a contraction sequence, we perform only one merge at a time. This can be expressed as follows.
(C6)
u v ≡ x y ∧ u ′ v ′ ≡ x y ∧ u ≠ v ∧ u ′ ≠ v ′ → ( u u ′ ≺ x y ∧ v v ′ ≺ x y ) ∨ ( u v ′ ≺ x y ∧ v u ′ ≺ x y ) . uv \equiv xy \land u'v' \equiv xy \land u \ne v \land u' \ne v'
\to(uu' \prec xy \land vv' \prec xy) \lor(uv' \prec xy \land vu' \prec xy). uv ≡ x y ∧ u ′ v ′ ≡ x y ∧ u = v ∧ u ′ = v ′ → ( u u ′ ≺ x y ∧ v v ′ ≺ x y ) ∨ ( u v ′ ≺ x y ∧ v u ′ ≺ x y ) .
For Red we enforce the following: The first statement says that whenever two parts of a partition are not homogeneous, then they must be marked as red-adjacent. The second statement ensures that being red-adjacent is a property of pairs of parts and not of pairs of individual vertices.
(R1) a a ′ ⪯ x y ∧ b b ′ ⪯ x y ∧ a b ⪯̸ x y ∧ E ( a , b ) ∧ ¬ E ( a ′ , b ′ ) → Red ( x , y , a , b ) aa' \preceq xy \land bb' \preceq xy \land ab \not\preceq xy \land E(a,b) \land\neg E(a',b') \to\operatorname{Red}(x,y,a,b) a a ′ ⪯ x y ∧ b b ′ ⪯ x y ∧ ab ⪯ x y ∧ E ( a , b ) ∧ ¬ E ( a ′ , b ′ ) → Red ( x , y , a , b ) .
(R2) Red ( x , y , a , b ) ∧ a a ′ ⪯ x y ∧ b b ′ ⪯ x y → Red ( x , y , a ′ , b ′ ) \operatorname{Red}(x,y,a,b) \land aa' \preceq xy \land bb' \preceq xy \to\operatorname{Red}(x,y,a',b') Red ( x , y , a , b ) ∧ a a ′ ⪯ x y ∧ b b ′ ⪯ x y → Red ( x , y , a ′ , b ′ ) .
Lastly, the number of red-adjacent parts must be forced to be at most k k k at all times. We express this by saying that there cannot be k + 1 k+1 k + 1 such parts at any merging step. Note that this is the only statement that makes use of parameter k k k .
(R3) ¬ ( ( ⋀ i = 0 k Red ( x , y , a , b i ) ) ∧ ( ⋀ 0 ≤ i < j ≤ k b i b j ⪯̸ x y ) ) . \text{(R3)}\quad\neg\left(\left(\bigwedge_{i=0}^{k}\operatorname{Red}(x,y,a,b_i)\right)\land\left(\bigwedge_{0\leq i<j\leq k}b_i b_j\not\preceq xy\right)\right). (R3) ¬ ( i = 0 ⋀ k Red ( x , y , a , b i ) ) ∧ 0 ≤ i < j ≤ k ⋀ b i b j ⪯ x y .
Finally, we let Φ k = ∃ C ∃ Red ∀ z ⃗ ψ k \Phi_k=\exists C\exists\operatorname{Red}\ \forall\vec{z}\ \psi_k Φ k = ∃ C ∃ Red ∀ z ψ k , where ∀ z ⃗ ψ k \forall\vec{z}\ \psi_k ∀ z ψ k is the conjunction of the universal closures of the statements (C1)–(R3). Every condition—except (R3)—has constant length, while (R3) consists of k + 1 k+1 k + 1 atoms of Red and ( k + 1 2 ) \binom{k+1}{2} ( 2 k + 1 ) atoms of C; hence Φ k \Phi_k Φ k has length O ( k 2 ) O(k^2) O ( k 2 ) and at most O ( k ) O(k) O ( k ) first-order variables, and it can be written down in time polynomial in k k k .
Correctness. (⇐ \Leftarrow ⇐ ) Let P n , … , P 1 P_n,\ldots,P_1 P n , … , P 1 be a contraction sequence of width at most k k k . Towards defining C and Red, let μ : V 2 → { 0 , … , n − 1 } \mu:V^2\to\{0,\ldots,n-1\} μ : V 2 → { 0 , … , n − 1 } with μ ( u , u ) = 0 \mu(u,u)=0 μ ( u , u ) = 0 for all u ∈ V u\in V u ∈ V and
μ ( u , v ) = min { j ≥ 1 : u ∼ P n − j v } , \mu(u,v)=\min\{j\geq1:u\sim_{P_{n-j}}v\}, μ ( u , v ) = min { j ≥ 1 : u ∼ P n − j v } ,
for all u , v ∈ V u,v\in V u , v ∈ V with u ≠ v u\ne v u = v . Intuitively, μ ( u , v ) \mu(u,v) μ ( u , v ) denotes the moment at which u u u and v v v are first put into a common part; such a moment exists because P 1 = { V } P_1=\{V\} P 1 = { V } .
Since the partitions only coarsen along the sequence, we have
u ∼ P n − j v ⟺ μ ( u , v ) ≤ j ( 0 ≤ j ≤ n − 1 ) . (2) u\sim_{P_{n-j}}v\Longleftrightarrow\mu(u,v)\leq j\qquad(0\leq j\leq n-1). \tag*{(2)} u ∼ P n − j v ⟺ μ ( u , v ) ≤ j ( 0 ≤ j ≤ n − 1 ) . (2)
and step j j j merges two parts A j , B j ∈ P n − j + 1 A_j,B_j\in P_{n-j+1} A j , B j ∈ P n − j + 1 with { ( u , v ) : μ ( u , v ) = j } = ( A j × B j ) ∪ ( B j × A j ) \{(u,v):\mu(u,v)=j\}=(A_j\times B_j)\cup(B_j\times A_j) {( u , v ) : μ ( u , v ) = j } = ( A j × B j ) ∪ ( B j × A j ) . Now, choose C and Red as follows.
C : = { ( u , v , x , y ) ∈ V 4 : μ ( u , v ) ≤ μ ( x , y ) } , C:=\{(u,v,x,y)\in V^4:\mu(u,v)\leq\mu(x,y)\}, C := {( u , v , x , y ) ∈ V 4 : μ ( u , v ) ≤ μ ( x , y )} ,
Red : = { ( x , y , a , b ) ∈ V 4 : x ≠ y , [ a ] ≠ [ b ] and [ a ] , [ b ] are red-adjacent in P n − μ ( x , y ) } , \operatorname{Red}:=\{(x,y,a,b)\in V^4:x\ne y,\ [a]\ne[b]\text{ and }[a],[b]\text{ are red-adjacent in }P_{n-\mu(x,y)}\}, Red := {( x , y , a , b ) ∈ V 4 : x = y , [ a ] = [ b ] and [ a ] , [ b ] are red-adjacent in P n − μ ( x , y ) } ,
where [ ⋅ ] [\cdot] [ ⋅ ] denotes parts of P n − μ ( x , y ) P_{n-\mu(x,y)} P n − μ ( x , y ) . It remains to verify the clauses for all assignments of the variables. Note that by (1), u v ⪯ x y uv\preceq xy uv ⪯ x y holds iff u ∼ P n − μ ( x , y ) v u\sim_{P_{n-\mu(x,y)}}v u ∼ P n − μ ( x , y ) v , and u v ≺ x y uv\prec xy uv ≺ x y holds iff u ∼ P n − μ ( x , y ) + 1 v u\sim_{P_{n-\mu(x,y)+1}}v u ∼ P n − μ ( x , y ) + 1 v (for x ≠ y x\ne y x = y ).
(C1), (C2): ≤ \leq ≤ on integers is total, reflexive, and transitive. (C3): μ \mu μ is symmetric. (C4): μ ( u , u ) = 0 ≤ μ ( x , y ) \mu(u,u)=0\leq\mu(x,y) μ ( u , u ) = 0 ≤ μ ( x , y ) , and μ ( x , y ) ≥ 1 > 0 \mu(x,y)\geq1>0 μ ( x , y ) ≥ 1 > 0 for x ≠ y x\ne y x = y . (C5): fix x , y x,y x , y and put j = μ ( x , y ) j=\mu(x,y) j = μ ( x , y ) . By (1), u v ⪯ x y uv\preceq xy uv ⪯ x y holds iff u u u and v v v lie in a common part of P n − j P_{n-j} P n − j . So if u v ⪯ x y uv\preceq xy uv ⪯ x y and v w ⪯ x y vw\preceq xy v w ⪯ x y , then u , v , w u,v,w u , v , w all lie in the part of v v v , hence u w ⪯ x y uw\preceq xy u w ⪯ x y .
(C6): If x = y x=y x = y , the antecedent is unsatisfiable by (C4), so let x ≠ y x\ne y x = y and j = μ ( x , y ) ≥ 1 j=\mu(x,y)\geq1 j = μ ( x , y ) ≥ 1 . Moreover, let ( u , v ) , ( u ′ , v ′ ) (u,v),(u',v') ( u , v ) , ( u ′ , v ′ ) be pairs with μ ( u , v ) = μ ( u ′ , v ′ ) = j \mu(u,v)=\mu(u',v')=j μ ( u , v ) = μ ( u ′ , v ′ ) = j and u ≠ v , u ′ ≠ v ′ u\ne v,u'\ne v' u = v , u ′ = v ′ . Then both lie in ( A j × B j ) ∪ ( B j × A j ) (A_j\times B_j)\cup(B_j\times A_j) ( A j × B j ) ∪ ( B j × A j ) . If u , u ′ ∈ A j u,u'\in A_j u , u ′ ∈ A j then v , v ′ ∈ B j v,v'\in B_j v , v ′ ∈ B j , so u ∼ P n − j + 1 u ′ u\sim_{P_{n-j+1}}u' u ∼ P n − j + 1 u ′ and v ∼ P n − j + 1 v ′ v\sim_{P_{n-j+1}}v' v ∼ P n − j + 1 v ′ , which is the first disjunct; the case u , u ′ ∈ B j u,u'\in B_j u , u ′ ∈ B j is symmetric; if u ∈ A j u\in A_j u ∈ A j and u ′ ∈ B j u'\in B_j u ′ ∈ B j then v ∈ B j v\in B_j v ∈ B j , v ′ ∈ A j v'\in A_j v ′ ∈ A j , giving the second disjunct; and symmetrically.
(R1): if a a ′ ⪯ x y aa'\preceq xy a a ′ ⪯ x y , b b ′ ⪯ x y bb'\preceq xy b b ′ ⪯ x y , a b ⪯̸ x y ab\not\preceq xy ab ⪯ x y , E ( a , b ) E(a,b) E ( a , b ) and ¬ E ( a ′ , b ′ ) \neg E(a',b') ¬ E ( a ′ , b ′ ) , then in P n − μ ( x , y ) P_{n-\mu(x,y)} P n − μ ( x , y ) the parts [ a ] ∋ a ′ [a]\ni a' [ a ] ∋ a ′ and [ b ] ∋ b ′ [b]\ni b' [ b ] ∋ b ′ are distinct and contain both an edge and a non-edge between them, hence are red-adjacent, so Red ( x , y , a , b ) \operatorname{Red}(x,y,a,b) Red ( x , y , a , b ) holds. (If x = y x=y x = y , the antecedent is unsatisfiable: a a ′ ⊀ x x aa'\not\prec xx a a ′ ≺ xx forces a = a ′ a=a' a = a ′ and b b ′ ⪯ x x bb'\preceq xx b b ′ ⪯ xx forces b = b ′ b=b' b = b ′ , contradicting E ( a , b ) ∧ ¬ E ( a , b ) E(a,b)\land\neg E(a,b) E ( a , b ) ∧ ¬ E ( a , b ) .) (R2): by definition, membership in Red depends only on the parts of a a a and b b b .
(R3): suppose Red ( x , y , a , b i ) \operatorname{Red}(x,y,a,b_i) Red ( x , y , a , b i ) for i = 0 , … , k i=0,\ldots,k i = 0 , … , k and b i b j ⪯̸ x y b_i b_j\not\preceq xy b i b j ⪯ x y for i < j i<j i < j . Then in P n − μ ( x , y ) P_{n-\mu(x,y)} P n − μ ( x , y ) the parts [ b 0 ] , … , [ b k ] [b_0],\ldots,[b_k] [ b 0 ] , … , [ b k ] are pairwise distinct, each distinct from [ a ] [a] [ a ] and red-adjacent to it, so rdeg ( P n − μ ( x , y ) ) ≥ k + 1 \operatorname{rdeg}(P_{n-\mu(x,y)})\geq k+1 rdeg ( P n − μ ( x , y ) ) ≥ k + 1 , contradicting the width bound. Hence G ⊨ Φ k G\models\Phi_k G ⊨ Φ k .
( ⇒ ) (\Rightarrow) ( ⇒ ) Now let ( V , E , C , Red ) ⊨ ∀ z ψ ˉ k (V,E,C,\operatorname{Red}) \models\forall z\,\bar{\psi}_k ( V , E , C , Red ) ⊨ ∀ z ψ ˉ k . We use ⪯ \preceq ⪯ , ≺ \prec ≺ , ≡ \equiv ≡ as defined above, also between pairs named by single letters p ∈ V 2 p \in V^2 p ∈ V 2 .
By (C1)–(C3), ⪯ \preceq ⪯ is a total preorder on V 2 V^2 V 2 that is invariant under swapping the two coordinates of either pair. Let L 0 ≺ L 1 ≺ ⋯ ≺ L m L_0 \prec L_1 \prec\cdots\prec L_m L 0 ≺ L 1 ≺ ⋯ ≺ L m be its ≡ \equiv ≡ -classes, which we call levels , listed in ⪯ \preceq ⪯ -order. By (C4), any two diagonal pairs u u uu uu and v v vv v v are tied, and u u ≺ x y uu \prec xy uu ≺ x y whenever x ≠ y x \ne y x = y ; so L 0 L_0 L 0 consists exactly of the diagonal pairs. For a pair p p p define two binary relations on V V V by
u ∼ p v ⟺ u v ⪯ p , u ∼ < p v ⟺ u v ≺ p . u \sim_p v \Longleftrightarrow uv \preceq p,\qquad u \mathrel{\sim_{<p}} v \Longleftrightarrow uv \prec p. u ∼ p v ⟺ uv ⪯ p , u ∼ < p v ⟺ uv ≺ p .
Both depend only on the level of p p p , and u ∼ < p v u \mathrel{\sim_{<p}} v u ∼ < p v implies u ∼ p v u \sim_p v u ∼ p v . For diagonal p p p , (C4) gives u ∼ p v u \sim_p v u ∼ p v iff u = v u=v u = v . Each ∼ p \sim_p ∼ p is an equivalence relation on V V V : it is reflexive by (C4), symmetric by (C3) and transitive by (C5). So is each ∼ < p \sim_{<p} ∼ < p with p ∈ L i p \in L_i p ∈ L i , i ≥ 1 i \ge1 i ≥ 1 : for p ′ ∈ L i − 1 p' \in L_{i-1} p ′ ∈ L i − 1 , u v ≺ p uv \prec p uv ≺ p holds iff u v uv uv lies in some L i ′ L_{i'} L i ′ with i ′ ≤ i − 1 i' \le i-1 i ′ ≤ i − 1 , which is true iff u v ⪯ p ′ uv \preceq p' uv ⪯ p ′ , so ∼ < p \sim_{<p} ∼ < p coincides with ∼ p ′ \sim_{p'} ∼ p ′ . Let P ( p ) \mathcal{P}(p) P ( p ) denote the partition of V V V into the classes of ∼ p \sim_p ∼ p , and write P ( L i ) \mathcal{P}(L_i) P ( L i ) for P ( p ) \mathcal{P}(p) P ( p ) with p ∈ L i p \in L_i p ∈ L i . Thus P ( L 0 ) \mathcal{P}(L_0) P ( L 0 ) is the discrete partition, and for p ∈ L i p \in L_i p ∈ L i with i ≥ 1 i \ge1 i ≥ 1 the classes of ∼ < p \sim_{<p} ∼ < p form P ( L i − 1 ) \mathcal{P}(L_{i-1}) P ( L i − 1 ) .
Next we show that for p ∈ L i p \in L_i p ∈ L i , i ≥ 1 i \ge1 i ≥ 1 , the partition P ( L i ) \mathcal{P}(L_i) P ( L i ) arises from P ( L i − 1 ) \mathcal{P}(L_{i-1}) P ( L i − 1 ) by merging exactly two parts. Let N p N_p N p be the set of pairs in the level of p p p , i.e. of those u v uv uv with u v ⪯ p uv \preceq p uv ⪯ p but not u v ≺ p uv \prec p uv ≺ p ; it contains p p p and no diagonal pair, and by definition u ∼ p v u \sim_p v u ∼ p v holds iff u ∼ < p v u \mathrel{\sim_{<p}} v u ∼ < p v or u v ∈ N p uv \in N_p uv ∈ N p . Fix u 0 v 0 ∈ N p u_0v_0 \in N_p u 0 v 0 ∈ N p and let A A A and B B B be the parts of P ( L i − 1 ) \mathcal{P}(L_{i-1}) P ( L i − 1 ) containing u 0 u_0 u 0 and v 0 v_0 v 0 , respectively; then A ≠ B A \ne B A = B , because u 0 ̸ ∼ < p v 0 u_0 \mathrel{\not\sim_{<p}} v_0 u 0 ∼ < p v 0 . For any u v ∈ N p uv \in N_p uv ∈ N p , clause (C6) applied to u v uv uv and u 0 v 0 u_0v_0 u 0 v 0 (with p = x y p=xy p = x y ) yields u ∼ < p u 0 u \mathrel{\sim_{<p}} u_0 u ∼ < p u 0 and v ∼ < p v 0 v \mathrel{\sim_{<p}} v_0 v ∼ < p v 0 , or u ∼ < p v 0 u \mathrel{\sim_{<p}} v_0 u ∼ < p v 0 and v ∼ < p u 0 v \mathrel{\sim_{<p}} u_0 v ∼ < p u 0 ; so every pair in N p N_p N p joins a vertex of A A A with a vertex of B B B . Conversely, for a ∈ A a \in A a ∈ A and b ∈ B b \in B b ∈ B we have a ∼ p u 0 a \sim_p u_0 a ∼ p u 0 , u 0 ∼ p v 0 u_0 \sim_p v_0 u 0 ∼ p v 0 and v 0 ∼ p b v_0 \sim_p b v 0 ∼ p b , hence a ∼ p b a \sim_p b a ∼ p b by transitivity of ∼ p \sim_p ∼ p . Therefore P ( L i ) \mathcal{P}(L_i) P ( L i ) is obtained from P ( L i − 1 ) \mathcal{P}(L_{i-1}) P ( L i − 1 ) by replacing A A A and B B B with A ∪ B A \cup B A ∪ B .
As a consequence, P ( L i ) \mathcal{P}(L_i) P ( L i ) has exactly one part fewer than P ( L i − 1 ) \mathcal{P}(L_{i-1}) P ( L i − 1 ) for every 1 ≤ i ≤ m 1 \le i \le m 1 ≤ i ≤ m , hence n − i n-i n − i parts. Every pair lies in some level, so all vertices are ∼ p \sim_p ∼ p -equivalent for p ∈ L m p \in L_m p ∈ L m , i.e. P ( L m ) = { V } \mathcal{P}(L_m)=\{V\} P ( L m ) = { V } ; hence m = n − 1 m=n-1 m = n − 1 . Setting P n − i : = P ( L i ) \mathcal{P}_{n-i}:=\mathcal{P}(L_i) P n − i := P ( L i ) for 0 ≤ i ≤ n − 1 0 \le i \le n-1 0 ≤ i ≤ n − 1 we obtain a contraction sequence P n , … , P 1 \mathcal{P}_n,\ldots,\mathcal{P}_1 P n , … , P 1 of G G G .
It remains to bound its width. The discrete partition has red degree 0. Now, fix 1 ≤ i ≤ n − 1 1 \le i \le n-1 1 ≤ i ≤ n − 1 and p = x y ∈ L i p=xy \in L_i p = x y ∈ L i , so that x ≠ y x \ne y x = y and u ∼ p v u \sim_p v u ∼ p v iff u v ⪯ x y uv \preceq xy uv ⪯ x y . First, Red ( x , y , ⋅ , ⋅ ) \operatorname{Red}(x,y,\cdot,\cdot) Red ( x , y , ⋅ , ⋅ ) contains every red pair of P ( p ) \mathcal{P}(p) P ( p ) : if A ≠ B A \ne B A = B are parts of P ( p ) \mathcal{P}(p) P ( p ) that are red-adjacent, choose a , a ′ ∈ A a,a' \in A a , a ′ ∈ A and b , b ′ ∈ B b,b' \in B b , b ′ ∈ B with E ( a , b ) E(a,b) E ( a , b ) and ¬ E ( a ′ , b ′ ) \neg E(a',b') ¬ E ( a ′ , b ′ ) ; then a a ′ ⪯ x y aa' \preceq xy a a ′ ⪯ x y , b b ′ ⪯ x y bb' \preceq xy b b ′ ⪯ x y and a b ⪯̸ x y ab \not\preceq xy ab ⪯ x y , so (R1) gives Red ( x , y , a , b ) \operatorname{Red}(x,y,a,b) Red ( x , y , a , b ) , and (R2) propagates this to Red ( x , y , a ′ ′ , b ′ ′ ) \operatorname{Red}(x,y,a'',b'') Red ( x , y , a ′′ , b ′′ ) for all a ′ ′ ∈ A a'' \in A a ′′ ∈ A and b ′ ′ ∈ B b'' \in B b ′′ ∈ B . Now suppose some part A A A of P ( p ) \mathcal{P}(p) P ( p ) had k + 1 k+1 k + 1 distinct red-adjacent parts B 0 , … , B k B_0,\ldots,B_k B 0 , … , B k . Pick a ∈ A a \in A a ∈ A and b j ∈ B j b_j \in B_j b j ∈ B j . Then Red ( x , y , a , b j ) \operatorname{Red}(x,y,a,b_j) Red ( x , y , a , b j ) for all j j j , and b j b j ′ ⪯̸ x y b_jb_{j'} \not\preceq xy b j b j ′ ⪯ x y for j < j ′ j<j' j < j ′ because B j ≠ B j ′ B_j \ne B_{j'} B j = B j ′ , which would violate (R3). Hence rdeg ( P ( p ) ) ≤ k \operatorname{rdeg}(\mathcal{P}(p)) \le k rdeg ( P ( p )) ≤ k . Consequently, the contraction sequence has width at most k k k , i.e. tww ( G ) ≤ k \operatorname{tww}(G) \le k tww ( G ) ≤ k . □ \square □
Corollary 47. Given a graph G G G and k ∈ N k \in\mathbb{N} k ∈ N , deciding tww ( G ) ≤ k \operatorname{tww}(G) \le k tww ( G ) ≤ k is fixed-parameter tractable with respect to td ( G ) \operatorname{td}(G) td ( G ) , and tww ( G ) \operatorname{tww}(G) tww ( G ) can be computed in time f ( td ( G ) ) ⋅ ∣ G ∣ f(\operatorname{td}(G)) \cdot|G| f ( td ( G )) ⋅ ∣ G ∣ for a computable function f f f .
Proof. By Theorem 46 , Φ k \Phi_k Φ k has length O ( k 2 ) O(k^2) O ( k 2 ) and is computable from k k k ; moreover, it is known that tww ( G ) ≤ 3 ⋅ 2 tw ( G ) − 1 \operatorname{tww}(G) \le3 \cdot2^{\operatorname{tw}(G)-1} tww ( G ) ≤ 3 ⋅ 2 tw ( G ) − 1 [[67 ] ], hence tww ( G ) ≤ 3 ⋅ 2 td ( G ) − 2 \operatorname{tww}(G) \le3 \cdot2^{\operatorname{td}(G)-2} tww ( G ) ≤ 3 ⋅ 2 td ( G ) − 2 . The statement then immediately follows from Lemma 37 . □ \square □
Boxicity
Boxicity was introduced by Roberts [[84 ] ] in 1969 as a natural higher-dimensional analogue of interval graphs: where an interval graph records overlaps of intervals on a line, a graph of boxicity d d d records overlaps of boxes in R d \mathbb{R}^d R d , and box ( G ) \operatorname{box}(G) box ( G ) measures how many dimensions are needed to realize G G G in this way; see Figure 5 for a small example.
Figure 5. (a) A graph G G G , (b) a 2-box representation of G G G , and (c) the interval models obtained by projecting the boxes onto the two coordinate axes. The projections define interval graphs G 1 G_1 G 1 (blue) and G 2 G_2 G 2 (purple) on V ( G ) V(G) V ( G ) with G = G 1 ∩ G 2 G = G_1 \cap G_2 G = G 1 ∩ G 2 .
Definition 48 (Boxicity). A d d d -box is a product I 1 × ⋯ × I d ⊆ R d I^1 \times\cdots\times I^d \subseteq\mathbb{R}^d I 1 × ⋯ × I d ⊆ R d of closed intervals. A d d d -box representation of G G G assigns to every vertex v v v a d d d -box B v B_v B v such that for all distinct u , v ∈ V u,v \in V u , v ∈ V ,
u v ∈ E ⟺ B u ∩ B v ≠ ∅ . uv \in E \Longleftrightarrow B_u \cap B_v \ne\varnothing. uv ∈ E ⟺ B u ∩ B v = ∅ . The boxicity box ( G ) \operatorname{box}(G) box ( G ) of G G G is the least d ≥ 1 d \ge1 d ≥ 1 such that G G G has a d d d -box representation. In particular, graphs of boxicity 1 are called interval graphs.
Computing boxicity is hard: deciding box ( G ) ≤ d \operatorname{box}(G) \le d box ( G ) ≤ d is NP-complete for every fixed d ≥ 2 d \ge2 d ≥ 2 [35 , 93 Kra94] , and for every ε > 0 \varepsilon> 0 ε > 0 there is no polynomial-time algorithm that approximates the boxicity of an n n n -vertex graph within a factor of n 1 − ε n^{1-\varepsilon} n 1 − ε unless NP = ZPP14 [32 ] . However, from the perspective of parameterized complexity, deciding box ( G ) ≤ d \operatorname{box}(G) \le d box ( G ) ≤ d is fixed-parameter tractable with respect to the vertex cover number [ACS10], the twin cover number [55 ] and the cluster vertex deletion number [6 ] , and can be approximated within an additive 1 in FPT time with respect to pathwidth [6 ] . Computing boxicity exactly has been conjectured to remain NP-complete on graphs of bounded treewidth [ACS10], and even on graphs of bounded bandwidth [6 ] .
Note that two boxes intersect if and only if they intersect in each of the d d d coordinates. This yields a fairly straightforward characterization.
Observation 49 ([84 ] ). For every graph G G G and d ≥ 1 d \ge1 d ≥ 1 , box ( G ) ≤ d \operatorname{box}(G) \le d box ( G ) ≤ d if and only if G = ( V , E ( G 1 ) ∩ ⋯ ∩ E ( G d ) ) G = (V, E(G_1) \cap\cdots\cap E(G_d)) G = ( V , E ( G 1 ) ∩ ⋯ ∩ E ( G d )) for interval graphs G 1 , … , G d G_1, \ldots, G_d G 1 , … , G d on V ( G ) V(G) V ( G ) .
Interval graphs in turn can be characterized by special vertex orderings.
Observation 50 ([85 , 79 ] ). A graph H = ( V , E ) H = (V,E) H = ( V , E ) is an interval graph if and only if there exists an interval ordering of V V V , i.e., a linear order < < < on V V V with
u < v < w and u w ∈ E ⟹ u v ∈ E for all u , v , w ∈ V . u < v < w \text{ and } uw \in E \Longrightarrow uv \in E \qquad\text{for all } u,v,w \in V. u < v < w and u w ∈ E ⟹ uv ∈ E for all u , v , w ∈ V .
We now have all the ingredients at hand to express boxicity in SNP.
Theorem 51. For every d ≥ 1 d \ge1 d ≥ 1 there is an SNP sentence Φ d \Phi_d Φ d such that for every finite graph G G G ,
G ⊨ Φ d ⟺ box ( G ) ≤ d . G \models\Phi_d \Longleftrightarrow\operatorname{box}(G) \le d. G ⊨ Φ d ⟺ box ( G ) ≤ d . Moreover, Φ d \Phi_d Φ d has 2 d 2d 2 d existentially quantified relation symbols, all of arity 2, three first-order variables, and length O ( d ) O(d) O ( d ) ; the map d ↦ Φ d d \mapsto\Phi_d d ↦ Φ d is computable in time polynomial in d d d .
Proof. The SNP sentence. We let Φ d \Phi_d Φ d existentially quantify over 2 d 2d 2 d binary relations L 1 , … , L d L_1,\ldots,L_d L 1 , … , L d and S 1 , … , S d S_1,\ldots,S_d S 1 , … , S d . The intended interpretation is that S i S_i S i is the edge relation of the i i i -th interval graph G i G_i G i , and L i L_i L i is a linear order on V V V that is an interval ordering of G i G_i G i (for instance, the order of left endpoints in the interval representation of G i G_i G i ). For each i ∈ { 1 , … , d } i \in\{1,\ldots,d\} i ∈ { 1 , … , d } we impose the following conditions.
Our first set of conditions ensures that each L i L_i L i is a strict linear order:
(O1) ¬ L i ( u , u ) (O2) L i ( u , v ) ∧ L i ( v , w ) → L i ( u , w ) (O3) L i ( u , v ) ∨ L i ( v , u ) ∨ u = v . \begin{aligned}
\text{(O1)}\quad&\neg L_i(u,u) \qquad
\text{(O2)}\quad L_i(u,v) \land L_i(v,w) \to L_i(u,w) \qquad
\text{(O3)}\quad L_i(u,v) \lor L_i(v,u) \lor u=v.
\end{aligned} (O1) ¬ L i ( u , u ) (O2) L i ( u , v ) ∧ L i ( v , w ) → L i ( u , w ) (O3) L i ( u , v ) ∨ L i ( v , u ) ∨ u = v .
Next, we define each S i S_i S i to be a graph that contains G G G , and let all S i S_i S i intersect in G G G .
(S1) S i ( u , v ) → S i ( v , u ) and ¬ S i ( u , u ) \text{(S1)}\quad S_i(u,v) \to S_i(v,u) \quad\text{and}\quad\neg S_i(u,u) (S1) S i ( u , v ) → S i ( v , u ) and ¬ S i ( u , u )
(S2) E ( u , v ) → S i ( u , v ) \text{(S2)}\quad E(u,v) \to S_i(u,v) (S2) E ( u , v ) → S i ( u , v )
(S3) S 1 ( u , v ) ∧ ⋯ ∧ S d ( u , v ) → E ( u , v ) \text{(S3)}\quad S_1(u,v) \land\cdots\land S_d(u,v) \to E(u,v) (S3) S 1 ( u , v ) ∧ ⋯ ∧ S d ( u , v ) → E ( u , v )
Lastly, we enforce that each L i L_i L i is an interval ordering of S i S_i S i .
(I1) L i ( u , v ) ∧ L i ( v , w ) ∧ S i ( u , w ) → S i ( u , v ) . \text{(I1)}\quad L_i(u,v) \land L_i(v,w) \land S_i(u,w) \to S_i(u,v). (I1) L i ( u , v ) ∧ L i ( v , w ) ∧ S i ( u , w ) → S i ( u , v ) .
Finally, Φ d = ∃ L 1 ⋯ ∃ L d ∃ S 1 ⋯ ∃ S d ∀ z ‾ ψ ‾ d \Phi_d = \exists L_1 \cdots\exists L_d \exists S_1 \cdots\exists S_d \ \forall\overline{z}\ \overline{\psi}_d Φ d = ∃ L 1 ⋯ ∃ L d ∃ S 1 ⋯ ∃ S d ∀ z ψ d , where ∀ z ‾ ψ ‾ d \forall\overline{z}\ \overline{\psi}_d ∀ z ψ d is the conjunction of the universal closures of (O1)–(I1) for all i i i . For each i i i , the conditions (O1)–(S2) and (I1) have constant length and (S3) consists of d + 1 d+1 d + 1 atoms; hence Φ d \Phi_d Φ d has length O ( d ) O(d) O ( d ) and three first-order variables, and it can be written down in time polynomial in d d d .
Correctness. When given graphs G i G_i G i , 1 ≤ i ≤ d 1 \le i \le d 1 ≤ i ≤ d with a common vertex set V V V , we will write ⋂ i G i \bigcap_i G_i ⋂ i G i to denote ( V , E ( G 1 ) ∩ ⋯ ∩ E ( G d ) ) (V,E(G_1) \cap\cdots\cap E(G_d)) ( V , E ( G 1 ) ∩ ⋯ ∩ E ( G d )) .
( ⇐ ) (\Leftarrow) ( ⇐ ) Let box ( G ) ≤ d \operatorname{box}(G) \le d box ( G ) ≤ d . By Observation 49 there are interval graphs G 1 , … , G d G_1,\ldots,G_d G 1 , … , G d on V V V with G = ⋂ i G i G = \bigcap_i G_i G = ⋂ i G i , and by Observation 50 each G i G_i G i has an interval ordering < i <_{i} < i . Interpret L i L_i L i as < i <_{i} < i and S i S_i S i as E ( G i ) E(G_i) E ( G i ) . Then (O1)–(O3) hold because < i <_{i} < i is a strict linear order; (S1) because G i G_i G i is a graph; (S2) because E ⊆ E ( G i ) E \subseteq E(G_i) E ⊆ E ( G i ) ; (S3) because ⋂ i E ( G i ) = E \bigcap_i E(G_i) = E ⋂ i E ( G i ) = E ; and (I1) says that < i <_{i} < i is an interval ordering of G i G_i G i : whenever u < i v < i w u <_{i} v <_{i} w u < i v < i w and u w ∈ E ( G i ) uw \in E(G_i) u w ∈ E ( G i ) , also u v ∈ E ( G i ) uv \in E(G_i) uv ∈ E ( G i ) . Hence G ⊨ Φ d G \models\Phi_d G ⊨ Φ d .
( ⇒ ) (\Rightarrow) ( ⇒ ) Let ( V , E , L 1 , … , L d , S 1 , … , S d ) ⊨ ∀ z ‾ ψ ‾ d (V,E,L_1,\ldots,L_d,S_1,\ldots,S_d) \models\forall\overline{z}\ \overline{\psi}_d ( V , E , L 1 , … , L d , S 1 , … , S d ) ⊨ ∀ z ψ d . Fix some i i i . By (O1)–(O3), L i L_i L i is a strict linear order on V V V , and by (S1), G i : = ( V , S i ) G_i := (V,S_i) G i := ( V , S i ) is a graph. By (I1), L i L_i L i is an interval ordering of G i G_i G i , so G i G_i G i is an interval graph by Observation 50. By (S2), E ⊆ S i E \subseteq S_i E ⊆ S i for every i i i , and by (S3), ⋂ i S i ⊆ E \bigcap_i S_i \subseteq E ⋂ i S i ⊆ E on pairs of distinct vertices; hence, since E E E is irreflexive, E = ⋂ i S i E = \bigcap_i S_i E = ⋂ i S i . Thus G = G 1 ∩ ⋯ ∩ G d G = G_1 \cap\cdots\cap G_d G = G 1 ∩ ⋯ ∩ G d is an intersection of d d d interval graphs, and box ( G ) ≤ d \operatorname{box}(G) \le d box ( G ) ≤ d by Observation 49.
Corollary 52. Given a graph G G G and d ∈ N d \in\mathbb{N} d ∈ N , deciding box ( G ) ≤ d \operatorname{box}(G) \le d box ( G ) ≤ d is fixed-parameter tractable with respect to td ( G ) \operatorname{td}(G) td ( G ) . Moreover, box ( G ) \operatorname{box}(G) box ( G ) can be computed in time f ( td ( G ) ) ⋅ ∣ G ∣ f(\operatorname{td}(G)) \cdot|G| f ( td ( G )) ⋅ ∣ G ∣ for a computable function f f f .
Proof. By Theorem 51, Φ d \Phi_d Φ d has length O ( d ) O(d) O ( d ) and is computable from d d d ; moreover, it is known that box ( G ) ≤ tw ( G ) + 2 \operatorname{box}(G) \le\operatorname{tw}(G)+2 box ( G ) ≤ tw ( G ) + 2 , hence box ( G ) ≤ td ( G ) + 1 \operatorname{box}(G) \le\operatorname{td}(G)+1 box ( G ) ≤ td ( G ) + 1 [36 ] . The statement then immediately follows from Lemma 37.
Barriers for Generalizing the Metatheorem
In this section, we exclude three natural generalizations of our result under the assumption P ≠ N P \mathrm{P} \ne\mathrm{NP} P = NP .
Pathwidth
Recall that Courcelle’s theorem [34 ] in combination with Bodlaender’s theorem [25 ] yields that M S O 2 \mathrm{MSO}_2 MSO 2 model checking is possible in time f ( ∣ φ ∣ , tw ( G ) ) ⋅ ∣ G ∣ f(|\varphi|,\operatorname{tw}(G)) \cdot|G| f ( ∣ φ ∣ , tw ( G )) ⋅ ∣ G ∣ , where tw ( G ) \operatorname{tw}(G) tw ( G ) is the treewidth of G G G .15 It is natural to ask if we can solve SNP Model Checking in time f ( ∣ φ ∣ , tw ( R ) ) ⋅ ∣ R ∣ O ( 1 ) f(|\varphi|,\operatorname{tw}(\mathcal{R})) \cdot|\mathcal{R}|^{O(1)} f ( ∣ φ ∣ , tw ( R )) ⋅ ∣ R ∣ O ( 1 ) too.
As shown in § 6 , it is possible to express the problem of deciding whether a graph has queue number at most one in an SNP sentence of constant length. However, detecting whether a graph has queue number at most one is NP-hard, even if the input graphs are restricted to have constant pathwidth [9 ] . Therefore, it is not possible to obtain a similar theorem when replacing the treedepth of the primal graph with the pathwidth of the primal graph, unless P = NP. Another example would be the problem of intervalizing 4-colored graphs, which is NP-hard on graphs with pathwidth at most 2 [ADS01]. Although we will not explicitly show this here, it is also easy to express the problem as a fixed SNP sentence on 4-colored graphs.
More Expressive Formulas
Another reasonable extension, also motivated by Courcelle’s theorem, would be to allow formulas of existential second-order logic (ESO) (see, e.g. [73 Definition 7.3] ), instead of just SNP formulas. ESO formulas are of the form ∃ R 1 , … , ∃ R r ψ \exists R_1,\ldots,\exists R_r\psi ∃ R 1 , … , ∃ R r ψ , where ψ \psi ψ is a first-order formula . Therefore, the difference between SNP and ESO formulas is that SNP restricts the first-order part of the formula to universal formulas, whereas ESO allows arbitrary first-order formulas.
Again, we show that this extension is unlikely to be possible. This is a straightforward consequence of Fagin’s theorem [48 ] , which essentially states ESO = NP. We combine this theorem with an elementary trick to encode a list of integer numbers as a star forest.16
Theorem 53. There is a fixed ESO sentence φ \varphi φ such that deciding whether G ⊨ φ G \models\varphi G ⊨ φ is NP-complete, even when the input graph G G G has treedepth at most 2.
Proof. We prove this by a reduction from 3-Partition, which is strongly NP-hard [58 , 59 ] . Let P \mathcal{P} P be the following graph property: a graph G G G is in P \mathcal{P} P if and only if it is a disjoint union of 3 n 3n 3 n stars, for some n ≥ 1 n \ge1 n ≥ 1 , and the stars can be partitioned into exactly n n n sets of size 3 each, such that the number of vertices of the stars contained in each set of the partition is equal.
It is easy to see that P \mathcal{P} P is a property closed under isomorphism, and in NP. By Fagin’s theorem [48 ] there exists a fixed ESO sentence φ \varphi φ such that G ∈ P G \in\mathcal{P} G ∈ P if and only if G ⊨ φ G \models\varphi G ⊨ φ .
Let I 1 , … , I 3 n ≥ 1 I_1,\ldots,I_{3n} \ge1 I 1 , … , I 3 n ≥ 1 be the given integers of the input instance of 3-Partition. Create a graph G G G by, for each I i I_i I i , adding a star with exactly I i I_i I i vertices. Then, it is easy to see that the input instance is a yes-instance of 3-Partition if and only if G ∈ P G \in\mathcal{P} G ∈ P , and hence if and only if G ⊨ φ G \models\varphi G ⊨ φ . The reduction runs in polynomial-time since we may assume that each integer in the input is given in unary, and since G G G is a forest of stars it has treedepth at most 2.
The NP-membership of the problem is obvious. □ \square □
MaxSNP
Finally, we consider extending the metatheorem to the natural optimization variant of SNP, introduced by Papadimitriou and Yannakakis [82 ] . We use the notation M a x S N P 0 \mathrm{MaxSNP}_0 MaxSNP 0 from [Pap94, Definition … inition 13.5], where MaxSNP is defined by making MaxSNP0 _0 0 closed under L L L -reductions. In SNP we ask for a solution such that each k k k -tuple of elements of R \mathcal{R} R satisfies the inner formula ψ \psi ψ . In MaxSNP0 _0 0 , we instead want to maximize the number of k k k -tuples that fulfill the inner formula. More formally, let ψ ( R 1 , … , R r , x 1 , … , x k ) \psi(R_1,\ldots,R_r,x_1,\ldots,x_k) ψ ( R 1 , … , R r , x 1 , … , x k ) be a quantifier-free formula. A problem in MaxSNP0 _0 0 takes a structure R = ( V , E 1 , … , E b ) \mathcal{R}=(V,E_1,\ldots,E_b) R = ( V , E 1 , … , E b ) and an integer p p p as input, and asks if there are relations R 1 , … , R r R_1,\ldots,R_r R 1 , … , R r such that there exist at least p p p k k k -tuples v ˉ \bar{v} v ˉ such that ψ ( R 1 , … , R r , v ˉ ) \psi(R_1,\ldots,R_r,\bar{v}) ψ ( R 1 , … , R r , v ˉ ) holds.
When using the natural parameter p p p , every fixed problem in this class is fixed-parameter tractable [29 ] and admits a polynomial kernel [69 ] . Here, we instead consider treedepth as the parameter.
Theorem 54. There is a fixed quantifier-free formula ψ ( A , x 1 , … , x 10 ) \psi(A,x_1,\ldots,x_{10}) ψ ( A , x 1 , … , x 10 ) , where A A A is a binary relation variable, for which the following decision problem is NP-complete: Given a relational structure R \mathcal{R} R and an integer p p p , determine whether there is a relation A ⊆ V ( R ) 2 A \subseteq V(\mathcal{R})^2 A ⊆ V ( R ) 2 such that
∣ { v ˉ ∈ V ( R ) 10 ∣ R ⊨ ψ ( A , v ˉ ) } ∣ ≥ p . \left|\left\{\bar{v}\in V(\mathcal{R})^{10}\mid\mathcal{R}\models\psi(A,\bar{v})\right\}\right|\geq p. { v ˉ ∈ V ( R ) 10 ∣ R ⊨ ψ ( A , v ˉ ) } ≥ p . This holds even when $\operatorname{td}(\mathcal{R})\leq 2.
Proof. It is clear that the described problem is in NP by guessing the solution relation A A A and verifying if the formula holds for each 10-tuple of the structure.
For the NP-hardness, we reduce from Exact Bin Packing, which is strongly NP-hard [65 , 58 ] . In this problem, the input consists of n n n positive integers I 1 , … , I n I_1,\ldots,I_n I 1 , … , I n , and a positive integer m ≥ 2 m\geq2 m ≥ 2 , such that ∑ i ∈ [ n ] I i \sum_{i\in[n]} I_i ∑ i ∈ [ n ] I i is divisible by m m m . The question is if it is possible to assign each number to one of m m m bins, such that the sum of the numbers in each bin is exactly ( ∑ i ∈ [ n ] I i ) / m (\sum_{i\in[n]} I_i)/m ( ∑ i ∈ [ n ] I i ) / m . We create a graph G G G by adding, for each integer I i I_i I i of the input, a star on I i I_i I i vertices. Let S S S be a unary relation containing all vertices of these stars. Add two additional isolated vertices q 1 , q 2 q_1,q_2 q 1 , q 2 , and two further unary relations Q 1 , Q 2 Q_1,Q_2 Q 1 , Q 2 , such that Q 1 = { q 1 } Q_1=\{q_1\} Q 1 = { q 1 } and Q 2 = { q 2 } Q_2=\{q_2\} Q 2 = { q 2 } . Finally, add m m m further isolated vertices b 1 , … , b m b_1,\ldots,b_m b 1 , … , b m , and another unary relation B = { b 1 , … , b m } B=\{b_1,\ldots,b_m\} B = { b 1 , … , b m } .
The integers of the input are encoded by stars, and the vertices b 1 , … , b m b_1,\ldots,b_m b 1 , … , b m represent the bins these integers can be assigned to. The vertices q 1 , q 2 q_1,q_2 q 1 , q 2 exist for technical reasons that become clear later. Let R \mathcal{R} R be the resulting relational structure, and observe that it is a labeled graph with treedepth at most 2.
For our formula ψ \psi ψ , we will use a binary relation A A A , the intended meaning of A ( x , c ) A(x,c) A ( x , c ) is that vertex x x x (of a star) is assigned to bin vertex c c c . Our first goal will be ensuring that each star is either assigned to no bin, or fully to a bin. For this purpose, we first introduce a formula TypeCheck ( A , x , c ) \operatorname{TypeCheck}(A,x,c) TypeCheck ( A , x , c ) which simply verifies that, when A ( x , c ) A(x,c) A ( x , c ) holds, then x x x is a star vertex and c c c a bin vertex that x x x is assigned to.
TypeCheck ( A , x , c ) : = ( A ( x , c ) → S ( x ) ∧ B ( c ) ) . \operatorname{TypeCheck}(A,x,c):=(A(x,c)\to S(x)\land B(c)). TypeCheck ( A , x , c ) := ( A ( x , c ) → S ( x ) ∧ B ( c )) .
Now, we define the formula Assigned ( A , x , y , c , d ) \operatorname{Assigned}(A,x,y,c,d) Assigned ( A , x , y , c , d ) that will ensure a star is either fully, or not at all assigned to a specific bin vertex.
Assigned ( A , x , y , c , d ) : = ( A ( x , c ) ∧ E ( x , y ) → A ( y , c ) ) ∧ ( A ( x , c ) ∧ A ( x , d ) → c = d ) . \operatorname{Assigned}(A,x,y,c,d):=(A(x,c)\land E(x,y)\to A(y,c))\land(A(x,c)\land A(x,d)\to c=d). Assigned ( A , x , y , c , d ) := ( A ( x , c ) ∧ E ( x , y ) → A ( y , c )) ∧ ( A ( x , c ) ∧ A ( x , d ) → c = d ) .
The first conjunct of the formula will later ensure that if a vertex x x x of a star is assigned to a bin vertex c c c , then all other vertices of the same star are also assigned to c c c . Note that this requires some (trivial) transitive argument based on the fact that a star is a connected graph. The second conjunct ensures that a vertex cannot be assigned to c c c and d d d at the same time when c ≠ d c\ne d c = d .
Now, if each 4-tuple ( x , y , c , d ) (x,y,c,d) ( x , y , c , d ) of elements fulfills TypeCheck ( A , x , c ) ∧ Assigned ( A , x , y , c , d ) \operatorname{TypeCheck}(A,x,c) \land\operatorname{Assigned}(A,x,y,c,d) TypeCheck ( A , x , c ) ∧ Assigned ( A , x , y , c , d ) , then each star is either fully assigned to a single bin by A A A , or not assigned to any bin. By using a simple trick that makes it catastrophic for the solution size if a 4-tuple does not fulfill this formula, we will ensure it indeed holds for each 4-tuple. Hence, the remaining task is encoding that the assignments to each bin all sum to the same integer.
The key is creating a formula which prefers even-spread assignments. Concretely, consider
Even ( A , x , y , c , d ) : = ( A ( x , c ) ∧ A ( y , d ) ∧ c ≠ d ) . \operatorname{Even}(A,x,y,c,d) := (A(x,c) \land A(y,d) \land c \ne d). Even ( A , x , y , c , d ) := ( A ( x , c ) ∧ A ( y , d ) ∧ c = d ) .
Let us give some intuition about the purpose of the formula Even ( A , x , y , c , d ) \operatorname{Even}(A,x,y,c,d) Even ( A , x , y , c , d ) . Consider some solution A A A , and assume that TypeCheck ( A , x , c ) ∧ Assigned ( A , x , y , c , d ) \operatorname{TypeCheck}(A,x,c) \land\operatorname{Assigned}(A,x,y,c,d) TypeCheck ( A , x , c ) ∧ Assigned ( A , x , y , c , d ) holds for each 4-tuple of elements ( x , y , c , d ) (x,y,c,d) ( x , y , c , d ) under the solution A A A . For each bin b i b_i b i , let ℓ i \ell_i ℓ i be the number of vertices assigned to b i b_i b i , that is, the number of elements x x x for which A ( x , b i ) A(x,b_i) A ( x , b i ) holds. Moreover, let N = ∑ i ∈ [ m ] ℓ i N = \sum_{i \in[m]} \ell_i N = ∑ i ∈ [ m ] ℓ i be the total number of assigned vertices. Then, the number of 4-tuples ( x , y , c , d ) (x,y,c,d) ( x , y , c , d ) for which Even holds is exactly N 2 − ∑ i ∈ [ m ] ℓ i 2 N^2 - \sum_{i \in[m]} \ell_i^2 N 2 − ∑ i ∈ [ m ] ℓ i 2 . This is because Even ( A , x , y , c , d ) \operatorname{Even}(A,x,y,c,d) Even ( A , x , y , c , d ) holds exactly when x x x is assigned to c c c , y y y is assigned to d d d , and c ≠ d c \ne d c = d . For each assigned vertex, there is exactly one bin c c c it is assigned to. Hence, each pair of the N 2 N^2 N 2 pairs of assigned vertices fulfills the first two conditions, and then we only need to remove those pairs again which are assigned to the same bin. The number of 4-tuples which fulfill the formula is maximized when all vertices are assigned and each bin contains exactly the same number of vertices.
Now, we have all ingredients necessary to describe the formula. Formally, the fixed formula ψ \psi ψ reads
ψ ( A , z , x , y , c , d , a 1 , … , a 5 ) : = [ Q 1 ( z ) ∧ TypeCheck ( A , x , c ) ∧ Assigned ( A , x , y , c , d ) ] ∨ [ Q 2 ( z ) ∧ Even ( A , x , y , c , d ) ∧ ⋀ i ∈ [ 5 ] a i = z ] . \psi(A,z,x,y,c,d,a_1,\ldots,a_5) := [Q_1(z) \land\operatorname{TypeCheck}(A,x,c) \land\operatorname{Assigned}(A,x,y,c,d)]
\lor[Q_2(z) \land\operatorname{Even}(A,x,y,c,d) \land\bigwedge_{i \in[5]} a_i = z]. ψ ( A , z , x , y , c , d , a 1 , … , a 5 ) := [ Q 1 ( z ) ∧ TypeCheck ( A , x , c ) ∧ Assigned ( A , x , y , c , d )] ∨ [ Q 2 ( z ) ∧ Even ( A , x , y , c , d ) ∧ i ∈ [ 5 ] ⋀ a i = z ] .
Set T = ∑ i ∈ [ n ] I i T = \sum_{i \in[n]} I_i T = ∑ i ∈ [ n ] I i and D = T / m D = T/m D = T / m . The integer p p p is set to ∣ V ( R ) ∣ 9 + T 2 − m D 2 |V(\mathcal{R})|^9 + T^2 - mD^2 ∣ V ( R ) ∣ 9 + T 2 − m D 2 . We will show that I 1 , … , I n , m I_1,\ldots,I_n,m I 1 , … , I n , m is a yes-instance of Exact Bin Packing if and only if there is a relation A A A such that at least p p p 10-tuples v ˉ \bar{v} v ˉ fulfill ψ ( A , v ˉ ) \psi(A,\bar{v}) ψ ( A , v ˉ ) .
Claim 55. If ( I 1 , … , I n , m ) (I_1,\ldots,I_n,m) ( I 1 , … , I n , m ) is a yes-instance of Exact Bin Packing, then there is a relation A A A such that at least p p p 10-tuples v ˉ \bar{v} v ˉ fulfill ψ ( A , v ˉ ) \psi(A,\bar{v}) ψ ( A , v ˉ ) .
Proof of claim. Let P 1 , … , P m P_1,\ldots,P_m P 1 , … , P m be the corresponding partition. We add ( v , b i ) (v,b_i) ( v , b i ) to A A A if and only if the integer corresponding to the star containing v v v is part of P i P_i P i .
It is easy to check that this means each 10-tuple ( z , x , y , c , d , a 1 , … , a 5 ) (z,x,y,c,d,a_1,\ldots,a_5) ( z , x , y , c , d , a 1 , … , a 5 ) with z = q 1 z=q_1 z = q 1 fulfills ψ \psi ψ . Indeed, then Q 1 ( z ) Q_1(z) Q 1 ( z ) is true, and we have clearly chosen A A A in such a way that TypeCheck ( A , x , c ) \operatorname{TypeCheck}(A,x,c) TypeCheck ( A , x , c ) and Assigned ( A , x , y , c , d ) \operatorname{Assigned}(A,x,y,c,d) Assigned ( A , x , y , c , d ) hold. This yields exactly ∣ V ( R ) ∣ 9 |V(\mathcal{R})|^9 ∣ V ( R ) ∣ 9 tuples for which ψ \psi ψ holds.
Now, we argue that there are T 2 − m D 2 T^2-mD^2 T 2 − m D 2 further tuples for which ψ \psi ψ holds. Concretely, fix some 4-tuple ( x , y , c , d ) (x,y,c,d) ( x , y , c , d ) , where the vertices belonging to stars, vertex x x x is assigned to c c c and vertex y y y is assigned to d d d by relation A A A , and c ≠ d c \ne d c = d . The number of such tuples is in fact exactly T 2 − m D 2 T^2-mD^2 T 2 − m D 2 by arguments provided earlier in this proof, and we have that Even ( A , x , y , c , d ) \operatorname{Even}(A,x,y,c,d) Even ( A , x , y , c , d ) holds. Then, the tuple ( q 2 , x , y , c , d , q 2 , q 2 , q 2 , q 2 , q 2 ) (q_2,x,y,c,d,q_2,q_2,q_2,q_2,q_2) ( q 2 , x , y , c , d , q 2 , q 2 , q 2 , q 2 , q 2 ) fulfills ψ \psi ψ , because it fulfills the second disjunct of ψ \psi ψ .
Claim 56. If there is a relation A A A such that at least p p p tuples v ˉ \bar{v} v ˉ fulfill ψ ( A , v ˉ ) \psi(A,\bar{v}) ψ ( A , v ˉ ) , then ( I 1 , … , I n , m ) (I_1,\ldots,I_n,m) ( I 1 , … , I n , m ) is a yes-instance of Exact Bin Packing.
Proof of claim. Observe that the maximum number of tuples that can fulfill ψ \psi ψ is bounded by ∣ V ( R ) ∣ 9 + ∣ V ( R ) ∣ 4 |V(\mathcal{R})|^9 + |V(\mathcal{R})|^4 ∣ V ( R ) ∣ 9 + ∣ V ( R ) ∣ 4 , because the first disjunct can only hold if the tuple starts with q 1 q_1 q 1 , and the
second disjunct can only hold if the tuple starts with q 2 q_2 q 2 , and the last five elements of the tuple are also q 2 q_2 q 2 .
We show that for each 4-tuple ( x , y , c , d ) ∈ V ( R ) 4 (x,y,c,d) \in V(\mathcal{R})^4 ( x , y , c , d ) ∈ V ( R ) 4 , TypeCheck( A , x , c ) (A,x,c) ( A , x , c ) and Assigned( A , x , y , c , d ) (A,x,y,c,d) ( A , x , y , c , d ) hold. Towards a contradiction, assume that this is not the case.
If, for a fixed tuple ( x , y , c , d ) (x,y,c,d) ( x , y , c , d ) we have that TypeCheck( A , x , c ) (A,x,c) ( A , x , c ) or Assigned( A , x , y , c , d ) (A,x,y,c,d) ( A , x , y , c , d ) do not hold, the number of tuples for which ψ \psi ψ holds immediately decreases by ∣ V ( R ) ∣ 5 |V(\mathcal{R})|^5 ∣ V ( R ) ∣ 5 , because the first disjunct of ψ \psi ψ leaves a 1 , … , a 5 a_1,\ldots,a_5 a 1 , … , a 5 free. So, the total number of tuples for which ψ \psi ψ holds is at most ∣ V ( R ) ∣ 9 − ∣ V ( R ) ∣ 5 + ∣ V ( R ) ∣ 4 |V(\mathcal{R})|^9-|V(\mathcal{R})|^5+|V(\mathcal{R})|^4 ∣ V ( R ) ∣ 9 − ∣ V ( R ) ∣ 5 + ∣ V ( R ) ∣ 4 . However, ∣ V ( R ) ∣ 9 − ∣ V ( R ) ∣ 5 + ∣ V ( R ) ∣ 4 < ∣ V ( R ) ∣ 9 < p |V(\mathcal{R})|^9-|V(\mathcal{R})|^5+|V(\mathcal{R})|^4 < |V(\mathcal{R})|^9 < p ∣ V ( R ) ∣ 9 − ∣ V ( R ) ∣ 5 + ∣ V ( R ) ∣ 4 < ∣ V ( R ) ∣ 9 < p , a contradiction.
Hence, for each 4-tuple ( x , y , c , d ) (x,y,c,d) ( x , y , c , d ) we have that TypeCheck( A , x , c ) (A,x,c) ( A , x , c ) and Assigned( A , x , y , c , d ) (A,x,y,c,d) ( A , x , y , c , d ) hold. As argued before, this ensures that either all vertices of a star are assigned to the same unique bin vertex, or the vertices of the star are not assigned.
We argue that then, the relation A A A gives us a solution to the input instance. This is because there must be at least T 2 − m D 2 T^2-mD^2 T 2 − m D 2 further tuples for which ψ \psi ψ holds, which must then be tuples of the form ( q 2 , x , y , c , d , q 2 , q 2 , q 2 , q 2 , q 2 ) (q_2,x,y,c,d,q_2,q_2,q_2,q_2,q_2) ( q 2 , x , y , c , d , q 2 , q 2 , q 2 , q 2 , q 2 ) . As argued earlier, the number of such tuples which fulfill ψ \psi ψ is exactly N 2 − ∑ i ∈ [ m ] ℓ i 2 N^2-\sum_{i\in[m]}\ell_i^2 N 2 − ∑ i ∈ [ m ] ℓ i 2 , where ℓ i \ell_i ℓ i is the number of vertices assigned to b i b_i b i , and N = ∑ i ℓ i N=\sum_i\ell_i N = ∑ i ℓ i .
By Cauchy–Schwarz, we have that N 2 / m ≤ ∑ i ∈ [ m ] ℓ i 2 N^2/m\leq\sum_{i\in[m]}\ell_i^2 N 2 / m ≤ ∑ i ∈ [ m ] ℓ i 2 . Therefore,
N 2 − ∑ i ∈ [ m ] ℓ i 2 ≤ ( 1 − 1 / m ) N 2 ≤ ( 1 − 1 / m ) T 2 = T 2 − m D 2 . N^2-\sum_{i\in[m]}\ell_i^2\leq(1-1/m)N^2\leq(1-1/m)T^2=T^2-mD^2. N 2 − i ∈ [ m ] ∑ ℓ i 2 ≤ ( 1 − 1/ m ) N 2 ≤ ( 1 − 1/ m ) T 2 = T 2 − m D 2 .
Since p = ∣ V ( R ) ∣ 9 + T 2 − m D 2 p=|V(\mathcal{R})|^9+T^2-mD^2 p = ∣ V ( R ) ∣ 9 + T 2 − m D 2 , equality must hold throughout. This implies T = N T=N T = N , and thus all vertices of stars must be assigned. Moreover, we must have ∑ i ∈ [ m ] ℓ i 2 = m D 2 \sum_{i\in[m]}\ell_i^2=mD^2 ∑ i ∈ [ m ] ℓ i 2 = m D 2 . From this and the fact that ∑ i ∈ [ m ] ℓ i = T = m D \sum_{i\in[m]}\ell_i=T=mD ∑ i ∈ [ m ] ℓ i = T = m D we obtain
∑ i ∈ [ m ] ( ℓ i − D ) 2 = ∑ i ∈ [ m ] ℓ i 2 − 2 D ∑ i ∈ [ m ] ℓ i + m D 2 = m D 2 − 2 m D 2 + m D 2 = 0. \sum_{i\in[m]}(\ell_i-D)^2=\sum_{i\in[m]}\ell_i^2-2D\sum_{i\in[m]}\ell_i+mD^2=mD^2-2mD^2+mD^2=0. i ∈ [ m ] ∑ ( ℓ i − D ) 2 = i ∈ [ m ] ∑ ℓ i 2 − 2 D i ∈ [ m ] ∑ ℓ i + m D 2 = m D 2 − 2 m D 2 + m D 2 = 0.
This directly yields that ℓ i = D \ell_i=D ℓ i = D for each i ∈ [ m ] i\in[m] i ∈ [ m ] , showing that exactly D D D vertices are assigned to each bin. Together with the previous observation that for each star either all or no vertices are assigned to a bin, this shows that the input instance of Exact Bin Packing is a yes-instance. ◁
Since Exact Bin Packing is strongly NP-hard, we can assume the integers of the input are given in unary, and hence the reduction runs in polynomial-time. This concludes the proof. □
AI Methodology
We used GPT-5.6 Sol to obtain a proof that computing the stack number of a graph is FPT parameterized by treedepth. Moreover, the same system was used to consider potential generalizations, eventually leading us to look into SNP Model Checking. The proofs of the main result for SNP Model Checking follow but go beyond the proof of stack number provided by GPT, and these proofs were written by the authors directly.
GPT-5.6 Sol was used to look for further examples of problems expressible by SNP, leading us to include Boxicity as an additional example application. GPT-5.6 Sol and GPT-6 Astra were used to look for an example of a problem that can witness the non-extendability of our main result, leading to Theorem 53. The result in Theorem 54 was obtained using GPT-6 Astra.
We also used various large language model tools (including GPT-5.6 Sol, GPT-6 Astra, Claude Opus 5, Opus 5.5, and Fable 5.1) to proofread the paper, to help with writing, and to search the literature. They also assisted in the creation of our figures.
The authors checked the correctness of the content, investigated relevant prior work, and take full responsibility for the article.
Acknowledgments
T. Depian, R. Ganian, M. Gründel, and S. Wietheger acknowledge support from the Austrian Science Fund (FWF Projects 10.55776/Y1329 and 10.55776/COE12) and the Vienna Science and Technology Fund (WWTF Project 10.47379/ICT22029).