Abstract 1 Introduction 2 Preliminaries 3 Ontology-mediated Queries and First-order Rewritability 4 A Uniform First-order Rewriter 5 Future Work References Appendix A Resolvents and Polishing Strategies Appendix B Validity Appendix C Proof of Lemma 10

First-Order Rewritability of Rule-Based Ontology Mediated Queries with Negation

Georg Gottlob ORCID University of Calabria, Rende, Italy Marco Manna ORCID University of Calabria, Rende, Italy Andreas Pieris ORCID University of Cyprus, Nicosia, Cyprus
University of Edinburgh, UK
Aldo Ricioppo ORCID University of Calabria, Rende, Italy
Abstract

The idea of using an ontology to enrich user queries with domain knowledge has attracted considerable attention from the database and KR communities during the last fifteen years or so. The ontology and the user query can be conveniently seen as two components of one composite query, called ontology-mediated query (omq), while an omq language (𝖮𝖫,𝖰𝖫) collects all such omqs where the ontology is expressed using the ontology language 𝖮𝖫 and the user query comes from the query language 𝖰𝖫. The evaluation problem for rule-based omq languages of the form (𝖮𝖫,𝖢𝖰), where 𝖮𝖫 is a rule-based ontology language, i.e., it collects ontologies modelled using tuple-generating dependencies (a.k.a. existential rules), and 𝖢𝖰 is the language of conjunctive queries, has been extensively studied in the literature. In particular, the notion of first-order rewritability of such languages, i.e., the property of being able to rewrite every omq from the language in question to an equivalent first-order query, has been studied in depth. This research effort led an algorithmic characterization of when a rule-based omq language (𝖮𝖫,𝖢𝖰) is first-order rewritable. More precisely, there is a uniform algorithm 𝖱𝖾𝗐𝗋𝗂𝗍𝖾 such that, for every rule-based ontology language 𝖮𝖫, the omq language (𝖮𝖫,𝖢𝖰) is first-order rewritable iff for every omq O from (𝖮𝖫,𝖢𝖰), the algorithm 𝖱𝖾𝗐𝗋𝗂𝗍𝖾 on input O terminates and constructs a first-order rewriting of O. The question that we are interested in is whether the above algorithmic characterization can be extended to rule-based omq languages of the form (𝖮𝖫,𝖢𝖰¬), where 𝖢𝖰¬ is the language of conjunctive queries with the useful feature of negation. The goal of this work is to initiate effort towards the settlement of the above highly non-trivial question. To this end, we provide a new algorithm, which is a non-trivial extension of the algorithm 𝖱𝖾𝗐𝗋𝗂𝗍𝖾 for positive omqs, and show the following: under the Skolem semantics, a well-established approach for defining the answer to a rule-based omq when the user query can use negation, the proposed algorithm is a first-order rewriter for (𝖮𝖫,𝖢𝖰¬), where 𝖮𝖫 is the language of linear or acyclic tuple-generating dependencies, two central rule-based ontology languages that ensure first-order rewritability for positive omqs. We strongly believe that the new algorithm can serve as a good starting point towards the full settlement of our main question.

Keywords and phrases:
ontology-mediated queries, tuple-generating dependencies, conjunctive queries with negation, first-order rewritability
Copyright and License:
[Uncaptioned image] © Georg Gottlob, Marco Manna, Andreas Pieris, and Aldo Ricioppo; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Logic
Funding:
This work was supported by the University of Cyprus, NextGenerationEU through the project FAIR (CUP H23C22000860006), Italian Ministry of University and Research through the project PRODE (CUP H53D23003420006), Italian Ministry of Enterprises and Made in Italy through the projects ASVIN (CUP B29J24000200005) and PreDiCI (CUP B29J24000300005), and Calabrian Region through the project NextGenGuides (CUP J39I24002040005).
Editors:
Balder ten Cate and Maurice Funk

1 Introduction

Ontology-mediates Queries.

Rule-based languages lie at the core of numerous areas of central importance to databases and artificial intelligence. It is widely accepted that tuple-generating dependencies (tgds) form a prominent rule-based language, originally introduced as a unifying framework for database constraints [1]. Tgds are first-order sentences of the form x¯y¯(ϕ(x¯,y¯)z¯ψ(x¯,z¯)), where ϕ (the body) and ψ (the head) are conjunctions of relational atoms, and they essentially state that certain tuples in a database imply the presence of some other tuples in the database. The last fifteen years or so, they have been employed for knowledge representation purposes, in particular, as an alternative way to model ontologies that are used to enrich user queries, typically conjunctive queries, with domain knowledge. The marriage of ontologies with user queries has been originally proposed in the context of ontology-based data integration in order to facilitate access to data that is heterogeneous and incomplete [14]. The ontology and the user query can be conveniently seen as two components of one composite query, called ontology-mediated query (omq) [6]. In this context, the main problem of interest is to compute the answer to such an omq over a database. In particular, given a database D and an omq O=(Σ,Q), where Σ is a finite set of tgds (the ontology) and Q a conjunctive query (the user query), the goal is compute the certain answers to O over D, denoted 𝖺𝗇𝗌(O,D), which are all the tuples of database elements that are answers to Q no matter on which model of D and Σ it is evaluated, i.e., the answers to Q derived by every model of D and Σ.

Answering Omqs via Query Rewriting.

Building ontology-aware database systems from scratch, with sophisticated optimization techniques, is a highly non-trivial task that requires a great effort. An alternative approach towards practical implementations of evaluating an omq over a database is to use conventional database systems. However, such systems are unaware of ontologies. This obstacle can be addressed by query rewriting: the omq O=(Σ,Q) is rewritten into a new query QO, the so-called rewriting, which has the same answer as the omq O over all input databases, i.e., for every database D, 𝖺𝗇𝗌(O,D) coincides with the answer to QO over D. It is of course essential that the query QO is expressed in a query language that can be handled by standard database systems. The typical target query language that is considered in this setting is that of first-order queries. The problem of rewriting omqs into first-order queries, when the ontology is a set of tgds and the user query a conjunctive query, has been extensively studied. This research effort led to several syntactic classes 𝖢 of tgds that give rise to first-order rewritable classes of omqs (𝖢,𝖢𝖰), i.e., every omq (Σ,Q) of (𝖢,𝖢𝖰), where Σ is a set of tgds from 𝖢 and Q a query from the class of conjunctive queries 𝖢𝖰, admits a first-order rewriting, together with prototype systems illustrating the effectiveness of this approach; see, e.g., [7, 8, 10, 12]. What is even more remarkable is the fact that every first-order rewritable tgd-based class of omqs, no matter how the class of tgds is defined, can be handled via one uniform rewriting algorithm. More precisely, there is a resolution-based algorithm 𝖱𝖾𝗐𝗋𝗂𝗍𝖾 such that, for every class 𝖢 of tgds, the omq class (𝖢,𝖢𝖰) is first-order rewritable iff for every omq O from (𝖢,𝖢𝖰), 𝖱𝖾𝗐𝗋𝗂𝗍𝖾 on input O terminates and returns a first-order rewriting of O [12]. This provides an algorithmic characterization of when an omq class (𝖢,𝖢𝖰), where 𝖢 is a class of tgds, is first-order rewritable.

Adding Negation.

Although conjunctive queries form a key tool for querying data, they are not able to express negation, a very useful construct that allows us to express non-monotonic queries that naturally appear in real-life scenarios. It is thus very natural to consider classes of tgd-based omqs (𝖢,𝖢𝖰¬), where the user query comes from the class of conjunctive queries with negation, denoted 𝖢𝖰¬. The problem of evaluating such non-positive omqs has also attracted attention in the literature; see, e.g., [3, 4, 7, 9, 11]. Having said that, answering non-positive omqs of this kind via first-order rewritability, unlike the case of positive omqs discussed above, is largely unexplored. An interesting question is whether the algorithmic characterization discussed above concerning the first-order rewritability of positive omqs can be extended to non-positive omqs. More precisely, we are asking whether there exists one uniform algorithm, which does not depend on any class of tgds, that acts as a first-order rewriter for every class (𝖢,𝖢𝖰¬) of tgd-based omqs that is first-order rewritable. The goal of this work is to initiate effort towards the settlement of this highly non-trivial question. But first we need to discuss how the answer to such omqs should be defined, and, in fact, whether the standard certain answers semantics is conceptually meaningful in this case.

Consider the database D={R(a),S(b)} and the omq O=(Σ,Q), where Σ consists of the tgd x(R(x)yP(x,y)) and Q is the Boolean query Ans:-R(x),P(x,y),¬S(x). The answer to O over D is empty (i.e., the query is false) since there exists at least one model of D and Σ that does not entail Q; e.g., the model I={R(a),S(b),P(a,a),S(a)} does not entail Q due to the atom S(a) since the only way to match the positive part of Q to I is by mapping both variables x and y to a, whereas S(a) belongs to I. On the other hand, S(a) is not supported by D and Σ. Indeed, there is no reason to derive the atom S(a) since the instance I{S(a)} is also a model of D and Σ. Hence, the model I should not be a valid reason for the non-entailment of Q by D and Σ. The above example can be generalized and show that for a database D and an omq O=(Σ,Q), where Σ is set of tgds and Q a conjunctive query with at least one negated atom, there is always a model I of D and Σ such that the answer to Q over I is empty – I is simply the model that collects all the atoms that can be formed using the predicates of the schema and the constants in D and Q.

The above discussion leads to the natural idea that has been adopted in the literature of considering only models without redundant information that may distort the expected answer to the given omq, i.e., considering only minimal models. Coming back to the above example, it is easy to see that Q is entailed by every minimal model of D and Σ. Hence, the main problem of interest in this context is as follows: given a database D and an omq (Σ,Q), where Σ is a set of tgds and Q a conjunctive query with negation, compute all the tuples of database elements that are answers to Q derived by every minimal model of D and Σ.

