Data-Complexity of the Two-Variable Fragment with Counting Quantifiers
The data-complexity of both satisfiability and finite satisfiability for the two-variable fragment with counting is NP-complete; the data-complexity of both query-answering and finite query-answering for the two-variable guarded fragment with countin…
Authors: Ian Pratt-Hartmann
Data-Complexity of the Tw o-V ariable F ragmen t with Coun ting Quan tifiers Ian Pratt-Hartmann Abstract The data-complexity o f b oth satisfiabilit y and finite satisfiabilit y for the tw o-v ariable fragmen t with counting is NP-complete; the data-complexity of b oth q uery-answ ering and finite query-answe ring for the tw o-v ariable guarded fragmen t with counting is co-NP-complete. Keywords: data-complexity , query answering, tw o-v ariable fragment with coun ting. 1 In tro duction Let ϕ b e a sentence (i.e. a formula with no fr ee v ariables) in s ome logic a l fra g- men t, ψ ( ¯ y ) a formula with free v ariables ¯ y , ∆ a set of gro und, function-free literals, a nd ¯ a a tuple o f individual constants with the same arity as ¯ y . W e a r e to think o f ∆ a s b eing a bo dy o f data , ϕ a b ackgr ound the ory , and ψ (¯ a ) a query which w e wis h to answer. That answer s ho uld b e p ositive just in case ∆ ∪ { ϕ } ent ails ψ (¯ a ). What is the computatio nal complexity of our ta s k? A fair r eply dep ends on wha t, precisely , we take the inputs to o ur problem to b e. F or, in prac tice, the background theor y ϕ is static , and the query ψ ( ¯ y ) smal l : only the database ∆, which is devoid o f log ical co mplex it y , is large and indefinitely extensible. Acco rdingly , we define the query-answering pr oblem with r esp e ct to ϕ and ψ ( ¯ y ) a s follows: given a set ∆ of gr ound, function-free literals and a tuple ¯ a o f individual constants with the same arity as ¯ y , determine whether ∆ ∪ { ϕ } en tails ψ (¯ a ). Similarly , w e define the finite query answering pr oblem with r esp e ct to ϕ and ψ ( ¯ y ) as follo ws: g iv en ∆ and ¯ a , determine whether ∆ ∪ { ϕ } ent ails ψ ( ¯ a ) under the a dditio na l as sumption that the domain of quantification is finite. The computatio nal complex it y of (finite) query-a nsw ering problems is t ypically low er than that of the corresp onding entailmen t problem in which all the comp onents are treated, on a par, as input. F rom a theo retical p oin t of view, it is natura l to consider the sp ecial ca se where ψ ( ¯ y ) is the fa ls um. T aking complements, we define the satisfiability pr oblem with r esp e ct to ϕ a s follows: given a set ∆ of ground, function- fr ee litera ls, determine whether ∆ ∪ { ϕ } is satisfiable. Likewise, we define the finite s atisfiability pr obl em with r esp e ct to ϕ is as follows: given ∆, determine whether ∆ ∪ { ϕ } is finitely satisfiable. 1 The complexity of these problems dep ends, o f co urse, on the logic al frag- men ts to which ϕ and ψ ( ¯ y ) are a ssumed to belong . It is common practice to ta k e ψ ( ¯ y ) to be a p ositive c onjunctive query —that is, a formula of the form ∃ ¯ xπ ( ¯ x, ¯ y ), where π ( ¯ x, ¯ y ) is a conjunction of atoms featuring no function- sym b ols. This re- striction is motiv ated b y the prev alence o f da tabase quer y-languages, such as , for example, SQL, in which the simplest and most natural queries have pr e - cisely this form. By con tras t, the choice of logical fragment for ϕ is muc h less constrained: in principle, it makes sense to consider a lmost any s et of formulas for this pur pose. O nce we hav e identified a lo gic L from whic h to choose ϕ , we can obtain bo unds on the complexity of the (finite) sa tis fia bilit y problem and the (finite) quer y answering pro blem with resp ect to any sentence ϕ in L and any p ositiv e conjunctive quer y ψ ( ¯ y ). These complexity b ounds are collectively referred to as data c omplexity b ounds for L . In this pap er, we a nalyse the data complexity o f tw o express iv e fr a gmen ts of first-order logic for whic h the complexity o f sa tisfiabilit y and finite satisfia- bilit y has recently been determined: th e tw o-v ariable frag men t with counting quantifiers, denoted C 2 , and the tw o-v ariable guarded fragment with co un ting quantifiers, denoted G C 2 . W e sho w that the satisfia bilit y and finite satisfia- bilt y problems with resp ect to an y C 2 -formula are in NP , and that the query- answering and finite q ue r y-answering problems with r e s pect to an y G C 2 -formula and any positive conjunctive query are in co-NP . W e show that these b ounds are the b est po ssible, and that the query-ans wering and finite quer y-answering problems with resp ect to a C 2 -formula and a p ositive conjunctive query are in general undecida ble. The data complexit y o f v arious logical fra gmen ts w ith counting quantifiers ha s b een inv estigated in the literature (see, for example, Hustadt et al. [6 ], Glimm et al. [4], Ortiz et al. [9 ], a nd Arta le et al. [1]). Ho w- ever, this is the first time that such r esults have b een established for the large (and mathematically natural) fragments C 2 and G C 2 . In a ddition, the pro ofs in this pap er a r e based ultimately on the technique of reductio n to P r esburger arithmetic, which is novel in this context. 2 Preliminaries W e employ the standar d apparatus o f first-or der lo gic (assumed to contain the equality predic a te ≈ ) augmented with the c ounting quant ifiers , ∃ 6 C , ∃ > C and ∃ = C (for C > 0), which we in terpre t in the o b vious wa y . The pr e dic ate c alculus with c ounting , deno ted C , is the the set of first-o rder formulas with counting quantifiers, ov er a purely relational signature. The two-varia ble fr agment with c ounting , deno ted C 2 , is the fragment of C in volving only the v ariables x and y , and only unar y or binary pr edicates. If r is any binary predicate (including ≈ ), we call a n a tomic formula having either of the forms r ( x, y ) or r ( y , x ) a guar d . Note that guar ds, by definition, co n tain tw o distinct v ariables. The two variable guar de d fr agment with c ounting , denoted G C 2 , is the smallest s et of formulas sa tisfying the following conditions : 1. G C 2 contains all atomic formulas, and is clos ed under Bo olea n combina- 2 tions; 2. if ϕ is a formula of G C 2 with a t most one free v ariable, and u is a v ariable (i.e. either x or y ), then the formulas ∀ uϕ and ∃ uϕ a re in G C 2 ; 3. if ϕ is a for m ula of G C 2 , γ a guard, u a v ariable, a nd Q any of the quantifiers ∃ , ∃ 6 C , ∃ > C , ∃ = C (for C > 0), then the formulas ∀ u ( γ → ϕ ), Qu ( γ ∧ ϕ ) and Q uγ a re in G C 2 . F or exa mple, ∃ 6 1 x (professor( x ) ∧ ∃ > 4 y (supe r vises( x, y ) ∧ grad student ( y ))) (1) is a C 2 -sentence, with the infor mal reading: At most one p rofessor su pervises mo re than three graduate s tudents . Likewise, ¬∃ x (professor( x ) ∧ ∃ > 41 y (supe r vises( x, y ) ∧ grad student( y ))) is a G C 2 -sentence, with the informa l r eading: No professor s upervises more tha n for ty graduate students . How ever, (1) is not in the fragment G C 2 , b ecause the quantifier ∃ 6 1 do es not o ccur in a guarded pattern. It will b e conv enient in the sequel to consider the following sma ller frag men ts. W e ta k e L 2 − to b e the fragment o f C 2 in which no counting quantifiers and no ins ta nces of ≈ o ccur; likewise, we take G 2 − to be the fra gmen t of G C 2 in whic h no counting quantifiers and no ins tances of ≈ o ccur. Evidently , G 2 − ⊆ L 2 − . Both C 2 and G C 2 lack the finite model prop erty . T he satisfiability and finite satisfiability problems for C 2 are b oth NEXPTIME-complete (Pr att-Hartmann [11]; see also Pac holski et al. [10]); the satisfiability and finite satisfiability prob- lems for G C 2 are b oth EXPTIME-co mplete (Kazakov [7], Pr att-Hartmann [12]). In the co n text of C 2 and G C 2 , pre dicates of arities other than 1 or 2 lea d to no int eres ting increa se in expressive p o wer. Adding individual constants to C 2 likewise lea ds to no interesting increase in expre ssiv e p ow er, and no increa se in complexit y , sinc e o ccurre nc e s of any c o nstan t c can be s im ulated with a unary predica te p c in the presence of the C 2 -formula ∃ =1 xp c ( x ). On the other hand, adding ev en a s ingle individual consta nt to G C 2 results in a fragment with NEXPTIME-co mplete satisfia bility and finite-satisfiability problems. Thus, it is most conv enient to assume these fragments to b e constant-free; and that is what we shall do in the sequel. A p ositive c onjunctive query (or , simply: query ) is a formula ψ ( ¯ y ) of the form ∃ ¯ x ( α 1 ( ¯ x, ¯ y ) ∧ · · · ∧ α n ( ¯ x, ¯ y )) , where n > 1 and, for all i (1 6 i 6 n ), α 1 ( ¯ x, ¯ y ) is an atomic formula whose predicate is not ≈ , a nd who se ar gumen ts are all v ariables o ccurring in ¯ x, ¯ y . Since we shall b e int eres ted in answering quer ies in the presence of C 2 - or G C 2 -formulas, ther e is little to be gained from allowing ψ ( ¯ y ) to cont ain predicates of ar it y g r eater than 2; in the sequel, therefore, w e assume that all predicates in po sitiv e c onjunctiv e queries a re unary or binary . An instanc e of ψ ( ¯ y ) is simply the corr esponding form ula ψ ( ¯ a ), where ¯ a is a tuple of constants. W e allow the tuples ¯ x a nd ¯ y to b e empt y . Allowing individua l constants to app ear in p ositive co njunctiv e queries do es no t ess e ntially c hange 3 the problem; in the sequel, therefore, we assume p ositiv e conjunctive queries to be consta n t-free. Definition 1. If ϕ is a sentence (in any lo gic), define S ϕ to b e the following problem: Given a finite set o f ground, function-fr e e literals ∆, is ∆ ∪ { ϕ } satisfiable? Likewise, define F S ϕ to b e the following problem: Given a finite set o f ground, function-fr e e literals ∆, is ∆ ∪ { ϕ } finitely sa tisfiable? W e call S ϕ the satisfiability pr oble m with r esp e ct to ϕ , and F S ϕ the finite sat- isfiability pr oblem with re sp e ct to ϕ . Definition 2. If ϕ is a sentence and ψ ( ¯ y ) a form ula (in any logic ) having no free v ariables apa r t from ¯ y , define Q ϕ,ψ ( ¯ y ) to b e the following problem: Given a finite set of ground, function-free literals ∆ and a tuple of constants ¯ a of the same arity as ¯ y , do es ∆ ∪ { ϕ } entail ψ ( ¯ a )? Likewise, define F Q ϕ,ψ ( ¯ y ) to b e the following problem: Given a finite set of ground, function-free literals ∆ and a tuple of constants ¯ a of the same ar it y as ¯ y , is ψ (¯ a ) true in every finite mo del of ∆ ∪ { ϕ } ? W e call Q ϕ,ψ ( ¯ y ) the query answering pr oble m with r esp e ct to ϕ and ψ ( ¯ y ), and F Q ϕ,ψ ( ¯ y ) the fin it e query answering pr oblem with r esp e ct to ϕ and ψ ( ¯ y ). Answering q ueries is at leas t as ha rd as de c iding un satisfiability: if p is any predicate not o ccurring in ∆ or ϕ , then then ∆ ∪ { ϕ } | = ∃ xp ( x ) if and o nly if ∆ ∪ { ϕ } is unsatisfiable. Similarly for the finite cas e . W e establis h the following complexity res ults. F or any C 2 -sentence ϕ , both S ϕ and F S ϕ are in NP . These bo unds are tigh t in the sense that there exists a C 2 -sentence—in fact, a G 2 − -sentence— ϕ such that the pr oblems S ϕ and F S ϕ coincide, and a re ar e NP-hard. The quer y-answering problem for C 2 is o f little int eres t from a c o mplexit y-theor e tic p oint of v iew: there exis t a C 2 -sentence ϕ and a p ositive conjunctiv e query ψ ( ¯ y ) such that Q ϕ,ψ ( ¯ y ) is undecidable; simi- larly for F Q ϕ,ψ ( ¯ y ) . How ever, by restricting atten tion to, G C 2 , we restor e upp er complexity b ounds compar able to thos e for S ϕ and F S ϕ : for any G C 2 -sentence ϕ a nd any p ositive conjunctive quer y ψ ( ¯ y ), both Q ϕ,ψ ( ¯ y ) and F Q ϕ,ψ ( ¯ y ) are in co-NP . Again, the fact that there exists a G 2 − -sentence ϕ for which S ϕ (= F S ϕ ) is NP-hard means that these b ounds ar e tight. The above results may be in- formally ex pressed b y saying: “The data-complexity of (finite) satisfia bilit y for C 2 is NP-co mplete; the data-complexity of (finite) quer y-answering for G C 2 is co-NP-co mplete.” These data-co mplexit y b ounds contrast with the complexity 4 bo unds for sa tis fia bilit y a nd finite satisfiabilit y in the fragments C 2 and G C 2 men tioned ab o ve. In the sequel, if ϕ is a formu la, k ϕ k denotes the size of ϕ , measur ed in the obvious wa y; similarly , if ϕ is a set o f formulas, k ϕ k denotes the total size of ϕ . If X is a n y set, | X | denotes the cardina lity of X . 3 The fragmen t C 2 In this section, w e revie w s ome fa c ts a bout the fr a gmen t C 2 , closely fo llo wing the analysis in Pratt-Har tmann [11]. W e hav e simplified the original ter minology where, for the purp oses of the present pap er, certain complications reg arding the sizes of data-structures c a n b e disregarded; and we have lightly reformulated some of the lemmas acco rdingly . Let Σ be a signature of unar y and binary predicates. A 1- typ e over Σ is a maximal co ns isten t s et of equality-free liter als inv olving o nly the v ariable x . A 2- typ e ov er Σ is a maximal consistent set of equality-free liter als involving only the v ariables x and y . If A is any structure in terpr e ting Σ, and a ∈ A , then there exists a unique 1-type π ( x ) over Σ such that A | = π [ a ]; we denote π by tp A [ a ]. If, in addition, b ∈ A is distinct from a , then there exists a unique 2-t yp e τ ( x, y ) over Σ such that A | = τ [ a, b ]; we denote τ by tp A [ a, b ]. W e do not define tp A [ a, b ] if a = b . If π is a 1-t yp e, we s a y that π is r e alize d in A if there exists a ∈ A with tp A [ a ] = π . If τ is a 2 -t yp e, we say tha t τ is r e alize d in A if there exist distinct a, b ∈ A with tp A [ a, b ] = τ . Notation 1. Let τ be a 2-type ov er a purely r e la tional signature Σ. The result of transp osing the v ariables x and y in τ is also a 2-type , denoted τ − 1 ; the set of literals in τ not featuring the v ariable y is a 1- type , denoted tp 1 ( τ ); likewise, the set of litera ls in τ not fea turing the v ariable x is also a 1 - t yp e, denoted tp 2 ( τ ). Remark 1 . If τ is any 2-typ e over a pur ely r elational signatur e Σ , t hen tp 2 ( τ ) = tp 1 ( τ − 1 ) . If A is a structur e interpr eting Σ , and a , b ar e distinct elements of A su ch that tp A [ a, b ] = τ , then tp A [ b, a ] = τ − 1 , tp A [ a ] = tp 1 ( τ ) and tp A [ b ] = tp 2 ( τ ) . Lemma 1. L et ϕ b e a C 2 -formula. Ther e exist ( i ) a C 2 -formula α c ontaining no quantifiers and no o c curr en c es of ≈ , ( ii ) a list of p ositive inte gers C 1 , . . . , C m and ( iii ) a list of binary pr e dic ates f 1 , . . . , f m , with the fol lowing pr op erty. If ϕ ∗ is the C 2 -formula ∀ x ∀ y ( α ∨ x ≈ y ) ∧ ^ 1 6 h 6 m ∀ x ∃ = C h y ( f h ( x, y ) ∧ x 6≈ y ) , (2) and C = max h C h , then ( i ) ϕ ∗ | = ϕ , and ( ii ) any mo del of ϕ over a domain having at le ast C + 1 elements may b e exp ande d to a mo del of ϕ ∗ . Pr o of. Routine a daptation of standard techniques. Se e , e.g . B¨ orger et al. [2], p. 37 8. 5 If ∆ is a set of gro und, function-free liter als, and ϕ and ϕ ∗ are as in Lemma 1, then ∆ ∪ { ϕ } evidently has a (finite) model if and o nly if either ∆ ∪ { ϕ } has a mo del of size C o r less, o r ∆ ∪ { ϕ ∗ } has a (finite) mo del. Lemma 1 assures us that fo rm ulas o f the form (2) are a s genera l a s w e need. So, for the re mainder of this s ection, le t us fix a formula ϕ ∗ given by (2). The predicates f 1 , . . . , f m will pla y a specia l r ole in the ens uing analysis. W e refer to them as the c ount ing pr e dic ates . How ever, we stress that no specia l assumptions are made a bout them: in pa r ticular, they can o ccur in ar bitrary co nfigurations in the sub-formula α . Fix the constant Z = ( mC + 1) 2 . Let Σ ∗ be the signa ture o f ϕ ∗ together with 2 ⌈ log Z ⌉ + 1 new unary predicates (i.e. not o ccurring in ϕ ∗ ). Henceforth, Σ ∗ will be implicit: thus, unless otherwise indicated, structu re means “str ucture int erpr eting Σ ∗ ”; 1- typ e means “1 -t yp e over Σ ∗ ”; 2- typ e mea ns “2-type over Σ ∗ ”; and so on. Definition 3. Let τ b e a 2-type. W e say that τ is a message-typ e if f h ( x, y ) ∈ τ for some h (1 6 h 6 m ). If τ is a messag e-t yp e such that τ − 1 is als o a mess a ge- t yp e, we say that τ is invertible . On the o ther hand, if τ is a 2-type suc h that neither τ no r τ − 1 is a messag e-t yp e, τ is a silent 2-t yp e. If τ is a 2-type suc h that neither q ( x, y ) nor q ( y , x ) is in τ for any binary pr edicate q , τ is vacuous . The terminology is mean t to sugges t the following imag ery . Let A be a structure. If tp A [ a, b ] is a message-type µ , then we may imag ine that a sends a message (of type µ ) to b . If µ is inv ertible, then b r eplies by sending a message (of t ype µ − 1 ) ba c k to a . If tp A [ a, b ] is sile nt, then neither element sends a message to the other. Note that ev ery v acuous 2-type is b y definition silent; but the co nverse is not genera lly tr ue. F or co n venience, w e decide up on some en umera tion π 1 , . . . , π L of the set o f all 1 -t yp es, and so me en umera tion µ 1 , . . . , µ M ∗ , µ M ∗ +1 , . . . , µ M of the set of all message-types , such that µ j is inv ertible if 1 6 j 6 M ∗ , a nd non- inv ertible if M ∗ + 1 6 j 6 M . (That is: the inv ertible messa ge-t yp es are lis ted first.) I n addition, let Ξ denote the set o f silent 2 -t yp es. The ab o ve notation, which will b e used throughout this section, is summar ized in T able 1. W e now introduce tw o notions necessa ry to state the key lemmas o f this section reg arding the satisfia bilit y of C 2 -formulas. Definition 4. A structure A is chr omatic if distinct elements connected by a chain of 1 or 2 inv ertible messa ge-t yp es hav e distinct 1- type s . That is, A is chromatic just in c a se, for a ll a, a ′ , a ′′ ∈ A : 1. if a 6 = a ′ and tp A [ a, a ′ ] is an inv ertible mes s age-type, then tp A [ a ] 6 = tp A [ a ′ ]; and 6 Symbol Definition Z ( mC + 1 ) 2 Σ ∗ signature of ϕ to g ether with 2 ⌈ log Z ⌉ + 1 new unary predicates π 1 , . . . , π L an enumeration of the 1-types ov er Σ ∗ µ 1 , . . . , µ M ∗ an enumeration of the inv ertible messa ge-types ov er Σ ∗ µ M ∗ +1 , . . . , µ M an enumeration of the non-inv ertible mes sage-types ov er Σ ∗ Ξ set of silent 2- type s over Σ ∗ T able 1: Quick refer e nc e g uide to symbols defined with res pect to F or m ula (2). 2. if a, a ′ , a ′′ are pairwise dis tinct and b oth tp A [ a, a ′ ] and tp A [ a ′ , a ′′ ] are in- vertible mes sage-types, then tp A [ a ] 6 = tp A [ a ′′ ]. Remark 2. A structur e is chr omatic if and only if ( i ) no obje ct sends an invertible message to any obje ct having t he same 1-typ e as its elf; and ( ii ) no obje ct sends invertible m ess ages to any t wo obje cts having the same 1-typ e as e ach other. Definition 5 . A structure A is differ entiate d if, for e very 1- t yp e π , the n umber u of ele men ts in A having 1- type π satisfies either u 6 1 or u > Z . By the L¨ owenheim-Skolem Theo rem, w e may co nfine attention in the sequel to finite or coun tably infinite structures. The following (routine) lemma ensures that we may further c onfine attent ion to c hro matic, differentiated structures of these cardina lities. Lemma 2. Supp ose A | = ϕ ∗ . Then, by r e-interpr eting 2 ⌈ log Z ⌉ of the 2 ⌈ log Z ⌉ + 1 unary pr e dic ates of Σ ∗ not o c curring in ϕ ∗ if ne c essary, we c an obtain a chr omatic, differ entiate d structu r e A ′ over the same domain, such that A ′ | = ϕ ∗ . Pr o of. Pratt-Hartma nn [11], Lemmas 2 and 3. In the sequel, we shall need to reco r d the c ardinalities of v arious finite or countably infinite sets. T o this end, w e let N ∗ = N ∪ {ℵ 0 } , and we ex tend the ordering > and the arithmetic op e rations + and · from N to N ∗ in the obvious wa y . Sp ecifically , we de fine ℵ 0 > n for all n ∈ N ; w e define ℵ 0 + ℵ 0 = ℵ 0 · ℵ 0 = ℵ 0 and 0 · ℵ 0 = ℵ 0 · 0 = 0; w e define n + ℵ 0 = ℵ 0 + n = ℵ 0 for all n ∈ N ; and we define n · ℵ 0 = ℵ 0 · n = ℵ 0 for all n ∈ N s uc h that n > 0. Under this extensio n, > rema ins a tota l order, and +, · rema in asso ciative and co mm utative. Our next task is to develop the means to ta lk ab out ‘lo cal configuratio ns ’ in structures. 7 Definition 6. A star-typ e is a pa ir σ = h π , ¯ v i , where π is a 1-type, and ¯ v = ( v 1 , . . . , v M ) is a n M - tuple over N ∗ satisfying the condition that, for all j (1 6 j 6 M ), v j > 0 implies tp 1 ( µ j ) = π. In this context, w e denote π by tp( σ ) a nd v j by σ [ j ]. If A is a finite or count ably infinite structure, and a ∈ A , we deno te by st A [ a ] the star- type h π , ( v 1 , . . . , v M ) i , where π = tp A [ a ] a nd v j = |{ b ∈ A \ { a } : tp A [ a, b ] = µ j }| for all j (1 6 j 6 M ). W e call st A [ a ] the star-typ e of a in A ; and we say that a star-type σ is r e alize d in A if σ = st A [ a ] for some a ∈ A . W e may think of st A [ a ] as a desc ription of the ‘lo cal environmen t’ of a in A : it records, in addition to the 1-type of a in A , the n umber o f other elements to which a sends a mess age of type µ j , for ea c h message- t yp e µ j . Prop erties of star-types re a lized in mo dels ca pture ‘lo cal’ information ab o ut those mo dels. Definition 7. Let σ = h π , ( v 1 , . . . , v M ) i b e a star-type. W e say that σ is D - b ounde d , for D a p ositive integer, if σ [ j ] 6 D for all j (1 6 j 6 M ). W e say that σ is chr omatic if, for every 1 -t yp e π ′ , the sum c = X { v j | 1 6 j 6 M ∗ and tp 2 ( µ j ) = π ′ } satisfies c 6 1, and satisfies c = 0 if π ′ = π . W e s ay that a finite or countably infinite structure A is D - b ounde d if every s ta r-t yp e re a lized in A is D -bo unded. Obviously , if A | = ϕ ∗ , then A is C -b ounded. Imp ortantly , information abo ut the po pulations of star-types re alized in models c a n tell us all that we need to know a bout tho s e mo de ls , from the p oint o f view of the frag men t C 2 . Definition 8. Let A b e a finite or countably infinite structure, and let ¯ σ = σ 1 , . . . , σ N be a list of star -t yp es. F or a ll k (1 6 k 6 N ), let w k ∈ N ∗ be given by w k = |{ a ∈ A | st A [ a ] = σ k }| . The ¯ σ - histo gr am of A , denoted H ¯ σ ( A ), is the N -tuple ( w 1 , . . . , w N ). W e may th us think of H ¯ σ ( A ) as a ‘statistical profile ’ of A . F or the next definitions, recall (T able 1) that π 1 , . . . , π L , is an e numeration of the 1-types, and that Ξ is the set of silent 2- t yp es. Definition 9. If A is a structure and π , π ′ are 1-types (no t necessar ily distinct), we say that π and π ′ form a quiet p air in A if ther e exist distinct elements a and a ′ of A , such that tp[ a ] = π , tp[ a ′ ] = π ′ and tp[ a, a ′ ] is silent. Definition 1 0. L et I be the set of unor dered pairs of (not necess a rily distinct) int eger s b et ween 1 and L : that is, I = { { i, i ′ } | 1 6 i 6 i ′ 6 L } . A fr ame is a triple F = ( ¯ σ , I , θ ), satisfying: 8 1. ¯ σ = ( σ 1 , . . . , σ N ) is a n N -tuple o f pairwise distinct star- type s for some N > 0; 2. I ⊆ I ; and 3. θ : I → Ξ is a function such that, for all { i, i ′ } ∈ I with i 6 i ′ , tp 1 ( θ ( { i , i ′ } )) = π i and tp 2 ( θ ( { i , i ′ } )) = π i ′ . The frame F is D - b oun de d if e v ery star-type in ¯ σ is D -bo unded. Likewise, F is chr omatic if every star- t yp e in ¯ σ is chromatic. Think of a frame F = ( ¯ σ , I , θ ) as a (putative) s chematic description of a structure, where ¯ σ tells us which star-type s ar e r ealized, I tells us which pairs of 1-types are q uiet, and θ selects , for e a c h q uiet pa ir of 1-types, a sile nt 2 -t yp e joining them. Mo re pr ecisely: Definition 11. Let A b e a structure and F = ( ¯ σ , I , θ ) a fra me. W e say that F describ es A if the following conditions hold: 1. ¯ σ is a lis t of all and o nly those s tar-types realized in A ; 2. if π i and π i ′ form a quiet pair in A , then { i, i ′ } ∈ I ; 3. if π i and π i ′ form a quiet pair in A , then there exist distinct a, a ′ ∈ A suc h that tp A [ a, a ′ ] = θ ( { i, i ′ } ). F rames co n tain the essential information required to determine whether cer- tain struc tur es they describ e are mo dels of ϕ ∗ . The next definition employs the notation esta blished in T able 1 and Definition 6. Definition 12. W e write F | = ϕ ∗ if the following conditions a r e satisfied: 1. for all k (1 6 k 6 N ) a nd all j (1 6 j 6 M ), if σ k [ j ] > 0 then | = V µ j → α ( x, y ) ∧ α ( y , x ); 2. for all { i, i ′ } ∈ I , | = V θ ( { i, i ′ } ) → α ( x, y ) ∧ α ( y , x ); 3. for all k (1 6 k 6 N ) and all h (1 6 h 6 m ), the sum of a ll the σ k [ j ] (1 6 j 6 M ) such that f h ( x, y ) ∈ µ j equals C h . The next lemma helps to motiv ate this definition. Lemma 3. If A | = ϕ ∗ , then ther e exists a fr ame F describing A , su ch that F | = ϕ ∗ . The proof is almost immediate: Conditions 1 and 2 in Definition 12 a re secured by the fa c t that A | = ∀ x ∀ y ( α ∨ x ≈ y ), while Condition 3 is secured b y the fact that A | = V 1 6 h 6 m ∀ x ∃ = C h y ( f h ( x, y ) ∧ x 6≈ y ). The follo wing Lemma also follows almost immedia tely from the ab ov e definitions. 9 Lemma 4. L et A b e a st ructur e, F a fr ame describing A , and D a p ositive inte ger. Then: 1. F is D - b ou n de d if and only if A is D -b ounde d; 2. F is chr oma tic if and only if A is chr omatic; How ever, while every structur e is descr ibed by some fra me, not every frame describ es a structure; and it is impo rtan t for us to define a clas s of frames which do. T o this end, we as socia te with a fra me F a collectio n of numerical parameters , as follows. Notation 2 . Let F = ( ¯ σ , I , θ ) b e a frame, where ¯ σ = ( σ 1 , . . . , σ N ), for some N > 0, and r e c all the notation establishe d in T a ble 1 a nd Definition 6. If F is clear from context, for integers i, k in the ranges 1 6 i 6 L , 1 6 k 6 N write: o ik = ( 1 if tp( σ k ) = π i 0 otherwise; p ik = ( 1 if, for all j (1 6 j 6 M ), tp 2 ( µ j ) = π i implies σ k [ j ] = 0 0 otherwise; r ik = X j ∈ J σ k [ j ] , wher e J = { j | M ∗ + 1 6 j 6 M and tp 2 ( µ j ) = π i } ; s ik = X j ∈ J σ k [ j ] , wher e J = { j | 1 6 j 6 M and tp 2 ( µ j ) = π i } . In additio n, fo r int eger s i, j in the ra nges 1 6 i 6 L , 1 6 j 6 M ∗ , wr ite: q j k = σ k [ j ] . With this notation in hand w e can characterize a clas s of frames whose mem b ers ar e guaranteed to describ e structures . Definition 13 . Let F = ( ¯ σ , I , θ ) b e a frame, where ¯ σ = ( σ 1 , . . . , σ N ). Let ¯ w = ( w 1 , . . . , w N ) be an N -tuple ov er N ∗ . Using Notation 2, for all i (1 6 i 6 L ), all i ′ (1 6 i ′ 6 L ) and all j (1 6 j 6 M ∗ ), let: u i = X 1 6 k 6 N o ik w k v j = X 1 6 k 6 N q j k w k x ii ′ = X 1 6 k 6 N o ik p i ′ k w k . W e say that an N -tuple ¯ w over N ∗ is a solution of F if the following conditions are sa tisfied for all i (1 6 i 6 L ), all i ′ (1 6 i ′ 6 L ), a ll j (1 6 j 6 M ∗ ) and all k (1 6 k 6 N ): (C1) v j = v j ′ , where j ′ is s uc h that µ − 1 j = µ j ′ ; (C2) s ik 6 u i ; 10 (C3) u i 6 1 or u i > Z ; (C4) if o ik = 1, then either u i > 1 or r i ′ k 6 x i ′ i ; (C5) if { i, i ′ } 6∈ I , then either u i 6 1 or u i ′ 6 1; (C6) if { i, i ′ } 6∈ I and o ik = 1, then r i ′ k > x i ′ i . The conditions C1 – C6 in Definition 13 may be written as a quan tifier- free for m ula in the lang ua ge o f Presburg er ar ithmetic—in other w ords, as a Bo olean combination of linear inequa lities with in teger coefficie nts and v ari- ables w 1 , . . . , w N . By treating a negated inequalit y as a r ev ers e d inequalit y in the obvious wa y , we may a ssume that the Bo olean combination in question is p ositive —i.e. inv olves only conjunction and disjunction. Denote this positive Bo olean com bination of inequalities by E . By definition, F has a solution if a nd only if E is satisfied over N ∗ ; and F has a finite solution (i.e. a solution in which all v alues ar e finite) if and o nly if E is satisfied ov er N . W e a r e at last in a p osition to state the key lemmas of this section. Lemma 5. If A is a differ entiate d stru ctur e and F = h ¯ σ , I , θ i is a fr ame de- scribing A , then H ¯ σ ( A ) is a solution of F . Pr o of. Pratt-Hartma nn [11], Lemma 13 , Lemma 16. Lemma 6. If F is a chr omatic fr ame su ch that F | = ϕ ∗ , and ¯ w is a solution of F , then ther e exists a structur e A su ch that: ( i ) A | = ϕ ∗ ; ( ii ) F describ es A ; and ( iii ) ¯ w = H ¯ σ ( A ) . Pr o of. Pratt-Hartma nn [11], Lemma 14 , Lemma 17. Lemmas 5 and 6 in effect state that, to determine the satisfiability of ϕ ∗ , it suffices to gue s s a C -b ounded, differentiated, chromatic frame F , a nd to tes t that F has a so lution a nd that F | = ϕ ∗ . F ur thermore, by testing ins tead whether F has a finite solution, we can determine the finite satisfiability o f ϕ ∗ . The pro of of Lemma 5 is relatively straightforw ar d; that of Lemma 6 is more challenging, bec ause it inv olves constructing a mo del A o f ϕ ∗ , given only the frame F and its solution. It can in fa c t be shown that we may without lo ss of gener alit y confine attent ion to frames whos e size (measur ed in the obvious wa y) is b ounded b y a singly expo nen tial function of the size of ϕ ∗ (Pratt-Hartma nn [11], Lemma 10 ). F rom this it follows that the pr oblems of determining the sa tis fia bilit y/finite satisfiability of a g iv en C 2 -formula ar e in NEXPT IME . In the present context of inv estiga ting the data -complexity of C 2 , ho wev er, this matter ma y be safely ignored. 11 4 Data-complexit y of satisfiabilit y and finite sat- isfiabilit y for C 2 In this section, we g iv e b ounds on the da ta -complexity o f satisfiability and finite satisfiability in C 2 . W e consider the upp er b ounds first. F o r a n y C 2 -formula ϕ , w e descr ibe a pair of no n-deterministic p olynomial-time pro cedures to de ter mine the satisfiability and finite satisfiabilit y of ∆ ∪ { ϕ } , whe r e ∆ is a given set o f gro und, non- functional literals. The stra tegy is as follows. Relying on Lemmas 5 a nd 6, we guess a fra me F suc h that F | = ϕ , and a ssem ble the ineq ualities required for F to hav e a so lution. By aug men ting these inequalities with extra co nditions (based o n ∆), we can chec k for the existence of a (finite) mo del of ϕ whose histogram (with res pect to some sequence o f star -t yp es) is such that a mo del of ∆ ca n be spliced in to it, th us yielding a mo del of ∆ ∪ { ϕ } . If ∆ is a set of ground, function-free literals, we denote by cons t (∆) the set of individual constants o ccurring in ∆. Theorem 1. F or any C 2 -sentenc e ϕ , b oth S ϕ and F S ϕ ar e in NP . Pr o of. Let ϕ b e a C 2 -formula, and ∆ a s et of g r ound, function-free literals, ov er a signature Σ ∆ . Let ϕ ∗ and C b e as in Lemma 1. Determining whether ∆ ∪ { ϕ } has a mo del of size C or less is stra ig h tforward. F or we may list, in constant time, all mo dels o f ϕ o f size C or less (in terpr eting the s ignature of ϕ ). Fixing any such mode l A , w e may then g uess an expansion A + of A interpreting Σ ∆ , and chec k that A + | = ∆. This (non-deter ministic) proc ess ca n b e executed in time b ounded by a linea r function of k ∆ k . Hence, it suffices to deter mine whether ∆ ∪ { ϕ ∗ } has a mo del. F rom now on, we fix the formula ϕ ∗ having the form (2), and employ the notation of T able 1 , together with the asso ciated notions o f 1-t yp e , message- typ e and star-typ e ov er the signatur e Σ ∗ . Since Σ ∗ contains 2 ⌈ log Z ⌉ + 1 unary predicates not o ccurring in ϕ , pick one of these extra predicates, o . W e call a 1-type π observable if o ( x ) ∈ π , we call a messa g e-t yp e ρ observab le if tp 1 ( ρ ) and tp 2 ( ρ ) are o bserv able, a nd we call a star-type σ observable if tp( σ ) is observ able. Informally (and somewhat approximately), we rea d o ( x ) as “ x is an element which interprets a constant in ∆”. W e now define tw o non-deterministic pro cedures o p erating on ϕ ∗ and ∆. W e show that bo th pro cedures run in time b ounded by a polyno mial function of k ∆ k , that the firs t of these pro cedures ha s a successful run if a nd only if ∆ ∪ { ϕ ∗ } is satisfiable, a nd that the s econd has a successful r un if and o nly if ∆ ∪ { ϕ ∗ } is finitely satisfiable. This prov es the theorem. Pro cedure I is as follows. 1. Guess a structure D + int erpr eting the signatur e Σ ∗ ∪ Σ ∆ ov er a do ma in D with | D | 6 const(∆); and let D b e the reduct of D + to the signature Σ ∗ . If D + 6| = ∆ or D 6| = ∀ x ∀ y ( α ∨ x ≈ y ), then fail. 2. Guess a list σ 1 , . . . , σ N ′ of observ able, C -bo unded, chromatic star-type s , 12 and guess a further list σ N ′ +1 , . . . , σ N of non-observ able, C -b ounded, chro- matic s ta r-t yp es. W rite ¯ σ = σ 1 , . . . , σ N ′ , σ N ′ +1 , . . . , σ N , and gues s a frame F = h ¯ σ , I , θ i with these star-types . If F 6| = ϕ ∗ , then fail. 3. Guess a function δ : D → { σ 1 , . . . , σ N ′ } mapping ev ery element o f D to one of the observ able star-types of F . W riting h π d , ( v d 1 , . . . , v d M ) i for δ ( d ), if, for any d ∈ D , either of the c o nditions (a) π d = tp D [ d ] (b) for all j (1 6 j 6 M ) s uc h that ρ j is a n observ able message-type, v d j = |{ d ′ ∈ D | d ′ 6 = d and tp D [ d, d ′ ] = µ j }| do es no t hold, then fail. Otherwise, record the n umbers n 1 , . . . , n N ′ , where, for all k (1 6 k 6 N ′ ), n k = | δ − 1 ( σ k ) | , and then forg et δ . 4. Let E b e the (p ositiv e) Bo olean combination o f inequalities required for F to have a solution, as explained in Section 3. Guess the truth-v alues of all the inequa lities inv olved in E . If the guess makes E false (considered as a Bo olean combination), fail; otherwise, let E ′ be the set of thes e inequa lities guessed to b e true. 5. Recalling the num b ers n k from Step 3 let E ′ δ = E ′ ∪ { w k = n k | 1 6 k 6 N ′ } . If there is no so lution of E ′ δ , then fail. 6. Succeed. Pro cedure II is ex actly the same as Pro cedure I, except in Step 5. Instead of failing if there is no solution of E ′ δ , we instea d fail if there is no finite so lutio n of E ′ δ . W e consider the r unning time of Pro cedure I, writing k ∆ k = n . Step 1 can b e executed in time O ( n 3 ). Step 2 can b e executed in cons ta n t time. In executing Step 3, w e no te that, once δ ( d ) has been gues sed a nd ch eck ed, the space requir ed to do so can b e r ecov ered; only the tallies n 1 , . . . , n N ′ need b e kept, a nd this never requires more than N ′ log n space. Moreover, in c hecking δ ( d ), the only difficult y is to compute the quant ities |{ d ′ ∈ D | d ′ 6 = d and tp D [ d, d ′ ] = µ j }| for observ able message types µ j ; but this never requires more than log n space. Hence Step 3, can b e executed in space O (log( n )), and hence in time bounded by a p olynomial function o f n . Step 4 can b e executed in co nstan t time. Step 5 inv olves determining the existence of a solution to the ineq ualities in E ′ δ . Since the size o f E ′ is b ounded by a cons tan t, the size of E ′ δ is in fact O (log n ); mor e- ov er, E ′ δ inv olves a fixed num b e r o f v ariables. After guessing which o f these 13 v ariables take infinite v alues, this problem ca n b e solved using Lenstr a ’s algo - rithm (Lenstra [8]) in time b ounded by some fixed p olynomial function of log n , and hence certainly in time O ( n ). Thus, Pro cedure I can be executed in p olyno- mial time. P ro cedure I I can a ls o b e executed in p olynomial time, by an almost ident ical argument. W e show that Pro cedure I has a success ful run if and o nly if ∆ ∪ { ϕ ∗ } is satisfi- able, and tha t Pro cedure I I has a successful run if and only if ∆ ∪ { ϕ ∗ } is finitely satisfiable. Supp ose A + is a finite or co untably infinite model of ∆ ∪ { ϕ ∗ } , in- terpreting the signa ture Σ ∗ ∪ Σ ∆ ov er a domain A ; le t A b e the reduct of A + to Σ ∗ ; and let D ⊆ A b e the s et of a ll and only those element s interpret- ing the co nstan ts const(∆) in A + . By as sumption, Σ ∗ contains 2 ⌈ log Z ⌉ + 1 unary predicates not o ccurring in ϕ ∗ , o ne of which is the predica te o . By re- int erpr eting these new predica tes if necessar y , we may assume that o A = D , and furthermore (by Lemma 2) that A is differentiated a nd chromatic. Let D + be the restriction of A + to D , and D the restr iction of A to D (so that D is a r educt of D + ). With these choices, Step 1 succeeds. By L e mma 3, let F be a frame describing A such that F | = ϕ ∗ . By Lemma 4, Parts 1 and 2, F is C -b ounded and c hroma tic. Without loss of generality , w e may as sume the star-types in F to b e ¯ σ = σ 1 , . . . , σ N ′ , σ N ′ +1 , . . . , σ N , where σ 1 , . . . , σ N ′ are the star-types realized in A by elements of D , a nd σ N ′ +1 , . . . , σ N are the star- t yp es realized in A b e elements of A \ D . Wit h these choices, Step 2 succ e eds. Define δ : D → { σ 1 , . . . , σ N ′ } by setting δ ( d ) = st A [ d ]. With these choices, Step 3 s uc- ceeds. Let ¯ w = H ¯ σ ( A ), so that, by Lemma 5, ¯ w is a solution o f E . Let E ′ be the set of inequalities men tioned in E whic h a r e satisfied b y ¯ w . With these choices, Step 4 succeeds. T he ab ov e c hoice of ¯ w ensur es that ¯ w satisfies E ′ ; to show that Step 5—and hence the whole pro cedure—succeeds, it suffices to s ho w that, for all k (1 6 k 6 N ′ ) w k = n k . Now, since o A = D , a ∈ A has an obser v able star-type σ k if a nd only if a ∈ D . But for d ∈ D , we hav e δ ( d ) = st A [ d ], whence n ′ k = | δ − 1 ( σ k ) | is the num ber of elements d ∈ D s uc h that st A [ d ] = σ k , and hence the n umber of elements a ∈ A such that st A [ a ] = σ k . That is: w k = n k as r equired. The corresp onding argument for Pro cedure I I is almos t iden tical, noting that, if A + is finite, then ¯ w = H ¯ σ ( A ) will co ns ist en tirely o f finite v alues. Suppo se, con versely , that Pro cedure I has a successful run. Let D + , D , δ , F , and E ′ be a s g uessed in this run, and let ¯ w = w 1 , . . . , w N be a so lution of E ′ δ , guaranteed b y the fact that Step 5 suc c e eds. Since Step 1 succeeds, we hav e D + | = ∆, and D | = ∀ x ∀ y ( α ∨ x ≈ y ). By a ssumption, F is chromatic; moreover, since Step 2 succeeds, F | = ϕ ∗ . Since Step 4 succeeds, ¯ w is a solution of the Bo olean combination of inequalities E , a nd hence a so lution of the frame F . By Lemma 6, then, let A b e a mo del of ϕ ∗ describ ed by F in which the star-types σ 1 , . . . , σ N are r ealized w 1 , . . . , w N times, r espectively . W e pro ceed to define a structure A ′ such that A ′ | = ∆ ∪ { ϕ ∗ } . Let D ′ = o A , and, for all k (1 6 k 6 N ′ ), let D ′ k = { a ∈ A | st A [ a ] = σ k } . Ev idently , the sets D ′ 1 , . . . , D ′ N ′ partition D ′ . On the o ther hand, co nsider the domain D of the structure D , a nd, for all k (1 6 k 6 N ′ ), le t D k = δ − 1 ( σ k ). These sets 14 are pair wise disjoint, and fro m the fa ct that ¯ w is a solution of E ′ δ , we hav e | D k | = | D ′ k | , for all k (1 6 k 6 N ′ ). By replacing A with a suitable isomorphic copy if necessary , w e can as sume that D k = D ′ k for all k (1 6 k 6 N ′ ). W e th us hav e: (i) D = D ′ ⊆ A ; (ii) st A [ d ] = δ ( d ) fo r a ll d ∈ D ; and (iii) o A = D . No w define the structure A ′ int erpr eting Σ ∗ ov er the do main A by setting: tp A ′ [ a, b ] = ( tp D [ a, b ] if a ∈ D and b ∈ D tp A [ a, b ] otherwise. T o ensure that no clashes can o ccur in these a ssignments, we must show that tp A [ a ] = tp D [ a ] for all a ∈ D . But this follo ws from the success of Step 3 (spe c ifically , fro m Condition 3a) and the already -established fact that st A [ a ] = δ ( a ). By constr uction, then, D ⊆ A ′ . Indeed, taking A + to b e the expansion of A ′ obtained by interpreting the sym b ols of Σ ∆ \ Σ ∗ in the same w ay a s D + , w e immediately ha ve A + | = ∆. T o sho w that ∆ ∪ { ϕ ∗ } is satisfiable, therefore, we r equire only to show that A ′ | = ϕ ∗ . Note first o f all that the only 2-types realized in A ′ are 2-types r ealized either in A or in D . But A | = ϕ ∗ , and D | = ∀ x ∀ y ( α ∨ x ≈ y ), whence A ′ | = ∀ x ∀ y ( α ∨ x ≈ y ). There fore, it suffices to show that, for a ll a ∈ A , st A ′ [ a ] = st A [ a ], from w hich it follows that A ′ | = V 1 6 h 6 m ∀ x ∃ = C h y ( f h ( x, y ) ∧ x 6≈ y ). If a 6∈ D , then s t A ′ [ a ] = s t A [ a ] is immediate fro m the constr uction of A ′ ; so supp ose a = d ∈ D . Let us wr ite st A [ d ] = δ ( d ) = h π , ( v d 1 , . . . , v d M ) i st A ′ [ d ] = h π , ( v ′ 1 , . . . , v ′ M ) i . Fix k (1 6 j 6 M ), and supp ose first that ρ j is not observ able. Since D ⊆ o A , we hav e, by the constr uction of A ′ , tp A ′ [ d, b ] = µ j if and only if b 6∈ D and tp A [ d, b ] = µ j ; it is then immediate that v ′ j = v d j . S upp ose, o n the other hand, that ρ j is obs erv a ble. Since o A ⊆ D , we hav e, by the co nstruction of A ′ tp A ′ [ d, b ] = µ j if and only if b ∈ D and tp D [ d, b ] = µ j ; but then the success of Step 3 (sp ecifically , Condition 3b) then g uarantees that v ′ j = v d j . Hence, for all a ∈ A , st A ′ [ a ] = st A [ a ], as re q uired. The corres ponding argument fo r Pro cedure II is almost iden tical: we need only observe that, by req uir ing the num bers w N ′ +1 , . . . , w N to b e in N , the constr ucted model A + will b e finite. The matching low er bo und to Theor em 1 is almost trivial. In fact, muc h smaller fra gmen ts than C 2 suffice for this purp ose: r ecall that G 2 − is the frag- men t of G C 2 in which no counting qua n tifiers and no instances of ≈ o ccur. Theorem 2 . Ther e exists a G 2 − -sentenc e ϕ for which the pr oblems S ϕ and F S ϕ c oincid e, and ar e NP -har d. Pr o of. By reduction of 3SA T. Let c and t b e unary predicates and l 1 , l 2 , l 3 , o and s binary predicates. (Rea d c ( x ) as “ x is a clause” , l i ( x, y ) as “ y is the i th literal of x ”, t ( x ) as “ x is a true literal”, o ( x, y ) as “ x a nd y are m utually 15 opp osite literals” , a nd s ( x, y ) as “ x a nd y ar e the sa me literal”.) Let ϕ b e ∀ x ( c ( x ) → _ 1 6 j 6 3 ∃ y ( l j ( x, y ) ∧ t ( y ))) ∧ ∀ x ∀ y ( o ( x, y ) → ( t ( x ) ↔ ¬ t ( y ))) ∧ ∀ x ∀ y ( s ( x, y ) → ( t ( x ) ↔ t ( y ))) ∧ ^ 1 6 j 6 3 ∀ x ( ∃ y ( l j ( x, y ) ∧ t ( y )) → ∀ y ( l j ( x, y ) → t ( y ))) . W e reduce 3SA T to the pro blems S ϕ and F S ϕ , which we simultaneously show to b e identical. Suppose a finite set Γ = { C 1 , . . . , C n } o f 3-liter al clauses is given, where C i = L i, 1 ∨ L i, 2 ∨ L i, 3 . Let a i (1 6 i 6 n ) a nd b i,j (1 6 i 6 n ; 1 6 j 6 3) be pairwise dis tinct individual consta n ts, and let ∆ Γ be the following set of ground, function-free literals : { c ( a i ) | 1 6 i 6 n } ∪ { l j ( a i , b i,j ) | 1 6 i 6 n a nd 1 6 j 6 3 }∪ { o ( b i,j , b i ′ ,j ′ ) | L i,j and L i ′ ,j ′ are o pposite literals }∪ { s ( b i,j , b i ′ ,j ′ ) | L i,j and L i ′ ,j ′ are the same literal } . It is ro utine to check that: ( i ) if { ϕ } ∪ ∆ Γ is satisfiable, then Γ is s atisfiable; ( ii ) if Γ is satisfiable, then { ϕ } ∪ ∆ Γ is finitely satisfiable. Since, as we r emarked ab ov e, the (finite) query-ans w ering problem is at least as hard as the (finite) u n satisfiability problem, Theorem 2 also pr ovides a low er bo und for the complexity of (finite) query answering in G C 2 (matchin g The- orem 4 b elow). Sp ecifically , let ϕ ∈ G C 2 be the sentence constructed in the pro of of Theorem 2, and p a unar y predicate; then the problems Q ϕ, ∃ xp ( x ) and F Q ϕ, ∃ xp ( x ) coincide, and are co-NP-complete. W e r emark that low er complex - it y bounds of co- NP for query-answering pro blems a re not always b e obtained in this wa y (i.e. by reduction to the co rresp onding unsatisfiability pr oblem), esp ecially in inexpres siv e fragments. A go o d exa mple is provided by the frag- men ts consider ed in Calv anese et al. [3] (Theorem 8), who use instead a closely related result on ‘instance chec king’ in description logic s (Schaerf [14], Theorem 3.2). F or simila r r esults concerning an expressive lo gic, see Hustadt et al. [6], Theorems 20 and 26 . W e conclude this section by sho wing that there is no hop e o f ex tending Theorem 1 to a result c o ncerning query answ ering : query-a ns w ering and finite query answ ering problems with res pect to C 2 -formulas are in g eneral undecid- able. (Again, m uch smaller frag men ts than C 2 suffice for this purp ose.) W e employ the standard appara tus of tiling systems. In this context, recall that a t iling system is a tr iple T = h C, H , V i , where C is a no n- empt y , finite set of tiles and H , V are binary r e lations on C . F or N ∈ N , let N N denote the set { 0 , 1 , . . . , N − 1 } . An infi n ite tiling for T is a function f : N 2 → C such that, for all i, j ∈ N , h f ( i, j ) , f ( i + 1 , j ) i ∈ H and h f ( i, j ) , f ( i, j + 1 ) i ∈ V . An N - tiling for T is a function f : N 2 N → C suc h that, for all i, j ∈ N N , h f ( i, j ) , f ( i + 1 , j ) i ∈ H and h f ( i, j ) , f ( i , j + 1) i ∈ V (addition mo dulo N ). The infi nite tiling pr ob- lem on T is the following problem: given a sequence c 0 , . . . , c n of elements of 16 C (repeats allow ed), determine whether there exists an infinite tiling f for T such that f ( i, 0) = c i for all i (0 6 i 6 n ). The finite tiling pr oblem on T is the following pro blem: given a sequence c 0 , . . . , c n of elements of C (repea ts allow ed), determine whether there exis t an N > n and a n N -tiling f for T such that f ( i, 0) = c i for all i (0 6 i 6 n ). It is well-known that there exist tiling systems for which the infinite tiling pr o blem is co-r.e.-co mplete, and that there exist tiling systems fo r which the finite tiling problem is r.e.-complete. Lemma 7. L et h and v b e binary pr e dic ates, and let γ b e the formula ∀ x 1 ∀ x 2 ∀ x 3 ∀ x 4 ( h ( x 1 , x 2 ) ∧ v ( x 1 , x 3 ) ∧ v ( x 2 , x 4 ) → h ( x 3 , x 4 )) . Ther e exists a senten c e ϕ in G 2 − such that the pr oblem S ϕ ∧ γ is c o-r.e.-c omple te. Ther e exists a sentenc e ϕ in G 2 − such that the pr oblem F S ϕ ∧ γ is r.e.-c omplete. Pr o of. Let T = h C, H , V i b e a tiling system whos e infinite tiling pro blem is co-r.e.-c o mplete. T reating the tiles c ∈ C as unary predica tes, let ϕ 0 be the formula ∀ x ∃ y h ( x, y ) ∧ ∀ x ∃ y v ( x, y ) , let ϕ T be the formula ∀ x _ c ∈ C c ( x ) ! ∧ ^ c 6 = c ′ ∀ x ( c ( x ) → ¬ c ′ ( x )) ∧ ^ h c,c ′ i6∈ H ∀ x ∀ y ( h ( x, y ) → ¬ ( c ( x ) ∧ c ( y ))) ∧ ^ h c,c ′ i6∈ V ∀ x ∀ y ( v ( x, y ) → ¬ ( c ( x ) ∧ c ( y ))) , and let ϕ be ϕ 0 ∧ ϕ T . Now, given a sequence ¯ c = c 0 , . . . , c n of elements of C (rep eats allow ed), let a 0 , . . . , a n be individual co nstan ts, and let ∆ ¯ c be the set of gro und, function- free literals { c 0 ( a 0 ) , h ( a 0 , a 1 ) , c 1 ( a 1 ) , h ( a 1 , a 2 ) , . . . , c n − 1 ( a n − 1 ) , h ( a n − 1 , a n ) , c n ( a n ) } . W e cla im that the instance ¯ c of the infinite tiling pr o blem for T is po sitiv e if a nd only if ∆ ∪ { ϕ ∧ γ } is satisfiable. Thus, the problem S ϕ ∧ γ is co-r.e.-complete, proving the first s tatemen t o f the lemma. T o pr o ve the claim, if f is an infinite tiling for T with f ( i, 0) = c i for a ll i (0 6 i 6 n ), co ns truct the mo del A as follows. Let A = N 2 ; let a A i = ( i, 0) for all i (0 6 i 6 n ); let h A = {h ( i, j ) , ( i + 1 , j ) i | i, j ∈ N } ; let v A = {h ( i, j ) , ( i , j + 1) i | i, j ∈ N } ; and let c A = { ( i, j ) | f ( i, j ) = c } for all c ∈ C . It is routine to check that A | = { ϕ ∧ γ } ∪ ∆ ¯ c . Conv ersely , suppose A | = { ϕ ∧ γ } ∪ ∆ ¯ c . Define a function g : N 2 → A a s follows. First, set g ( i, 0 ) = a A i for all i (0 6 i 6 n ). Now, if i is the largest integer suc h that g ( i, 0) has been defined, select an y b ∈ A such that h g ( i, 0 ) , b i ∈ h A (po ssible, s inc e A | = ϕ 0 ), a nd set g ( i + 1 , 0) = b . This 17 defines g ( i, 0) for all i ∈ N . Fixing any i , if j is the la rgest in teger s uc h that g ( i, j ) has b een defined, select any b ∈ A such tha t h g ( i, j ) , b i ∈ v A (po ssible, since A | = ϕ 0 ), and se t g ( i, j + 1) = b . This defines g ( i, j ) for a ll i, j ∈ N . Since A | = ∆ ¯ c ∪ { γ } , we ha ve, for a ll i, j ∈ N , h ( i, j ) , ( i + 1 , j ) i ∈ h A and h ( i, j ) , ( i, j + 1) i ∈ v A . W e now define an infinite tiling f : N 2 → C a s follows. Since A | = ϕ T , we set f ( i, j ) to b e the unique c ∈ C such that A | = c [ g ( i, j )]. Finally , since A | = ∆ ¯ c , we hav e f ( i, 0 ) = c i for all i (1 6 i 6 n ). The se c ond statement of the lemma is prov ed analog ously . Recall that we deno te b y L 2 − the fragment of C 2 in which no coun ting quantifiers and no ins tances of ≈ o ccur. Theorem 3. Ther e exist an L 2 − -sentenc e ϕ ′ and a p ositive c onjunctive query ψ ( ¯ y ) such that Q ϕ ′ ,ψ ( ¯ y ) is u nde cidable. Similarl y for F Q ϕ ′ ,ψ ( ¯ y ) . Pr o of. W e dea l with Q ϕ ′ ,ψ ( ¯ y ) only; the pro of for F Q ϕ ′ ,ψ ( ¯ y ) is ana logous. Let the bina ry predica te h and the formulas γ and ϕ be as in (the first statemen t of ) Lemma 7. Let p b e a new unary predicate and ¯ h a new binary predicate. Now let ϕ ′ be the formula ϕ ∧ ∀ xy ( ¯ h ( x, y ) ↔ ¬ h ( x, y )) , and ψ the p ositive conjunctiv e query ∃ x 1 ∃ x 2 ∃ x 3 ∃ x 4 ∃ x ( h ( x 1 , x 2 ) ∧ v ( x 1 , x 3 ) ∧ v ( x 2 , x 4 ) ∧ ¯ h ( x 3 , x 4 ) ∧ p ( x )) . It is ob vious that, if ∆ is any s et of g round, non- functional liter als (not in volving the predic a tes p or ¯ h ), then ∆ ∪ { ϕ ′ } | = ψ iff ∆ ∪ { ϕ ′ ∧ γ } | = ∃ xp ( x ) iff ∆ ∪ { ϕ ′ ∧ γ } is unsatisfiable iff ∆ ∪ { ϕ ∧ γ } is unsatisfiable . It follows from Lemma 7 tha t Q ϕ ′ ,ψ is undecida ble. W e remark that, at the cost of co mplicating the ab ov e pro ofs, the for- m ula γ in Lemma 7 could in fact hav e been r eplaced by the simpler formula ∀ x 1 ∀ x 2 ∀ x 3 ( r ( x 1 , x 2 ) ∧ r ( x 2 , x 3 ) → r ( x 1 , x 3 )), a sserting the transitivity of a bi- nary relation. Indeed, it is known that extending C 2 —or even G C 2 —with the ability to express tr ansitivit y of relations renders the satisfiability problem for this frag men t undecidable. (T endera [15] shows this in the case of four tr ansi- tive r elations; see also Gr¨ adel a nd Otto [5] for clos e ly r elated results.) No tice in this con text that the for m ula ϕ ′ constructed in the pr oo f of Theorem 3 is not in G C 2 , since it contains the non-guarded conjunct ∀ xy ( h ( x, y ) ↔ ¬ ¯ h ( x, y )). As we sha ll see in the next s e ction, this is no accident: query-a nsw ering and finite query-ans wering ar e decida ble with resp ect to sentences of G C 2 and p ositive conjunctive quer ies. F or an in vestigation of the data-complexity of satisfiabil- it y and query-a nsw ering in certain log ics fea turing b oth coun ting quantifiers and tra nsitiv e pr edicates—and indeed of practical methods for so lving these problems—see, for example, Hustadt et al. [6], Glimm et al. [4], Ortiz et al. [9]. 18 5 The fragmen t G C 2 In this section, we e stablish some facts ab o ut G C 2 which will subseque ntly be used to analyse the complexity of query-answering and finite query-answering within this fragment. T o help motiv ate this analysis, we b egin with an ov erv iew of our approach. Let ϕ b e a s en tence of G C 2 , ∆ a set of gr ound, function-free literals, a nd ϕ ( ¯ y ) a p ositive conjunctive query . F or simplicity , let us assume for the moment that the tuple ¯ y is empty—that is, ψ is the Bo olean quer y ∃ x 1 . . . ∃ x n ( p 1 ( y 1 , z 1 ) ∧ · · · ∧ p s ( y s , z s )) , (3) where the y i and z i are chosen from among the set of v ar iables V = { x 1 , . . . , x n } . F ormula (3) defines a gr aph ( G, E ) on this set in a natural wa y: ( x i , x j ) ∈ E just in cas e i 6 = j and, for so me k (1 6 k 6 s ), { x i , x j } = { y k , z k } . Again, for simplicity , let us assume for the moment that the resulting g r aph, ( V , E ), is connected. Now, there are tw o p ossibilities: either the gra ph ( V , E ) contains a lo op (that is: it is 2-connected) or it do es not (that is: it is a tree). If the latter, it can be shown (Lemma 16, below) that ψ is logically equiv alent to some G C 2 -formula π . But then the problem Q ϕ,ψ is the complement of the proble m S ϕ ∧¬ π , which is in NP by Theorem 1. Supp ose, therefore, that ( V , E ) c o n tains a lo op, and consider any model A | = ψ . It is obvious that A contains a sequence of elements a 0 , . . . , a t − 1 ( t 6 s ) such that for all i (1 6 i < t ), there is a bina ry predica te p with either A | = p [ a i , a i +1 ] or A | = p [ a i +1 , a i ] (where the addition in the indice s is mo dulo t ). Let us call such a se quence a cycle . W e therefor e establish the following ‘big-cycles’ lemma for G C 2 -formulas ϕ (Lemma 1 3, b elow): if ∆ ∪ { ϕ } is (finitely) satis fia ble, then, for arbitrarily large Ω ∈ N , ∆ ∪ { ϕ } has a (finite) mo del in which no cycles with t 6 Ω exist . It follows that ∆ ∪ { ϕ } is (finitely) satisfiable if and only if ∆ ∪ { ϕ, ¬ ψ } is (finitely) s a tisfiable. That is, the problem Q ϕ,ψ is the complement of the problem S ϕ , which, aga in, is in NP b y Theor em 1; similarly , mutatis mutandis , for finite satisfiability . F or satisfiability (as opp osed to fi n ite sa tisfiabilit y), this ‘big-cycles’ lemma is relatively stra igh tforward, a nd clo s e to the familiar fact that G C 2 has the ‘tree- mo del prop ert y’ (see K azako v [7], Theorem 1 ). F o r finite satisfia bilit y , how ever, more work is re q uired. W e now pr oceed to lay the founda tio ns for that work. Lemma 8. L et ϕ b e a formula of G C 2 , A a structu r e interpr eting the signature of ϕ , and I a nonempty set. F or i ∈ I , let A i b e a c op y of A , with the domains A i p airwi se disjoint. If ϕ is satisfie d in A , then it is satisfie d in t he structu r e A ′ with domain A ′ = S i ∈ I A i and interpr etations q A ′ = S i ∈ I q A i for every pr e dic ate q . Pr o of. If θ : { x, y } → A is any v ariable assig nmen t, and i ∈ I , let θ i be the v ariable assignment which maps x a nd y to the corr esponding elements in A i ⊆ A ′ . A r outine structural induction on ϕ sho ws that A | = θ ϕ if and only if, for some (= for all) i ∈ I , A ′ | = θ i ϕ . 19 It fo llows immediately that, if a for m ula o f G C 2 has a finite mo del, then it has ar bitrarily la rge finite mo de ls , and indeed infinite mode ls . As with C 2 , so to o with G C 2 , we can limit the nesting o f quantifiers. Lemma 9. L et ϕ b e a G C 2 -formula. Ther e exist ( i ) a quantifier-fr e e G C 2 - formula α with x as its only variable, ( ii ) binary pr e dic ates e 1 , . . . , e l , and f 1 , . . . , f m ( differ en t fr om ≈ ) , ( iii ) quantifier-fr e e G C 2 -formulas β 1 , . . . , β l , ( iv ) p ositive inte gers C 1 , . . . , C m with the fol lowing pr op erty. If ϕ ∗ is the G C 2 - formula ∀ xα ∧ ^ 1 6 h 6 l ∀ x ∀ y ( e h ( x, y ) → ( β h ∨ x ≈ y )) ∧ ^ 1 6 i 6 m ∀ x ∃ = C i y ( f i ( x, y ) ∧ x 6≈ y ) , (4) and C = max h C h , then ( i ) ϕ ∗ | = ϕ , and ( ii ) any mo del of ϕ over a domain having at le ast C + 1 elements may b e exp ande d to a mo del of ϕ ∗ . Pr o of. Routine a daptation of standard techniques. Se e , e.g . B¨ orger et al. [2], p. 37 8. In view of Lemma 9 , we fix a signature Σ ∗ of unary and bina r y predica tes and a G C 2 -sentence ϕ ∗ ov er this signature, having the form (4 ). F or the rema inder of Section 5, all structures will in terpret the signa ture Σ ∗ . W e refer to the predicates f 1 , . . . , f m in (4) as the c ounting pr e dic ates o f Σ ∗ ; and w e understand the notions of message typ e , invertible message typ e , silent 2 -typ e a nd vacuous 2-type as in Definition 3. F or the next definition, if π is a 1-type we denote by π [ y /x ] the set of formulas obtained by re placing all o ccurr ences of x in π b y y . (Recall that 1 -t yp es, o n our definition, always involv e the v ariable x : s o, technically , π [ y /x ] is not a 1 -t yp e.) Definition 1 4. Let π and π ′ be 1-types ov er Σ ∗ . Denote by π × π ′ the v acuous 2-type π ∪ π ′ [ y /x ] ∪ { ¬ q ( x, y ) , ¬ q ( y , x ) | q a binary predicate of Σ ∗ } . Lemma 10. Supp ose A | = ϕ ∗ , and let ˆ A b e the st ructur e obtaine d by r epl acing every silent 2-t yp e in A by t he c orr esp onding vacuous 2-typ e, that is: tp ˆ A [ a, b ] = ( tp A [ a ] × tp A [ b ] if tp A [ a, b ] is silent tp A [ a, b ] otherwi se . Then ˆ A | = ϕ ∗ . 20 Pr o of. Since the 1-types o f elements are the same in A and ˆ A , ˆ A | = ∀ xα . Since the only 2-types rea lized in ˆ A but not in A are v acuous, a nd since the guards in e h are not s atisfied by pairs of elements having v a cuous 2-types, ˆ A | = V 1 6 h 6 l ∀ x ∀ y ( e h ( x, y ) → ( β h ∨ x ≈ y )). Since all elements send the same messages in A a nd ˆ A , ˆ A | = V 1 6 i 6 m ∀ x ∃ = C i y ( f i ( x, y ) ∧ x 6≈ y ). Lemma 1 1. S upp ose that A | = ϕ ∗ , and that B and B ′ ar e disjoint subsets of A such that | B | > ( mC ) 2 + mC + 1 , and | B ′ | > mC + 1 . Then ther e exist elements b ∈ B and b ′ ∈ B ′ such that tp A [ b, b ′ ] is silent. Pr o of. Pick a n y B ′ 0 ⊆ B ′ such that | B ′ 0 | = mC + 1. Now set B 0 = { b ∈ B | for some b ′ ∈ B ′ 0 , b ′ sends a messag e to b } . Since A | = ϕ ∗ , no elemen t of B ′ 0 sends a message to more than mC o ther elements, and since | B ′ 0 | = mC +1, | B 0 | 6 mC ( mC +1). But | B | > mC ( mC + 1 ); so let b ∈ B \ B 0 . Again, b can send a message to at most mC elemen ts o f B ′ 0 , yet | B ′ 0 | > mC ; so let b ′ be an element o f B ′ 0 to which b do es not send a message. The ensuing analysis hinges on the sp ecial notion of a ‘t-cycle’, which we now pro ceed to define. In the sequel, we employ the notions of p ath and cycle in a gra ph G in the usual wa y , wher e paths and cycles are not p ermitted to encounter no des more than once (except of course that cycles lo op back to their starting p oints). W e take the lengt h of a path v 0 , . . . , v l to b e l , and the length of a cycle v 0 , . . . , v l (where v l = v 0 ) to b e l . W e insist that, by definition, all cycles have length at least 3. Definition 15. Let A be any str ucture in terpreting Σ ∗ ov er a domain A ; le t O ⊆ A ; and let E = { ( a, b ) ∈ A 2 | a 6 = b and either tp A [ a, b ] is not v acuous or a and b are bo th in O } , so that G = ( A, E ) is a gra ph. By a t- cycle in ( A , O ), we mean a cycle in G containing a t least one no de lying o utside O . A t-cycle in ( A , O ) is st r ong if, for any consecutive pair of elements a and b in that cycle, either a and b are both in O or tp A [ a, b ] is an inv ertible messa ge-t yp e. T o mo tiv ate these notions , think of O as the s et of ‘observ able elements’ of A —th e elements that will interpret the consta nts in so me set of ground, function-free literals ∆. By contrast, the elements o f A \ O are the ‘theoretica l’ elements—elemen ts whose e xistence may b e p erhaps forc ed b y the ba c kgro und theory ϕ ∗ . A t-cycle is th us a cycle in the g raph G of Definition 15 whic h inv olves at lea st one theore tica l element . Our first ta sk is to show that, giv en any (finite) model A of ϕ ∗ and any O ⊆ A , w e ca n remove all ‘sho rt’ strong t-cycles in ( A , O ). 21 Lemma 12. Supp ose A 0 | = ϕ ∗ ; and let O ⊆ A 0 and Ω > 0 . We c an find a mo del B | = ϕ ∗ such t hat: ( i ) O ⊆ B ; ( ii ) A 0 | O = B | O ; and ( iii ) ther e ar e n o str ong t-cycles in ( B , O ) of lengt h less than Ω . Mor e over, if A 0 is finite, then we c an ensure that B is finite. Pr o of. Assume without loss of genera lit y that Ω > 4, let K = 2( | O | + 1)(( mC ) Ω − 1) / ( mC − 1) + 2 , and let A 1 , . . . , A K be isomo rphic co pies of A 0 , with A i ∩ A j = ∅ for all i, j (0 6 i < j 6 K ). Let A (with do main A ) b e the union of A 0 together with all of these copies. F ormally: A = [ 0 6 i 6 K A i q A = [ 0 6 i 6 K q A i for any predicate q . By Lemma 8, A | = ϕ ∗ . (Here, we requir e that ϕ ∗ is in G C 2 , not just in C 2 .) Moreov er, if any element of A sends a message of type µ in A , then at leas t K elements of A \ O do so. F or a, b ∈ A , let us say that b is dir e ctly ac c essible fr om a if either (i) a = b , (ii) tp A [ a, b ] is a mess age-type (not necessarily inv ertible), or (iii) a a nd b are bo th in O ; further , let us say that b is ac c essible fr om a in l steps , if there ex ists a sequence of elements a 0 , . . . , a l of A such that a 0 = a , a l = b and, for all i (0 6 i < l ), a i +1 is directly ac cessible from a i . If a ∈ A , the num be r of elements accessible from a in l steps is cer tainly b ounded by ( | O | + 1) P 0 6 i 6 l ( mC ) i . Suppo se then γ = a 0 , a 1 , a 2 . . . , a 0 is a strong t- cycle in ( A , O ) of minimal length l < Ω; and a ssume, without loss of gene r alit y , that a 0 6∈ O . W e mo dify A (without affecting A | O ) so a s to destroy this t-cy cle, taking ca re o nly to cr eate new strong t-cycles of grea ter length. L e t a = a 0 and b = a 1 , and let µ b e the inv ertible message-type such that tp A [ a, b ] = µ . Claim. Ther e exist p airwise distinct elements c, d, e , f ∈ A \ O su ch that 1. tp A [ c, d ] = µ ; 2. neither c n or d is ac c essible fr om either a or b in Ω − 2 steps; 3. tp A [ e ] = tp A [ a ] , and tp A [ f ] = tp A [ b ] ; 4. tp A [ e, f ] is s ilent; 5. tp A [ d, e ] is not a message-typ e. 22 µ − 1 µ ✲ ✛ q q a b elemen ts accessible from eith er a or b in Ω − 2 steps ✬ ✫ ✩ ✪ µ − 1 µ ✲ ✛ q q c d q ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✯ e q f ( ) ✓ ✒ ✏ ✑ ✓ ✒ ✏ ✑ E F Figure 1 : The co nfiguration o f the cla im in the pro of of Lemma 12. An arrow o n a line indicates a message- t yp e; a bsence of an arrow on a line indicates a non- message type; a parenthetical arrow on a line indicates a 2-type which may or may not b e a message-type . F or definiteness , e and f have b een drawn outside the set of elemen ts acces sible from a or b in Ω − 2 steps; how ever, this is not required by the claim. Pr o of of Claim. Refer to Fig. 1. The num ber o f element s of A \ O acc e ssible from either a o r b in Ω − 1 steps is b ounded by 2( | O | + 1 ) Ω − 1 X i =0 ( mC ) i ! = 2( | O | + 1 )(( mC ) Ω − 1) / (( mC ) − 1) < K. So choo se c ∈ A \ O such that c sends a message o f type µ , and c is not accessible from either a or b in Ω − 1 steps; and cho ose d ∈ A s uch that tp A [ c, d ] = µ . It follows that d is not accessible from a or b in Ω − 2 steps. Let E b e the set o f elements of A \ O having the same 1-type as a , a nd F the set of elements of A \ O ha ving the same 1- t yp e as b . Now, E and F hav e c a rdinality at least K , where, since Ω > 4, K > 2(( mC ) 4 − 1) / ( mC − 1) + 2 = 2(( mC ) 3 + ( mC ) 2 + mC + 2) , Hence | E \ { a, b, c, d }| > 2 mC (( mC ) 2 + mC + 1 ); and similar ly , | F \ { a, b, c, d }| > 2 mC (( mC ) 2 + m C + 1 ). The r efore, we may s elect subsets E 1 , . . . , E mC of E \ { a, b , c, d } and s ubsets F ′ 1 , . . . , F ′ mC of F \ { a, b , c, d } , each containing at least ( mC ) 2 + mC + 1 elements, and with these 2 mC sets pa ir wise disjoint. Applying Lemma 1 1 to E i and F i for all i (1 6 i 6 cM ), s elect e i ∈ E i and f i ∈ F i such that tp A [ e i , f i ] is silent. But d c a nnot send a mess a ge to more than mC − 1 of the e i (since it already sends a message to c ), so we may pick e to b e some e i such that tp A [ d, e i ] is no t a messag e-t yp e, and f to b e the corresp onding f i . The elements c , d , e and f then hav e all the pr oper ties re q uired by the claim. Having o btained c, d, e , f , and returning to the pr oo f of the lemma, we mo dify A so as to ensure that the 2-type connecting a a nd d is silent. (Note that tp A [ a, d ] is certainly not a message- t yp e, but tp A [ d, a ] migh t b e.) More prec is ely , we 23 µ − 1 µ ✲ ✛ q q a b ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❨ ( ) µ − 1 µ ✲ ✛ q q c d q q ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ e f ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✯ ( ) A ⇒ µ − 1 µ ✲ ✛ q q a b ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✙ tp A [ e, f ] µ − 1 µ ✲ ✛ q q c d tp A [ a, d ] q q ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ e f ✲ ( ) ( ) tp A [ e, d ] A ′ Figure 2: E nsuring that tp A ′ [ a, d ] is silent . Typ e s display ed in the drawing of A ′ are to be rea d left-to-r igh t: thus, tp A ′ [ a, d ] = tp A [ e, f ], tp A ′ [ e, d ] = tp A [ a, d ], and tp A ′ [ e, f ] = tp A [ e, d ]. Lines and ar rows are interpreted as in Fig. 1. define the structure A ′ ov er A to b e exactly like A except tha t tp A ′ [ a, d ] = tp A [ e, f ] tp A ′ [ e, d ] = tp A [ a, d ] tp A ′ [ e, f ] = tp A [ e, d ] . The tra nsformation of A into A ′ is depicted in Fig. 2. The elemen ts a , c and e all hav e the same 1 -t yp e in A ; similarly for b , d and f . Therefore, these type-ass ig nmen ts are legitimate, and do not affect the 1 - t yp es of an y elements, whence A ′ | = ∀ xα . Since no new 2- t yp es are introduced, A ′ | = V 1 6 h 6 l ∀ x ∀ y ( e h ( x, y ) → ( β h ∨ x ≈ y )). By inspection of Fig. 2, every element sends the sa me messages in A ′ as in A (though to differ en t elemen ts), whence A ′ | = V 1 6 i 6 m ∀ x ∃ = C i y ( f i ( x, y ) ∧ x 6≈ y ). Thus, A ′ | = ϕ ∗ . Since a, e 6∈ O , A ′ | O = A | O ; and by constr uction, tp A ′ [ a, d ] is silen t. Note also that A and A ′ never differ with resp ect to any inv ertible messa ge-types: in particula r, the strong t-cycles in ( A , O ) are exactly the strong t-cycles in ( A ′ , O ). W e ar e now rea dy to destroy the strong t-cy c le γ in ( A ′ , O ). Let A ′′ be exactly like A ′ , exc e pt tha t tp A ′′ [ a, b ] =tp A ′ [ a, d ] tp A ′′ [ a, d ] =tp A ′ [ a, b ] tp A ′′ [ c, b ] =tp A ′ [ c, d ] tp A ′′ [ c, d ] =tp A ′ [ c, b ] . The tr ansformation of A ′ int o A ′′ is depicted in Fig. 3. Aga in, these assignments are legitimate, with 1-t yp es unaffected; no ne w 2-types are in tro duced; and every element of A sends the s ame mes sages in A ′′ as it do es in A ′ (though to different elements). Thus A ′′ | = ϕ ∗ . Since a, c 6∈ O , A ′′ | O = A ′ | O = A | O ; and by construction, γ is not a s tr ong t-cycle in ( A ′′ , O ). Moreover, we claim that a ny sequence γ ′ which is a s trong t-cycle in ( A ′′ , O ), but no t in ( A ′ , O ), is longer than γ . T o show this, w e supp ose | γ ′ | 6 | γ | < Ω, and derive a contradiction. 24 µ − 1 µ ✲ ✛ q q a b ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✯ ( ) µ − 1 µ ✲ ✛ q q c d A ′ ⇒ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❥ ( ) ❍ ❍ ❍ ❨ q q a b ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ ❍ tp A ′ [ a, b ] tp A ′ [ c, d ] tp A ′ [ a, d ] ✲ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✟ ✯ ✟ ✟ ✟ ✙ q q c d tp A ′ [ c, b ] A ′′ Figure 3: Destroying a strong t-cycle: the t wo-t yp es in A ′′ are to b e r ead from left to rig h t; th us, tp A ′′ [ a, b ] = tp A ′ [ a, d ], tp A ′′ [ a, d ] = tp A ′ [ a, b ], tp A ′′ [ c, b ] = tp A ′ [ c, d ] and tp A ′′ [ c, d ] = tp A ′ [ c, b ]. Lines and arrows are in terpreted a s in Fig. 1. Since γ ′ is not a strong t-cycle in ( A ′ , O ), at least one of the pairs ( a, d ), ( d, a ), ( b, c ) or ( c, b ) is consecutive in γ ′ ; so supp ose, without loss o f generality , that ( a, d ) is. Indeed, b y s tarting the cycle γ ′ at d , we may wr ite γ ′ = d, . . . , a, d. Now b certainly occur s in γ ′ . F o r o ther wise, a ll cons e c utiv e pairs o f γ ′ except ( a, d ) s end each o ther messages in A ′ , contradicting the fact that d is not ac- cessible fro m a in Ω − 2 steps. In fact, an ex actly similar a rgument shows that ( c, b ) o ccurs as a c onsecutiv e pair in γ ′ , since d is not accessible from b in Ω − 2 steps either. Thus, we may write: γ ′ = d, c 1 , . . . , c s , c, b, b 1 , . . . , b t , a, d, ( s, t > 0). Retur ning to the structure A ′ , then, we s ee that γ 1 = d, c 1 , . . . , c s , c, d γ 2 = b, b 1 , . . . , b t , a, b are strong t-cycles in ( A ′ , O ); and so, by the minimality of γ in A ′ , we have s + 2 > | γ | and t + 2 > | γ | . It follows tha t | γ ′ | = s + t + 4 > 2 | γ | > | γ | , a contradiction. Thu s, in tr ansforming A in to A ′′ , we destro y one strong t-cycle of length less than Ω, a nd create only longer stro ng t-cycles. Pro ceeding in this wa y , then, w e even tually destroy all stro ng t-cy c le s of leng th less than Ω. Our next task is to show that, given any (finite) mo del A of ϕ ∗ and a ny O ⊆ A , w e ca n remove all ‘sho rt’ t-cycles in ( A , O ), strong or otherwise. Lemma 13. Supp ose A 0 | = ϕ ∗ ; and let O ⊆ A 0 and Ω > 0 . We c an find a mo del B | = ϕ ∗ such t hat: ( i ) O ⊆ B ; ( ii ) A 0 | O = B | O ; and ( iii ) ther e ar e n o t-cycles in ( B , O ) of lengt h less than Ω . Mor e over, if A 0 is finite, t hen we c an ensur e that B is finite. 25 ❄ ✻ Ω + 1 A ǫ = A s ✟ ✟ ✟ ✟ ✟ ✟ ✟ ❍ ❍ ❍ ❍ ❍ ❍ ❍ s s ❅ ❅ ❅ ❅ ❅ ❅ A s 1 A s Y . . . ✛ ✲ Y s s s s ✂ ✂ ✂ ✂ ✂ ❇ ❇ ❇ ❇ ❇ ✂ ✂ ✂ ✂ ✂ ❇ ❇ ❇ ❇ ❇ A s 1 ,s 1 A s 1 ,s Y A s Y ,s 1 A s Y ,s Y ✲ ✛ Y ✲ ✛ Y s s s s A s 1 ,s 1 ,...,s 1 A s 1 ,s Y ,...,s Y A s Y ,s 1 ,...s 1 A s Y ,s Y ,...,s Y Figure 4: O rganization o f A ∗ as a tree of copies of A 0 , in the case where Y = | S | is finite; for legibility , the elements of S are n umbered, arbitrarily , as s 1 , . . . s Y . Pr o of. By Le mma 12, let A be a finite or co un table mode l of ϕ ∗ , with A finite if A 0 is, such tha t: (i) O ⊆ A ; (ii) A 0 | O = A | O ; and (iii) there a re no strong t-cycles in ( A , O ) of length less tha n Ω. Let S = {h a, b i ∈ A 2 | a 6 = b and tp A [ a, b ] is a non-inv ertible messa g e-t yp e } , and let Y = | S | . O b viously , if A is finite, then so is Y . In addition, let S ∗ Ω be the set of seq uenc e s of elemen ts of S of length 6 Ω. W e denote the length of σ ∈ S ∗ Ω by | σ | ; we w r ite empty seq ue nc e as ǫ and the concatenation of sequences σ a nd τ a s σ τ ; as usual, we identify sequences of leng th 1 with the corres p onding elements of S . Let A ǫ = A . F or σ ∈ S ∗ Ω \ { ǫ } , let A σ be a new copy of A , with domain A σ ; and fo r a n y a ∈ A , denote by a σ the co r resp o nding element of A σ . W e assume that the A σ ( σ ∈ S ∗ Ω ) ar e pair wise disjoint. Now let A ∗ be given by: A ∗ = [ σ ∈ S ∗ Ω A σ q A ∗ = [ σ ∈ S ∗ Ω q A σ for any predicate q . Note that O ⊆ A ⊆ A ∗ . W e ma y picture A ∗ as a tree of co pies of A , with A ǫ = A at the r oo t, and having branching factor Y . W e notio nally divide the tree into tiers, ta king the r oo t to b e the first tier, and the leav es to b e the (Ω + 1)th tier . The cas e wher e Y is finite is illustrated in Fig. 4; the cas e where Y = ℵ 0 may be pictured analogously . By Lemma 8, A ∗ | = ϕ ∗ . (Here, we r equire that ϕ ∗ is in G C 2 , not just in C 2 .) Mo reov er, there a re no str ong t-cycles in ( A ∗ , O ) o f length less than Ω. W e mo dify A ∗ as follows to obtain a s tructure B ov er the domain B = A ∗ . As a first (easy) step, if a and b are a n y dis tinct elements of A ∗ , not bo th in O , s uch that tp A [ a, b ] is sile nt but not v acuous, we can apply L e mma 10, and replac e tp A [ a, b ] with the v acuous 2-type tp A [ a ] × tp A [ b ]. (Notice that this transformatio n do es not affect A ∗ | O .) Hence, we may assume that, if ( a, b ) is a co nsecutiv e pair in some t- c ycle in ( A ∗ , O ), with a, b not b oth in O , then at 26 least o ne of tp A [ a, b ] and tp A [ b, a ] is a message-type. F urthermo re, since there are no strong t-cycles in ( A ∗ , O ) of length less than Ω, any t-cycle in ( A ∗ , O ) of length less tha n Ω contains at least one consecutive pair ( a, b ), such that: (i) a and b are not b oth in O , a nd (ii) ex actly one of tp A [ a, b ] and tp A [ b, a ] is a message-type (and hence a non-inv ertible mes sage-type). W e obtain B fro m A ∗ by r e-directing non-inv ertible messag es in s uccessive tiers of the tree in Fig. 4 as follows. Firs t, we cons ider the str ucture A ǫ = A at the r oo t of the tree. Let a, b b e an y distinct e lemen ts of A , not b oth in O . If tp A [ a, b ] is a non-inv ertible messag e-t yp e µ , then we divert the message which a sends to b in A ∗ so that it instead points to the element co rresp onding to b in the structure at the h a, b i th p osition in the second tier of the tr ee in Fig . 4 . F ormally , we set tp B [ a, b ] = tp A ∗ [ a ] × tp A ∗ [ b ] tp B [ a, b h a,b i ] = tp A ∗ [ a, b ] . Otherwise, we leav e the elements of A ǫ unaffected. This transforma tio n is de- picted in Fig. 5 . Next, we consider the copies of A in tier s 2 to Ω: i.e. those A σ such that 1 6 | σ | < Ω. Let a, b b e any distinct element s of A . If tp A [ a, b ] is a non-inv ertible message-type µ , then we divert the message which a σ sends to b σ in A ∗ so that it instead p oin ts to the element co r resp onding to b in the co py of A lo cated at the h a, b i th da ug h ter of A σ . F ormally , we set tp B [ a σ , b σ ] = tp A ∗ [ a σ ] × tp A ∗ [ b σ ] tp B [ a σ , b σ h a,b i ] = tp A ∗ [ a σ , b σ ] . Otherwise, we leav e the element s of A σ unaffected. Finally , we consider the copies of A in the bo ttom tier: i.e. those A σ such that | σ | = Ω. Let a , b b e a n y distinct elemen ts of A . If tp A [ a, b ] is a non- inv ertible messa ge-type µ , then we divert the messa ge which a σ sends to b σ in A ∗ so that it instead lo ops back to the element cor resp onding to b in the structure lo cated a t the h a, b i th no de of the se c ond tier o f the tr e e. F o rmally , we set tp B [ a σ , b σ ] = tp A ∗ [ a σ ] × tp A ∗ [ b σ ] tp B [ a σ , b h a,b i ] = tp A ∗ [ a σ , b σ ] . Otherwise, we leav e the element s of A σ unaffected. It is obvious that these assig nmen ts are le g itimate, leave 1- t yp es unaffected, int ro duce no new 2-types, and leave the num b er of messa ges of e ac h type sent by a n y element unaffected. Hence, B | = ϕ ∗ . It is equally ob vious tha t B | O = A ∗ | O = A 0 | O , and that ther e are no t-cycles in ( B , O ) of leng th less than Ω. W e remar k that the method of removing short t-cycles used in Lemma 1 3 works o nly for cycles featuring non-inv ertible message types. In particular, the la rge ‘fan-in’ at elemen ts of structures in the second tier requir es that the message-type s b eing r edirected are non-inv ertible. 27 A h a,b i q q ✲ a h a,b i b h a,b i µ A ∗ A h a,b i q q ✲ a h a,b i b h a,b i µ B ⇒ A ǫ q q ✲ a b µ A ǫ q q ❇ ❇ ❇ ❇ ❇ ❇ ❇ ❇ ❇ ❇ ❇ ❇ ◆ a b µ Figure 5 : Re-direction of no n- in vertible messages in A ǫ in the pro of o f Lemma 13. 6 Data-complexit y of query-answ ering and finite qu ery-answ eri ng In this section, we prov e that the query-a ns w ering and finite query-a nsw ering problems with r espect to a po s itiv e conjunctive query ψ ( ¯ y ) and a formula ϕ o f G C 2 are in the class co- NP . Lemma 13 pla ys a key role in this pro of, by allo wing us to re-write p ositive conjunctive queries as disjunctions of q ueries inv olving only tw o v ariables (at which po in t we can apply Theor em 1). T he r emainder of the pro of is largely a matter of b o ok-keeping. W e b egin with a g eneralization o f the o bs erv a tion that ∀ x ∀ y θ ( x, y ) is log ically equiv alen t to ∀ xθ ( x, x ) ∧ ∀ x ∀ y ( x 6≈ y → θ ( x, y )). W e emplo y the following notation. Fix some s e t of constants K and tuple o f v ariables ¯ x = x 1 , . . . , x n . Let Ξ b e the set of all functions ξ : ¯ x → ¯ x ∪ K . F or ea c h ξ ∈ Ξ, deno te by ¯ x ξ the (p ossibly empty) tuple of v ariables ξ ( x 1 ) , . . . , ξ ( x n ) with all constants and duplica tes r emo ved. F urther, for any for m ula θ , denote by θ ξ the result of simult aneo usly substituting the terms ξ ( x 1 ), . . . , ξ ( x n ) for a ll free occur rences of the resp ectiv e v aria bles x 1 , . . . , x n in θ . Lemma 14. L et ¯ x b e a tuple of variables, K a finite set of c onstants, and Ξ the set of al l fu n ctions ξ : ¯ x → ¯ x ∪ K . If θ is any formula, t hen ∀ ¯ xθ is lo gic al ly e quivalent to ^ ξ ∈ Ξ ∀ ¯ x ξ ^ x ∈ ¯ x ξ c ∈ K x 6≈ c ∧ ^ x,x ′ ∈ ¯ x ξ x 6 = x ′ x 6≈ x ′ → θ ξ . (5) In fact, let Ξ 1 and Ξ 2 b e disjoint ( p ossibly empty ) subsets of Ξ su ch that Ξ 1 ∪ Ξ 2 = Ξ . Then ∀ ¯ xθ is lo gic al ly e quivale nt to ^ ξ ∈ Ξ 1 ∀ ¯ x ξ ^ x ∈ ¯ x ξ c ∈ K x 6≈ c ∧ ^ x,x ′ ∈ ¯ x ξ x 6 = x ′ x 6≈ x ′ → θ ξ ∧ ^ ξ ∈ Ξ 2 ∀ ¯ x ξ θ ξ . (6) 28 Pr o of. Denote by ϕ 1 the formula (5), a nd by ϕ 2 the formula (6). It is ob vious that | = ∀ ¯ xθ → ϕ 2 , | = ϕ 2 → ϕ 1 , a nd | = ϕ 1 → ∀ ¯ xθ . The next lemma allows us to remove individual constants from universally quantified for m ulas a t the exp ense of adding some gr ound literals. Lemma 15. L et ϕ b e a fo rmula, Θ a set of formulas, and c an individual c onstant. L et p b e a new u nary pr e dic ate and z a new variable ( ‘new’ me ans ‘not o c curring in ϕ or Θ ’ ) . Denote by ϕ ′ the r esult of r epla cing al l o c curr enc es of c in ϕ by z , and let ψ b e t he fo rmula ∀ z ( ϕ ′ ∨ ¬ p ( z )) . Then the sets of formulas Θ ∪ { ϕ } and Θ ∪ { p c ( c ) , ψ } ar e satisfiable over the same domains. Pr o of. Obviously , { p c ( c ) , ψ } | = ϕ . On the other hand, if A | = Θ ∪ { ϕ } , expand A to a str ucture A ′ by setting p A ′ = { c A } . Recall that a clause is a disjunction of litera ls (with the empty clause , ⊥ , allow ed), and that a c lause is ne gative if all its literals are nega tive. In the sequel, we contin ue to confine attention to sig natures in volving only unar y a nd binary pr edicates to gether with individual co nstan ts. Definition 16. L e t η b e a claus e, let T be the set of terms (v ariables or con- stants) o ccurr ing in η , and let E = { ( t 1 , t 2 ) ∈ T 2 | t 1 6 = t 2 and either t 1 , t 2 bo th o ccur in some litera l of η or t 1 and t 2 are b oth constants } . Denote the gr a ph ( T , E ) b y G η . (W e allow the empty gra ph for the case η = ⊥ .) W e say η is v-cyclic if G η contains a cycle (in the us ua l g raph-theoretic se nse) at least one o f whose no des is a v ariable; otherwise, we say η is v-acyclic . Definition 17. Let K b e a set of individual co nstan ts. A v-formula ( with r esp e ct t o K ) is a sentence of the form ∀ ¯ x ^ x ∈ ¯ x c ∈ K x 6≈ c ∧ ^ x,x ′ ∈ ¯ x x 6 = x ′ x 6≈ x ′ → η , (7) where η is a v-cyclic neg ativ e cla use. The in tuition behind v-for m ulas is that they provide a co un terpart to the notion of a t-cy cle in a pair ( A , O ), given in Definition 15. Sp ecifically: Remark 3. L et A b e a structur e, K the set of indivi dual c onstants interpr ete d by A , and O = { c A | c ∈ K } . S upp ose that distinct individual c onstants in K have distinct interpr etations in A . L et υ b e a v-formula with r esp e ct to K . If A 6| = υ , t hen ther e is a t - cycle in ( A , O ) of lengt h at most k υ k . Definition 18. Let η be a cla use. W e ca ll η splittable if, b y re-o r dering its literals, it can be written a s η 1 ∨ η 2 , where V ars( η 1 ) ∩ V ars( η 2 ) = ∅ ; o ther wise, η is unsplittable . 29 Remark 4. L et η b e a non-gr ound clause. If η is u nsplittable and v-acyclic, then it c ontains at most one individual c onstant. Lemma 16. L et η ( x, ¯ x ) b e a ne gative clause with no individual c onstants, in- volving exactly the variables x, ¯ x . Supp ose further that η ( x, ¯ x ) is non-empty, unsplittable and v-acyclic. Then ther e exists a G C 2 -formula of ψ ( x ) such that ∀ ¯ xη ( x, ¯ x ) and ψ ( x ) ar e lo gic al ly e quivalent. Pr o of. W e pro ceed by induction on the num ber o f v ariables inv olved. If ¯ x is the empty tuple, there is nothing to pr o ve, so supp ose o therwise. Since η is unsplittable and v-acyclic, and contains the v aria ble x , G η may be viewed as a tree with x at the ro ot. Let x 1 , . . . , x n be the immediate des cendan ts o f x in the tree G η . F ur ther , for all i (1 6 i 6 n ), let ¯ x i be a (po ssibly empty) tuple consisting of those v ariables in ¯ x which are prop er descendants of x i in G η . Then ∀ ¯ xη ( x, ¯ x ) is log ically equiv alent to some formula δ ( x ) ∨ _ 1 6 i 6 n ∀ x i ( ǫ i ( x, x i ) ∨ ∀ ¯ x i η i ( x i , ¯ x i )) , where δ ( x ) is a neg a tiv e clause in v olving exa ctly the v ar iables { x } , and, for all i (1 6 i 6 n ): (i) ǫ i ( x, x i ) is a non-e mpty nega tiv e clause each of whos e literals inv olves the v ariables { x, x i } , and (ii) η i ( x i , ¯ x i ) is a nega tive cla use which inv olves exactly the v ariables { x i } ∪ ¯ x i . By inductive hypo thesis, there exists a G C 2 -formula ψ i ( x i ) logically equiv alent to ∀ ¯ x i η i ( x i , ¯ x i ). But then ∀ ¯ xη ( x, ¯ x ) is logically equiv alent to δ ( x ) ∨ _ 1 6 i 6 n ∀ y ( ǫ i ( x, y ) ∨ ψ i ( y )) , which in turn is trivially logically equiv alent to a G C 2 -formula. Lemma 17. L et ϕ b e a G C 2 -formula, ∆ a finite s et of gr ound, fun ction-fr e e liter als, and Υ a fin ite set of v-formulas. Supp ose t hat ∆ c ontains the liter al c 6≈ d for al l distinct individual c onstants c , d o c curring in ∆ ∪ Υ . Then ∆ ∪ { ϕ } ∪ Υ is ( finitely ) satisfiable if and only if ∆ ∪ { ϕ } is ( finitely ) satisfiable. Pr o of. The only- if direction is tr ivial. So suppose A + 0 is a (finite) mo del of { ϕ } ∪ ∆, with do main A 0 . Let O ⊆ A 0 be the set of elements interpreting the individual consta n ts in ∆ ∪ Υ, and let A 0 be the reduct of A + 0 obtained by ignoring the interpretations of thos e individual constants. Let ϕ ∗ and C b e obtained fro m ϕ a s in Lemma 9. Let A 1 , . . . , A C be is o- morphic copies of A 0 with the domains A i (0 6 i 6 C ) pa irwise disjoint; and let A be the unio n of thes e mo dels as in Lemma 8 . Thus, O ⊆ A 0 ⊆ A , A | = ϕ , and | A | > C . By Lemma 9, let A ′ be an expansion of A such that A ′ | = ϕ ∗ . Obviously , A ′ is finite if A + 0 is. Let Ω > k υ k for all υ ∈ Υ. Applying Lemma 13 to A ′ , let B b e a mo del of ϕ ∗ (and hence of ϕ ), finite if A ′ is finite , such that: (i) O ⊆ B ; (ii) B | O = A ′ | O = A 0 | O ; and (iii) there ar e no t-cycles in ( B , O ) of le ngth less than Ω. Let 30 B + be the expansion of B obtained by interpreting any cons tan ts as in A + 0 . Thu s, B + | = ∆ ∪ { ϕ } . If B + fails to satisfy so me for m ula in Υ o f the for m (7), then, by Remark 3 , there is a t-cycle in ( B , O ) o f length less than Ω, which is impo ssible. Hence B + | = Υ, as required. Theorem 4. F or any G C 2 -sentenc e ϕ and any p ositive c onjunctive qu ery ψ ( ¯ y ) , b oth Q ϕ,ψ ( ¯ y ) and F Q ϕ,ψ ( ¯ y ) ar e in co- NP . Pr o of. W e give the pro of for F Q ϕ,ψ ( ¯ y ) ; the pro of for Q ϕ,q ( ¯ y ) is a nalogous. Let an instance h ∆ , ¯ a i of F Q ϕ,ψ ( ¯ y ) be given, where ∆ is a se t o f gr ound, function-free literals, and ¯ a a tuple of individual constants. By r e-naming in- dividual constants if necessa ry , we may assume that the co nstan ts ¯ a a ll hav e co des of fixed length, so that ¯ a may b e regarded a s a constant . Let n = k ∆ k , then. The instance h ∆ , ¯ a i is p ositive if and only if ψ ( ¯ a ) is true in every finite mo del of ∆ ∪ { ϕ } . Hence, it suffices to give a non-deterministic pro cedure for determining the finite sa tisfiabilit y o f the for m ula ^ ∆ ∧ ϕ ∧ ¬ ψ (¯ a ) , (8) running in time b ounded b y a p olynomial function o f n . W e ma y assume without los s of generality that all pr e dicates in ∆ occur in ϕ or ψ ( ¯ y ), since—pr o vided ∆ contains no direct co n tradictions—liter als in volving foreign predicates ca n simply b e remov ed. F urther, we may assume that, for every g round atom α ov er the relev an t signa ture, ∆ co n tains either α or ¬ α . F or if not, non-deterministically add either of these literals to ∆; since all pr e dic a tes of ϕ a nd ψ ( ¯ y ) a re by hypothesis of arity 1 or 2, this pro cess may be car ried out in time bounded by a quadra tic function of n . Finally , we may assume that, fo r all distinct c, d ∈ const(∆) ∪ ¯ a , ∆ contains the literal c 6≈ d , s ince, if ∆ contains c ≈ d , either of these constants can b e e limina ted. Since ψ ( ¯ y ) is a p ositive conjunctive query , we ma y take ¬ ψ (¯ a ) to b e ∀ ¯ xη , where η is a nega tiv e clause. Let K = const(∆) ∪ ¯ a , and let Ξ be the set of functions from ¯ x to ¯ x ∪ K . Thus, | Ξ | 6 ( n + l 1 + l 2 ) l 1 , where l 1 is the ar it y of ¯ x and l 2 is the ar it y of ¯ y . Employing the notation o f Lemma 14, a nd recalling Definition 16, let Ξ 1 = { ξ ∈ Ξ | η ξ is v - cyclic } Ξ 2 = { ξ ∈ Ξ | η ξ is v - acyclic } . Thu s, F ormula (8) is logically equiv alent to ^ ∆ ∧ ϕ ∧ ^ ξ ∈ Ξ 1 ∀ ¯ x ξ ^ x ∈ ¯ x ξ c ∈ K x 6≈ c ∧ ^ x,x ′ ∈ ¯ x ξ x 6 = x ′ x 6≈ x ′ → η ξ ∧ ^ ξ ∈ Ξ 2 ∀ ¯ x ξ η ξ ; (9) moreov er, this latter form ula can be computed in time bounded b y a p olynomial function of | Ξ | , and hence of n . Let us write (9) as ^ ∆ ∧ ϕ ∧ ^ Υ ∧ ^ ξ ∈ Ξ 2 ∀ ¯ x ξ η ξ ; (10) 31 where Υ is a finite set of v-formulas with res pect to K . Let η ∆ ξ denote ⊤ if any ground literal of η ξ app ears in ∆; o therwise, let η ∆ ξ be the res ult of deleting from η ξ all gr o und literals whos e negation a pp ears in ∆. (If no literals r emain, η ∆ is ta k en to be ⊥ .) Thus, (10) is logica lly equiv alent to ^ ∆ ∧ ϕ ∧ ^ Υ ∧ ^ ξ ∈ Ξ 2 ∀ ¯ x ξ η ∆ ξ . (11) Since ∆ contains every g round liter al or its negation o ver the relev ant signature, no gr ound literal can a ppear in any of the η ∆ ξ . Moreover, if any of the η ∆ ξ is empt y , (11) is trivia lly unsa tis fia ble; so we may suppo se otherwis e. Lis t the formulas ∀ ¯ x ξ η ∆ ξ for ξ ∈ Ξ 2 , as ∀ ¯ x i η i (1 6 i 6 s ); and re-write ea c h ∀ ¯ x i η i as a disjunction ∀ ¯ x i, 1 η i, 1 ∨ · · · ∨ ∀ ¯ x i,t i η i,t i where the η i,j are unsplittable. F or eac h i (1 6 i 6 s ), pick a v alue j (1 6 j 6 t i ) and wr ite ∀ ¯ x i,j η i,j as ∀ ¯ x ′ i η ′ i . Thus, (11) is finitely satisfiable if a nd only if, for some way of making the ab ov e c hoices, the resulting formula ^ ∆ ∧ ϕ ∧ ^ Υ ∧ ^ 1 6 i 6 s ∀ ¯ x ′ i η ′ i (12) is finitely satisfiable. This (non-de ter ministic) step ma y again b e executed in time bo unded by a p olynomial function of n . Note that e ac h η ′ i is v-acyclic, unsplittable and non-g round; hence, by Remark 4, it cont ains at most one indi- vidual constant. W e may assume for simplicity , and without los s of gener alit y , that η ′ i contains exactly one individual constant—sa y , c i . Let η ′′ i be the result of replacing all o ccurrences of c i in η ′ i by x (where x do es not o ccur in η ′ i ), and let p i be a new unar y predica te dep ending only on the clause η ′′ i (and no t on i ): that is, if η ′′ i = η ′′ j , then p i = p j . Since η ′ i contains at most one individual constant, η ′′ i is a c la use in the sig nature o f ψ ( ¯ y ); therefo re, the num ber o f distinct predica tes p i is bo unded b y some consta n t, independent of ∆. Let ∆ ′ = { p i ( c i ) | 1 6 i 6 s } . By Lemma 15, then, (12) is satisfiable ov er the sa me domains as ^ (∆ ∪ ∆ ′ ) ∧ ϕ ∧ ^ Υ ^ 1 6 i 6 s ∀ x ¯ x ′ i ( η ′′ i ∨ ¬ p i ( x )) . (13) Evidently , (13) can be co mputed in time b o unded b y a p olynomial function of n ; in par ticular, | ∆ ′ | is also bounded in this wa y . How ever, the num ber of formulas ∀ x ¯ x ′ i ( η ′′ i ∨ ¬ p i ( x )) occur ring in (13)—assuming duplicates to b e omitted—is b ounded by a constant. By Lemma 1 6, there exists, for each such ∀ x ¯ x ′ i ( η ′′ i ∨ ¬ p i ( x )), a lo gically eq uiv alent G C 2 -formula ∀ xθ i ( x ). Let θ b e the conjunction of all these ∀ xθ i ( x ). Then (1 3) is lo gically equiv alen t to ^ (∆ ∪ ∆ ′ ) ∧ ( ϕ ∧ θ ) ∧ Υ . (14) Finally , by Lemma 17, (14) is finitely satisfia ble if and only if ^ (∆ ∪ ∆ ′ ) ∧ ( ϕ ∧ θ ) (15) 32 is finitely satisfiable. Since ( ϕ ∧ θ ) is a one of a finite n umber H of pos sible G C 2 - (and hence C 2 -) for m ulas, where H dep ends only on the signature of ψ ( ¯ y ), a nd not on ∆, the finite satisfiability o f (15) can be tested nondeterministically in time b ounded by a p olynomial function o f n , by Theo rem 1. That the same complexity bo unds are obtained for the query-answering a nd finite query - answ ering problems in Theorem 4 is, incidentally , not something that should be taken for gra nted. F or example, Rosa ti [13] presents a r elativ ely simple logic (not a subset of C 2 ) fo r which query - answ ering is alwa ys decida ble, but finite query-a ns w ering in g eneral undecidable. Ac kno wledgme nts This pap er was written during a v is it to the F aculty of Computer Science at the F ree University of Bo zen-Bolzano. The author wishes to express his a ppreciation for this opp ortunit y and to ackno wledge the help of Diego Calv anese, Da vid T o man and Alessandr o Artale in discuss io ns o n this topic. References [1] A. Arta le, D. Calv anese, R. Kontc hako v, and M. Zakharyaschev. DL-Lite in the light of fir st-order log ic. In Pr o c e e dings of the Twenty-Se c ond AAAI Confer enc e on Artificia l Intel ligenc e, AAAI’07 , pa ges 361 – 366. AAAI Press, 2007. [2] Ego n B¨ org er, Er ich Gr¨ adel, and Y uri Gurevich. The Classic al De cision Pr oblem . P ersp ectives in Mathematica l Logic. Springer-V er lag, Berlin, 1997. [3] D. Calv anese, G. De Gia como, D. Lembo, M. Lenzer ini, and R. Ro sati. Data complexity of query answering in description lo gics. In Principles of Know le dge R epr esentation and R e asoning, KR’06 , pages 260– 270. AAAI Press, 2006. [4] Birte Glimm, Ian Horro cks, Carsten Lutz, and Ulrike Sa ttler . C o njunc- tive query answering for the description logic SHIQ. Journal of Artificial Intel ligenc e Rese ar ch , 31 :1 57–204 , 2 008. [5] Erich Gr¨ adel and Martin Otto. On logics w ith tw o v ariables . The or etic al Computer S cienc e , 224(1 –2):73–11 3 , 19 9 9. [6] Ullrich Hustadt, Boris Motik, and Ulrike Sattler. Reasoning in desc rip- tion logics by a reduction to disjunctive Datalog. J ournal of Automate d R e asoning , 39(3):35 1 –384, 20 07. [7] Y. Kazakov. A p olynomial translation from the tw o-v ariable guarded fra g- men t with n umber re strictions to the g uarded fra g men t. In J. J. Alferes a nd J. Leite, editors, L o gics in Artificial Intel ligenc e: 9th Eur op e an Confer enc e, 33 JELIA 2004 , volume 3229 of L e ct u r e N otes in Artificial Intel ligenc e , pages 372–3 84, Ber lin, 2004. Springer . [8] H.W Lenstra, Jr . In teger progr amming with a fixed n umber of v ar iables. Mathematics of Op er ations R ese ar ch , 8 :538–548 , 1983. [9] Magda le na Ortiz, Diego Ca lv anes e, and Thomas Eiter . Data complexity of query answ ering in expressive des cription logic s via tableaux. J. of Auto- mate d R e asoning , 2008 . F o rthcoming. [10] Leszek Pacholski, Wieslaw Szwast, and Lidia T endera. Complexity re sults for fir st-order t wo-v a riable logic with co un ting. SIAM Journal on Comput- ing , 29 (4):1083–11 17, 1999. [11] Ian P ratt-Hartmann. Complexit y of the tw o-v ariable fragment with count- ing quant ifiers. Journal of L o gic, L anguage and In forma tion , 14:369– 395, 2005. [12] Ian Pratt-Hartmann. Complexity of the g uarded tw o-v ariable fra gmen t with counting quantifiers. J ournal of L o gic and Computation , 1 7 :133–15 5, 2007. [13] Riccardo Rosati. On the decidability and finite controllabilit y o f query pro cessing in databases with inco mplete information. In Pr o c e e dings of the Twenty-fifth ACM SIGACT SIGMOD SIGAR T S ymp osium on Principles of Datab ase Systems, PODS 2006 , pages 356 –365, 20 06. [14] Andrea Schaerf. On the complexity o f the insta nce c hecking problem in concept languages with existen tial qua n tification. Journal of Intel ligent Information Syst ems , 2(3):265 –278, 19 93. [15] L. T endera. Co unting in the tw o v ariable guar ded logic with transitivity . In V. Diekert and B. Durand, editors , Pr o c e e dings, ST ACS’05 , volume 3 404 of L e ct ur e n otes in Computer Scienc e , pages 83–96 . Spring e r, Berlin, 20 0 5. 34
Original Paper
Loading high-quality paper...
Comments & Academic Discussion
Loading comments...
Leave a Comment