Second-Order Logic
2
Manuel Bodirsky
!Ï3
TU Dresden, Institut für Algebra, Germany
4
Simon Knäuer
!Ï5
TU Dresden, Institut für Algebra, Germany
6
Sebastian Rudolph
!Ï7
TU Dresden, Computational Logic Group, Germany
8
Abstract
9
We characterise the sentences in Monadic Second-order Logic (MSO) that are over finite structures
10
equivalent to a Datalog program, in terms of an existential pebble game. We also show that for
11
every classCof finite structures that can be expressed in MSO and is closed under homomorphisms,
12
and for allℓ, k∈N, there exists acanonical Datalog program Π of width (ℓ, k), that is, a Datalog
13
program of width (ℓ, k) which is sound forC (i.e., Π only derives the goal predicate on a finite
14
structureAifA∈ C) and with the property that Π derives the goal predicate wheneversomeDatalog
15
program of width (ℓ, k) which is sound forC derives the goal predicate. The same characterisations
16
also hold for Guarded Second-order Logic (GSO), which properly extends MSO. To prove our results,
17
we show that every classC in GSO whose complement is closed under homomorphisms is a finite
18
union of constraint satisfaction problems (CSPs) ofω-categorical structures.
19
2012 ACM Subject Classification Theory of computation→Finite Model Theory
20
Keywords and phrases Monadic Second-order Logic, Guarded Second-order Logic, Datalog, con-
21
straint satisfaction, homomorphism-closed, conjunctive query, primitive positive formula, pebble
22
game,ω-categoricity
23
Digital Object Identifier 10.4230/LIPIcs.CVIT.2016.23
24
Funding Manuel Bodirsky: The author has received funding from the European Research Council
25
(Grant Agreement no. 681988, CSP-Infinity).
26
Simon Knäuer: The author is supported by DFG Graduiertenkolleg 1763 (QuantLA).
27
Sebastian Rudolph: The author has received funding from the European Research Council (Grant
28
Agreement no. 771779, DeciGUT).
29
1 Introduction
30
Monadic Second-order Logic (MSO)is an important logic in theoretical computer science.
31
By Büchi’s theorem, a formal language can be defined in MSO if and only if it is regular (see,
32
e.g., [24]). MSO sentences can be evaluated in polynomial time on classes of structures whose
33
treewidth is bounded by a constant; this is known as Courcelle’s theorem [16]. The latter
34
result even holds for the more expressive logic ofGuarded Second-order Logic (GSO) [21, 18],
35
which extends First-order Logic by second-order quantifiers overguarded relations. Guarded
36
Second-order Logic containsGuarded First-order Logic(which itself captures many description
37
logics [20]).
38
Another fundamental formalism in theoretical computer science, which is heavily studied
39
in database theory, isDatalog (see, e.g., [24]). Every Datalog program can be evaluated on
40
finite structures in polynomial time. Like MSO, Datalog strikes a good balance between
41
expressivity and good mathematical and computational properties. Two important parameters
42
of a Datalog program Π are the maximal arityℓ of its auxiliary predicates (IDBs), and the
43
© Manuel Bodirsky and Simon Käuer and Sebastian Rudolph;
maximal numberkof variables per rule in Π. We then say that Π has width(ℓ, k), following
44
the terminology of Feder and Vardi [19]. These parameters are important both in theory
45
and in practice: ℓclosely corresponds to the exponent of the size of the memory space and k
46
to the exponent of the number of computation steps needed when evaluating Π on a given
47
structure (see, e.g., [4]).
48
In some scenarios we are interested in having the good computational properties of
49
expressibility in Datalogand having the good computational properties of expressibility in
50
MSO. A wide variety of popular query formalisms (among them (unions of) conjunctive queries,
51
(2-way conjunctive) regular path queries, monadic Datalog, guarded Datalog, monadically
52
defined queries, or nested monadically defined queries) are known to be both in Datalog
53
and GSO [25]. Also, all these formalisms have favourable properties when it comes to static
54
analysis, most notably decidable query containment [25]. Note that on the contrary, query
55
containment in unrestricted Datalog is undecidable, as is query containment in unrestricted
56
MSO / GSO. So it is really the interplay of the restrictions imposed by both formalisms that
57
is required to ensure decidability of a central task in databases and that makes this fragment
58
interesting and worthwhile investigating.
59
In this paper we investigate two questions that (perhaps surprisingly) turn out to be
60
closely related:
61
1. Which classes of finite structures are simultaneously expressible in MSO and in Datalog?
62
2. Which constraint satisfaction problems (CSPs) can be expressed in MSO, or, more
63
generally, in GSO?
64
For a structureBwith a finite relational signature τ, the constraint satisfaction problem forB is the class of all finiteτ-structures that homomorphically map toB. Every finite- domain constraint satisfaction problem can already be expressed in monotone monadic SNP (MMSNP; [19]), which is a small fragment of MSO. On the other hand, the constraint satisfaction problem for (Q;<), which is the class of all finite acyclic digraphs (V;E), cannot be expressed in MMSNP [6], but can be expressed in MSO by the sentence
∀X̸=∅ ∃x∈X ∀y∈X:¬E(x, y).
The class of CSPs of arbitrary infinite structuresB is quite large; it is easy to see that a
65
classDof finite structures with a finite relational signatureτ is a CSP of a countably infinite
66
structure if and only if
67
it is closed under disjoint unions, and
68
A∈ Dfor anyAthat maps homomorphically to someA′∈ D.
69
The second item can equivalently be rephrased as thecomplement of D(meant within the class of all finiteτ-structures; this comment applies throughout and will be omitted in the following) beingclosed under homomorphisms: a classC is closed under homomorphisms if for any structureA∈ C that maps homomorphically to someCwe haveC∈ C. Examples of classes of structures that are closed under homomorphisms naturally arise from Datalog.
We say that a classCof finiteτ-structuresis definable in Datalog1 if there exists a Datalog program Π with a distinguished predicate nullarygoalsuch that Π derivesgoalon a finite τ-structure if and only if the structure is inC; in this case, we writeJΠKforC. Every class of τ-structures in Datalog is closed under homomorphisms. However, not every class of finite structures in Datalog describes the complement of a CSP: consider for example, for unary predicatesR andB, the classCR,B of finite{R, B}-structuresAsuch thatRAis empty or
1 Warning: Feder and Vardi [19] say that a CSP is in Datalog if itscomplementin the class of all finite τ-structures is in Datalog.
BA is empty. Clearly,CR,B is not closed under disjoint unions. However, a finite structure is inCR,B if and only if the Datalog program that consists of just one rule
goal:−R(x), B(y) does not derivegoalon that structure.
70
An important class of CSPs is the class of CSPs for structures B that are countably
71
infinite and ω-categorical. A structure B is ω-categorical if all countable models of the
72
first-order theory ofBare isomorphic. A well-known example of anω-categorical structure is
73
(Q;<), which is a result due to Cantor [15]. Constraint satisfaction problems ofω-categorical
74
structures can be evaluated in polynomial time on classes of treewidth bounded by some
75
constant k∈N, by a result of Bodirsky and Dalmau [7]. The polynomial-time algorithm
76
presented by Bodirsky and Dalmau is in fact a Datalog program of width (k−1, k). A
77
Datalog program Π is calledsound for a class of τ-structuresC if JΠK⊆ C. Bodirsky and
78
Dalmau showed that ifC is the complement of the CSP of anω-categoricalτ-structureB
79
then there exists for all ℓ, k∈Na canonical Datalog program of width(ℓ, k) for C, i.e., a
80
Datalog program Π of width (ℓ, k) such that
81
Π is sound for C, and
82
JΠ′K⊆JΠKfor every Datalog program Π′ of width (ℓ, k) which is sound forC.
83
Moreover, whether the canonical Datalog program of width (ℓ, k) for C derives goalon a
84
givenτ-structureAcan be characterised in terms of the existential pebble game from finite
85
model theory, played on (A,B) [7]. The existentialℓ, k pebble gameis played by two players,
86
calledSpoiler andDuplicator (see, e.g., [17, 19, 23]). Spoiler starts by placingkpebbles on
87
elementsa1, . . . , ak ofA, and Duplicator responds by placingkpebblesb1, . . . , bk onB. If
88
the map that sendsa1, . . . , ak tob1, . . . , bk is not a partial homomorphism fromAtoB, then
89
the game is over and Spoiler wins. Otherwise, Spoiler removes all but at mostℓpebbles from
90
A, and Duplicator has to respond by removing the corresponding pebbles fromB. Then
91
Spoiler can again place all his pebbles onA, and Duplicator must again respond by placing
92
her pebbles onB. If the game continues forever, then Duplicator wins. IfBis a finite, or
93
more generally a countableω-categorical structure then Spoiler has a winning strategy for
94
the existentialℓ, kpebble game on (A,B) if and only if the canonical Datalog program for
95
CSP(B) derivesgoalonA(Theorem 19). This connection played an essential role in proving
96
Datalog inexpressibility results, for example for the class of finite-domain CSPs [2] (leading
97
to a complete classification of those finite structuresBsuch that the complement of CSP(B)
98
can be expressed in Datalog [3]).
99
Results and Consequences
100
We present a characterisation of those GSO sentences Φ that are over finite structures
101
equivalent to a Datalog program. Our characterisation involves a variant of the existential
102
pebble game from finite model theory, which we call the (ℓ, k)-game. This game is defined
103
for a homomorphism-closed classC of finiteτ-structures, and it is played by the two players
104
Spoiler and Duplicator on a finiteτ-structureAas follows.
105
Duplicator picks a countable τ-structureBsuch that CSP(B)∩ C=∅.
106
The game then continues as the existential (ℓ, k) pebble game played by Spoiler and
107
Duplicator on (A,B).
108
In Section 4 we show that a GSO sentence Φ is over finite structures equivalent to a Datalog
109
program of width (ℓ, k) if and only if
110
JΦKis closed under homomorphisms, and
111
Spoiler wins the existential (ℓ, k)-game forJΦKonAif and only if A|= Φ.
112
We also show that for every GSO sentence Φ whose class of finite modelsCis closed under
113
homomorphisms and for allℓ, k∈Nthere exists a canonical Datalog program Π of width
114
(ℓ, k) for C (Theorem 22). To prove these results, we first show that every class of finite
115
structures in GSO whose complement is closed under homomorphisms is a finite union of
116
CSPs that can also be expressed in GSO (Lemma 16; an analogous statement holds for MSO).
117
Moreover, every CSP in GSO is the CSP of a countableω-categorical structure (Corollary 10);
118
this allows us to use results from [7] to make the link to existential pebble games. We also
119
present an example of such a CSP which is even expressible in MSO and coNP-complete, and
120
hence not the CSP of a reduct of a finitely bounded homogeneous structure, unless NP=coNP
121
(Proposition 23). Note that our results imply that every class of finite structures that can be
122
expressed both in in GSO and in Datalog is a finite intersection of the complements of CSPs
123
forω-categorical structures. In general, it is not true that a Datalog program describes a
124
finite intersection of complements of CSPs (we present a counterexample in Example 18).
125
2 Preliminaries
126
In the entire text,τ denotes a finite signature containing relation symbols and sometimes
127
also constant symbols. IfR∈τ is a relation symbol, we writear(R) for its arity. IfAis a
128
τ-structure we use the corresponding capital romanAletter to denote the domain of A; the
129
domains of structures are assumed to be non-empty. IfR∈τ, thenRA⊆Aar(R) denotes
130
the corresponding relation ofA.
131
A primitive positive τ-formula (in database theory also conjunctive query) is a first- orderτ-formula without disjunction, negation, and universal quantification. Every primitive positive formula is equivalent to a formula of the form
∃x1, . . . , xn(ψ1∧ · · · ∧ψm)
whereψ1, . . . , ψm are atomicτ-formulas, i.e., formulas built from relation symbols inτ or equality. Anexistential positiveτ-formulais a first-orderτ-formula without negation and universal quantification. We writeψ(x1. . . , xn) if the free variables ofψare from x1, . . . , xn. IfAis a τ-structure andψ(x1, . . . , xn) is a τ-formula, then the relation
R:={(a1, . . . , an)|A|=ψ(a1, . . . , an)}
is called the relationdefined by ψ over A; ifψ can be chosen to be primitive positive (or
132
existential positive) thenRis calledprimitively positively definable(orexistentially positively
133
definable, respectively).
134
For all logics over the signature τ considered in this text, we say that two formulas Φ(x1, . . . , xn) and Ψ(x1, . . . , xn) are equivalent (over finite structures)if for all (finite) τ- structuresAand alla1, . . . , an∈Awe have
A|= Φ(a1, . . . , an)⇔A|= Ψ(a1, . . . , an).
It is easy to see that every existential positiveτ-formula is a disjunction of primitive positive
135
τ-formulas (and hence referred to as a union of conjunctive queries in database theory).
136
Formulas without free variables are calledsentences; in database theory, formulas are often
137
calledqueriesand sentences are often calledBoolean queries. If Φ is a sentence, we write
138
JΦKfor the class of all finite models of Φ.
139
Areduct of a relational structureAis a structureA′ obtained fromAby dropping some
140
of the relations, andAis called anexpansion ofA′.
141
2.1 Datalog
142
In this section we refer to the finite set of relation and constant symbols τ as EDBs(for extensional database predicates). Letρbe a finite set of new relation symbols, called the IDBs(forintensional database predicates). A Datalog program is a set of rules of the form
ψ0:−ψ1, . . . , ψn
whereψ0is an atomicρ-formula andψ1, . . . , ψn are atomic (ρ∪τ)-formulas; we also assume that every variable that appears in the head also appears in the body. IfAis aτ-structure, and Π is a Datalog program with EDBsτ and IDBsρ, then a (τ∪ρ)-expansionA′ ofAis called afixed point of Πon AifA′ satisfies the sentence
∀¯x(ψ0∨ ¬ψ1∨ · · · ∨ ¬ψn)
for each ruleψ0:−ψ1, . . . , ψn. IfA1andA2are two (ρ∪τ)-structures with the same domain
143
A, thenA1∩A2denotes the (ρ∪τ)-structure with domainAsuch thatRA1∩A2 :=RA1∩RA2.
144
Note that ifA1 andA2 are two fixed points of Π onA, thenA1∩A2 is a fixed point of Π on
145
A, too. Hence, there exists a unique smallest (with respect to inclusion) fixed point of Π on
146
A, which we denote by Π(A). It is well-known that ifAis a finite structure then Π(A) can
147
be computed in polynomial time in the size ofA[24]. If R∈ρ, we also say that Πdefines
148
RΠ(A)on A. A Datalog program together with a distinguished predicateR∈ρmay also be
149
viewed as a formula, which we also call aDatalog query, and which over a given τ-structure
150
A denotes the relationRΠ(A). If the distinguished predicate has arity 0, we often call it
151
thegoal predicate; we say that Πderivesgoalon AifgoalΠ(A)={()}. The classC of finite
152
τ-structuresAsuch that Π derivesgoalonAis calledthe class of finite τ-structures defined
153
byΠ, and denoted byJΠK. Note that this classCis definable in universal second-order logic
154
(we have to express that in every expansion of the input by relations for the IDBs that
155
satisfies all the rules of the Datalog program the goal predicate is non-empty).
156
2.2 Second-Order Logic
157
Second-order logicis the extension of first-order logic which additionally allows existential
158
and universal quantification over relations; that is, if R is a relation symbol and ϕ is a
159
second-orderτ∪ {R}-formula, then∃R:ϕand∀R:ϕare second-orderτ-formulas. IfAis a
160
τ-structure and Φ is a second-orderτ-sentence, we writeA|= Φ (and say thatAis a model of
161
Φ) ifAsatisfies Φ, which is defined in the usual Tarskian style. We writeJΦKfor the class of
162
all finite models of Φ. A second-order formula is calledmonadic if all second-order variables
163
are unary. We use syntactic sugar and also write∀x∈X:ψinstead of∀x(X(x)⇒ψ) and
164
∃x∈X: ψinstead of∃x(X(x)∧ψ).
165
2.3 Guarded Second-Order Logic
166
Guarded Second-order Logic (GSO), introduced by Grädel, Hirsch, and Otto [21], is the
167
extension of guarded first-order logic by second-order quantifiers. Guarded (first-order)
168
τ-formulas are defined inductively by the following rules [1]:
169
1. all atomicτ-formulas are guardedτ-formulas;
170
2. ifϕandψare guarded τ-formulas, then so areϕ∧ψ,ϕ∨ψ, and¬ϕ.
171
3. if ψ(¯x,y) is a guarded¯ τ-formula and α(¯x,y) is an atomic¯ τ-formula such that all free
172
variables ofψoccur inαthen∃y α(¯¯ x,y)∧ψ(¯¯ x,y)¯
and∀¯y α(¯x,y)¯ ⇒ψ(¯x,y)¯
are guarded
173
τ-formulas.
174
v1 v2 v3 v4
w1 w2 w3 w4
S R R T
N N N
N N N
(a)StructureB
v1 v2 v3 v4
w1 w2 w3 w4
< < <
< < <
>
Pb Pb Pb Pb
Pa Pa Pa Pa (b)StructureA
aaaabbbb
(c)WordwA Figure 1An example of an{S, T, R, N}-structureBin the classC of Proposition 3.
Guarded second-order formulas are defined similarly, but we additionally allow (unrestricted)
175
second-order quantification; GSO generalises Courcelle’s logic MSO2 from graphs to general
176
relational structures.
177
▶Definition 1. A second-orderτ-formula is called guarded if it is defined inductively by
178
the rules (1)-(3) for guarded first-order logic and additionally by second-order quantification.
179
There are many semantically equivalent ways of introducing GSO [21]. Let B be a
180
τ-structure. Then (t1, . . . , tn)∈Bn is calledguarded inBif there exists an atomicτ-formula
181
ϕand b1, . . . , bk such thatB|=ϕ(b1, . . . , bk) and{t1, . . . , tn} ⊆ {b1, . . . , bk}. Note that (for
182
n= 1) every element of B is guarded (because of the atomic formulax=x). A relation
183
R ⊆ Bn is called guarded if all tuples in R are guarded. Note that all unary relations
184
are guarded. If Ψ is an arbitrary second-order sentence, we say that a finite structureA
185
satisfiesΨ with guarded semantics, in symbols A|=gΦ, if all second-order quantifiers in Ψ
186
are evaluated over guarded relations only. Note that for MSO sentences, the usual semantics
187
and the guarded semantics coincide.
188
▶Proposition 2 (see [21]). Guarded Second-order Logic and full Second-order Logic with
189
guarded semantics are equally expressive.
190
It follows that GSO is at least as expressive as MSO. There are Datalog programs that
191
are equivalent to a GSO sentence, but not to an MSO sentence. The proof is based on a
192
variant of an example of a Datalog query in GSO given in [13] (Example 2).
193
▶Proposition 3. There is a Datalog query that can be expressed in GSO but not in MSO.
194
Proof. Letτ be the signature consisting of the binary relation symbolsS, T, R, N, and letC
195
be the class of finiteτ-structures such that the following Datalog program with one binary
196
IDBU derivesgoal.
197
U(x, y) :−S(x, y)
198
U(x′, y′) :−U(x, y), N(x, x′), N(y, y′), R(x′, y′)
199
goal:−U(x, y), T(x, y) ◀
200201
On the left of Figure 1 one can find an example of a{S, T, R, N}-structure B where the
202
given Datalog program derives goal. To show that C is not MSO definable, suppose for
203
contradiction that there exists an MSO sentence Φ such thatJΦK=C. We use Φ to construct
204
an MSO sentence Ψ which holds on a finite wordw∈ {a, b}∗(represented as a structure with
205
signaturePa, Pb, <in the usual way [24]) if and only ifw∈ {anbn|n≥1}; this contradicts
206
the theorem of Büchi-Elgot-Trakhtenbrot (see, e.g., [24]). Let Φ′ be the MSO sentence
207
obtained from Φ by replacing all subformulas of Φ of the form
208
S(x, y) by a formulaϕS(x, y) that states thatxis the smallest element with respect to
209
<, thatPb(y), and that there is noz < y inPb;
210
T(x, y) by a formulaϕT(x, y) that states that Pa(x), that there is noz > xinPa, and
211
that y is the largest element with respect to<;
212
R(x, y) by the formulaϕR(x, y) given byx < y;
213
N(x, y) by a formulaϕN(x, y) stating thaty is the next element afterxwith respect to
214
<.
215
The resulting MSO sentence Ψ1has the signature{Pa, Pb, <}; let Ψ be the conjunction of Ψ1
216
with the sentence Ψ2 which states that for allx, y∈A, ifx < y andPa(y) then Pa(x). We
217
first show that ifAis a{<, Pa, Pb}-structure that represents a wordwA∈ {a, b}∗, thenA|= Ψ
218
if and only ifwA is of the formanbn for somen≥1. LetB be the{S, T, R, N}-structure
219
such that forX ∈ {S, T, R, N}we haveXB:={(x, y)|A|=ϕX(x, y)}. See Figure 1 for an
220
example of a structureAsuch thatwA=a4b4 and the corresponding{S, T, R, N}-structure
221
B.
222
If wA is of the form anbn for some n≥ 1, then Aclearly satisfies Ψ2. To show that
223
it also satisfies Ψ1, let v1, . . . , vn, w1, . . . , wn ∈ A be such that {v1, . . . , vn} = PaA and
224
{w1, . . . , wn}=PbAsuch that for alli, j∈ {1, . . . , n}, if i < jthenvi <Avj andwi <Awj.
225
Then
226
(v1, w1)∈SB, (vn, wn)∈TB,
227
(vi, wi)∈RBfor alli∈ {2, . . . , n−1}, (1)
228
(vi, vi+1),(wi, wi+1)∈NBfor alli∈ {1, . . . , n−1}.
229230
It follows thatBsatisfies Φ and thereforeA|= Ψ.
231
For the converse direction, suppose that A|= Ψ. Clearly,wA∈a∗b∗ becauseA|= Ψ2.
232
Moreover, sinceA|= Ψ1 we have thatB|= Φ, and hence there exist n∈Nand elements
233
v1, . . . , vn, w1, . . . , wn∈Asuch thatB satisfies (1). We first prove thatPaA={v1, . . . , vn}
234
and |PaA| = n. Since (vn, wn) ∈ TB we have ϕT(vn, wn) and hence vn ∈ PaA. Since
235
B |= N(v1, v2), . . . , N(vn−1, vn) we have that v1 < v2 < · · · < vn−1 < vn holds in A
236
and it also follows that |PaA| = n. Then for every i ∈ n we have that vi ∈ PaA because
237
vi ≤ vn, vn ∈ PaA, and wA ∈ a∗b∗. Now suppose for contradiction that there exists
238
x∈PaA\ {v1, . . . , vn}; choosexlargest with respect to<A. Since (vn, wn)∈TBandx∈PaA
239
we must havex≤vn, and hencex < vn sincex /∈ {v1, . . . , vn}. Then there existsy∈Asuch
240
thatϕN(x, y) holds inA. Sincey≤vn,vn∈PaA, andwA∈a∗b∗, we must havePaA. By the
241
maximal choice ofxwe get thaty=vi for somei∈ {1, . . . , n}. But thenϕN(x, vi) implies
242
thatx∈ {v1, . . . , vn−1}, a contradiction. Similarly, one can prove thatPbA={w1, . . . , wn}
243
and that|PbA|=n. This implies thatwA=anbn.
244
We finally have to prove thatC is in GSO. Let Φ be the GSO{S, T, R, N} sentence with
245
existentially quantified unary relations V, W, and existentially quntified binary relations
246
R′⊆RandN′⊆N, which states that
247
there are elements v1, vn∈V andw1, wn∈W such thatS(v1, w1) andT(vn, wn) hold;
248
for every x∈V \ {v1} there exists a unique element y ∈ V \ {vn} such that N′(y, x)
249
holds;
250
for every x∈V \ {vn} there exists a unique elementy ∈V \ {v1} such that N′(x, y)
251
holds;
252
for everyx∈W \ {w1}there exists a unique elementy∈W\ {wn} such thatN′(y, x)
253
holds;
254
for everyx∈W \ {wn} there exists a unique elementy ∈W \ {w1} such thatN′(x, y)
255
holds;
256
for allv∈V andw∈W we have thatN′(v1, v)∧N′(w1, w) impliesR′(v, w).
257
for allv, v′ ∈V \ {v1, vn} andw, w′∈W \ {w1, wn}we have thatR′(v, w)∧N′(v, v′)∧
258
N′(w, w′) impliesR′(v, w).
259
For allv∈V andw∈W we have thatN′(v, vn)∧N′(w, wn) impliesR′(v, w).
260
Then Φ holds on a finite{S, T, R, N}-structureBif and only ifBhas elementsv1, . . . , vn, w1, . . . , wn
261
satisfying (1), which is the case if and only ifB∈ C.
262
Sometimes, we will also use the term GSO (MSO, Datalog) to denote all problems (i.e.,
263
all classes of structures) that can be expressed in the formalism. In particular, this justifies
264
to say that a certain CSP isinGSO (MSO, Datalog).
265
3 Homomorphism-Closed GSO
266
We prove that the class of finite models of a GSO sentence is a finite union of CSPs of
267
ω-categorical structures whenever its complement is closed under homomorphisms. In
268
particular, every CSP in GSO (and therefore every CSP in MSO) is the CSP of an ω-
269
categorical structure. CSPs that can be formulated as the CSP of anω-categorical structure
270
have been characterised [10]; this characterisation will be recalled in the next section.
271
3.1 CSPs for Countably Categorical Structures
272
By the theorem of Ryll-Nardzewski, a countable structureBisω-categorical if and only if for
273
everyn∈Nthere are finitely many orbits of the componentwise action of the automorphism
274
group ofBonBn (see, e.g., [22]). We now present a condition that characterises classes of
275
structures that are CSPs ofω-categorical structures. LetCbe a class of finiteτ-structures. Let
276
Λnbe the class of primitive positiveτ-formulas with free variablesx1, . . . , xn whose canonical
277
database is inC. We define∼Cnto be the equivalence relation on Λnsuch thatϕ1∼Cnϕ2holds if
278
for all primitive positiveτ-formulasψ(x1, . . . , xn) we have thatϕ1(x1, . . . , xn)∧ψ(x1, . . . , xn)
279
is satisfiable in a structure fromC if and only ifϕ2(x1, . . . , xn)∧ψ(x1, . . . , xn) is satisfiable
280
in a structure fromC. Theindex of an equivalence relation is the number of its equivalence
281
classes.
282
▶Theorem 4(Bodirsky, Hils, Martin [10], Theorem 4.27). Let C be a constraint satisfaction
283
problem. Then there is anω-categorical structureBsuch that C= CSP(B)iff∼Cn has finite
284
index for alln. Moreover, the structure Bcan be chosen so that for alln∈Nthe orbits of
285
the componentwise action of the automorphism group ofB onBn are primitively positively
286
definable in B.
287
▶Example 5. The structureB1:= (Z;<) is notω-categorical. However,∼CSP(Bn 1)has finite
288
index for alln, and indeed CSP(Z;<) = CSP(Q;<) and (Q;<) isω-categorical. On the
289
other hand, forB2:= (Z; Succ) we have that the index∼CSP(B2 2) is infinite, and it follows
290
that there is noω-categorical structureBsuch that CSP(B2) = CSP(B); see [6].
291
A rich source of examples ofω-categorical structures are structures with finite relational
292
signature that arehomogeneous, i.e., every isomorphism between finite substructures can
293
be extended to an automorphism. There are uncountably many countable homogeneous
294
digraphs with pairwise distinct CSP, and it follows that there are homogeneous digraphs
295
with undecidable CSPs. A structureBis calledfinitely bounded if there exists a finite setF
296
of finite structures such that a finite structureAembeds intoBif and only if no structure in
297
F embeds intoA.
298
It is well-known that if a structure isω-categorical, then all of itsreductsareω-categorical
299
as well [22]. Moreover, it is easy to see that the CSP of reducts of finitely bounded structures
300
is in NP. It has been conjectured that the CSP of reducts of finitely bounded homogeneous
301
structures is in P or NP-complete [12]; this conjecture generalises the finite-domain complexity
302
dichotomy that was conjectured by Feder and Vardi [19] and proved by Bulatov [14] and by
303
Zhuk [26].
304
3.2 Quantifier Rank
305
In order to constructω-categorial structures for a given CSP in GSO, we need to verify the
306
condition given in Theorem 4; in this context, it will be convenient to work with signatures
307
that also contain constant symbols. Thequantifier rank of a second-orderτ-formula Φ is the
308
maximal number of nested (first-order or second-order) quantifiers in Φ; for this definition,
309
we view Φ as a second-order sentence with guarded semantics, just as in [5]. IfAandB are
310
τ-structures and q∈Nwe writeA≡GSOq BifAandBsatisfy the same GSOτ-sentences of
311
quantifier rank at mostq.
312
▶Lemma 6(Proposition 3.3 in [5]). Let q∈Nandτ be a finite signature with relation and
313
constant symbols. Then≡GSOq is an equivalence relation with finite index on the class of all
314
finite τ-structures. Moreover, every class of ≡GSOq can be defined by a single GSO sentence
315
with quantifier rank q. The analogous statements hold for MSO as well.
316
If A is a τ-structure and ¯a is a k-tuple of elements of A, then we write (A,¯a) for a
317
τ∪ {c1, . . . , ck}-structure expandingAwherec1, . . . , ck denote fresh constant symbols being
318
mapped to the corresponding entries of ¯a. IfAandBareτ-structures and ¯a∈Ak, ¯b∈Bk,
319
and when writing (A,a)¯ ≡GSOq (B,¯b) we implicitly assume that we have chosen the same
320
constant symbols for ¯aand for ¯b.
321
▶ Lemma 7 (Proposition 3.4 in [5]). Let q ∈ N and let A and B be τ-structures. Then
322
A≡GSOq+1 B if and only if the following properties hold:
323
(first-order forth) For every a∈A, there exists b∈B such that(A, a)≡GSOq (B, b).
324
(first-order back) For everyb∈B, there existsa∈A such that (A, a)≡GSOq (B, b).
325
(second-order forth) For every expansion A′ of Aby a guarded relation, there exists an
326
expansion B′ ofB by a guarded relation such that A′ ≡GSOq B′.
327
(second-order back) For every expansion B′ of Bby a guarded relation, there exists an
328
expansion A′ of Aby a guarded relation such that A′ ≡GSOq B′.
329
In the following,τ denotes a finite relational signature.
330
▶Definition 8. Letρ:={c1, . . . , cn} be a finite set of constant symbols. ThenDn is defined
331
to be the set of all pairs (A,B)of finite(τ∪ρ)-structures such that
332
cA=cB for all constant symbolsc∈ρ;
333
{cA1, . . . , cAn}=A∩B={cB1 , . . . , cBn}.
334
We writeA⊎Bfor the structure with domain A∪B such that RA⊎B:=RA∪RB for each
335
relation symbolR∈τ andcA⊎B=cA=cBfor each constant symbol c∈ρ.
336
The following theorem in the special case of n= 0 is Proposition 4.1 in [5].
337
▶Theorem 9. Letq, n, r, s∈N, let(A1,B1),(A2,B2)∈ Dn, and let¯a1∈(A1)r,¯a2∈(A2)r,
¯b1 ∈ (B1)s, ¯b2 ∈ (B2)s be such that (A1,¯a1) ≡GSOq (A2,¯a2) and (B1,¯b1) ≡GSOq (B2,¯b2).
Then
(A1⊎B1,¯a1,¯b1)≡GSOq (A2⊎B2,¯a2,¯b2).
Proof. Our proof is by induction onq. Every quantifier-free formula is a Boolean combination
338
of atomic formulas, so forq= 0 it suffices to consider atomic formulasϕ. By symmetry, it
339
suffices to show that if (A1⊎B1,¯a1,¯b1)|=ϕthen (A2⊎B2,¯a2,¯b2)|=ϕ. Thenϕis built using
340
a relation symbolR∈τ, and the tuple that witnesses the truth ofϕinA1⊎B1must be from
341
RA1 or fromRB1, by the definition ofA1⊎B1. We first consider the former case; the latter
342
case can be treated similarly. If a constant that appears inϕis fromA1∩B1, then by the
343
definition ofDn this element is denoted by a constant symbolc∈ρ, and therefore we may
344
assume without loss of generality thatϕis a formula over the signature of (A1,¯a1). Hence,
345
(A1,¯a1)|=ϕand by assumption (A2,¯a2)|=ϕ. This in turn implies that (A2⊎B2,a¯2,¯b2)|=ϕ.
346
For the inductive step, suppose that the claim holds forq, and that (A1,¯a1)≡GSOq+1 (A2,a¯2) and (B1,¯b1)≡GSOq+1 (B2,¯b2). By symmetry and Lemma 7 it suffices to verify the properties (first-order forth) and (second-order forth). Letc1∈A1∪B1. We may assume thatc1∈A1; the case thatc1∈B1 can be shown similarly. By Lemma 7, there existsc2∈A2 such that (A1,¯a1, c1)≡GSOq (A2,¯a2, c2). By the inductive assumption, this implies that
(A1⊎B1,a¯1, c1,¯b1)≡GSOq (A2⊎B2,a¯2, c2,¯b2) and concludes the proof of (first-order forth).
347
Now letRbe a guarded relation of A1⊎B1 of arityk. LetA′1be the expansion of A1
348
by the guarded relationR∩Ak1, and B′1 be the expansion of B1 by the guarded relation
349
R∩B1k. By Lemma 7 there are expansions A′2 of A andB′2 of B2 by guarded relations
350
such that (A′1,a¯1)≡GSOq (A′2,a¯2) and (B′1,¯b1)≡GSOq (B′2,¯b2). By the inductive assumption,
351
this implies that (A′1⊎B′1,¯a1,¯b1) ≡GSOq (A′2⊎B′2,¯a2,¯b2), which completes the proof of
352
(second-order forth). ◀
353
▶Corollary 10. Let Cbe a CSP that can be expressed in GSO. Then there exists a countable
354
ω-categorical structure Bsuch that C= CSP(B).
355
Proof. Letτ be the signature ofC, and let Φ be a GSOτ-formula with quantifierrankqsuch
356
thatC=JΦK. By Theorem 4 it suffices to show that the equivalence relation∼Cn has finite
357
index for everyn∈N. Letρ:={c1, . . . , cn}be a set of new constant symbols. By Lemma 6,
358
there exists anm∈Nsuch that ≡GSOq hasmequivalence classes on (τ∪ρ)-structures. If
359
ϕ(x1, . . . , xn) is a primitive positiveτ-formula, then defineSϕ to be the (τ∪ρ)-structure
360
whose elements are the equivalence classes of the smallest equivalence relation on the variables
361
of ϕ that contains all pairsx, y such that ϕcontains the conjunct x =y, and such that
362
(C1, . . . , Cn) ∈ RS for R ∈ τ if and only if there are y1 ∈ C1, . . . , yn ∈ C2 such that
363
R(y1, . . . , yn) is a conjunct ofϕ; finally, we setcSi ϕ := [xi] for alli∈ {1, . . . , n}.
364
We claim that ifSϕ≡GSOq Sψ, thenϕ∼Cn ψ. Letθ(x1, . . . , xn) be a primitive positive
365
τ-formula; we may assume that the existentially quantified variables ofθare disjoint from
366
the existentially quantified variables ofϕand ofψ, so that (Sϕ,Sθ),(Sψ,Sθ)∈ Dn. Since
367
Sϕ ≡GSOq Sψ andSθ ≡GSOq Sθ, we have Sϕ⊎Sθ ≡GSOq Sψ⊎Sθ by Theorem 9. Now
368
suppose thatϕ∧θ is satisfiable in a model of Φ. This is the case if and only ifSϕ⊎Sθ
369
satisfies Φ, which in turn implies thatSψ⊎Sθ satisfies Φ since Φ has quantifierrankq. This
370
in turn is the case if and only ifψ∧θis satisfiable in a model of Φ, which proves the claim.
371
The claim implies that∼Cn has at mostm equivalence classes, concluding the proof. ◀
372
▶Example 11. Let Φ be the following MSO sentence.
373
∀X ∃x:X(x)⇒ ∃x, y∈X ∀z∈X(¬E(x, z)∨ ¬E(y, z))
374375
It is easy to see thatJΦKis closed under disjoint unions and that its complement is closed
376
under homomorphisms. Corollary 10 implies that there exists a countable ω-categorical
377
structure with CSP(B) =JΦK.
378
3.3 Finite Unions of CSPs
379
In this section we prove that every class in GSO whose complement is closed under homo-
380
morphisms is a finite union of CSPs (Lemma 16); the statement announced at the beginning
381
of Section 3 then follows (Corollary 17). Throughout this section, letC be a non-empty class
382
of finiteτ-structures whose complement is closed under homomorphisms. In particular, C
383
contains the structure Iwith only one element where all relations are empty.
384
Let ∼be the equivalence relation defined onCby letting A∼Bif for everyC∈ C we
385
haveA⊎C∈ Cif and only ifB⊎C∈ C; here⊎denotes the usual disjoint union of structures,
386
which is a special case of Definition 8 forn= 0. Note that the equivalence classes of∼are
387
in one-to-one correspondence to the equivalence classes of∼C0. Also note thatC is closed
388
under disjoint unions if and only if∼has only one equivalence class.
389
IfA∈ C, then we write [A] for the equivalence class ofAwith respect to∼. The following
390
observations are immediate consequences from the definitions:
391
1. each∼-equivalence class is closed under homomorphic equivalence.
392
2. each∼-equivalence class is closed under disjoint unions.
393
3. A∈[I] if and only ifA⊎B∈ C for allB∈ C.
394
▶Lemma 12. LetA∈ C and letD be the smallest subclass ofC that contains[A] and whose
395
complement is closed under homomorphisms. Then
396
1. D is a union of equivalence classes of∼, and
397
2. if ∼has more than one equivalence class, then C \ D is non-empty.
398
Proof. LetC∈[A], letBbe a finite structure with a homomorphism toC, and letB′ ∈[B].
399
SinceB⊎CandCare homomorphically equivalent, we have thatB⊎C∼C. We claim that
400
B′⊎C∼C. To see this, letD∈ C. Then
401
C⊎D∈ C ⇔(B⊎C)⊎D∈ C (since B⊎C∼C)
402
⇔B⊎(C⊎D)∈ C
403
⇔B′⊎(C⊎D)∈ C (since B∼B′)
404
⇔(B′⊎C)⊎D∈ C
405406
which shows the claim. SoB′⊎C∈[C] = [A]. SinceB′ has a homomorphism toB′⊎Cwe
407
obtain thatB′∈ D; this proves the first statement.
408
To prove the second statement, first observe that the statement is clear if A∈[I], since
409
the complement of [I] is closed under homomorphisms. The statement therefore follows from
410
the assumption that∼has more than one equivalence class. Otherwise, ifA∈/[I], then there
411
exists a structureB∈ C such thatA⊎B∈ C. Then/ B∈ C \ Dcan be shown indirectly as
412
follows: otherwiseBwould have a homomorphism to a structureA′∈[A]. Since B⊎A′ is
413
homomorphically equivalent toA′, we haveB⊎A′∼A′∼Aand in particularB⊎A′∈ C.
414
But B⊎A′ ∈ C if and only if B⊎A ∈ C since A ∼A′. This is in contradiction to our
415
assumption onB. ◀
416
▶Example 13. We consider a signatureτ:={R1, R2, R3}of unary relation symbols. Define for everyi∈ {1,2,3}theτ-structureSi to be a one-element structure whereRiis non-empty