Once we adopt the minimal model semantics, there is one more aspect that we need to carefully consider, which has to do with the existentially quantified variables in tgd-heads, that greatly affects the obtained semantics: either keep those existentially quantified variables, or eliminate them via the standard technique of Skolemization. Both approaches are quite relevant and have been considered in the literature; see, e.g., [2, 9]. In this work, we focus on the latter, which we call Skolem semantics. Let us clarify that for positive tgd-based omqs, considering all the models or only the minimal models, and keeping or eliminating the existentially quantified variables in tgd-heads, lead to the exact same semantics.

Our Contribution.

This work makes a first non-trivial step towards an algorithmic characterization of when an omq class (𝖢,𝖢𝖰¬), where 𝖢 is a class of tgds, is first-order rewritable. In particular, we establish the existence of an algorithm that, no matter which class 𝖢 of tgds we consider among linear or acyclic tgds – two central classes of tgds that ensure first-order rewritability for positive omqs – is a first-order rewriter for (𝖢,𝖢𝖰¬) under the Skolem semantics. This new algorithm is significantly more sophisticated than the one for positive omqs as it needs to carefully treat the negative part of the user query. We strongly believe that it can serve as a good starting point towards an algorithmic characterization of first-order rewritability for non-positive classes of tgd-based omqs under the Skolem semantics. Interestingly, the proposed algorithm produces rewritings that fall in a novel fragment of first-order queries, which is strictly less expressive than the full language of first-order queries. We also show that unions of conjunctive queries with equality and negation are not powerful enough for our purposes as one might think, influenced by the fact that unions of conjunctive queries with equality are enough for positive tgd-based omqs.

2 Preliminaries

We proceed to introduce the basic notions about relational instances and databases, relational queries, and tuple-generating dependencies that will be used throughout the paper. For brevity, given an integer n>0, we may write [n] for the set of integers {1,,n}.

Basic Vocabularies.

Let 𝐂, 𝐍 and 𝐕 be disjoint countably infinite sets of constants, (marked) nulls and variables, respectively. We further consider the countably infinite set 𝐅 of function symbols (each of them associated with a positive arity), which is disjoint from 𝐂, 𝐍 and 𝐕. We assume that different constants represent different objects and different function symbols represent different functions (unique name assumption). Functional terms are inductively defined as follows: (i) variables are functional terms, and (ii) f(t1,,tn), where n>0, f is an n-ary function symbol of 𝐅, and t1,,tn are functional terms, is a functional term. Ground functional terms are defined similarly: (i) constants of 𝐂 are ground functional terms, and (ii) f(t1,,tn), where n>0, f is an n-ary function symbol of 𝐅, and t1,,tn are ground functional terms, is a ground functional term. We refer to constants, nulls, variables, functional terms, and ground functional terms as terms.

Relational Atoms and Homomorphisms.

A schema 𝐒 is a finite set of relation names (or predicates) with associated positive arity. We write R/n to say that R has arity n>0; we may write 𝖺𝗋(R) for the integer n. A (relational) atom α over 𝐒 is an expression of the form R(t¯), where R/n𝐒 and t¯ is an n-tuple of terms; note that we may treat a tuple as the set of its elements. For a set A of atoms, we write 𝗍𝖾𝗋𝗆𝗌(A) and 𝗏𝖺𝗋(A) for the set of terms and variables, respectively, mentioned in the atoms of A.

A central notion is that of homomorphism that allows us to embed a set of atoms into another set of atoms while preserving its structure. Formally, a homomorphism from a set of atoms A to a set of atoms B is a function h:𝗍𝖾𝗋𝗆𝗌(A)𝗍𝖾𝗋𝗆𝗌(B) that is the identity on 𝐂 with R(h(t¯))B for every R(t¯)A; for a term f(t1,,tn), h(f(t1,,tn))=f(h(t1),,h(tn)). We write AB to denote that there is a homomorphism from A to B.

Relational Instances and Databases.

We make the distinction between instances that mention only constants and nulls and instances that mention only ground functional terms. A null instance over a schema 𝐒 is a (possibly infinite) set of atoms over 𝐒 that mention only constants and nulls. A functional instance over 𝐒 is a (possibly infinite) set of atoms over 𝐒 that mention only ground functional terms. A database over 𝐒 is a non-empty finite set of atoms over 𝐒 that mention only constants. Clearly, a database over 𝐒 is trivially a null and a functional instance over 𝐒. We write 𝖽𝗈𝗆(I) for the set of terms occurring in an instance I.

First-order Queries.

We assume the reader is familiar with the syntax and semantics of first-order logic. We consider only function-free first-order formulas, i.e., formulas that mention variables and constants of 𝐂, but no function symbols. For such a formula Φ, we write 𝖿𝗏(Φ) and 𝖽𝗈𝗆(Φ) for the set of its free variables and the set of constants occurring in it, respectively. We use the standard symbol for the notion of satisfaction of sentences. A first-order query Q over a schema 𝐒 is an expression {(x1,,xk)Φ}, for k0, where Φ is a first-order formula over 𝐒 and (x1,,xk) is a tuple over 𝖿𝗏(Φ) such that each variable of 𝖿𝗏(Φ) occurs in (x1,,xk) at least once, i.e., 𝖿𝗏(Φ)={x1,,xk}. Note that a first-order query is always a finite object, i.e., the first-order formula Φ above is finite. For a tuple of constants (c1,,ck), we write Φ(c1,,ck) for the sentence obtained from Φ after replacing each occurrence of xi with ci, for each i[k]. Given a database D over 𝐒, the answer to Q over D is the set Q(D)={(c1,,ck)(𝖽𝗈𝗆(D)𝖽𝗈𝗆(Φ))kDΦ(c1,,ck)}.

Conjunctive Queries with Negation.

A restricted class of first-order queries that is crucial for our work is that of conjunctive queries with negation. Formally, a conjunctive query with negation (ncq) Q over a schema 𝐒 is a first-order query {x¯Φ} over 𝐒 with Φ being a formula of the form y¯(R1(y¯1)Rn(y¯n)¬P1(z¯1)¬Pm(z¯m)) for n1 and m0, where (i) Ri(y¯i) and Pj(z¯j) are atoms with y¯i and z¯j being tuples of constants and variables mentioned in x¯ and y¯, for each i[n] and j[m], and (ii) for each j[m], each variable in z¯j is mentioned in y¯i for some i[n]; the latter condition means that the negation in Q is safe. Note that if m=0, i.e., there are no negated atoms, then Q is simply a conjunctive query (cq). We write Q+ for the non-empty set of atoms {R1(y¯1),,Rn(y¯n)} and Q for the (possibly empty) set of atoms {P1(z¯1),,Pm(z¯m)}. Let 𝖢𝖰¬ be the set of all ncqs and 𝖢𝖰 the set of all cqs. It is well-known that the semantics of ncqs can be conveniently defined via homomorphisms. Given a null or functional instance I, the answer to Q over I, denoted Q(I), is the set of all tuples c¯𝐂|x¯| such that (i) there is a homomorphism h from Q+ to I with h(x¯)=c¯, and (ii) for each i[m], Pi(h(z¯i))I. Note that, unlike arbitrary first-order queries, the answer to ncqs is defined over arbitrary instances, and not only over databases, since this is needed for our technical development.

Tuple-generating Dependencies.

A tuple-generating dependency (tgd) σ over a schema 𝐒 is a first-order sentence x¯y¯(ϕ(x¯,y¯)z¯ψ(x¯,z¯)), where ϕ and ψ are (non-empty) conjunctions of atoms over 𝐒 that mention only variables. For brevity, we write σ as ϕ(x¯,y¯)z¯ψ(x¯,z¯) and use comma instead of for joining atoms. We call ϕ(x¯,y¯) and ψ(x¯,z¯) the body and head of σ, denoted 𝖻𝗈𝖽𝗒(σ) and 𝗁𝖾𝖺𝖽(σ), respectively. Note that we may treat a conjunction of atoms as the set of its atoms, which means that 𝖻𝗈𝖽𝗒(σ) and 𝗁𝖾𝖺𝖽(σ) can be treated as sets of atoms. We denote by 𝖿𝗋(σ) the so-called frontier variables of σ, i.e., the universally quantified variables of σ that appear in 𝗁𝖾𝖺𝖽(σ). Let 𝖳𝖦𝖣 be the family of all finite sets of tgds; in the rest of the paper, a set of tgds is always finite. A class 𝖢 of tgds is simply a subset of 𝖳𝖦𝖣. A null instance I over 𝐒 satisfies σ, written Iσ, if, whenever ϕ(x¯,y¯)I via h, then ψ(x¯,z¯)I via h that agrees with h on x¯. The null instance I satisfies a set Σ of tgds, written IΣ, if Iσ for each σΣ. Given a database D over 𝐒, a model of D and Σ is a (possibly infinite) null instance ID such that IΣ.

From Tuple-generating Dependencies to Logic Programs.

We now discuss how a set of tgds can be transformed into a logic program by eliminating the existentially quantified variables via Skolemization. This is needed for defining the semantics of ontology-mediated queries below. The Skolemization of a tgd σ of the form ϕ(x¯,y¯)z¯ψ(x¯,z¯), denoted 𝖲𝗄(σ), is the logic programming rule (or simply LP-rule), ϕ(x¯,y¯)ψ(x¯,𝐟σ(x¯,y¯)), where 𝐟σ is a vector of function symbols fσ,z𝐅, one for each variable zz¯. For example, the Skolemization of the tgd σ=R(x,y)zwP(z,y,w) is the LP-rule R(x,y)P(fσ,z(x,y),y,fσ,w(x,y)). The Skolemization of a set Σ of tgds, denoted 𝖲𝗄(Σ), is the set of LP-rules {𝖲𝗄(σ)σΣ}. A functional instance I satisfies 𝖲𝗄(σ), where σ is a tgd as above, written I𝖲𝗄(σ), if, whenever ϕ(x¯,y¯)I via a homomorphism h, then ψ(x¯,𝐟σ(x¯,y¯))I via h. The instance I satisfies 𝖲𝗄(Σ) for a set Σ of tgds, written I𝖲𝗄(Σ), if I𝖲𝗄(σ) for each σΣ. Given a database D, a model of D and 𝖲𝗄(Σ) is a (possibly infinite) functional instance ID such that IΣ. A model I of D and 𝖲𝗄(Σ) is minimal if there is no JI that is a model of D and 𝖲𝗄(Σ). In fact, it is easy to show that there is a unique minimal model of D and 𝖲𝗄(Σ), and thus, we can refer to the minimal model of D and 𝖲𝗄(Σ), denoted 𝗆𝗆(D,𝖲𝗄(Σ)).

Ontology-mediated Queries.

An ontology-mediated query (omq) over a schema 𝐒 is a pair O=(Σ,Q), where Σ is a set of tgds over 𝐒 (the ontology) and Q is an ncq over 𝐒 (the user query). For a class 𝖢𝖳𝖦𝖣 of tgds, let (𝖢,𝖢𝖰¬) be the class of omqs (Σ,Q), where Σ𝖢 and Q𝖢𝖰¬. The class of omqs (𝖢,𝖢𝖰) is defined analogously. One of the standard ways for defining the answer to an omq (Σ,Q) is to first convert Σ into the logic program 𝖲𝗄(Σ) and then evaluate the user query over the unique minimal model of the input database and 𝖲𝗄(Σ). Formally, given a database D and an omq O=(Σ,Q), the answer to O over D, denoted 𝖺𝗇𝗌𝖲𝗄(O,D), is defined as Q(𝗆𝗆(D,𝖲𝗄(Σ))). At this point, let us stress that this semantics extends the well-established certain answers semantics for positive omqs, where the user query is a cq without negation. More precisely, for an omq O=(Σ,Q) over 𝐒, where Q is a cq without negation, the certain answers of O over a database D, denoted 𝖼𝖾𝗋𝗍𝖺𝗂𝗇(O,D), is defined as I𝗆𝗈𝖽𝗌(D,Σ)Q(I), where 𝗆𝗈𝖽𝗌(D,Σ) collects all the models of D and Σ. It is then not difficult to show that 𝖼𝖾𝗋𝗍𝖺𝗂𝗇(O,D)=𝖺𝗇𝗌𝖲𝗄(O,D).

Querying the Unique Minimal Model and the Chase Procedure.

Given a database D and an omq O=(Σ,Q), we can use the chase procedure, a useful tool when reasoning with tgds, to construct a model of D and Σ that is isomorphic to the unique minimal model of D and 𝖲𝗄(Σ), which in turn can be used for computing 𝖺𝗇𝗌𝖲𝗄(O,D). This allows us to directly work with the original set of tgds, instead of its Skolemized version, which is technically more convenient. We assume the reader is familiar with the oblivious version of the chase procedure; see, e.g., [5]. Given a chase derivation δ of a database D w.r.t. a set Σ of tgds, which is essentially a sequence of instances (Ii)i0 where I0=D and, for each i>0, Ii+1 is obtained from Ii by applying a tgd of Σ, we write 𝖼𝗁𝖺𝗌𝖾δ(D,Σ) for the result of δ, that is, the instance i0Ii. It is not difficult to show that there is a bijection μ from the constants and nulls in 𝖼𝗁𝖺𝗌𝖾δ(D,Σ) to the ground functional terms in 𝗆𝗆(D,𝖲𝗄(Σ)), which is the identity on 𝐂, such that μ(𝖼𝗁𝖺𝗌𝖾δ(D,Σ))=𝗆𝗆(D,𝖲𝗄(Σ)) and μ1(𝗆𝗆(D,𝖲𝗄(Σ)))=𝖼𝗁𝖺𝗌𝖾δ(D,Σ). Thus, we get the following result that allows us to use the chase procedure for our purposes:

Proposition 1.

Consider a database D and an omq (Σ,Q). For every chase derivation δ of D w.r.t. Σ, it holds that 𝖺𝗇𝗌𝖲𝗄(O,D)=Q(𝖼𝗁𝖺𝗌𝖾δ(D,Σ)).

3 Ontology-mediated Queries and First-order Rewritability

Our main objective is to study the central concept of first-order rewritability for omqs, which essentially states that we can compute the answer to an omq by relying on first-order query evaluation. The formal definition of first-order rewritability for omqs follows:

Definition 2 (First-order Rewritability).

Consider an omq O=(Σ,Q) over a schema 𝐒. A first-order rewriting of O is a first-order query QO over 𝐒 such that, for every database D over 𝐒, 𝖺𝗇𝗌𝖲𝗄(O,D)=QO(D). A class (𝖢,𝖢𝖰¬) of omqs, where 𝖢𝖳𝖦𝖣, is first-order rewritable if every omq from (𝖢,𝖢𝖰¬) has a first-order rewriting. A first-order rewriter for a first-order rewritable class (𝖢,𝖢𝖰¬) of omqs is a deterministic algorithm that takes as input an omq O(𝖢,𝖢𝖰¬) and constructs a first-order rewriting of O. The notions of first-order rewritability and first-order rewriter for a class of omqs (𝖢,𝖢𝖰) are defined analogously.  

The notion of first-order rewritability for positive classes of omqs, i.e., classes of omqs (𝖢,𝖢𝖰), where 𝖢𝖳𝖦𝖣, has been extensively studied in the database and KR literature. As discussed in Section 1, this research effort led to an algorithmic characterization:

Theorem 3 ([12]).

There exists a deterministic algorithm 𝖱𝖾𝗐𝗋𝗂𝗍𝖾 such that, for every class 𝖢 of tgds, (𝖢,𝖢𝖰) is first-order rewritable iff 𝖱𝖾𝗐𝗋𝗂𝗍𝖾 is a first-order rewriter for (𝖢,𝖢𝖰).

We are still far from an analogous characterization for non-positive omqs. However, we can establish the existence of an algorithm that, no matter which class 𝖢 of tgds we consider among linear or acyclic tgds, it is a first-order rewriter for (𝖢,𝖢𝖰¬). The syntactic notions of linearity [7] and acyclicity [13], which we recall below, give rise to central classes of tgds that ensure first-order rewritability for positive omqs:

Linearity.

A tgd σ is called linear if it has exactly one atom in its body, i.e., |𝖻𝗈𝖽𝗒(σ)|=1. We write 𝖫𝗂𝗇𝖾𝖺𝗋 for the class of linear tgds, i.e., the family of all finite sets of linear tgds.

Acyclicity.

The notion of acyclicity essentially forbids recursive statements. This is typically formalized via the acyclictiy of the predicate graph of a set Σ of tgds. The predicate graph of Σ, denoted 𝗉𝗀(Σ), is a directed graph (V,E), where V (the set of nodes) consists of all the predicates occurring in Σ, and E (the set of edges) contains an edge (R,P) iff there is a tgd σΣ that mentions R in its body and P in its head. Essentially, an edge (R,P) encodes the fact that P depends on R. We say that Σ is acyclic if 𝗉𝗀(Σ) is acyclic. We write 𝖠𝖼𝗒𝖼𝗅𝗂𝖼 for the family of all finite sets of tgds that are acyclic.

The main result of our work, which can be seen as a first non-trivial step towards an algorithmic characterization of first-order rewritability for non-positive omqs, follows:

Theorem 4.

There exists a deterministic algorithm 𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬ that is a first-order rewriter for (𝖫𝗂𝗇𝖾𝖺𝗋,𝖢𝖰¬) and (𝖠𝖼𝗒𝖼𝗅𝗂𝖼,𝖢𝖰¬).

The rest of the paper is devoted to discussing the proof of the above result.

Target Query Language

Before we present the algorithm 𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬ in Section 4, and show that is indeed a first-order rewriter for (𝖢,𝖢𝖰¬), where 𝖢{𝖫𝗂𝗇𝖾𝖺𝗋,𝖠𝖼𝗒𝖼𝗅𝗂𝖼}, let us conclude this section by discussing its target query language. In the case of positive omq classes (𝖢,𝖢𝖰), we know that there is no need to go beyond unions of cqs with equality, which forms a strictly less expressive query language than first-order queries; let 𝖴𝖢𝖰= be the set all unions of cqs with equality. In other words, for every omq O from (𝖢,𝖢𝖰), the algorithm 𝖱𝖾𝗐𝗋𝗂𝗍𝖾, provided by Theorem 3, on input O outputs a first-order rewriting of O that falls in 𝖴𝖢𝖰=. With this in mind, one may be tempted to think that the algorithm 𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬ should target a query that falls in the language of unions of cqs with equality and negation, denoted 𝖴𝖢𝖰=,¬. However, we can show that the latter language is not expressive enough for our purposes.

Proposition 5.

There exists an omq O=(Σ,Q), where Σ𝖫𝗂𝗇𝖾𝖺𝗋𝖠𝖼𝗒𝖼𝗅𝗂𝖼 and Q𝖢𝖰¬, that admits a first-order rewriting but, for every query Q from 𝖴𝖢𝖰=,¬, there exists a database D such that 𝖺𝗇𝗌𝖲𝗄(O,D)Q(D).

As we shall see, whenever 𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬ terminates, the obtained query falls in a restricted class of first-order queries, which we call unions of conditional conjunctive queries with equalities, that forms a query language that is strictly less expressive than arbitrary first-order queries. Roughly, a conditional conjunctive query with equality is a cq with equality with additional conditions that can be expressed via inequalities and the negation of conjunctions of atoms (hence the name conditional cq with equality). For instance, ncqs form a special case of conditional cqs with equality. Formally, a conditional conjunctive query with equality (ccq=) Q over a schema 𝐒 is a first-order query {u¯Φ} over 𝐒 with Φ being a formula of the form

v¯(Φ1(x¯)Φ2(y¯)¬(i=1nz¯i(Φ3i(z¯i,w¯i))))

for x¯=𝖿𝗏(Φ)v¯ and n0 (if n=0, then the negated disjunction is not present), where

  • Φ1(x¯) is a non-empty conjunction of atoms and equalities that mention constants and variables of x¯, which means that {u¯v¯Φ1(x¯)} is a cq with equality; for brevity, we write 𝗋𝖾𝗅(Φ1(x¯)) for the set of relational atoms and 𝖾𝗊(Φ1(x¯)) for the set of equalities in Φ1(x¯),

  • Φ2(y¯) is a (possibly empty) conjunction of inequalities over 𝐂 and y¯x¯, and

  • Φ3i(z¯i,w¯i), for each i[n], is a non-empty conjunction of atoms that mention constants and variables of z¯iw¯i with x¯z¯i= and w¯ix¯.

Let 𝖢𝖢𝖰= be the set of all ccqs with equality. The semantics of ccqs with equality can be defined via homomorphisms. Formally, given a null instance I, the answer to Q over I, denoted Q(I), is the set of all tuples of constants c¯𝐂|u¯| such that (i) there is a homomorphism h from 𝗋𝖾𝗅(Φ1(x¯)) to I with h(u¯)=c¯, (ii) for each t=t in 𝖾𝗊(Φ1(x¯)), h(t)=h(t), (iii) for each tt in Φ2(y¯), h(t)h(t), and (iv) for each i[n], there is no homomorphism from Φ3i(z¯i,h(w¯i)) to I. A union of ccqs with equality (uccq=) Q over 𝐒 is a first-order query {u¯Φ} over 𝐒 with Φ being a formula of the form Ψ1Ψn, for n1, and Qi={u¯Ψi} being a ccq=, for every i[n]. Let 𝖴𝖢𝖢𝖰= be the set of all uccqs with equality. Given a null instance I, the answer to Q over I, denoted Q(I), is i[n]Qi(I). Let us stress that uccqs with equality are indeed strictly less expressive than first-order queries. For instance, we can show that the first-order query {()xP(x)} cannot be equivalently expressed as a uccq=, which implies the following result:

Proposition 6.

There exists a first-order query Q such that, for every query Q from 𝖴𝖢𝖢𝖰=, there exists a database D with Q(D)Q(D).

In our analysis, we will also consider unions of ccqs with equality that have infinitely many disjuncts. Formally, an infinitary union of ccqs with equality Q over 𝐒 is an expression {(x1,,xk)Φ}, for k0, where Φ is a formula i>0Ψi, the set of free variables 𝖿𝗏(Φ) of Φ is {x1,,xk}, and Qi={(x1,,xk)Ψi} is a ccq=, for every i>0. The answer to Q over a null instance I, denoted Q(I), is i>0Qi(I). Note that, strictly speaking, Q is not a first-order query since it is an infinite object, whereas first-order queries are always finite.

4 A Uniform First-order Rewriter

We now establish the existence of the algorithm 𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬ claimed in Theorem 4. To this end, we are going to show the following, which is the main technical result of our work:

Proposition 7.

There exists a nondeterministic algorithm 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬ such that:

  1. 1.

    For every 𝖢𝖳𝖦𝖣 with (𝖢,𝖢𝖰) being first-order rewritable and every omq O(𝖢,𝖢𝖰¬), the following holds: every execution of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬(O) leads to an infinitary uccq= QO such that, for every database D, 𝖺𝗇𝗌𝖲𝗄(O,D)=QO(D).

  2. 2.

    For every 𝖢{𝖫𝗂𝗇𝖾𝖺𝗋,𝖠𝖼𝗒𝖼𝗅𝗂𝖼} and every omq O(𝖢,𝖢𝖰¬), it holds that every execution of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬(O) terminates.

As we shall discuss later, the assumption in item (1) that (𝖢,𝖢𝖰) is first-order rewritable is crucial for guaranteeing that a possibly non-terminating execution of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬ on input O converges into an infinitary uccq= QO such that, for every database D, 𝖺𝗇𝗌𝖲𝗄(O,D)=QO(D). Since the properties stated in items (1) and (2) of Proposition 7 hold for every execution of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬, we get that every branch of the computation tree of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬ corresponds to the computation of a deterministic algorithm that is a first-order rewriter for (𝖢,𝖢𝖰¬), where 𝖢{𝖫𝗂𝗇𝖾𝖺𝗋,𝖠𝖼𝗒𝖼𝗅𝗂𝖼}, as needed. The rest of the section is devoted to discussing the proof of Proposition 7. We start by presenting the nondeterministic algorithm 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬.

4.1 The Nondeterministic Algorithm NRewrite¬

As for positive omqs, the high-level idea of the rewriting algorithm is to start from the positive part of the given ncq and mimic backwards the chase steps that lead to its image in the result of the chase via resolution steps that use the tgds as rewriting rules until we reach the input database; the latter is implemented using the notion of chunk unifier that has been used for rewriting positive omqs. This rewriting process should lead to a union of ccqs with equality that can be directly evaluated over the input database. Unlike the positive case, however, we need to carefully treat the negative part of the query, which makes our task significantly more challenging compared to the positive case. We start by recalling the notion of chunk unifier from [5], which is the building block of our algorithm, explain how it operates on ccqs with equality, and then discuss the rewriting algorithm itself.

Chunk Unifiers

Let A and B be non-empty sets of atoms with constants and variables. The sets A and B unify if there is a function θ, which is the identity over constants, called unifier for A and B, such that θ(A)=θ(B). A most general unifier (mgu) for A and B is a unifier θA,B for A and B such that, for each unifier θ for A and B, θ=θθA,B for some function θ. It is known that if two sets of atoms unify, then there is a unique mgu (up to variable renaming). Now, consider a set of atoms A with constants and variables and a set U𝗏𝖺𝗋(A). Consider also a tgd σ that does not share variables with A. A (most general) chunk unifier of A with σ that respects U is a triple (A1,A2,θ), where A1A, A2𝗁𝖾𝖺𝖽(σ), and θ is a (most general) unifier for A1 and A2 such that, for each existential variable x of σ occurring in A2, (i) θ(x)𝐂, and (ii) for every variable y with xy, θ(x)=θ(y) implies y𝗏𝖺𝗋(A1)U.

We now proceed to define the notion of chunk unifier for formulas that define ccqs with equality. Recall that a ccq= is a first-order query {t¯Φ} with Φ being a formula of the form

v¯(Φ1(x¯)Φ2(y¯)¬(i=1nz¯i(Φ3i(z¯i,w¯i))))

for x¯=𝖿𝗏(Φ)v¯ and n0, where (i) Φ1(x¯) is a non-empty conjunction of atoms and equalities that mention constants and variables of x¯, (ii) Φ2(y¯) is a (possibly empty) conjunction of inequalities over constants and variable of y¯x¯, and (iii) Φ3i(z¯i,w¯i), for each i[n], is a non-empty conjunction of atoms that mention constants and variables of z¯iw¯i with x¯z¯i= and w¯ix¯. In what follows, for convenience, we refer to formulas of the above form as formulas in rewrite form. For technical clarity, we will actually focus on certain formulas in rewrite form that we call saturated. Formally, a formula Φ in rewrite form as above is saturated if (i) for every pair of distinct variables x,y in x¯, either the equality x=y occurs in 𝖾𝗊(Φ1(x¯)) or the inequality xy belongs to Φ2(y¯), and (ii) for every variable xx¯ and constant c𝖽𝗈𝗆(Φ), either x=c occurs in 𝖾𝗊(Φ1(x¯)) or xc belongs to Φ2(y¯). This can be done w.l.o.g. since every ccq= can be equivalently rewritten as a uccq= that is defined via a disjunction of formulas in rewrite form that are saturated.

Consider now a formula Φ in rewrite form as above that is saturated. Given a subset A of 𝗋𝖾𝗅(Φ1(x¯)) (recall that a conjunction of atoms may be treated as a set of atoms), a variable x𝗏𝖺𝗋(A) is called shared if it belongs to 𝖿𝗏(Φ)𝗏𝖺𝗋(𝗋𝖾𝗅(Φ1(x¯)A)); in simple words, x is shared if its a free variable of Φ or it also occurs somewhere in 𝗋𝖾𝗅(Φ1(x¯)) other than the atoms of A. Consider also a tgd σ. A (most general) chunk unifier of Φ with σ is a quadruple τ=(A1,A2,θ,θ), where (i) (A1,A2,θ) is a (most general) chunk unifier of 𝗋𝖾𝗅(Φ1(x¯)) with σ that respects the shared variables of A1, (ii) θ is the identity on 𝗏𝖺𝗋(A1), and (ii) θ:𝗏𝖺𝗋(𝖻𝗈𝖽𝗒(σ))𝗍𝖾𝗋𝗆𝗌(A2)𝗏𝖺𝗋(Φ1(x¯)A1)𝖽𝗈𝗆(Φ)𝗏𝖺𝗋(θ(𝖻𝗈𝖽𝗒(σ))). Note that, strictly speaking, θ is not defined on the variables of 𝗏𝖺𝗋(𝖻𝗈𝖽𝗒(σ))𝗍𝖾𝗋𝗆𝗌(A2), and thus, we adopt the convention that θ is the identity over those variables.

Resolvents

Intuitively, an mgcu τ=(A1,A2,θ,θ) of Φ with σ essentially indicates that the subset A1 of 𝗋𝖾𝗅(Φ1(x¯)) can be satisfied in the result of the chase by applying the tgd σ. Thus, we can mimic this chase application backwards by resolving A1 using σ, which is done by simply replacing A1 in Φ1(x¯) with 𝖻𝗈𝖽𝗒(σ) and properly updating the variables according to λ=θθ; note that θ specifies how to update the variables of 𝖻𝗈𝖽𝗒(σ) that are not already in A2, and thus, θθ is a well-defined function. It should not be overlooked, however, that such a resolution step may lead to an unsafe formula, i.e., a formula where the negative part (including the inequalities) has a free variable that does not appear in the positive part, that is also not saturated. Hence, after resolving A1 using σ, we need to apply a polishing step that converts the obtained formula into a safe formula in rewrite form that is saturated. Of course, the polishing should be carefully performed in order to avoid the generation of undesirable formulas that will lead to a uccq= that either computes wrong answers (it is unsound) or misses to compute correct answers (it is incomplete).

The above intuitive discussion about the resolution and the polishing steps are formalized via the notion of (σ,τ)-resolvent. In particular, the (σ,τ)-resolvent of Φ is defined as

u¯(α(Φ1(x¯)A1)𝖻𝗈𝖽𝗒(σ)λ(α)Ψ1Φ2^(y¯)Ψ2¬(i=1nz¯i(Φ3i^(z¯i,w¯i)Ψ3i))),

where

  • u¯=𝗏𝖺𝗋(Ψ1)𝖿𝗏(Φ), i.e., it collects the variables in Ψ1 other than the free variables of Φ,

  • Ψ2 is obtained from Φ2(y¯) by (i) removing all the inequalities that mention a variable that does not occur in Ψ1, and (ii) adding as conjuncts all the inequalities of the form tt, where t and t are different variables of 𝗏𝖺𝗋(Ψ1)𝗏𝖺𝗋(Φ1(x¯)), or t𝗏𝖺𝗋(Ψ1)𝗏𝖺𝗋(Φ1(x¯)) and t𝗏𝖺𝗋(Φ1(x¯))𝗏𝖺𝗋(Ψ1), or t𝗏𝖺𝗋(Ψ1)𝗏𝖺𝗋(Φ1(x¯)) and t𝖽𝗈𝗆(Φ), and

  • Ψ3i=z¯iΦ3i(z¯i,w¯i) if w¯i𝗏𝖺𝗋(Ψ1); otherwise,

    Ψ3i=μMiz¯μ(αμ(Φ3i(z¯i,w¯i))μ(𝗁𝖾𝖺𝖽(σ))α),

    where z¯μ=z¯i𝗏𝖺𝗋(μ(Φ3i(z¯i,w¯i))μ(𝗁𝖾𝖺𝖽(σ))), and Mi is the set of all functions of the form μ:𝗍𝖾𝗋𝗆𝗌(B1)𝗏𝖺𝗋(𝗁𝖾𝖺𝖽(σ))𝗏𝖺𝗋(B1)𝗏𝖺𝗋(A1)𝗏𝖺𝗋(Ψ1)𝖽𝗈𝗆(Φ), where B1Φ3i(z¯i,w¯i) and B2𝗁𝖾𝖺𝖽(σ), such that the following hold:

    • μ(B1)=μ(B2),

    • for each existential variable z of σ, if t is a constant, or a variable of 𝖿𝗋(σ), or an existential variable of σ other than z, or a variable in Φ3i(z¯i,w¯i)B1, then μ(z)μ(t),

    • μ is the identity over x¯, and

    • μ(v)=λ(v), for every variable v𝖿𝗋(σ).

The crucial polishing step is performed when we convert Φ2(y¯) into Ψ2 and z¯iΦ3i(z¯i,w¯i) into Ψ3. The conversion of Φ2(y¯) into Ψ2 is done in the obvious way: item (i) is ensuring safety by removing inequalities, and item (ii) is performing the saturation of the formula by adding inequalities. We now elaborate on the sophisticated conversion of z¯iΦ3i(z¯i,w¯i) into Ψ3. The two obvious polishing strategies that one might think of are:

Polishing Strategy I.

For each i[n], simply remove the conjunction of atoms z¯iΦ3i(z¯i,w¯i) as a whole if Φ3i(z¯i,w¯i) mentions a variable that is neither in 𝗏𝖺𝗋(Ψ1) nor in z¯i.

Polishing Strategy II.

For each i[n], remove only the atoms occurring in Φ3i(z¯i,w¯i) that mention a variable that is neither in 𝗏𝖺𝗋(Ψ1) nor in z¯i.

Although both strategies ensure safety, it is not difficult to show that they are both problematic. Loosely speaking, the first polishing strategy removes more than necessary from the negative part and this leads to an unsound result, whereas the second strategy removes less than necessary from the negative part, which leads to an incomplete result; this is illustrated via examples in the appendix (Section A). The way that we actually convert z¯iΦ3i(z¯i,w¯i) into Ψ3 in the definition of (σ,τ)-resolvent somehow balances what we need to remove and what we need to keep in order ensure both the soundness and the completeness of the final result. The key idea underlying this conversion can be described as follows. Assume that Ξ is a subformula of Φ3i(z¯i,w¯i) such that (i) all the variables in Φ3i(z¯i,w¯i)Ξ occur in 𝗏𝖺𝗋(Ψ1) or z¯i, and (ii) Ξ is satisfied by the result of the chase due to some homomorphism h that maps Ξ to the set of atoms H obtained by a applying a trigger of the form (σ,) during the construction of the chase. We then keep the conjunction consisting of the atoms of Φ3i(z¯i,w¯i)Ξ after updating their variables in such a way that the part of Φ3i(z¯i,w¯i) that we keep cannot be mapped to H via the same homomorphism h used to map Ξ to H, which means that Φ3i(z¯i,w¯i) as a whole is not satisfied by the result of the chase due to h.

Algorithm 1 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬(Σ,Q={t¯𝑜𝑢𝑡Ξ}).
Algorithm 2 𝖠𝗍𝗈𝗆𝖱𝖾𝗐𝗋𝗂𝗍𝖾(Σ,R(t1,,tn)).

The Algorithm NRewrite¬

We now have the key ingredients to discuss the nondeterministic algorithm 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬, claimed in Proposition 7, which is depicted in Algorithm 1. It takes as input an omq O=(Σ,Q={t¯𝑜𝑢𝑡Ξ}) from a class (𝖢,𝖢𝖰¬) of omqs with the assumption that (𝖢,𝖢𝖰) is first-order rewritable, and rewrites O by proceeding in two phases: (i) the preparatory phase, where it converts Ξ into a set of formulas in rewrite form that are saturated by considering all the specialized versions of Ξ and properly rewriting their negative part, and (ii) the rewriting phase, where it exhaustively rewrites the formulas produced during the preparatory phase via resolution steps and constructs formulas in rewrite form that are saturated, which are stored in a set 𝑅𝑒𝑤. The final result is {t¯𝑜𝑢𝑡Φ𝑅𝑒𝑤Φ}, which is, in general, an infinitary uccq=. We proceed to discuss the details of the preparatory phase and the rewriting phase.

Preparatory Phase

Let lex be some arbitrary lexicographic order over 𝐂𝐕 such that (i) the constants are preceding the variables, and (ii) the variables of 𝖿𝗏(Ξ) are preceding the variables of 𝐕𝖿𝗏(Ξ). For a finite set T of constants and variables, we write [T] for the term of T that precedes all other terms of T according to lex. A partition π={T1,,Tm} of the set of terms occurring in Q, denoted 𝗍𝖾𝗋𝗆𝗌(Q), is called proper if, for each i[m], Ti contains at most one constant, i.e., two different constants occurring in Q appear in different sets of π. Essentially, a proper partition π of 𝗍𝖾𝗋𝗆𝗌(Q) fixes the way that the variables in Q should be mapped to the constants of the input database, i.e., two variables should be mapped to the same constant iff they occur in the same set of π. Furthermore, if a variable x occurs in a set of π that has a constant c, then x should be mapped to c. To implement this intuitive idea, we further define the function μπ:𝗍𝖾𝗋𝗆𝗌(Q)𝗍𝖾𝗋𝗆𝗌(Q) in such a way that, for each t𝗍𝖾𝗋𝗆𝗌(Q), tTi implies μπ(t)=[Ti]. Now, for a proper partition π={T1,,Tm} of 𝗍𝖾𝗋𝗆𝗌(Q), the algorithm builds the formula ΦQ,π defined as

x¯π(αQ+μπ(α)i[m],xTix=[Ti]1i<jm[Ti][Tj]¬(αQz¯α𝖠𝗍𝗈𝗆𝖱𝖾𝗐𝗋𝗂𝗍𝖾(Σ,μπ(α)))),

where x¯π are the variables occurring in αQ+μπ(α)i[m],xTix=[Ti], other than the variables of 𝖿𝗏(Ξ), and z¯α are the variables occurring in 𝖠𝗍𝗈𝗆𝖱𝖾𝗐𝗋𝗂𝗍𝖾(Σ,μπ(α)) but not in x¯π. The procedure 𝖠𝗍𝗈𝗆𝖱𝖾𝗐𝗋𝗂𝗍𝖾 (see Algorithm 2) with input (Σ,μπ(α)) essentially rewrites the atom μπ(α), via resolution steps that use the tgds of Σ, into a disjunction of conjunctions of atoms. Crucially, the rewriting should not remove any of the variables in μπ(α) since, by definition, they also occur in the positive part of the formula ΦQ,π. Moreover, it should not unify any of those variables with a constant or some other variable since the inequalities in ΦQ,π state that, for ij, the variables [Ti] and [Tj] cannot be unified. In other words, 𝖠𝗍𝗈𝗆𝖱𝖾𝗐𝗋𝗂𝗍𝖾 should treat the variables occurring in μπ(α) as constants, and thus, the final result would be a disjunction of conjunctions of atoms where each disjunct contains all the terms t1,,tn. The above intuition is implemented by

  1. 1.

    renaming all the variables in μπ(α) into new constants via a bijective function ρ (i.e., ρ(t)=t if t is a constant, otherwise ρ(t) is a new constant),

  2. 2.

    exhaustively applying resolution steps (using the basic notion of mgcu of a set of atoms that respects a set of variables) in the expected way starting from {ρ(μπ(α))}, and

  3. 3.

    finally, converting the constructed collection of sets of atoms into a disjunction of conjunctions of atoms after replacing each constant ρ(t) with t by applying ρ1.

Note that during a resolution step the procedure considers the tgd σi obtained from σ by renaming each variable x in σ to xi. This is a mechanism that allows us to avoid undesirable clatter among variables during a resolution step. Moreover, at each resolution step, the produced set of atoms A is added to the collection 𝐶𝑜𝑙 only if there is no set of atoms B𝐶𝑜𝑙 such that B can be homomorphically mapped to A, i.e., A is added to 𝐶𝑜𝑙 if there is no B𝐶𝑜𝑙 that is more general than A since in this case A will be redundant. The following lemma, which relies on the assumption that the input omq O belongs to a class of omqs (𝖢,𝖢𝖰¬) such that (𝖢,𝖢𝖰) is first-order rewritable, is crucial in our development:

Lemma 8.

For every proper partition π of 𝗍𝖾𝗋𝗆𝗌(Q), {t¯𝑜𝑢𝑡ΦQ,π} is a ccq=.

Now, the formula ΦQ,π (in fact, the pair (ΦQ,π,ϵ) – this will be clarified in the discussion of the rewriting phase) is kept in the set 𝑆𝑝𝑒𝑐 if the query Qπ={t¯𝑜𝑢𝑡ΦQ,π} is satisfiable, i.e., if there is a database D such that Qπ(D). By Lemma 8, Qπ is a ccq=. Hence, to be able to perform the above satisfiability check, we need a procedure that allows us to decide whether a query from 𝖢𝖢𝖰= is satisfiable. We can show the following result:

Lemma 9.

Deciding whether a query from 𝖢𝖢𝖰= is satisfiable is coNP-complete.

Note that the satisfiability procedure for ccqs with equality is also used in the rewriting phase of the algorithm. Now, if none of the queries Qπ, where π is a proper partition of 𝗍𝖾𝗋𝗆𝗌(Q), is satisfiable (i.e., 𝑆𝑝𝑒𝑐=), then we can show that 𝖺𝗇𝗌𝖲𝗄(O,D)= for every database D. Hence, it suffices to return a simple unsatisfiable ncq over the underlying schema. In case 𝑆𝑝𝑒𝑐 is not empty, then the algorithm proceeds with the rewriting phase in order to rewrite via resolution the formulas occurring in the pairs of the set 𝑆𝑝𝑒𝑐.

Rewriting Phase

In this phase, the algorithm exhaustively rewrites the positive part of each formula of 𝑆𝑝𝑒𝑐 via resolution steps. During this process, it is important to keep track of the sequence of resolution steps that lead to a certain formula Φ. This is because, for ensuring the soundness of the algorithm, we need to guarantee that in the sequence of resolution steps that lead to a formula Φ, we use only active resolution steps, i.e., resolution steps that mimic different chase steps. To achieve this, we initially flag each formula Φ of 𝑆𝑝𝑒𝑐 with the empty sequence of resolution steps, denoted ϵ, which will be updated accordingly during the rewriting process, and add the pair (Φ,ϵ) to 𝑅𝑒𝑤. Then, for each pair (Φ,s)𝑅𝑒𝑤 and for each tgd σ, the algorithm considers all the valid mgcus τ of Φ with σi such that (σi,τ) is s-active, and constructs the (σi,τ)-resolvent of Φ, denoted Φ. Now, providing that Φ is not blocked by some Ψ𝑅𝑒𝑤, the pair (Φ,s(σi,τ)) is added to 𝑅𝑒𝑤, where s(σi,τ) is the sequence of resolution steps that lead to Φ, that is, the sequence of resolution steps that led to Φ plus the resolution step applied on Φ using the tgd σi and the mgcu τ of Φ with σi. We proceed to formalize the three auxiliary notions used above, namely validity, activeness, and blocking. Note that, as in 𝖠𝗍𝗈𝗆𝖱𝖾𝗐𝗋𝗂𝗍𝖾, at each step we consider the tgd σi obtained from σ by renaming each variable x in σ to xi in order to avoid undesirable clatter among variables during a resolution step. Crucially, there is no clutter among the variables introduced during the rewriting phase and those introduced by 𝖠𝗍𝗈𝗆𝖱𝖾𝗐𝗋𝗂𝗍𝖾, since in the rewriting phase we use positive indices to rename variables, whereas in 𝖠𝗍𝗈𝗆𝖱𝖾𝗐𝗋𝗂𝗍𝖾 we use negative indices.

Validity.

The reason why we cannot use all the mgcus of Φ with σi, but only the so-called valid ones, is because invalid mgcus lead to unsound resolution steps. By applying an invalid mgcu, we may produce a formula that gives rise to a satisfiable ccq= from a formula that defines an unsatisfiable ccq=, which is problematic; this is shown in the appendix (Section B). Validity ensures that the resolution of a formula that defines an unsatisfiable ccq= will produce a formula that defines an unsatisfiable ccq=. An mgcu τ=(,,θ,θ) of

Φ=v¯(Φ1(x¯)Φ2(y¯)¬(i=1nz¯i(Φ3i(z¯i,w¯i)))),

produced either during the preparatory phase or the rewriting phase of the algorithm, with σi is valid if the ccq= {t¯𝑜𝑢𝑡u¯Ψ}, where u¯=𝖿𝗏(Ψ)𝖿𝗏(Φ) and Ψ is the formula

α𝗁𝖾𝖺𝖽(σi)λ(α)Φ1(x¯)Φ2(y¯)¬(i=1nz¯i(Φ3i(z¯i,w¯i))),

for λ=θθ, is satisfiable. Note that Ψ is in rewrite form, but it might not be saturated. This is not problematic since we do not apply a resolution step on Ψ, but we only check whether it gives rise to a satisfiable ccq=; the latter is done using the algorithm from Lemma 9.

Activeness.

We now discuss the notion of activeness. Consider a formula-sequence pair (Φ,s), where s=((σ1i1,τ1),,(σkik,τk)), for k>0 and τi=(,,θi,θi), which is produced during the rewriting phase of the algorithm and stored in 𝑅𝑒𝑤, and a mgcu τ=(,,θ,θ) of Φ with σi. As said above, the goal of activeness is to ensure that the resolution step that uses the pair (σi,τ) mimics a different chase step than the resolution steps that use a pair occurring in s. This is guaranteed by the following condition: we say that (σi,τ) is s-active if, for every j[k], σ=σj implies λ(𝖻𝗈𝖽𝗒(σi))λj(𝖻𝗈𝖽𝗒(σjij)) for λ=θθ and λj=θjθj.

Blocking.

It is crucial for the termination of the algorithm (see item (2) of Proposition 7) not to add a formula in 𝑅𝑒𝑤 that gives rise to a ccq= that is redundant in the sense that its answer, no matter the input database, is always contained in the answer of a ccq= defined by a formula that is already in 𝑅𝑒𝑤. Having said that, we can show that the containment problem for ccqs with equality is undecidable, which is a fact of independent interest. The latter essentially tells us that we need to isolate a condition over ccqs with equality that is sufficient for containment, can be effectively checked, and it ensures the termination of the algorithm whenever the input omq obeys linearity or acyclicity, despite the fact that some formulas that give rise to redundant queries will be unavoidably added to the set 𝑅𝑒𝑤. This is the intention underlying blocking. Consider

Φ=v¯(Φ1(x¯)Φ2(y¯)¬(i=1nz¯i(Φ3i(z¯i,w¯i))))

and

Ψ=v¯(Ψ1(x¯)Ψ2(y¯)¬(i=1mz¯i(Ψ3i(z¯i,w¯i))))

that are produced during the rewriting phase of the algorithm. We say that Ψ blocks Φ, denoted ΨΦ, if the following four conditions hold: (i) 𝗋𝖾𝗅(Ψ1(x¯))𝗋𝖾𝗅(Φ1(x¯)) via a homomorphism h that is the identity over 𝖿𝗏(Ψ), (ii) for each equality t=t in 𝖾𝗊(Ψ1(y¯)), where either t,t𝖿𝗏(Ψ) or t𝖿𝗏(Ψ) and t𝖽𝗈𝗆(Ψ), the equality t=t occurs in 𝖾𝗊(Φ1(y¯)), (iii) for each inequality tt in Ψ2(y¯), the inequality h(t)h(t) occurs in Φ2(y¯), and (iv) for each i[m], there exists j[n] such that Ψ3i(z¯i,h(w¯i))=Φ3j(z¯j,w¯j). This completes the description of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬, which is indeed nondeterministic since, in both of its phases, there is no fixed order in which we apply the resolution steps.

4.2 Correctness and Termination of 𝗡𝗥𝗲𝘄𝗿𝗶𝘁𝗲¬

Correctness – Item (1) of Proposition 7

We first argue that every execution of the algorithm leads to an infinitary uccq=. Let 𝑒𝑥𝑒𝑐(O) be an arbitrary execution of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬(O). We proceed by considering the two cases where the set 𝑆𝑝𝑒𝑐 computed during the preparatory phase of the algorithm is empty or not. If 𝑆𝑝𝑒𝑐=, then 𝑒𝑥𝑒𝑐(O) terminates and returns an unsatisfiable ncq, which is trivially an infinitary uccq=. Assume now that 𝑆𝑝𝑒𝑐. We proceed to argue that it consists of finitely many formulas of finite size. By Lemma 8, we get that, for every partition π of 𝗍𝖾𝗋𝗆𝗌(Q), {t¯𝑜𝑢𝑡ΦQ,π} is a ccq=. This implies that ΦQ,π is a formula in rewrite form of finite size. Moreover, since 𝗍𝖾𝗋𝗆𝗌(Q) is finite, it is clear that there are finitely many different proper partitions of it. Consequently, 𝑆𝑝𝑒𝑐 consists of finitely many formulas (one for each proper partition of 𝗍𝖾𝗋𝗆𝗌(Q)) in rewrite form, each of finite size. With this fact in mind, to conclude that 𝑒𝑥𝑒𝑐(O) leads to an infinitary uccq= it suffices to observe that, for every pair of the form (Φ,) occurring in the set 𝑅𝑒𝑤, and every valid mgcu τ of Φ with σi, for some i>0, the (σi,τ)-resolvent Φ of Φ is, by construction, a formula in rewrite form of finite size with 𝖿𝗏(Φ)=t¯𝑜𝑢𝑡. Thus, for every pair (Φ,) that occurs in the (possibly infinite) set 𝑅𝑒𝑤 computed by the rewriting phase of the algorithm, it holds that Φ is a formula in rewrite form of finite size with 𝖿𝗏(Φ)=t¯𝑜𝑢𝑡. This in turn implies that {t¯𝑜𝑢𝑡(Φ,)𝑅𝑒𝑤Φ}, which we denote by QO, is indeed an infinitary uccq=, as needed.

We finally need to argue that, for every database D, 𝖺𝗇𝗌𝖲𝗄(O,D)=QO(D); recall that O=(Σ,Q). To this end, we establish the following lemma, which, together with Proposition 1, implies the claim. Given a formula Φ in rewrite form with 𝖿𝗏(Φ)=t¯𝑜𝑢𝑡, let QΦ={t¯𝑜𝑢𝑡Φ}.

Lemma 10.

Fix an arbitrary tuple c¯𝖽𝗈𝗆(D)|t¯𝑜𝑢𝑡|. There exists a chase derivation δ of D w.r.t. Σ such that c¯Q(𝖼𝗁𝖺𝗌𝖾δ(D,Σ)) iff there exists (Φ,)𝑅𝑒𝑤 such that c¯QΦ(D).

Further details about the proof of Lemma 10 are given in the appendix (Section C).

Termination – Item (2) of Proposition 7

Fix an arbitrary execution 𝑒𝑥𝑒𝑐(O) of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬(O). By linearity and acyclicity, we get a database-independent bound on the number of atoms that can appear in the positive part of a formula produced by 𝑒𝑥𝑒𝑐(O). This in turn allows us to show that the formulas produced by 𝑒𝑥𝑒𝑐(O) share finitely many positive parts (up to renaming of the non-free variables). Note, however, that this is not enough to conclude that the output of 𝑒𝑥𝑒𝑐(O) is finite since we may have several different formulas with the same positive part but different negative part. Interestingly, we can argue that the way the polishing of formulas is performed (see the discussion above about resolvents), ensures that only finitely many different negative parts (up to renaming of the non-free variables) can be produced, and thus, 𝑒𝑥𝑒𝑐(O) is finite.

5 Future Work

Although we are still far from an algorithmic characterization of first-order rewritability for non-positive classes of tgd-based omqs, where the user query is a cq with negation, we believe that the algorithm 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬ introduced in this work is a good basis towards such a characterization. In particular, since item (1) of Proposition 7 holds for every class 𝖢 of tgds such that (𝖢,𝖢𝖰¬) is first-order rewritable, the next obvious step is to try to generalize item (2) of Proposition 7 to every class 𝖢 of tgds such that (𝖢,𝖢𝖰¬) is first-order rewritable. This highly non-trivial task is our next target, which will establish the desired characterization.

References

  • [1] Serge Abiteboul, Richard Hull, and Victor Vianu. Foundations of Databases. Addison-Wesley, 1995.
  • [2] Mario Alviano, Michael Morak, and Andreas Pieris. Stable model semantics for tuple-generating dependencies revisited. In PODS, pages 377–388, 2017. doi:10.1145/3034786.3034794.
  • [3] Mario Alviano and Andreas Pieris. Default negation for non-guarded existential rules. In PODS, pages 79–90, 2015. doi:10.1145/2745754.2745758.
  • [4] Jean-François Baget, Fabien Garreau, Marie-Laure Mugnier, and Swan Rocher. Extending acyclicity notions for existential rules. In ECAI, pages 39–44, 2014. doi:10.3233/978-1-61499-419-0-39.
  • [5] Gerald Berger, Georg Gottlob, Andreas Pieris, and Emanuel Sallinger. The space-efficient core of vadalog. ACM Trans. Database Syst., 47(1):1:1–1:46, 2022. doi:10.1145/3488720.
  • [6] Meghyn Bienvenu, Balder ten Cate, Carsten Lutz, and Frank Wolter. Ontology-based data access: A study through disjunctive datalog, CSP, and MMSNP. ACM Trans. Database Syst., 39(4):33:1–33:44, 2014. doi:10.1145/2661643.
  • [7] Andrea Calì, Georg Gottlob, and Thomas Lukasiewicz. A general Datalog-based framework for tractable query answering over ontologies. J. Web Sem., 14:57–83, 2012. doi:10.1016/J.WEBSEM.2012.03.001.
  • [8] Andrea Calì, Georg Gottlob, and Andreas Pieris. Towards more expressive ontology languages: The query answering problem. Artif. Intell., 193:87–128, 2012. doi:10.1016/J.ARTINT.2012.08.002.
  • [9] Georg Gottlob, André Hernich, Clemens Kupke, and Thomas Lukasiewicz. Stable model semantics for guarded existential rules and description logics: Decidability and complexity. J. ACM, 68(5):35:1–35:87, 2021. doi:10.1145/3447508.
  • [10] Georg Gottlob, Giorgio Orsi, and Andreas Pieris. Query rewriting and optimization for ontological databases. ACM Trans. Database Syst., 39(3):25:1–25:46, 2014. doi:10.1145/2638546.
  • [11] André Hernich, Clemens Kupke, Thomas Lukasiewicz, and Georg Gottlob. Well-founded semantics for extended datalog and ontological reasoning. In PODS, pages 225–236, 2013. doi:10.1145/2463664.2465229.
  • [12] Mélanie König, Michel Leclère, Marie-Laure Mugnier, and Michaël Thomazo. Sound, complete and minimal ucq-rewriting for existential rules. Semantic Web, 6(5):451–475, 2015. doi:10.3233/SW-140153.
  • [13] Thomas Lukasiewicz, Enrico Malizia, Maria Vanina Martinez, Cristian Molinaro, Andreas Pieris, and Gerardo I. Simari. Inconsistency-tolerant query answering for existential rules. Artif. Intell., 307:103685, 2022. doi:10.1016/J.ARTINT.2022.103685.
  • [14] Antonella Poggi, Domenico Lembo, Diego Calvanese, Giuseppe De Giacomo, Maurizio Lenzerini, and Riccardo Rosati. Linking data to ontologies. J. Data Semantics, 10:133–173, 2008. doi:10.1007/978-3-540-77688-8_5.

Appendix A Resolvents and Polishing Strategies

As discussed in the main body of the paper, the two immediate polishing strategies for the conversion of z¯iΦ3i(z¯i,w¯i) into a safe formula in rewrite form are:

Polishing Strategy I.

For each i[n], simply remove the conjunction of atoms z¯iΦ3i(z¯i,w¯i) as a whole if Φ3i(z¯i,w¯i) mentions a variable that is neither in 𝗏𝖺𝗋(Ψ1) nor in z¯i.

Polishing Strategy II.

For each i[n], remove only the atoms occurring in Φ3i(z¯i,w¯i) that mention a variable that is neither in 𝗏𝖺𝗋(Ψ1) nor in z¯i.

It is clear that both strategies will ensure safety. It is not difficult, however, to illustrate that both strategies are problematic. Let us start with the first polishing strategy.

Example 11.

Consider the sentence in rewrite form (that is saturated) and the tgd

Φ=x(P(x)¬(z(T(x)U(z))))andσ=R(x)y(P(y),T(y)),

respectively. The only available mgcu of Φ with σ is

τ=({P(x)},{P(y)},{xx,yx},{xx}).

Hence, by resolving {P(x)} using σ we get the sentence

Ψ=x(R(x)¬(z(T(x)U(z)))),

which needs polishing since the free variable x occurs in the negative part but not in the positive part. According to the first strategy, we remove the negative part as a whole and get

Ψ^=xR(x).

It is easy to see that the obtained sentence is unsound in the following sense: there is a database D such that the result of the chase of D w.r.t. {σ} does not satisfy the original sentence Φ, but D satisfies the obtained sentence Ψ^; in particular, for D={R(a),U(a)}.  

Loosely speaking, the first polishing strategy removes more than necessary from the negative part and this leads to an unsound result. Let us now discuss the second strategy.

Example 12.

Consider the sentence in rewrite form (that is saturated) and the tgd

Φ=x(P(x)¬(z(T(x)U(z))))andσ=R(x)yP(y),

respectively. The only available mgcu of Φ with σ is

τ=({P(x)},{P(y)},{xx,yx},{xx}).

Hence, by resolving {P(x)} using σ we get the sentence

Ψ=x(R(x)¬(z(T(x)U(z)))),

which needs polishing since the free variable x occurs in the negative part but not in the positive part. According to the second strategy, we remove T(x) from the negative part, which is the only atom that mentions x, and get the sentence

Ψ^=x(R(x)¬(zU(z))).

It is easy to see that the obtained sentence is incomplete in the following sense: there is a database D such that the result of the chase of D w.r.t. {σ} satisfies the original sentence Φ, but D does not satisfy the obtained sentence Ψ^; in particular, for D={R(a),U(a)}.  

Roughly speaking, the second strategy removes less than necessary from the negative part, which leads to an incomplete result. Coming back to Examples 11 and 12, our correct polishing strategy will give the sentences

x(R(x)¬(zU(z)))andxR(x),

respectively, which both correspond to sound and complete rewriting steps.

Appendix B Validity

As discussed in the main body of the paper, the reason why we cannot use all the mgcus of Φ with σi, but only valid ones, is because invalid mgcus lead to unsound resolution steps. More precisely, by applying an invalid mgcu, we may produce a formula that gives rise to a satisfiable ccq= from a formula that defines an unsatisfiable ccq=, which is problematic.

Example 13.

Consider the sentence in rewrite form (that is saturated) and the tgd

Φ=x(P(x)¬T(x))andσ=R(y)z(P(z),T(z)),

respectively. It is clear that, for every null instance I that (i) contains an atom R(c), (ii) Iσ, and (iii) IP(x)T(x), it holds that I⊧̸Φ, i.e., the query {()Φ} is unsatisfiable w.r.t. instances with the properties (i) - (iii). Now, observe that the only available mgcu of Φ with σ is τ=({P(x)},{P(z)},{xx,zx},{yy}) and the (σ,τ)-resolvent of Φ is the sentence Ψ=yR(y), and thus, the query {()Ψ} has a non-empty answer over every null instance that contains an atom R(c). Hence, given the database D={R(c)}, the answer to the query {()Φ} over the result of the chase of D w.r.t. {σ}, which is an instance that enjoys the properties (i) - (iii), is empty, whereas the answer to {()Ψ} over D is non-empty. Summing up, the mgcu τ is not valid since the sentence x(P(x)T(x)¬T(x)), which is essentially the conjunction of the head of σ (after updating its variables according to the functions of τ) with Φ, gives rise to an unsatisfiable query.  

Appendix C Proof of Lemma 10

The proof of Lemma 10 relies on four useful auxiliary technical lemmas. We proceed to state those lemmas and then we proceed with the final proof.

Four Auxiliary Lemmas

Recall that O=(Σ,Q). Moreover, given a formula Φ in rewrite form with 𝖿𝗏(Φ)=t¯𝑜𝑢𝑡, we write QΦ for the query {t¯𝑜𝑢𝑡Φ}. The first auxiliary lemma shows that the rewriting of the negative atoms, performed by the procedure 𝖠𝗍𝗈𝗆𝖱𝖾𝗐𝗋𝗂𝗍𝖾, is sound.

Lemma 14.

Let δ be a 𝑐ℎ𝑎𝑠𝑒 derivation of D w.r.t Σ. The following are equivalent:

  1. 1.

    c¯Q(𝖼𝗁𝖺𝗌𝖾δ(D,Σ)).

  2. 2.

    There exists Ψ𝑆𝑝𝑒𝑐 such that c¯QΨ(𝖼𝗁𝖺𝗌𝖾δ(D,Σ)).

The next lemma is crucial for establishing the completeness of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬, i.e., the direction () of Lemma 10. It states that from a prefix p of a chase derivation of D w.r.t. Σ, where its last instance I is such that c¯QΦ(I) with Φ being a formula in rewrite form that is saturated and 𝖿𝗏(Φ)=t¯𝑜𝑢𝑡, we can extract a sequence of resolution steps starting from Φ, and mimicking backwards the chase applications that gave rise to p, that leads to a formula Φ in rewrite form that is saturated with 𝖿𝗏(Φ)=t¯𝑜𝑢𝑡 such that c¯QΦ(D). This is shown by induction on the length of the prefix p.

Lemma 15.

Consider a formula Φ in rewrite form that is saturated with 𝖿𝗏(Φ)=t¯out. Let (Ii)i{0,,m}, for m0, be a prefix of a chase derivation of D w.r.t. Σ with Iiσi,hiIi+1, for i{0,,m1}, such that c¯QΦ(Im). There is a sequence (Ψi)i{0,,m} of formulas in rewrite form that are saturated with 𝖿𝗏(Ψi)=t¯out, for each i{0,,m}, such that:

  1. 1.

    Ψ0=Φ

  2. 2.

    Ψi=Ψi1 or Ψi is a (σmii,τ)-resolvent of Ψi1 for some valid mgcu τ of Ψi1 with σmii, for each i[m], and

  3. 3.

    c¯QΨi(Imi), for each i{0,,m}.

The next lemma is also needed for establishing the completeness of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬, i.e., the direction () of Lemma 10. Intuitively, it states that if a formula Φ in rewrite form is blocked by some formula of 𝑅𝑒𝑤 produced by the algorithm, then all the rewritten formulas obtained via resolution steps from Φ will be blocked by some other formula of 𝑅𝑒𝑤.

Lemma 16.

Consider a set Θ of formulas in rewrite form, and a formula Φ in rewrite form such that Φ is Θ-blocked. Let τ=(S,S,θ,θ) be a chunk unifier of Φ with a tgd σΣ such that the (σ,τ)-resolvent Ψ of Φ is satisfiable. One of the following holds:

  1. 1.

    Ψ is Θ-blocked, or

  2. 2.

    Ψ is {Ψ}-blocked, where Ψ is the (σ,τ)-resolvent of some ΦΘ, where τ=(,,θ1,θ1) is a chunk unifier of Φ with σ such that λ(𝖻𝗈𝖽𝗒(σ))=λ1(𝖻𝗈𝖽𝗒(σ)), where λ=θθ and λ1=θ1θ1.

The last lemma is crucial for the direction () of Lemma 10, that is, the soundness of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬. A rewriting Σ-sequence is a sequence of pairs ((Φi,si))i{0,,m}, for m0, where Φ0𝑆𝑝𝑒𝑐, s0=ϵ, and, for each i{0,,m1}, Φi+1 is a (σi+1,τ)-resolvent of Φi, where σΣ, for some valid mgcu τ of Φi with σi+1 such that (σi+1,τ) is si-active, and si+1=si(σi+1,τ). The lemma in question essentially states that, for a rewriting Σ-sequence r=((Φi,si))i{0,,m}, c¯QΦm(D) implies c¯QΦ0(I), where I is an null instance obtained by some chase derivation of D w.r.t. Σ. This is shown by induction on the length of r.

Lemma 17.

Consider a rewriting Σ-sequence ((Ψi,si))i{0,,m}. There exists a prefix of a chase derivation (Ii)i{0,,m} of D w.r.t. Σ such that c¯QΨm(I0) implies c¯QΨ0(Im).

The Final Proof

We are now ready to establish Lemma 10.

() By hypothesis, there exists a chase derivation δ of D w.r.t. Σ such that c¯Q(𝖼𝗁𝖺𝗌𝖾δ(D,Σ)). By Lemma 14, there exists Φ𝑆𝑝𝑒𝑐 such that c¯QΦ(𝖼𝗁𝖺𝗌𝖾δ(D,Σ)). Therefore, there exists a prefix (Ii)i{0,,m}, for m0, of δ such that ImΦ. By Lemma 15, there is a sequence s=(Ψi)i{0,,m}, for m0, with the properties stated in the statement of the lemma. Note that there is no guarantee that all the elements in s are produced by the execution of 𝖭𝖱𝖾𝗐𝗋𝗂𝗍𝖾¬(O) under consideration. This is due on the one hand to the activeness condition of the triggers considered and on the other to the blocking condition that must not be satisfied to maintain a formula produced through a resolution phase. As regards the activeness condition of the triggers, it is easy to prove that the use of inactive triggers cannot be put in one-to-one correspondence with a prefix p of a chase derivation, in fact the same trigger cannot be used more than once by definition. For what concerns the blocking condition, by induction on the length of s, we show that Ψm is Θ-blocked, where Θ is the set that collects all the disjuncts of QO:

Base Step.

If s is of length 1, then s=Ψ0. Therefore, Ψ0 is {Φ}-blocked, which in turn implies that Ψ0 is Θ-blocked since ΦΘ, and the claim follows.

Inductive Step.

Suppose now that s is of length m+1, i.e., s=Ψ0,,Ψm. By induction hypothesis, Ψm1 is Θ-blocked. If Ψm=Ψm1, then we immediately get that Ψm is Θ-blocked. Assume now that Ψm is the (σ,τ)-resolvent of Ψm1, where τ is a valid mgcu of Ψm1 with σ. By Lemma 16, we get that Ψm is Θ-blocked or Ψm is {Ψ}-blocked, where Ψ is the (σ,τ)-resolvent of some ΦΘ. Clearly, Ψ is Θ-blocked, and thus, Ψm is Θ-blocked.

Since c¯QΨm(D) and Φm is Θ-blocked, c¯QΦ(D) for some disjunct Φ of QO.

() By hypothesis, there exists (Φ~,)𝑅𝑒𝑤 such that c¯QΦ~(D). This implies that there is a rewriting Σ-sequence ((Ψi,si))i{0,,m}, with Ψm=Φ~. By Lemma 17, there exists a prefix of a chase derivation (Ii)i{0,,m} of D w.r.t. Σ such that, for i{0,,m}, c¯QΨi(Imi) implies c¯QΨ0(Im). Therefore, since D=I0, we get that c¯QΨm(I0), and thus, c¯QΨ0(Im). Since Ψ0𝑆𝑝𝑒𝑐, we can establish the following monotonicity property: for a chase derivation δ=(Ji)i0 such that Ii=Ji for each i{0,,m}, it holds that c¯QΨ0(𝖼𝗁𝖺𝗌𝖾δ(D,Σ)). Thus, there is a chase derivation δ of D w.r.t. Σ such that c¯QΨ0(𝖼𝗁𝖺𝗌𝖾δ(D,Σ)). Since Ψ0𝑆𝑝𝑒𝑐, and c¯QΨ0(𝖼𝗁𝖺𝗌𝖾δ(D,Σ)), Lemma 14 implies that c¯Q(𝖼𝗁𝖺𝗌𝖾δ(D,Σ)), and the claim follows.