Sebastian Rudolph
email: sebastian.rudolph@tu-dresden.de

Michaël Thomazo
email: michael.thomazo@tu-dresden.de

Jean-François Baget
email: baget@lirmm.fr

Marie-Laure Mugnier
email: mugnier@lirmm.fr

Query Answering for Greedy Sets of Existential Rules Worst-case Optimal Query Answering for Greedy Sets of Existential Rules and Their Subclasses

The need for an ontological layer on top of data, associated with advanced reasoning mechanisms able to exploit the semantics encoded in ontologies, has been acknowledged both in the database and knowledge representation communities. We focus in this paper on the ontological query answering problem, which consists of querying data while taking ontological knowledge into account. More specifically, we establish complexities of the conjunctive query entailment problem for classes of existential rules (also called tuplegenerating dependencies, Datalog ± rules, or ∀∃-rules). Our contribution is twofold. First, we introduce the class of greedy bounded-treewidth sets (gbts) of rules, which covers guarded rules, and their most well-known generalizations. We provide a generic algorithm for query entailment under gbts, which is worst-case optimal for combined complexity with or without bounded predicate arity, as well as for data complexity and query complexity. Secondly, we classify several gbts classes, whose complexity was unknown, with respect to combined complexity (with both unbounded and bounded predicate arity) and data complexity to obtain a comprehensive picture of the complexity of existential rule fragments that are based on diverse guardedness notions. Upper bounds are provided by showing that the proposed algorithm is optimal for all of them.

Introduction

Intelligent methods for searching and managing large amounts of data require rich and elaborate schematic "ontological" knowledge. The need for an ontological layer on top of that data, associated with advanced querying mechanisms able to exploit the semantics encoded in ontologies 1 , has been widely acknowledged both in the knowledge representation (KR) and database communities.

Deductive databases and KR typically adopt two different perspectives on how to add this ontological layer to the picture of plain query answering (cf. [START_REF] Rudolph | The two views on ontological query answering[END_REF]. In deductive databases, this knowledge is considered part of the query, forming a so-called ontologymediated query to be executed on the database. According to the KR perspective, knowledge is encoded in an ontology, and queries are asked to a knowledge base composed of the data and the ontology. In this paper, we will focus on the KR perspective.

Indeed, ontologies, which typically encode general knowledge about the domain of interest, can be used to infer data that are not explicitely stored, hence palliating incompleteness in databases [START_REF] Calì | On the decidability and complexity of query answering over inconsistent and incomplete databases[END_REF]. They can also be used to enrich the vocabulary of data sources, which allows a user to abstract from the specific way data are stored. Finally, when several data sources use different vocabularies, ontologies can be used to align these vocabularies.

Given a knowledge base (KB) composed of an ontology and of factual knowledge, and a query, the ontology-based query answering problem consists in computing the set of answers to the query on the KB, while taking implicit knowledge represented in the ontology into account. We make here the simplifying assumption that the ontology and the database use the same vocabulary. Otherwise, mappings have to be defined between both vocabularies, as in the ontology-based data access framework [START_REF] Poggi | Linking data to ontologies[END_REF]. As most work in this area, we focus on conjunctive queries (CQs), the basic and most frequent querying formalism in databases.

In the Semantic Web area, one of the most prominent fields where KR technology is practically applied, ontological knowledge is often represented by means of formalisms based on description logics (DLs, (Baader, Calvanese, McGuinness, Nardi, & Patel-Schneider, 2007;[START_REF] Rudolph | Foundations of description logics[END_REF]). However, DLs are restricted in terms of expressivity in that they usually support only unary and binary predicates and that terminological expressiveness is essentially restricted to tree-like dependencies between the atoms of a formula. Moreover, DL research has traditionally been focusing on so-called standard reasoning tasks about the knowledge base, which are reducible to knowledge base satisfiability, for instance classifying concepts; querying tasks were essentially restricted to ground atom entailment. Answering full conjunctive queries (CQs) over DL knowledge bases has become a subject of research only recently 2 , turning out to be extremely complex (e.g., for the classical DL ALCI, it is already 2ExpTime-complete, and still NP-complete in the size of the data). Consequently, conjunctive query answering has been particularly studied on less expressive DLs, such as DL-Lite [START_REF] Calvanese | Tractable Reasoning and Efficient Query Answering in Description Logics: The DL-Lite Family[END_REF] and EL [START_REF] Baader | Least common subsumers and most specific concepts in a description logic with existential restrictions and terminological cycles[END_REF][START_REF] Lutz | Conjunctive Query Answering in the Description Logic EL Using a Relational Database System[END_REF]. These DLs are the basis of so-called tractable profiles OWL 2 QL and OWL 2 EL of the Semantic Web language OWL 2 (W3C OWL Working Group, 2009;Motik, Cuenca Grau, Horrocks, Wu, Fokoue, & Lutz, 2009a). 3On the other hand, querying large amounts of data is the fundamental task in databases. Therefore, the challenge in this domain is now to access data while taking ontological knowledge into account. The deductive database language Datalog allows to express some ontological knowledge. However, in Datalog rules, variables are range-restricted, i.e., all variables in the rule are universally quantified, which does not allow to infer the existence of initially unknown domain individuals (a capability called value invention in databases [START_REF] Abiteboul | Foundations of Databases[END_REF]). Yet, this feature has been recognized as crucial in an open-world perspective, where it cannot be assumed that all individuals are known in advance.

To accommodate the requirements sketched above -value invention and complex relationships -we consider here an extension of first-order function-free Horn rules that allows for existentially quantified variables in the rule heads and thus features value invention. More precisely, these extended rules are of the form Body → Head , where Body and Head are conjunctions of atoms, and variables occurring only in the Head are existentially quantified, hence their name "existential rules" in [START_REF] Baget | Walking the Complexity Lines for Generalized Guarded Existential Rules[END_REF][START_REF] Krötzsch | Extending Decidable Existential Rules by Joining Acyclicity and Guardedness[END_REF].

Example 1. Consider the existential rule R = ∀x human(x) → ∃y hasParent(x, y) ∧ human(y) and a fact F = human(a), where a is a constant. The application of R to F produces new factual knowledge, namely ∃y 0 hasParent(a, y 0 ) ∧ human(y 0 ) , where y 0 is a variable denoting an unknown individual. Note that R could be applied again to human(y 0 ), which would lead to create another existentially quantified variable, and so on.

Such rules are well-known in databases as Tuple-Generating Dependencies (TGDs) [START_REF] Beeri | A Proof Procedure for Data Dependencies[END_REF] and have been extensively used, e.g., for data exchange [START_REF] Fagin | Data Exchange: Semantics and Query Answering[END_REF]. Recently, the corresponding logical fragment has gained new interest in the context of ontology-based query answering. It has been introduced as the Datalog ± framework in [START_REF] Calì | Taming the Infinite Chase: Query Answering under Expressive Relational Constraints[END_REF][START_REF] Calì | A General Datalog-Based Framework for Tractable Query Answering over Ontologies[END_REF][START_REF] Calì | Datalog+/-: A family of logical knowledge representation and query languages for new applications[END_REF], and independently, stemming from graph-based knowledge representation formalisms [START_REF] Chein | Graph-based Knowledge Representation and Reasoning-Computational Foundations of Conceptual Graphs[END_REF], as ∀∃ rules [START_REF] Baget | Extending Decidable Cases for Rules with Existential Variables[END_REF][START_REF] Baget | Walking the Decidability Line for Rules with Existential Variables[END_REF].

This rule-based framework generalizes the core of the lightweight description logics mentioned above, namely DL-Lite and EL. 4 Moreover, in the case of the DL-Lite family (Cal-vanese et al., 2007), it has been shown that this covering by a Datalog ± fragment is done without increasing complexity [START_REF] Calì | A General Datalog-Based Framework for Tractable Query Answering over Ontologies[END_REF].

Several fundamental decision problems can be associated with conjunctive query answering under existential rules. In this paper, we consider the entailment problem of a Boolean conjunctive query under existential rules, which we are now able to define formally. A Boolean conjunctive query is an existentially closed conjunction of (function-free) atoms. A set of facts has the same form. A knowledge base is composed of a set of facts and a set of existential rules. The entailment problem takes as input a knowledge base and a Boolean conjunctive query and asks if this query is entailed by the knowledge base.

The presence of existentially quantified variables in rule heads, associated with arbitrarily complex conjunctions of atoms, makes the entailment problem undecidable [START_REF] Beeri | The implication problem for data dependencies[END_REF]Chandra, Lewis, & Makowsky, 1981a). Since the birth of TGDs, and recently within the Datalog ± and ∀∃ rule frameworks, various conditions of decidability have been exhibited. Three "abstract" classes have been introduced in [START_REF] Baget | Walking the Decidability Line for Rules with Existential Variables[END_REF] to describe known decidable behaviors: an obvious condition of decidability is the finiteness of the forward chaining (known as the chase in the TGD framework [START_REF] Maier | Testing implications of data dependencies[END_REF][START_REF] Johnson | Testing containment of conjunctive queries under functional and inclusion dependencies[END_REF][START_REF] Beeri | A Proof Procedure for Data Dependencies[END_REF]); sets of rules ensuring this condition are called finite expansion sets (fes); a more general condition introduced in [START_REF] Calì | Taming the Infinite Chase: Query Answering under Expressive Relational Constraints[END_REF] accepts infinite forward chaining provided that the facts generated have a bounded treewidth (when seen as graphs); such sets of rules are called bounded-treewidth sets (bts); then decidability follows from the decidability of first-order logic (FOL) classes with the bounded-treewidth model property [START_REF] Courcelle | The Monadic Second-Order Logic of Graphs: I. Recognizable Sets of Finite Graphs[END_REF]. The third condition, giving rise to finite unification sets (fus), relies on the finiteness of (a kind of) backward chaining mechanism, this condition is also known as first-order rewritability. None of these three abstract classes is recognizable, i.e., the problem of deciding whether a given set of rules is fes, bts, or fus is undecidable [START_REF] Baget | Walking the Decidability Line for Rules with Existential Variables[END_REF].

In this paper, we focus on the bts paradigm and its main "concrete" classes. (Pure) Datalog rules (i.e., without existential variables) are fes (thus bts). Guarded (g ) rules [START_REF] Calì | Taming the Infinite Chase: Query Answering under Expressive Relational Constraints[END_REF] are inspired by the guarded fragment of FOL [START_REF] Andréka | Modal languages and bounded fragments of FOL[END_REF][START_REF] Andréka | Modal Languages and Bounded Fragments of Predicate Logic[END_REF]. Their body has an atom, called a guard, that contains all variables from the body. Guarded rules are bts (and not fes). They are generalized by weakly guarded rules (wg ), in which the guarding condition is relaxed: only so-called "affected" variables need to be guarded; intuitively, affected variables are variables that are possibly mapped, during the forward chaining process, to newly created variables [START_REF] Calì | Taming the Infinite Chase: Query Answering under Expressive Relational Constraints[END_REF]. wg rules include Datalog rules (in which there are no affected variables). Other decidable classes rely on the notion of the frontier of a rule (the set of variables shared between the body and the head of a rule). In a frontier-one rule (fr1), the frontier is restricted to a single variable [START_REF] Baget | Extending Decidable Cases for Rules with Existential Variables[END_REF]. In a frontier-guarded rule (fg ), an atom in the body guards the frontier [START_REF] Baget | Walking the Decidability Line for Rules with Existential Variables[END_REF]. Hence, fg rules generalize both guarded rules and fr1 rules. When requiring only affected variables from the frontier to be guarded, we obtain the still decidable class of weakly frontier-guarded rules (wfg ), which generalizes both fg and wg classes [START_REF] Baget | Walking the Decidability Line for Rules with Existential Variables[END_REF]. Not considered until now were rule sets obtained by straightforward combinations of the above properties: guarded frontier-one rules (gfr1) as well as weak frontier-one rules (wfr1) and weakly guarded frontier-one rules (wgfr1). Table 1 summarizes the considered existential rule fragments with respect to their constraints on frontier variables and guardedness. Example 2. We consider the following relations, where the subscripts indicate the arity of the relation: project /3 , projectField /2 , projectDpt /2 , hasManager /2 , memberOf /2 , isSensitiveField /1 and isCriticalManager /1 . Intuitively, project(x, d, z) means that x is a project in department d and is about field z; relations projectField and projectDpt are projections of the project relation; hasManager(x, y) and member(y, d) respectively mean that x is managed by y and y is member of d; relations isSensitiveField and isCriticalManager respectively apply to fields and managers. Let R be the following set of existential rules built on this vocabulary:

• Decomposition of the relation project into two binary relations R 0 = ∀x∀d∀z(project(x, d, z) → projectDpt(x, d) ∧ projectF ield(x, z)

• "Every project has a manager" R 1 = ∀x∀z(projectF ield(x, z) → ∃y hasM anager(x, y))

• "Every managed project has some field" R 2 = ∀x∀y(hasM anager(x, y) → ∃z projectF ield(x, z))

• "The manager of a project is a member of the department that owns the project" R 3 = ∀x∀y∀d(hasM anager(x, y) ∧ projectDpt(x, d) → memberOf (y, d))

• "If a manager manages a project in a sensitive field, then (s)he is a critical manager" R 4 = ∀x∀y∀z(hasM anager(x, y) ∧ projectF ield(x, z) ∧ isSensitiveF ield(z) → isCriticalM anager(y))

• "Every critical manager manages a project in a sensible field" R 5 = ∀y(isCriticalM anager(y) → ∃x∃z(hasM anager(x, y) ∧ projectF ield(x, z) ∧ isSensitiveF ield(z)))

Note that rules R 0 , R 3 and R 4 do not introduce any existential variable. Rules R 0 , R 1 , R 2 and R 5 have an atomic body, hence they are trivially guarded. Rule R 4 is not guarded, but it is frontier-one. Hence, if we exclude R 3 , all rules are frontier-guarded. R 3 is not frontier-guarded, since no atom from the body contains both frontier variables y and d; however, we remark that variable d is not affected, i.e., it can never be mapped to a newly created variable (indeed, the only rule able to produce an atom with predicate projectDpt is R 0 ; the variables in this atom come from the body atom with predicate project, which never appears in a rule head, hence can only be mapped to initially present data). Affected frontier-variables are guarded in all rules, hence R is weakly frontier-guarded. R is even weakly frontier-one, since for each rule the frontier contains at most one affected variable.

Contrarily to fes and fus, the definition of bts is not based on a constructive entailment procedure. The complexity of the subclasses g and wg is known and an algorithm for the corresponding entailment problem has been provided [START_REF] Calì | Taming the Infinite Chase: Query Answering under Expressive Relational Constraints[END_REF][START_REF] Calì | A General Datalog-Based Framework for Tractable Query Answering over Ontologies[END_REF]. However, this is not the case for the classes gfr1, fr1, fg , wgfr1, wfr1, wfg , and gbts. The aim of this paper is to solve these algorithmic and complexity issues.

Our contribution is threefold. First, by imposing a restriction on the allowed forwardchaining derivation sequences, we define a subclass of bts, namely greedy bounded-treewidth sets of rules (gbts), which have the nice property of covering the wfg class. gbts are defined by a rather simple condition: when such a set is processed in forward chaining and a rule R is applied, all frontier variables of R which are not mapped to terms from the initial data set must be uniformly mapped to terms introduced by one single previous rule application.

The fundamental property satisfied thanks to this condition is that any derivation can be naturally associated with a bounded-width tree decomposition of the derived facts, which can be built in a "greedy manner", that is, on the fly during the forward chaining process.

We also prove that wfg and gbts have essentially the same expressivity. Secondly, we provide a generic algorithm for the gbts class, which is worst-case optimal for data complexity, for combined complexity (with or without bound on the arity of involved predicates), and for query complexity. We furthermore show that this algorithm can be slightly adapted to be worse-case optimal for subclasses with smaller complexities.

Thirdly, we classify gfr1, fr1, fg , wgfr1, wfr1, wfg , and gbts with respect to both combined (with and without predicate arity bound) and data complexities. We also consider the case of rules with an acyclic (more precisely, hypergraph-acyclic) body and point out that bodyacyclic fg rules coincide with guarded rules from an expressivity and complexity perspective.

Fig. 1 shows the complexity lines for these classes of rules with three complexity measures, namely combined complexity without or with bound on the predicate arity, and data complexity. Notice in particular that the two direct extensions of guarded rules, i.e., weakly guarded and frontier-guarded rules, do not behave in the same way with respect to the different complexity measures: for data complexity, fg rules remain in PTime, while wg rules are in ExpTime; on the other hand, for bounded-arity combined complexity, fg rules are in 2ExpTime, while wg rules remain in ExpTime. This article is an extended version of two papers published at IJCAI 2011 (Baget et al., 2011) and KR 2012 [START_REF] Thomazo | A generic querying algorithm for greedy sets of existential rules[END_REF], respectively. It provides detailed proofs of the results presented in these conference papers and benefits from further clarifications concerning the gbts algorithm, stemming from Michaël Thomazo's PhD thesis [START_REF] Thomazo | Conjunctive Query Answering Under Existential Rules-Decidability, Complexity, and Algorithms[END_REF]. Furthermore, it contains complexity results for new classes of rules which complement the picture, namely gfr1, wgfr1 and wfr1.

Preliminaries

We assume the reader to be familiar with syntax and semantics of first-order logic. We do not consider functional symbols except constants, hence a term is simply a variable or a constant. An atom is thus of the form p(t 1 , . . . , t k ) where p is a predicate with arity k, and the t i are terms. If not otherwise specified, a conjunction is a finite conjunction of atoms. We denote it by C[x], where x is the set of variables occurring in C.

A fact is the existential closure of a conjunction. 5 A Boolean conjunctive query (CQ) has the same form as a fact. We may also represent conjunctions of atoms, facts, and CQs as sets of atoms. Given an atom or a set of atoms A, we denote by vars(A) the set of variables, and by terms(A) the set of terms, occurring in A. Given conjunctions F and Q, a homomorphism π from Q to F is a substitution of vars(Q) by terms(F ) such that π(Q) ⊆ F (we say that Q maps to F by π). For convenience, we often assume the domain of π extended to terms(Q), by mapping constants to themselves. Given an atom a = p(t 1 , . . . , t n ), we let π(a) = p(π(t 1 ), . . . , π(t n )) and similarly for a set of atoms. First-order semantic entailment is denoted by |=. It is well-known that, given two facts or CQs F and Q, F |= Q iff there is a homomorphism from Q to F .

Definition 1 (Existential Rule

). An existential rule (or simply rule when not ambiguous) is a first-order formula:

R = ∀x∀y B[x, y] → ∃zH[y, z] ,
where B is a conjunction, called the body of R (also denoted by body(R)), and H is a conjunction called the head of R (denoted by head(R)). The frontier of R, denoted by fr(R), is the set of variables y = vars(B) ∩ vars(H) occurring both in the rule's body and head.

Note that an existential rule could be equivalently defined as the formula ∀y(∃xB[x, y] → ∃zH [y, z]). In the following, we will omit quantifiers since there is no ambiguity.

A knowledge base (KB) K = (F, R) is composed of a fact (in database terms: a database instance) F and a finite set of rules (in database terms: a TGD set) R. W.l.o.g. we assume that the rules have pairwise disjoint sets of variables. We denote by C the set of constants occurring in (F, R) and by T 0 (called the set of "initial terms") the set vars(F ) ∪ C, i.e., T 0 includes not only the terms from F but also the constants occurring in rules. Next, we formally define the problem considered by us.

Definition 2 (BCQ-Entailment). The decision problem of entailment of Boolean conjunctive queries under existential rules is defined as follows:

• Name: BCQ-Entailment

• Input: A knowledge base K = (F, R) and a Boolean conjunctive query Q.

• Output: YES iff K |= Q, NO otherwise.
Depending on which parts of the input are assumed to be fixed, we distinguish the following three complexity notions when investigating BCQ-Entailment:

• When considering data complexity, we assume R and Q to be fixed, only F (the data) can vary.

• When investigating query complexity, F and R are fixed and Q may vary.

• In case of combined complexity, F , R and Q can all change arbitrarily.

We now define the fundamental notions of rule application and R-derivation, which we relate to the chase procedure in databases.

Definition 3 (Application of a Rule).

A rule R is applicable to a fact F if there is a homomorphism π from body(R) to F ; the result of the application of R to F w.r.t. π is a fact α(F, R, π) = F ∪ π safe (head(R)) where π safe is a substitution of head(R), which replaces each x ∈ fr(R) with π(x), and each other variable with a fresh variable. As α(F, R, π) does not depend on the whole π, but only on π |fr(R) (the restriction of π to fr(R)), we also write α(F, R, π |fr(R) ).

Example 3. Let F = {r(a, b), r(c, d), p(d)} and R = r(x, y) → r(y, z). There are two applications of R to F , respectively by π 1 = {x →a, y →b)} and π 2 = {x →c, y →d}. We obtain

F 1 = α(F, R, π 1 ) = F ∪ {r(b, z 1 )} and F 2 = α(F, R, π 2 ) = F ∪ {r(d, z 2 )}.
Definition 4 (R-Derivation). Let F be a fact and R be a set of rules. An R-derivation

(from F to F k ) is a finite sequence (F 0 = F ), (R 0 , π 0 , F 1 ), . . . , (R k-1 , π k-1 , F k ) such that for all 0 ≤ i < k, R i ∈ R and π i is a homomorphism from body(R i ) to F i such that F i+1 = α(F i , R i , π i ).
When only the successive facts are needed, we note (F 0 = F ), F 1 , . . . , F k .

The following theorem essentially stems from earlier results on conceptual graph rules [START_REF] Salvat | Sound and Complete Forward and Backward Chainings of Graph Rules[END_REF].

Theorem 1 (Soundness and Completeness of R-Derivations). Let K = (F, R) be a KB and Q be a CQ. Then F, R |= Q iff there exists an R-derivation from F to some

F k such that F k |= Q.
It follows that a breadth-first forward chaining mechanism yields a positive answer in finite time when K |= Q. Let F 0 = F be the initial fact. Each step is as follows: (1) check if Q maps by homomorphism to the current fact, say F i-1 at step i (i > 0): if it is the case, Q has a positive answer; (2) otherwise, produce a fact F i from F i-1 , by computing all new homomorphisms from each rule body to F i-1 , then performing all corresponding rule applications. A homomorphism to F i-1 is said to be new if it has not been already computed at a previous step, i.e., it uses at least an atom added at step i -1. The fact F k obtained at the end of step k is called the k-saturation of F and is denoted by

α k (F, R); we define the saturation of F by R as α ∞ (F, R) = ∪ k≥0 α k (F, R).
Preceding notions are closely related to classical database notions. Forward chaining (with existential rules) is known as the chase (with TGDs) [START_REF] Maier | Testing implications of data dependencies[END_REF][START_REF] Aho | The theory of joins in relational databases[END_REF]. Hence, the notion of an R-derivation corresponds to a chase sequence. The chase is seen as a tool for computing the saturation of a database with respect to a set of TGDs. Several variants of the chase are known, which all produce a result homomorphically equivalent to α ∞ (F, R). The chase yields a canonical model of (F, R), which is isomorphic to the output of the chase, and has the property of being universal, which means that it maps by homomorphism to any model of (F, R). It follows that (F, R) |= Q if and only if Q maps by homomorphism to α ∞ (F, R) [START_REF] Deutsch | The chase revisited[END_REF][START_REF] Baget | On rules with existential variables: Walking the decidability line[END_REF] in the setting of existential rules).

We now formally specify some other notions that we have already introduced informally. A fact can naturally be seen as a hypergraph whose nodes are the terms in the fact and whose hyperedges encode the atoms. The primal graph of this hypergraph has the same set of nodes and there is an edge between two nodes if they belong to the same hyperedge. The treewidth of a fact is defined as the treewidth of its associated primal graph. Given a fact F i , a derivation S yielding F i , or a tree decomposition T of F i , we let atoms(S) = atoms(T) = F i .

Definition 5 (Tree Decomposition and Treewidth of a Fact). Let F be a (possibly infinite) fact. A tree decomposition of F is a (possibly infinite) tree T, with set of nodes B = {B 0 , . . . , B k , . . .}, and two functions terms : B → 2 terms(F ) and atoms : B → 2 F , where:

1. i terms(B i ) = terms(F ); 2. i atoms(B i ) = F ; 3. For each B i ∈ B holds terms(atoms(B i )) ⊆ terms(B i );
4. For each term e in F , the subgraph of T induced by the nodes B i with e ∈ terms(B i ) is connected ("Running intersection property").

The width of a tree decomposition T is the size of the largest node of T, minus 1. The treewidth of a fact F is the minimal width among all its possible tree decompositions.

A set of rules R is called a bounded-treewidth set (bts) if for any fact F there exists an integer b such that the treewidth of any fact F that can be R-derived from F is less or equal to b. The entailment problem is decidable when R is bts [START_REF] Calì | Taming the Infinite Chase: Query Answering under Expressive Relational Constraints[END_REF]Baget et al., 2011). The main argument of the proof, introduced by Calì et al., relies on the observation that K ∧ ¬Q enjoys the bounded-treewidth model property, i.e, has a model with bounded treewidth when it is satisfiable, i.e., when K |= Q. Decidability follows from the decidability of the satisfiability problem for classes of first-order formulas having the bounded-treewidth property, a result from Courcelle [START_REF] Courcelle | The Monadic Second-Order Logic of Graphs: I. Recognizable Sets of Finite Graphs[END_REF]. However, the proof of this latter result does not lead (or at least not directly) to an algorithm for BCQ-Entailment under bts rules. We now focus on "concrete" subclasses of bts.

A rule R is guarded (g ) if there is an atom a ∈ body(R) with vars(body(R)) ⊆ vars(a). We call a a guard of the rule. R is weakly guarded (wg ) if there is a ∈ body(R) (called a weak guard) that contains all affected variables from body(R). The notion of affected variable is relative to the rule set: a variable is affected if it occurs only in affected predicate positions, which are positions that may contain an existential variable generated by forward chaining [START_REF] Fagin | Data Exchange: Semantics and Query Answering[END_REF]. More precisely, the set of affected positions w.r.t. R is the smallest set that satisfies the following conditions: (1) if there is a rule head containing an atom with predicate p and an existentially quantified variable in position i, then position (p, i) is affected; (2) if a rule body contains a variable x appearing in affected positions only and x appears in the head of this rule in position (q, j) then (q, j) is affected. The important point is that a rule application necessarily maps non-affected variables to terms from the initial fact (and more generally to T 0 in the case where rules may add constants).

The g and wg rule classes were described and their complexity was analyzed by [START_REF] Calì | Taming the Infinite Chase: Query Answering under Expressive Relational Constraints[END_REF]Calì et al. ( , 2013)).

R is frontier-one (fr1) if |fr(R)| = 1 and it is guarded frontier-one (gfr1) if it is both g and fr1. R is frontier-guarded (fg ) if there is a ∈ body(R) with vars(fr(R)) ⊆ vars(a).
The weak versions of these classes-weakly frontier-one (wfr1), weakly guarded frontier-one (wgfr1) and weakly frontier-guarded (wfg ) rules-are obtained by relaxing the above criteria so that they only need to be satisfied by the affected variables. The syntactic inclusions holding between these bts subclasses are displayed in Fig. 1.

Greedy Bounded-Treewidth Sets of Rules

This section introduces greedy bounded-treewidth sets of rules (gbts). It is pointed out that gbts strictly contains the wfg class. However, in some sense, gbts is not more expressive than wfg : indeed, we exhibit a polynomial translation τ from any KB K = (F, R) to another KB τ (K) = (τ (F ), τ (R)) with τ (R) being wfg , which satisfies the following property: if R is gbts, then K and τ (K) are equivalent. This translation can thus be seen as a polynomial reduction from BCQ-Entailment under gbts to BCQ-Entailment under wfg .

Definition of the gbts Class

In a greedy derivation, every rule application maps the frontier of the rule in a special way: all the frontier variables that are mapped to terms introduced by rule applications are jointly mapped to variables added by one single previous rule application.

Definition 6 (Greedy Derivation

). An R-derivation (F 0 = F ), . . . , F k is said to be greedy if, for all i with 0 < i < k, there is j < i such that π i (fr(R i )) ⊆ vars(A j ) ∪ vars(F 0 ) ∪ C, where A j = π safe j (head(R j )).

Note that, in the above definition, any j < i can be chosen if fr(R i ) is mapped to vars(F 0 ) ∪ C.

Example 4 (Non-Greedy Derivation). Let R = {R 0 , R 1 } where:

R 0 = r 1 (x, y) → r 2 (y, z) and R 1 = r 1 (x, y) ∧ r 2 (x, z) ∧ r 2 (y, t) → r 2 (z, t)
Let F 0 = {r 1 (a, b) ∧ r 1 (b, c)} and S = F 0 , . . . , F 3 with:

F 1 = α(F 0 , R 0 , {(y →b)}) with A 0 = {r 2 (b, x 1 )}, F 2 = α(F 1 , R 0 , {(y →c)}) with A 1 = {r 2 (c, x 2 )}, F 3 = α(F 2 , R 1 , π 2 ) with π 2|fr(R 1 ) = {z →x 1 , t →x 2 }
Then fr(R 1 ) = {z, t} is mapped to newly introduced variables in F 3 , however, there is no A j such that {π 2 (z), π 2 (t)} ⊆ vars(A j ). Thus S is not greedy.

Any greedy derivation can be associated with a so-called derivation tree, formally defined below. Intuitively, the root of the tree corresponds to the initial fact F 0 , and each other node corresponds to a rule application of the derivation. Each node is labeled by a set of terms and a set of atoms. The set of terms assigned to the root is T 0 , i.e., it includes the constants that are mentioned in rule heads. Moreover, T 0 is included in the set of terms of all nodes. This ensures that the derivation tree is a decomposition tree of the associated derived fact.

Definition 7 (Derivation Tree). Let S = (F 0 = F ), . . . , F k be a greedy derivation. The derivation tree assigned to S, denoted by DT (S), is a tree T with nodes B = {B 0 , . . . , B k , . . .} and two functions terms : B → 2 terms(F k ) and atoms : B → 2 F k , defined as follows:

1. Let T 0 = vars(F )∪C. The root of the tree is B 0 with terms(B 0 ) = T 0 and atoms(B 0 ) = atoms(F ).

2. For 0 < i ≤ k, let R i-1 be the rule applied according to homomorphism π i-1 to produce F i ; then terms(B i ) = vars(A i-1 )∪T 0 and atoms(B i ) = atoms(A i-1 ). The parent of B i is the node B j for which j is the smallest integer such that π i-1 (fr(R i-1 )) ⊆ terms(B j ).

The nodes of DT (S) are also called bags.

Example 5 (Example 3 contd.). We consider F = {r(a, b), r(c, d), p(d)} and R = r(x, y) → r(y, z). We build DT (S) for S = (F 0 = F ), (R, π 1 , F 1 ), (R, π 2 , F 2 ) as depicted in Figure 2. Let B 0 be the root of DT (S). (R, π 1 ) yields a bag B 1 child of B 0 , with atoms(B 1 ) = {r(b, z 1 )} and terms(B Note that, in the second point of the definition of a derivation tree, there is at least one j with π i-1 (fr(R i-1 )) ⊆ terms(B j ) because S is greedy. The following property is easily checked, noticing that T 0 occurs in each bag, which ensures that the running intersection property is satisfied.

1 ) = {a, b, c, d, z 1 }. (R, π 2 ) yields a bag B 2 with atoms(B 2 ) = {r(d, z 2 )} and terms(B 2 ) = {a, b, c, d, z 2 }. fr(R 0 ) = {y} and π 2 (y) = d,
z 1 z 3 z 2 z 4 r(b, z 1 ) r(d, z 2 ) r(z 1 , z 3 ) r(z 2 , z 4 ) B 0 B 1 B 2 B 3 B 4 (R 0 , b) (R 0 , d) (R 0 , z 1 ) (R 0 , z 2 )
Figure 2: Derivation tree of Example 5. Only the image of the single frontier variable from R 0 is mentioned in edge labels. Proof. Let R be a wfg rule set. Given any R-derivation, consider the application of a rule R i , with weak frontier-guard g. Let a = π i (g). Either a ∈ F or a ∈ A j for some j ≤ i. In the first case, π i (fr(R i )) ⊆ terms(F ) ⊆ vars(F 0 ) ∪ C; in the second case, π i (fr(R i )) ⊆ terms(A j ) ⊆ vars(A j ) ∪ C. We conclude that R is gbts.

r 1 r 2 r 1 r 2 r r r a b c x 1 y 1 z 1 A 1 F Figure
The obtained inclusion is strict since there are gbts rule sets which are not wfg as shown in the following example.

Example 6 (gbts but not wfg ). Let R = r 1 (x, y) ∧ r 2 (y, z) → r(x, x ) ∧ r(y, y ) ∧ r(z, z ) ∧ r 1 (x , y ) ∧ r 2 (y , z ). {R} is gbts, but not wfg (nor fes). First, let us notice that all positions of r 1 and r 2 are affected, and that x, y and z belong to the frontier of R. Thus, {R} is not wfg . Moreover, let us consider F = {r 1 (a, b), r 1 (b, c)}. R is applicable to F , which leads to create r(a, x 1 ), r(b, y 1 ), r(c, z 1 ), r 1 (x 1 , y 1 ), and r 2 (y 1 , z 1 ), as shown in Fig. 3. R is thus newly applicable, mapping its frontier to x 1 , y 1 , and z 1 . This can be repeated infinitely often, therefore {R} is not fes. Last, the only way to map the body of R to terms that do not belong to an arbitrary initial fact is to map the frontier of R to terms that have been created in the same bag (for instance, to the atoms in A 1 in Fig. 3), thus ensuring that {R} is gbts.

A Translation into Weakly Frontier-Guarded Rules

Next we will present a translation applicable to any set of existential rules. This translation can be computed in polynomial time, its result is always wfg and it is guaranteed to preserve query answers if the input is gbts.

The translation introduces two new predicates: a unary predicate initial and a predicate samebag of higher arity. Intuitively, initial will mark terms from the initial fact F , as well as constants added by rule applications, and samebag will gather terms that are "in the same bag".

Definition 9 (wfg Translation). Let K = (F, R) be a KB. The wfg translation of K is the KB τ (K) = (τ (F ), τ (R)) where τ (F ) = F ∪ {initial (t)|t ∈ terms(F )} and τ (R) = R same ∪ R trans , where R same and R trans are defined as follows (where initial is a fresh unary predicate and samebag is fresh predicate with arity q = max(|terms(head(R))| R∈R ) + |T 0 |):

• R same contains the following rules:

R same 1 = initial (x) → samebag(x, . . . , x), R same 2 = samebag(x 1 , x 2 , . . . , x q ) ∧ initial (x) → samebag(x, x 2 . . . , x q ),
one rule of the following type for each 1 ≤ i ≤ q: R same 3i = samebag(x 1 , . . . , x i , . . . , x q ) → samebag(x i , . . . , x 1 , . . . x q ), and R same 4 = samebag(x 1 , . . . , x q-1 , x q ) → samebag(x 1 , . . . , x q-1 , x 1 ).

• R trans contains one translated rule τ (R) for every rule R from R: for some rule

R = B[x, y] → H[y, z] with c 1 , . . . , c k being the constants occurring in H, we let τ (R) = B[x, y] ∧ samebag(y, v) → H[y, z] ∧ samebag(y, z, w) ∧ i:1,...,k initial (c i ),
where w ⊆ v and v is a set of fresh variables.

Intuitively, Rules R same 1 and R same 2 express that the initial terms (as well as constants added by rule applications) are in all bags; rules R same 3i and rule R same 4 respectively allow any permutation and any duplication of arguments in an atom with predicate samebag. In the translation of the rules from R, the sets of variables v and w are used to fill the atoms with predicate samebag to obtain arity q. We next establish that, assuming we do not consider consequences involving initial or samebag, τ (R) is sound with respect to R and it is even complete in case R is gbts.

Property 5. For any Boolean CQ Q over the initial vocabulary, if τ (K) |= Q then K |= Q.
Moreover, if R is gbts, then the reciprocal holds, i.e., τ (K) and K are equivalent (w.r.t. the initial vocabulary).

Proof. ⇒: Any τ (R)-derivation S from τ (F ) can be turned into an R-derivation S from F by simply ignoring the applications of rules from R same and replacing each application of a rule τ (R i ) by an application of the rule R i with ignoring the atoms with predicate samebag. Moreover, the facts respectively obtained by both derivations are equal on the initial vocabulary (i.e., when considering only the atoms with predicate in the initial vocabulary, and up to a variable renaming).

⇐:

We assume that R is gbts. We show that any R-derivation S = (F 0 = F ), F 1 , . . . , F k can be turned into a τ (R)-derivation S = (F 0 = τ (F )), . . . , F 1 , . . . F k that satisfies: (a) for all i such that 0 ≤ i ≤ k, F i and F i are equal on the initial vocabulary; and, (b) for all i such that 0 ≤ i < k, F i+1 is obtained by applying τ (R i ) with a homomorphism π i that extends π i . The proof is by induction on the length of S. The property is true for = 0. Assume it is true for = n. Consider the application of R n with homomorphism π n from body(R n ) to F n . We note fr(R n ) = {y 1 . . . y p } such that body(τ (R n )) contains the atom samebag(y 1 , . . . , y p , . . .). Since R is gbts, there is an A j such that some variables from fr(R n ), say y i 1 . . . y im are mapped to vars(A j ), and the remaining variables from fr(R n ), say y i m+1 . . . y ip are mapped to T 0 = vars(F ) ∪ C. The application of τ (R j ) in S has produced a samebag atom s 1 that contains π n (y i 1 ) . . . π n (y im ) (by induction hypothesis (b)). By applying Rules R same 3i and Rule R same 4 , we permute, and duplicate if needed (i.e., if some y i 1 . . . y im have the same image by π), the arguments in s 1 to obtain the atom s 2 = samebag(π n (y i 1 ), . . . , π n (y im ), . . .). Then, with Rule R same 2 , we add each π n (y i j ) for m < j ≤ p (note that F n necessarily contains initial (π n (y i j ))) and build the atom s 3 = samebag(π n (y i m+1 ), . . . , π n (y ip ), π n (y i 1 ) . . . π n (y im ), . . .). Finally, with Rules R same 3i , we permute the p first arguments in s 3 to obtain s 4 = samebag(π n (y 1 ), . . . , π n (y p ), . . .). Since F n and F n are equal on the initial vocabulary by induction hypothesis (a), the fact obtained from F n after application of the previous rules from R trans is still equal to F n on the initial vocabulary. We build π n by extending π n such that the atom with predicate samebag in body(τ (R n )) is mapped to s 4 . Parts (a) and (b) of the induction property are thus satisfied for = n + 1.

An Algorithm for gbts: PatSat

We give here an informal high-level description of the PatSat algorithm (for pattern saturation). Due to the existentially quantified variables in rule heads, a forward chaining mechanism does not halt in general. However, as we have seen in the preceding section, for gbts, each sequence of rule applications gives rise to a so-called derivation tree, which is a decomposition tree of the derived fact; moreover, this tree can be built in a greedy way: each rule application produces a new tree node B (called a bag), which contains the atoms created by the rule application, such that the derived fact is the union of all bag atoms from this tree. The derived fact is potentially infinite, but thanks to its tree-like structure, the forward chaining process can be stopped after a finite number of rule applications as some periodic behavior will eventually occur.

The PatSat algorithm proceeds in two steps: first, it computes a finite tree, called a (full) blocked tree, which finitely represents all possible derivation trees; second, it evaluates a query against this blocked tree. Building a blocked tree relies on the following notions:

• bag patterns: Each bag B is associated with a pattern P , which stores all ways of mapping any (subset of any) rule body to the current fact (that is: the intermediate fact associated with the tree at the current stage of the construction process), while using some terms from terms(B). It follows that a rule is applicable to the current fact if and only if one of the bag patterns contains a mapping of its entire rule body.

Then, the forward chaining can be performed "on the bag-level" by forgetting about the underlying facts and considering solely the derivation tree decorated with patterns.

At each step, patterns are maintained and kept up-to-date by a propagation procedure based on a join operation between the patterns of adjacent bags.

• an equivalence relation on bags: Thanks to patterns, an equivalence relation can be defined on bags, so that two bags are equivalent if and only if the "same" derivation subtrees can be built under them. The algorithm develops (that is: adds children nodes to) only one node per equivalence class, while the other nodes of that class are blocked (note, however, that equivalence classes evolve during the computation, thus a blocked node can later become non-blocked, and vice-versa). This tree grows until no new rule application can be performed to non-blocked bags: the full blocked tree is then obtained.

• creation and evolution rules: The equivalence relation that we propose is however not directly computable: the "natural" way to compute would require to have already computed the greedy tree decomposition of the canonical model. In order to compute a full blocked tree, we make use of creation rules and evolution rules. These rules are meant to describe the patterns that may appear in the tree decomposition of the canonical model, as well as the relationships between patterns. For instance, creation rules intuitively state that any bag of pattern P that appears in the tree decomposition of the canonical model has a child of pattern P . We propose such rules, and show how to infer new rules in order to get a complete -but finite -description of the tree decomposition of the canonical model.

A first way to perform query answering is then to consider the query as a rule with a head reduced to a nullary prediate. In that case, it is enough to check if one pattern contains the entire body of this added rule. If one do not want to consider the query as a rule, one has to be more cautious. Indeed, the evaluation of a Boolean conjunctive query against a blocked tree cannot be performed by a simple homomorphism test. Instead, we define the notion of an APT-mapping, which can be seen as a homomorphism to an "unfolding" or "development" of this blocked tree. As the length of the developed paths that is relevant for query answering is bounded with an exponent that depends only on the rule set (more precisely, the exponent is the maximal number of variables shared by the body and the head of a rule), checking if there is an APT-mapping from a conjunctive query to a blocked tree is time polynomial in data complexity and nondeterministically time polynomial in query complexity.

In order to illustrate the numerous definitions of this section, we will employ a running example. This example has been designed with the following requirements in mind. First, it should be easy enough to understand. Second, it should illustrate every aspect of our approach, and explain why simpler approaches we could think of are not sufficient. Last, it should not be expressible by means of description logics.

Example 7 (Running Example). Let us consider R ex = {R ex 1 , . . . , R ex 7 } defined as follows:

• R ex 1 = q 1 (x 1 , y 1 , z 1 ) → s(y 1 , t 1 ) ∧ r(z 1 , t 1 ) ∧ q 2 (t 1 , u 1 , v 1 ); • R ex 2 = q 2 (x 2 , y 2 , z 2 ) → s(y 2 , t 2 ) ∧ r(z 2 , t 2 ) ∧ q 3 (t 2 , u 2 , v 2 ); • R ex 3 = q 3 (t 3 , u 3 , v 3 ) → h(t 3 ); • R ex 4 = q 2 (x 4 , y 4 , z 4 ) ∧ s(y 4 , t 4 ) ∧ r(z 4 , t 4 ) ∧ h(t 4 ) → h(x 4 ) ∧ p 1 (y 4 ) ∧ p 2 (z 4 ); • R ex 5 = q 1 (x 5 , y 5 , z 5 ) ∧ s(y 5 , t 5 ) ∧ r(z 5 , t 5 ) ∧ h(t 5 ) → p 1 (y 5 ) ∧ p 2 (z 5 ); • R ex 6 = p 1 (x p ) ∧ i(x p ) → r(x p , y p ) ∧ p 2 (y p ) ∧ i(y p ); • R ex 7 = p 2 (x q ) ∧ i(x q ) → s(x q , y q ) ∧ p 1 (y q ) ∧ i(y q ).
The initial fact will be:

F ex = q 1 (a, b, c) ∧ q 1 (d, c, e) ∧ q 1 (f, g, g) ∧ i(c) ∧ i(g).
The subset {R ex 1 , R ex 2 , R ex 3 } is a finite expansion set 6 . Applying these rules will create some existentially quantified variables. A first interesting phenomenon is that these existential variables allow to infer some new information about the initial terms. Last, R ex 4 and R ex 5 will generate infinitely many fresh existential variables, which will allow us to illustrate both the blocking procedure and the querying operation. While it can be argued that these rules are slightly complicated, it will allow to illustrate why we cannot block nodes without being careful.

Let us illustrate this rule set with an example of greedy derivation of F ex under R ex .

Example 8. Let us consider the following sequence of rule applications:

• R ex 1 is applied to F ex by π 1 = {x 1 →a, y 1 →b, z 1 →c}, creating {s(b, t 1 1 ), r(c, t 1 1 ), q 2 (t 1 1 , u 1 1 , v 1 1 )}. • R ex 2 is applied to α(F ex , R ex 1 , π 1 ) by π 2 = {x 2 →t 1 1 , y 2 →u 1 1 , z 2 →v 1 1 }, creating {s(u 1 1 , t 1 2 ), r(v 1 1 , t 1 2 ), q 3 (t 1 2 , u 1 2 , v 1 2 )} • R ex 3 is applied on the resulting fact by π 3 = {x 3 →t 2 1 , y 3 →u 2 1 , z 3 →v 2 1 }, creating a single new atom h(t 1 2 ).
This derivation is greedy, and its derivation tree is represented in Figure 4.

More generally, let us take a look at k-saturations of F ex with respect to R ex .

On F ex , only R ex 1 is applicable by three homomorphisms, creating three sets of three new atoms: {s(b,

t 1 1 ), r(c, t 1 1 ), q 2 (t 1 1 , u 1 1 , v 1 1 )}, {s(c, t 2 1 ), r(e, t 2 1 ), q 2 (t 2 1 , u 2 1 , v 2 1 )} and {s(g, t 3 1 ), r(g, t 3 1 ), q 2 (t 3 1 , u 3 1 , v 3 1 )}. α 1 (F ex , R ex
) is equal to the union of F ex and these three sets of atoms.

On α 1 (F ex , R ex ), three new rule applications are possible, each of them mapping the body of R ex 2 to one of the atoms with predicate q 2 . Again, three new sets of atoms are introduced, which are {s(u

1 1 , t 1 2 ), r(v 1 1 , t 1 2 ), q 3 (t 1 2 , u 1 2 , v 1 2 )}, {s(u 2 1 , t 2 2 ), r(v 2 1 , t 2 2 ), q 3 (t 2 2 , u 2 2 , v 2
2 )} and

{s(u 3 1 , t 3 2 ), r(v 3 1 , t 3 2 ), q 3 (t 3 2 , u 3 2 , v 3 2 )}. This yields α 2 (F ex , R ex ). On this fact, three new rule applications of R ex 3 are possible, which introduce h(t 1 2 ), h(t 2 2 ), h(t 3
2 ). The introduction of these atoms triggers new applications of R ex 4 , creating

h(t 1 1 ), h(t 2 1 ), h(t 3 1 ), p 1 (u 1 1 ), p 1 (u 2 1 ), p 1 (u 3 1 ), p 2 (v 1 1 ), p 2 (v 2 1 ), p 2 (v 3 1 ). R ex 5 is now triggered, creat- ing p 1 (b), p 2 (c), p 1 (c), p 2 (e), p 1 (f ), p 2 (f ).
The union of all atoms considered so far is equal to α 5 (F ex , R ex ). R ex 6 and R ex 7 are now applicable, both mapping their frontier to c and g. They will create infinite branches.

6. Because, for example, their graph of rule dependency is acyclic [START_REF] Baget | Extending Decidable Cases for Rules with Existential Variables[END_REF] q 1 (a, b, c), q 1 (d, c, e) This section focuses on bag patterns. For all following considerations, we assume an arbitrary but fixed rule set R which is gbts. We first show that forward chaining can be performed by considering solely the derivation tree endowed with bag patterns. Then we define joins on patterns in order to update them incrementally after each rule application. We last explain why patterns are interesting: they allow to formally capture some notion of "regularity" in a derivation tree, which will be exploited in the next section to finitely represent potentially infinite derivation trees.

q 1 (f, g, g), i(c), i(g) s(b, t 1 1 ), r(c, t 1 1 ) q 2 (t 1 1 , u 1 1 , v 1 1 ) s(u 1 1 , t 1 2 ), r(v 1 1 , t 1 2 ) q 3 (t 1 2 , u 1 2 , v 1 2 ) B 0 B 1 B 2 h(t 1 2 ) B 3
Definition 10 (Pattern, Patterned Derivation Tree). A pattern of a bag B is a set of pairs (G, π), where G is a conjunction of atoms and π is a partial mapping from terms(G) to terms(B). G and π are possibly empty.

For any R-derivation S with derivation tree DT (S), we obtain a patterned derivation tree, noted (DT (S), P ), where P is a function assigning a pattern P (B) to each bag B of DT (S).

The patterns that we consider are subsets of the rule bodies in R.

Definition 11 (Pattern Soundness and Completeness). Let F k be a fact obtained via a derivation S and let B be a bag in (DT (S), P ). P (B) is said to be sound w.r.t.

F k if for all (G, π) ∈ P (B), π is extendable to a homomorphism from G to F k . P (B) is said to be complete w.r.t. F k (and R), if for any R ∈ R, any sb R ⊆ body(R) and any homomorphism π from sb R to F k , P (B) contains (sb R , π )
, where π is the restriction of π to the inverse image of the terms of B, i.e., π = π |π -1 (terms(B)) . Finally, (DT (S), P ) is said to be sound and complete w.r.t. F k if for all its bags B, P (B) is sound and complete w.r.t. F k .

Provided that (DT (S), P ) is sound and complete w.r.t. F k , a rule R is applicable to F k iff there is a bag in (DT (S), P ) whose pattern contains a pair (body(R), -); then, the bag created by a rule application (R, π) to F k has parent B j in DT (S) iff B j is the bag in (DT (S), P ) with the smallest j such that P (B j ) contains (body(R), π ) for some π which coincides with π on fr(R), i.e., π |fr(R) = π |fr(R) . Patterns are managed as follows: [START_REF](z 1 , z 2 ) ∧ in(x, z 1 ) → in[END_REF] The pattern of B 0 is the maximal sound and complete pattern with respect to F ; (2) after each addition of a bag B i , the patterns of all bags are updated to ensure their soundness and completeness with respect to F i . It follows that we can define a patterned derivation, where rule applicability is checked on patterns, and the associated sound and complete patterned derivation tree, which can be shown to be isomorphic to the derivation tree associated with the (regular) derivation.

Remember that our final rationale is to avoid computations on the "fact level". We will instead incrementally maintain sound and complete patterns by a propagation mechanism on patterns. This is why we need to consider patterns with subsets of rule bodies and not just full rule bodies. We recall that the rules have pairwise disjoint sets of variables.

Definition 12 (Elementary Join). Let B 1 and B 2 be two bags,

e 1 = (sb 1 R , π 1 ) ∈ P (B 1 ) and e 2 = (sb 2 R , π 2 ) ∈ P (B 2 ) where sb 1 R and sb 2 R are subsets of body(R) for some rule R. Let V = vars(sb 1 R ) ∩ vars(sb 2 R
). The (elementary) join of e 1 with e 2 , noted J(e 1 , e 2 ), is defined if for all x ∈ V , π 1 (x) and π 2 (x) are both defined and

π 1 (x) = π 2 (x). Then J(e 1 , e 2 ) = (sb R , π), where sb R = sb 1 R ∪ sb 2 R and π = π 1 ∪ π 2
, where π 2 is the restriction of π 2 to the inverse image of terms(B 1 ) (i.e., the domain of π 2 is the set of terms with image in terms(B 1 )).

Note that V may be empty. The elementary join is not a symmetrical operation since the range of the obtained mapping is included in terms(B 1 ).

Example 9. Let us consider the bags B 1 andB 2 in Figure 4. Let e 1 = ({q 2 (x 4 , y 4 , z 4 )}, π = {x 4 →t 1 1 , y 4 →u 1 1 , z 4 →v 1 1 }) be in the pattern of B 1 , ande 2 = ({s(y 4 , t 4 ), r(z 4 , t 4 ), h(t 4 )}, π = {y 4 →u 1 1 , z 4 →v 1 1 , t 4 →t 1 2 }) be in the pattern of B 2 . The elementary join of e 1 with e 2 is ({q 2 (x 4 , y 4 , z 4 ), s(y 4 , t 4 ), r(z 4 , t 4 ), h(t 4 )}, π).

Definition 13 (Join). Let B 1 and B 2 be two bags with respective patterns P (B 1 ) = P 1 and P (B 2 ) = P 2 . The join of P 1 with P 2 , denoted J(P 1 , P 2 ), is the set of all defined J(e 1 , e 2 ), where

e 1 = (sb 1 R , π 1 ) ∈ P 1 , e 2 = (sb 2 R , π 2 ) ∈ P 2 .
Note that P 1 ⊆ J(P 1 , P 2 ) since each pair from P 1 can be obtained by an elementary join with (∅, ∅). Similarly, J(P 1 , P 2 ) contains all pairs (G, π) obtained from (G, π 2 ) ∈ P 2 by restricting π 2 to the inverse image of terms(B 1 ). Note that join preserves soundness, as stated in the following property. Property 6. If P 1 and P 2 are sound w.r.t.

F i then J(P 1 , P 2 ) is sound w.r.t. F i .
Proof. Follows from the definitions: for all (G, π) ∈ J(P 1 , P 2 ), either (G, π) ∈ P 1 , or is obtained by restricting an element of P 2 , or is equal to J(e 1 , e 2 ) for some e 1 = (sb 1 R , π 1 ) ∈ P 1 and e 2 = (sb 2 R , π 2 ) ∈ P 2 . In the latter case, let us consider two homomorphisms, h 1 and h 2 with co-domain F i , which respectively extend π 1 and π 2 . The union of h 1 and h 2 is a mapping from terms(G) to F i (remember that h 1 and h 2 are equal on the intersection of their domains). Moreover, it is a homomorphism, because every atom in G is mapped to an atom in F i by h 1 or by h 2 .

We consider the step from F i-1 to F i in a (patterned) derivation sequence: let B c be the bag created in this step and let B p be its parent in (DT (S), P ).

Definition 14 (Initial Pattern). The initial pattern of a bag B c , denoted by P init (B c ), is the set of pairs (G, π) such that G is a subset of some rule body of R and π is a homomorphism from G to atoms(B c ).

Example 10 (Initial Pattern). Let us consider the initial pattern of B 2 in Figure 4. The atoms of B 2 are:

{s(u 1 1 , t 1 2 ), r(v 1 1 , t 1 2 ), q 3 (t 1 2 , u 1 2 , v 1 2 )}. For rules R ex 1 , R ex 2 , R ex 6 and R ex 7
, no subset of a rule body maps to the atoms of B 2 . Thus, they do not contribute to the initial pattern of B 2 . There is one homomorphism from the body of R ex 3 to atoms of B 2 , and thus its initial pattern contains:

({q 3 (t 3 , u 3 , v 3 )}, {t 3 →t 1 2 , u 3 →u 1 2 , v 3 →v 1 2
). As for subsets of the body of R ex 4 , there are three elements added to the initial pattern of B 2 :

• ({s(y 4 , t 4 )}, {y 4 →u 1 1 , t 4 →t 1 2 }), • ({r(z 4 , t 4 )}, {t 4 →t 1 2 , z 4 →v 1 1 }), • ({s(y 4 , t 4 ), r(z 4 , t 4 )}, {y 4 →u 1 1 , t 4 →t 1 2 , z 4 →v 1 1 }).
Similar elements are added by taking subsets of the body of R ex 5 .

Property 7 (Soundness of Initial Pattern of B c w.r.t. F i ). The initial pattern of B c is sound with respect to F i .

Proof. For any (G, π)

∈ P init (B c ), π is a homomorphism from G to atoms(B c ) ⊆ F i .
Obviously, if a pattern is sound w.r.t. F i-1 then it is sound w.r.t. F i . The following property focus on completeness.

Property 8 (Completeness of J(P (B c ),

P (B p )) w.r.t. F i ). Assume that P (B p ) is complete w.r.t. F i-1 and R. Then J(P init (B c ), P (B p )) is complete w.r.t. F i .
Proof. Let π be a homomorphism from sb R ⊆ body(R) to F i , for some rule R. We show that J(P init (B c ), P (B p )) contains (sb R , π ), where π is the restriction of π to the inverse image of terms(B c ). Let us partition sb R into b i-1 , the subset of atoms mapped by π to F i-1 , and b i the other atoms from sb R , which are necessarily mapped by π to Proof. From Property 8, we know that P (B c ) is complete w.r.t. F i . It remains to prove the following property: let P (B) be obtained by computing J(P (B), P (B )); if P (B ) is complete w.r.t. F i , then J(P (B), P (B )) is complete w.r.t. F i . We partition sb R in the same way as in the proof of Property 8. If one of the subsets is empty, we are done. Otherwise, the partition allows to select an element e 1 from P (B) and an element e 2 from P (B ), and J(e 1 , e 2 ) is the element we want to find. The crucial point is that if π maps an atom a of sb R to an atom b of F i \ F i-1 , and b shares a term e with B, then e ∈ terms(B c ), hence, thanks to the running intersection property of a decomposition tree, e ∈ terms(B ), thus (e, π(e)) will be propagated to P (B).

F i \ F i-1 , i.
It follows that the following steps performed at each bag creation (where B c is introduced as a child of B p ) allow to maintain the soundness and completeness of the patterned derivation tree throughout the derivation:

1. initialize: compute P init (B c ) for the newly created pattern B c ; 2. update: P (B c ) = J(P init (B c ), P (B p )); 3. propagate: first, propagate from P (B c ) to P (B p ), i.e., P (B p ) = J(P (B p ), P (B c )); then, for each bag B updated from a bag B , update its children B i (for B i = B ) by P (B i ) = J(P (B i ), P (B)) and its parent B j by P (B j ) = J(P (B j ), P (B)). Iterate this step until every pattern is updated (i.e., P (B) is determined for every bag B of the current derivation tree).

Bag Equivalence

We now show how bag patterns allow us to identify a certain kind of regularity in a derivation tree. We first need some technical, but nonetheless natural definitions. We start with the notion of a fusion of the frontier induced by a rule application: given a rule application, it summarizes which frontier terms are mapped to the same term, and if they are mapped to a term of T 0 (that is, an initial term or a constant).

Definition 15 (Fusion of the Frontier Induced by π). Let R be a rule and V be a set of variables with V ∩ T 0 = ∅. Let π be a substitution of fr(R) by T 0 ∪ V . The fusion of fr(R) induced by π, denoted by σ π , is the substitution of fr(R) by fr(R) ∪ T 0 such that for every variable

x ∈ fr(R), if π(x) ∈ V then σ π (x) is the smallest 7 variable y of fr(R) such that π(x) = π(y); otherwise σ π (x) = π(x) ∈ T 0 . Example 11. Let us consider R ex 2 = q 2 (x 2 , y 2 , z 2 ) → s(y 2 , t 2 ) ∧ r(z 2 , t 2 ) ∧ q 3 (t 2 , u 2 , v 2 )
. Let π 1 = {y 2 →y 0 , z 2 →y 0 }. The substitution of the frontier of R 2 induced by π 1 is defined by σ π 1 = {y 2 →y 2 , z 2 →y 2 }. Let b be a constant, and π 2 be a substitution of the frontier of R 1 defined by π 2 = {y 2 →b, z 2 →b}. The fusion of the frontier induced by π 2 is defined by σ π 2 = {y 2 →b, z 2 →b}. Last, if π 3 maps y 2 and z 2 to two different existentially quantified variables, then σ π 3 is the identity on the frontier of R 2 .

This notion of fusion is the main tool to define structural equivalence, which is an equivalence relation on the bags of a derivation tree.

Definition 16 (Structural Equivalence). Let B and B be two bags created by applications (R, π i ) and (R, π j ), respectively, of the same rule R. B and B are structurally equivalent, written B B if the fusions of fr(R) induced by the restrictions of π i and π j to fr(R) are equal.

We will see later that structural equivalence is not sufficient to formalize regularity in a derivation tree. However, there is already a strong similarity between structurally equivalent bags: the purpose of Definition 17 is to formalize it.

Definition 17 (Natural Bijection). Let B and B be two structurally equivalent bags created by applications (R, π i ) and (R, π j ). The natural bijection from terms(B) to terms(B ) (in short from B to B ), denoted ψ B→B , is defined as follows:

• if x ∈ T 0 , let ψ B→B (x) = x 7.
We assume variables to be totally ordered (for instance by lexicographic order).

• otherwise, let orig(x) = {u ∈ vars(head(R))|π safe i (u) = x}. Since B and B are structurally equivalent, ∀u, u ∈ orig(x), π safe j (u) = π safe j (u ). We define ψ B→B (x) = π safe j (u).

The natural bijection is thus an isomorphism between two bags. This natural bijection between structurally equivalent bags gives us a way to partially order patterns, by ensuring that the ranges of partial applications are on the same set of terms.

Definition 18 (Pattern Inclusion, Pattern Equivalence). Let B and B be two bags, with respective patterns P (B) and P (B ). We say that P (B ) includes P (B), denoted by P (B) P (B ), if :

• B and B are structurally equivalent, i.e., B B ,

• P (B ) contains all elements from P (B), up to a variable renaming given by the natural bijection:

(G, π) ∈ P (B) ⇒ (G, ψ B→B • π) ∈ P (B ).
We say that P (B) and P (B ) are equivalent, denoted P (B) ∼ P (B ), if P (B ) P (B) and P (B) P (B ). By extension, two bags are said to be equivalent if their patterns are equivalent.

Property 10 helps to understand why Definition 18 provides us with a good notion of pattern equivalence, by linking the equivalence of patterns to the applicability of rules on bags having these patterns. Let us note that this property does not hold if we put structural equivalence in place of pattern equivalence.

Property 10. Let S be a derivation, and B and B two bags of (DT(S), P ) such that P (B) ∼ P (B ). If a rule R is applicable to B by π, then R is applicable to B by ψ B→B • π.

Proof. Since R is applicable to B by π, (body(R), π |fr(R) ) belongs to P (B). By definition of the equivalence of patterns, (body(R), ψ B→B • π |fr(R) ) belongs to P (B ), which implies that R is applicable to B .

We now present how this equivalence relation will be used to finitely represent the (potentially infinite) set of derived facts. Intuitively, a blocked tree T b is a subtree (with the same root) of a patterned derivation tree (DT(S), P ) of a sufficiently large derivation sequence S. Additionally every bag in T b is marked by either "blocked" or "non-blocked". Assuming that we know which length of derivation is enough, T b is constructed such that it has the following properties:

• for each equivalence class appearing in (DT(S), P ), there is exactly one non-blocked node of T b of that class;

• if a bag B is blocked in T b , it is a leaf, i.e., it has no child in T b (although it may have children in (DT(S), P ));

• if a bag is non-blocked in T b , all children of B in (DT(S), P ) are present in T b .

Definition 19 (Blocked Tree). A blocked tree is a structure (T b , ∼), where T b is an initial segment of a patterned derivation tree and ∼ is the equivalence relation on the bags of T b such that for each ∼-class, all but one bag are said to be blocked; this non-blocked bag is called the representative of its class and is the only one that may have children.

A blocked tree T b can be associated with a possibly infinite set of decomposition trees obtained by iteratively copying its bags. We first define the bag copy operation:

Definition 20 (Bag Copy). Let B 1 and B 2 be structurally equivalent bags with natural bijection

ψ B 1 →B 2 . Let B 1 be a child of B 1 . Copying B 1 under B 2 (according to ψ B 1 →B 2 ) is performed by adding a child B 2 to B 2 , such that terms(B 2 ) = {ψ B 1 →B 2 (t) | t ∈ terms(B 1 )} and atoms(B 2 ) = {ψ B 1 →B 2 (a) | a ∈ atoms(B 1 )}, where ψ B 1 →B 2 is defined as follows: for all x ∈ terms(B 1 ), if x ∈ terms(B 1 ) then ψ B 1 →B 2 (x) = ψ B 1 →B 2 (x), otherwise ψ B 1 →B 2 (x) is a fresh variable.
Assume that, in the previous definition, the bag B 1 has been created by (R, π). Then B 2 can be seen as obtained by the fusion of fr(R) induced by the potential application of R to B 2 with the homomorphism ψ B 1 →B 2 • π. Since the fusions of fr(R) induced by π and ψ B 1 →B 2 • π are equal, B 1 and B 2 are structurally equivalent, which justifies the use of ψ B 1 →B 2 for the bijection.

Starting from a blocked tree T b and using iteratively the copy operation when applicable, one can build a possibly infinite set of trees, that we denote by G(T b ). This set contains pairs, whose first element is a tree, and the second element is a mapping from the bags of this tree to the bags of T b , which encodes which bags of T b have been copied to create the bags of the generated tree.

Definition 21 (Trees Generated by a Blocked Tree). Given a blocked tree T b , let the set G(T b ) of trees generated by T b be inductively defined as follows:

• Let B 0 be the root of T b ; the pair ({B 0 }, {B 0 →B 0 }) belongs to G(T b ). For each pair (T, f ) ∈ G(T b ), T is said to be generated by T b via f . The tree T is said to be generated by T b if there exists an f such that T is generated by T b via f .

• Given a pair (T, f ) ∈ G(T b ), let B be
Note that a patterned decomposition tree thus generated is not necessarily a derivation tree, but it is an initial segment of a derivation tree. Among blocked trees, so-called full blocked trees are of particular interest.

Definition 22 (Full Blocked Tree). A full blocked tree T * (of F and R) is a blocked tree satisfying the two following properties:

• (Soundness) If T is generated by T * , then there is some T generated by T * and an R-derivation S from F such that atoms(T ) = atoms(DT (S)) (up to fresh variable renaming) and T is an initial segment of T .

• (Completeness) For all R-derivations from F , DT (S) is generated by T * .

The procedure outlined above (considering a particular tree prefix of a sufficiently large derivation tree) is however not constructive. We show how to circumvent this problem in the next section.

Abstract Patterns and Abstract Pattern Saturation

We now aim at computing a full blocked tree. To this end, we fix a representative for each structural equivalence class, as well as for each (pattern-based) equivalence class. This is the purpose of abstract bags and abstract patterns. We also need to describe on an abstract level how bags of a derivation tree are related to each other: links are introduced to that aim. Having defined these basic components, we will focus on getting structural knowledge about the derivation trees that can be created starting from a fact and a set of rules: creation rules and evolution rules will be defined. In the last step, we use these rules to compute a full blocked tree.

We start by defining abstract bags. Each abstract bag can be seen as a canonical representative of a class of the structural equivalence relation. In order to have a uniform presentation, we consider the initial fact as a rule with empty body.

Definition 23 (Abstract Bag, Frontier Terms, Generated Variables). Let R be a rule from R and σ a fusion of fr(R). The abstract bag associated with R and σ (notation:

B(R, σ)) is defined by terms(B(R, σ)) = σ(terms(head(R))) ∪ T 0 and atoms(B(R, σ)) = σ(head(R)).
The frontier terms of B(R, σ) are the elements of σ(fr(R)). Variables from terms(B(R, σ)) that are not frontier terms are called generated variables.

The notion of the natural bijection between structurally equivalent bags is extended to abstract bags in the straightforward way (note that there is exactly one abstract bag per structural equivalence class).

Example 12 (Abstract Bag). Let us consider R ex 2 = q 2 (x 2 , y 2 , z 2 ) → s(y 2 , t 2 ) ∧ r(z 2 , t 2 ) ∧ q 3 (t 2 , u 2 , v 2 )
, and three fusions of its frontier, namely: σ π 1 = {y 2 →y 2 , z 2 →y 2 }, σ π 2 = {y 2 →b, z 2 →b} and σ π 3 = {y 2 →y 2 , z 2 →z 2 }. The abstract bag B(R ex 2 , σ π 1 ) associated with R ex 2 and σ π 1 has as terms {y 2 , t 2 , u 2 , v 2 } and as atoms {s(y 2 , t 2 ), r(y 2 , t 2 ), q 3 (t 2 , u 2 , v 2 )}. The terms of the abstract bag

B(R ex 2 , σ π 2 ) are {b, t 2 , u 2 , v 2 }; its atoms are {s(b, t 2 ), r(b, t 2 ), q 3 (t 2 , u 2 , v 2 )}. For B(R ex 2 , σ π 3 ), its terms are {y 2 , t 2 , u 2 , v 2 , z 2 } and its atoms are {s(y 2 , t 2 ), r(z 2 , t 2 ), q 3 (t 2 , u 2 , v 2 )}.
Since abstract bags provide us with a canonical representative for each structural equivalence class, we can now define a canonical representative for each class of equivalent patterns: abstract patterns. To distinguish the abstract bags and patterns from their concrete counterparts, we will denote them by B and P (possibly with subscripts) instead of B and P .

Definition 24 (Abstract Pattern, Support). Let R be a set of rules, R be a rule and σ be a fusion of fr(R). An abstract pattern P with support B = B(R, σ) is a set of pairs (G, π) where G is a subset of a rule body (of some rule of R) and π is a partial mapping from terms(G) to terms(B). G and π are possibly empty.

Example 13 (Abstract Pattern). Let us consider again the initial pattern described in Example 10. This pattern contains the following elements:

• ({q 3 (t 3 , u 3 , v 3 )}, {t 3 →t 1 2 , u 3 →u 1 2 , v 3 →v 1 2 }),
• ({s(y 4 , t 4 )}, {t 4 →t 1 2 , y 5 →u 1 1 }),

• ({r(z 4 , t 4 )}, {t 4 →t 1 2 , z 4 →v 1 1 }),

• ({s(y 4 , t 4 ), r(z 4 , t 4 )}, {t 4 →t 1 2 , y 4 →u 1 1 , t 4 →v 1 1 }),

• ({s(y 5 , t 5 )}, {t 5 →t 1 2 , y 5 →u 1 1 }),

• ({r(z 5 , t 5 )}, {t 5 →t 1 2 , z 5 →v 1 1 }),

• ({s(y 5 , t 5 ), r(z 5 , t 5 )}, {t 5 →t 1 2 , y 5 →u 1 1 , z 5 →v 1 1 }).

This pattern is associated with a bag equivalent to the abstract bag B(R 2 , id). Thus, the abstract pattern P associated with this initial pattern contains the same elements, where the mappings are modified by substituting t 1 2 by t 2 , u 1 2 by u 2 , v 1 2 by v 2 , u 1 1 by y 2 and v 1 1 by z 2 .

Definition 25 (Initial Abstract Pattern). Let B be an abstract bag. The initial abstract pattern of B, denoted by P init (B) is the set of pairs (G, π) such that G is a subset of a rule body and π is a (full) homomorphism from G to atoms(B).

Let B 1 and B 2 be two bags of a derivation tree such that B 2 is a child of B 1 . B 1 and B 2 share some terms. Let us assume that B 1 is structurally equivalent to an abstract bag B 1 and that B 2 is structurally equivalent to an abstract bag B 2 . If we only state that a bag equivalent to B 2 is a child of a bag equivalent to B 1 , we miss some information about the above mentioned shared terms. Capturing this information is the purpose of the notion of link.

Definition 26 (Link). Let B 1 and B 2 be two abstract bags. A link from B 2 to B 1 is an injective mapping λ from the frontier terms of B 2 to the terms of B 1 such that the range of λ has a non-empty intersection with the generated terms of B 1 .

Please note that we define a link from a bag to its parent. It ensures that each bag has exactly one link. We will thus refer without ambiguity to the link of an abstract bag.

Example 14 (Link). Let us consider R ex 1 = q 1 (x 1 , y 1 , z 1 ) → s(y 1 , t 1 )∧r(z 1 , t 1 )∧q 2 (t 1 , u 1 , v 1 ) and R ex 2 = q 2 (x 2 , y 2 , z 2 ) → s(y 2 , t 2 ) ∧ r(z 2 , t 2 ) ∧ q 3 (t 2 , u 2 , v 2 )
, and the two abstract bags

B 1 = B(R 1 , id) and B 2 = B(R 2 , id). Then λ = {y 2 →u 1 , z 2 →v 1 } is a link from B 2 to B 1 .
We are also interested in the link that describes a particular situation in a derivation tree, hence the notion of induced link.

Definition 27 (Induced Link). Let B 1 and B 2 be two bags of a derivation tree such that B 2 is a child of B 1 . Let B 1 and B 2 be two abstract bags such that B 1 B 1 and B 2 B 2 . The link induced by B 1 and B 2 is the mapping λ of the frontier terms of B 2 to terms(B 1 ) defined by λ(y) = ψ B 1 →B 1 (ψ B 2 →B 2 (y)). We then also say that B 2 is linked to B 1 by λ.

Previous Property 10 states that the pattern of a bag determines the rules that are applicable on it. We will thus gather information relative to the structure of derivation trees by means of "saturation rules" whose intuition is explained by the following example. Note that these rules have nothing to do with existential rules.

Example 15. Let us consider R 1 = r(x 1 , y 1 ) → s(x 1 , y 1 ) and R 2 = s(x 2 , y 2 ) → p(x 2 ). Let P 1 be the following pattern: {r(x, y), {x →a, y →b}}. For any bag B of a derivation tree DT(S) such that P 1 P (B). R 1 is applicable by mapping x 1 to a and y 1 to b. This allows to derive s(a, b) (which may be used to apply R 2 ). Thus, the pattern of B in some derivation starting with S contains P 2 = {(r(x 1 , y 1 ), {x 1 →a, y 1 →b}), (s(x 2 , y 2 ), {x 2 →a, y 2 →b})}. Let us point out that this pattern inclusion is valid in "sufficiently complete" derivations, but not necessarily in the derivation tree of each derivation sequence.

Example 15 gives the intuition behind evolution rules: it exhibits a case where we can infer that if a bag has a pattern including P 1 , then its pattern can evolve into a pattern including P 2 . Such information will be gathered by evolution rules, and will be denoted by P 1 P 2 with P 1 and P 2 being the abstract counterparts of P 1 and P 2 , respectively. To deal with the creation of new bags, we design creation rules. They allow us to derive information about the children that a bag with a given pattern must have. Such a rule will be denoted by P 1 λ.P 2 , and intuitively means that rules may be applied to ensure that any bag B 1 with pattern P 1 has a child B 2 with pattern P 2 such that the link induced by B 1 and B 2 is λ and P 1 and P 2 are again the abstract counterparts of P 1 and P 2 , respectively.

In the following, we show how to derive a set of sound creation and evolution rules by means of Properties 11 to 16.

Definition 28 (Sound Creation Rule). Let P 1 , P 2 be two abstract patterns, and λ be a link between the support of P 2 and the support of P 1 . A creation rule is a rule of the following form:

γ c : P 1 λ.P 2 .
γ c is sound if for any derivation S, for any bag B 1 of (DT(S), P ) such that P 1 P (B 1 ), there exists a derivation S extending S with a child B 2 of B 1 in (DT(S ), P ) linked by λ to B 1 , and for which P 2 P (B 2 ).

Definition 29 (Sound Evolution Rule). Let P 1 , P 2 be two abstract patterns. An evolution rule is a rule of the following form:

γ e : P 1 P 2 .
γ e is sound if P 1 P 2 and for any derivation S and for any bag B of (DT(S), P ) satisfying P 1 P (B), there exists a derivation S extending S with patterned derivation tree (DT(S ), P ) such that P 2 P (B).

We now exhibit properties allowing to build sound rules.

Property 11. Let P be an abstract pattern with support B, let R be a rule from R, and let π be a mapping from fr(R) to terms(B) such that its range has a non empty intersection with the generated terms in P. Let (body(R), π) be an element of P. Let σ be the fusion of fr(R) induced by π. Then P λ.P init (B(R, σ)) is a sound creation rule, where λ is equal to π restricted to {σ(y) | y ∈ fr(R)}.

Proof. Since the range of π has a non-empty intersection with the set of generated terms of B(R, σ), λ is a link from B(R, σ) to the support of P. Moreover, let B be a bag of a derivation tree such that P P (B). Then (body(R), ψ support(P)→B • π) ∈ P (B). Thus, R is applicable, by mapping its frontier to terms(B) (and at least one term generated in B is the image of an element of the frontier). Thus B has a child with link λ and with a pattern that includes P init (B(R, σ)).

We now define the counterpart of elementary joins for abstract patterns. The main difference is that the relationships between terms of different abstract patterns cannot be checked by equality as it was done previously. We thus define abstract elementary joins, where these relationships are specified by the link between two abstract patterns. A link between two patterns is not symmetric: we thus define two join operations, to update either the abstract pattern that is the domain of the link or the abstract pattern that is the range of the link.

Definition 30 (Elementary Abstract Upper/Lower Join). Let P 1 and P 2 be two abstract patterns, and let λ be a link from P 2 to P 1 . Let R be a rule in R and let (sb 1 , π 1 ) ∈ P 1 and (sb 2 , π 2 ) ∈ P 2 for sb 1 , sb 2 ⊆ body(R). The elementary abstract upper and lower joins of (sb 1 , π 1 ) with (sb 2 , π 2 ) are defined if π 1 (x) and λ(π 2 (x)) are defined and equal for all x ∈ vars(sb 1 ) ∩ vars(sb 2 ). In that case, it is the pair (sb 1 ∪ sb 2 , π) with:

• π = π 1 ∪ λ • π 2
, where π 2 is the restriction of π 2 to π -1 2 (domain(λ)), for the upper join;

• π = π 2 ∪ λ -1 • π 1
, where π 1 is the restriction of π 1 to π -1 1 (range(λ)), for the lower join.

Definition 31 (Abstract Upper/Lower Join). Let P 1 and P 2 be two abstract patterns, and let λ be a link from P 2 to P 1 .

The abstract upper join of P 1 w.r.t. (λ, P 2 ) is the set of all existing elementary abstract upper joins of (sb 1 , π 1 ) ∈ P 1 with (sb 2 , π 2 ) ∈ P 2 , where sb 1 , sb 2 ⊆ body(R) for some R ∈ R. It is denoted by Join u (P 1 , λ, P 2 ).

The abstract lower join of P 2 w.r.t. (λ, P 1 ) is the set of all existing elementary abstract lower joins of (sb 1 , π 1 ) ∈ P 1 with (sb 2 , π 2 ) ∈ P 2 , where sb 1 , sb 2 ⊆ body(R) for some R ∈ R. It is denoted by Join l (P 1 , λ, P 2 ).

We now exploit this notion of join in order to define new sound creation and evolution rules.

Property 12. If P 1 λ.P 2 is a sound creation rule, then so is P 1 λ.Join l (P 1 , λ, P 2 ).

Proof. Let S be a derivation, B 1 be a bag of (DT(S), P ) such that P 1 P (B 1 ). Since P 1 λ.P 2 is sound, there are a derivation S with patterned derivation tree (DT(S ), P ) and a child B 2 of B 1 in S linked to B 1 by λ such that P 2 P (B 2 ). By soundness of join propagation, Join(P (B 2 ), P (B 1 )) P (B 2 ). By monotonicity of the join operation, we obtain that P 1 λ.Join l (P 1 , λ, P 2 )) is a sound rule.

Property 13. If P 1 λ.P 2 is a sound creation rule, then P 1 Join u (P 1 , λ, P 2 ) is a sound evolution rule.

Proof. Similar to the proof of Prop 12.

Property 14. If P 1 P 2 and P 2 P 3 are sound evolution rules, then P 1 P 3 is also a sound evolution rule.

Proof. Let S be a derivation, and let B be a bag of (DT(S), P ) such that P 1 P (B). Since P 1 P 2 is sound, there exists a derivation S extending S such that P 2 P (B). Since P 2 P 3 is sound, there exists a derivation S extending S such that P 3 P (B). Since S is also a derivation extending S, it holds that P 1 P 3 is sound.

Property 15. If P 1 P 2 and P 1 λ.P 3 are sound evolution/creation rules, then P 2 λ.P 3 is a sound creation rule.

Proof. The property holds by monotonicity of the join operation, and by the condition that P 1 P 2 being sound implies P 1 P 2 .

Property 16. If P 1 λ.P 2 and P 2 P 3 are sound creation/evolution rules, then P 1 λ.P 3 is a sound creation rule.

Proof. Let S be a derivation, and let B 1 be a bag of (DT(S), P ) such that P 1 P (B 1 ). Since P 1 λ.P 2 is sound, there are a derivation S with patterned derivation tree (DT(S ), P ) and a child B 2 of B 1 in S that is linked to B 1 by λ such that P 2 P (B 2 ). Since P 2 P 3 is sound, there exists a derivation S extending S such that P 3 P (B 2 ). S extends S as well, and thus P 1 λ.P 3 is a sound creation rule.

We call (abstract) pattern saturation the already outlined procedure that builds all creation and evolution rules w.r.t. F and R, obtained via an exhaustive application of all deduction rules displayed in Fig. 5. We now prove that this process terminates.

Property 17 (Termination). For any fact F and any gbts set of rules R, abstract pattern saturation terminates.

Proof. There is a finite number of abstract patterns and links between them, and thus a finite number of evolution and creation rules. At each step, the number of created rules can only increase, which shows the termination of pattern saturation.

For technical purposes, we will use the rank of an evolution/creation rule.

Definition 32 (Rank). The rank of an evolution or a creation rule is the minimum number of deduction rules (Figure 5) necessary to derive that rule.

This notion of rank helps us to prove the following technical lemma, that states that the pattern saturation respects some notion of monotonicity: at least as much information can be derived from an abstract pattern P 2 as from an abstract pattern P Proof. We prove the result by induction on the rank of P 1 P 1 (resp. P 1 λ.P 1 ). At rank 0, the result is vacuously true.

• Let P 1 P 1 be a rule of rank n of the pattern saturation. It has been obtained by applying Property 13 or Property 14 to rules of rank strictly smaller than n. Let us first consider that Property 13 has been applied. Let P 1 λ. P1 be the rule on which Property 13 has been applied. By induction hypothesis, there exists a rule P 2 λ. P2 in the pattern saturation such that P1 P2 . By monotonicity of the join operation, it holds that P 1 = Join u (P 1 , λ, P1 ) Join u (P 2 , λ, P2 ) = P 2 . Thus P 2 P 2 is in the pattern saturation and P 1 P 2 . Let us now consider that Property 14 has been used to create P 1 P 1 . Then, there are two rules of rank strictly smaller than n, namely P 1 P 1 and P 1 P 1 . By induction hypothesis, there is a rule P 2 P 2 in the pattern saturation such that P 1 P 2 . We can once again apply the induction hypothesis, and we conclude that there exists a rule P 2 P 2 in the pattern saturation, where P 1 P 2 . By applying Property 14, we conclude that P 2 P 2 is in the pattern saturation.

• Let γ e : P 1 λ.P 1 be a rule of rank n of the pattern saturation. It may have been created by application of Properties 11, 12, 15 or 16.

-If γ e has been created by Property 11, then the rule P 2 λ.P 1 can also be created thanks to this property, since P 1 P 2 .

-If γ e has been created by Property 12, then there is a rule P 1 λ.P 1 of rank strictly smaller than n in the pattern saturation, which has been used to create γ e . By induction hypothesis, there is a rule P 2 λ.P 2 . We define P 2 = Join l (P 2 , λ, P 2 ). By monotonicity of the join operation, we have that P 1 = Join l (P 1 , λ, P 1 ) Join l (P 2 , λ, P 2 ) = P 2 . By applying Property 12, we create P 2 λ.P 2 , which shows the claim.

-If γ e has been created by Property 15, there are two rules P 1 P 1 and P 1 λ.P 1 of rank strictly less than n in the pattern saturation. Since P 1 P 1 P 2 , we can directly apply the induction hypothesis and state the existence of P 2 λ.P 2 with P 1 P 2 .

-If γ e has been created by Property 16, there exists two rules P 1 λ.P 1 and P 1 P 1 of rank strictly less than n in the pattern saturation. By induction hypothesis, there exists a rule P 2 λ.P 2 in the pattern saturation, with P 1 P 2 . We can once again apply the induction hypothesis, inferring the existence of P 2 P 2 in the pattern saturation, with P 1 P 2 . By applying Property 16, we infer the existence of P 2 λ.P 2 , which concludes the proof.

In the obtained fixpoint, some rules are redundant. For instance, if there exist two rules P 1 λ.P 2 and P 1 λ.P 3 , with P 2 P 3 , then the first rule is implied by the second one. This motivate the definition of most informative rules.

Definition 33 (Most informative rules). Let F be a fact and R be a gbts set of rules. The set of most informative rules associated with F and R, denoted by I F,R is the maximal subset of the abstract pattern saturation such that:

• a creation rule P 1 λ.P 2 belongs to I F,R if there is no rule in the abstract P 1 λ.P 2 with P 2 = P 3 and P 2 P 3 ;

• an evolution rule P 1 P 2 belongs to I F,R if there is no rule P 1 P 2 in the abstract pattern saturation that satisfies P 2 = P 3 and P 2 P 3 .

Let us notice that we can without ambiguity speak about the evolution rule of the most informative rule set having a given abstract pattern as left hand side (when it exists), as there is at most one such rule.

Property 19. Let F be a fact, R be a gbts set of rules, and P be an abstract pattern. I F,R contains at most one evolution rule and at most one creation rule having P as left-hand side.

Proof. We show that if P λ.P 1 and P λ.P 2 (resp. P P 1 and P P 2 ) belong to the pattern saturation, then there exists P 3 with P 1 P 3 and P 2 P 3 such that P λ.P 3 (resp. P P 3 ) belongs to the pattern saturation as well. We assume without loss of generality that P λ.P 1 (resp. P P 1 ) is the rule of smallest rank, and we prove the result by induction on that rank. A rule can be of rank 1 if and only if it has been created thanks to Property 11. Since the only way to create a rule of the shape P λ.P 1 is to use that property and that other deduction rules may only make the patterns grow, it holds that P 1 P 2 , and we can take P 3 = P 2 . The results thus holds if the first rule is of rank 1. Let us assume the result to be true for any rule up to rank n, and let us show that it is true as well for any rule of rank k + 1. We first consider creation rules and we distinguish three cases:

• P λ.P 1 has been created by Property 12. We can apply the induction hypothesis on the premises of that deduction rule, say P λ.P 1 . There exists thus P 3 such that P λ.P 3 belongs to the pattern saturation and P 1 P 3 and P 2 P 3 . By applying then Property 12, and by monotonicity of the join operation, one get P λ.P 3 as desired.

• P λ.P 1 has been created by Property 15. We apply the induction hypothesis on the premise that is a creation rule, which allows us to conclude.

• P λ.P 1 has been created by Property 16. We apply the induction hypothesis on the premise that is a creation rule; Lemma 18 then allows us to conclude.

We now consider evolution rules. We distinguish two cases:

• P P 1 has been created by Proposition 13. As in the first case of the creation rules, the result follow by induction hypothesis and monotonicity of the join operation.

• P P 1 has been created by Proposition 14. The result follow by induction hypothesis on the first premise and by Lemma 18.

We illustrate pattern saturation by expanding the running example. Writing down absolutely every element of each pattern would impede the ease of reading. We will thus allow ourselves to skip some elements, and focus on the most important ones.

Example 16. The initial pattern P F of F ex (Example 7) contains the following elements:(q 1 (x 1 , y 1 , z 1 ), {x 1 →a, y 1 →b, z 1 →c}), (q 1 (x 1 , y 1 , z 1 ), {x 1 →d, y 1 →c, z 1 →e}) and (q 1 (x 1 , y 1 , z 1 ), {x 1 →f, y 1 →g, z 1 →g}. By application of Property 11, three novel rules are created: P 0 ∅.P b,c 1 , P 0 ∅.P c,e 1 and P 0 ∅.P g,g 1 , where P b,c 1 , P c,e 1 , and P g,g 1 are described below.

The atoms of the abstract bag associated with P b,c 1 are {s(b, t 1 ), r(c, t 1 ), q 2 (t 1 , u 1 , v 1 )}, and its link is empty (since the whole frontier of R ex 1 is mapped to constants). The atoms of the abstract bag associated with P c,e 1 are {s(c, t 1 ), r(e, t 1 ), q 2 (t 1 , u 1 , v 1 )}, and those of the abstract bag associated with P g,g 1 are {s(g, t 1 ), r(g, t 1 ), q 2 (t 1 , u 1 , v 1 )}. P b,c

1 contains the following pairs:

• ({q 2 (x 2 , y 2 , z 2 )}, {x 2 →t 1 , y 2 →u 1 , z 2 →v 1 }); • ({q 2 (x 4 , y 4 , z 4 )}, {x 4 →t 1 , y 4 →u 1 , z 4 →v 1 });
• ({s(y 4 , t 4 )}, {y 4 →b, t 4 →t 1 });

• ({r(z 4 , t 4 )}, {z 4 →c, t 4 →t 1 });

• ({s(y 4 , t 4 ), r(z 4 , t 4 )}, {y 4 →b, z 4 →c, t 4 →t 1 });

• ({s(y 5 , t 5 )}, {y 5 →b, t 5 →t 1 });

• ({r(z 5 , t 5 )}, {z 5 →c, t 5 →t 1 });

• ({s(y 5 , t 5 ), r(z 5 , t 5 )}, {y 5 →b, z 5 →c, t 5 →t 1 }).

P c,e

1 contains the same pairs, except that every occurrence of b is replaced by c and every occurrence of c is replaced by e, whereas P g,g 1 contains the same pairs, except that every occurrence of b is replaced by g and every occurrence of c is replaced by g. P b,c 1 is graphically represented in Figure 6. These three patterns contain ({q 2 (x 2 , y 2 , z 2 )}, {x 2 →t 1 , y 2 →u 1 , z 2 →v 1 }), and we thus create the three following rules: s(b, t 1 ), r(c, t 1 ), q 2 (t 1 , u 1 , v 1 )

q 2 (x 2 , y 2 , z 2 ) q 2 (x 4 , y 4 , z 4 ) s(y 4 , t 4 ) s(y 5 , t 5 ) r(z 4 , t 4 ) r(z 5 , t 5 ) r(z 4 , t 4 ), s(y 4 , t 4 )
Atoms of the abstract bag: r(z 5 , t 5 ), s(y 5 , t 5 ) • P c,e 1 λ .P 2 ,

t 1 b c u 1 v 1
• P g,g

1 λ .P 2 ,
where λ = {y 2 →u 1 , z 2 →v 1 } and P 2 is defined below. The atoms of P 2 are {s(y 2 , t 2 ), r(z 2 , t 2 ), q 3 (t 2 , u 2 , v 2 )}. It contains the following elements:

• ({q 3 (t 3 , u 3 , v 3 )}, {t 3 →t 2 , u 3 →u 2 , v 3 →v 2 }),
• ({s(y 4 , t 4 )}, {y 4 →y 2 , t 4 →t 2 }),

• ({r(z 4 , t 4 )}, {z 4 →z 2 , t 4 →t 2 }),

• ({s(y 4 , t 4 ), r(z 4 , t 4 )}, z 4 →z 2 , y 4 →y 2 , t 4 →t 2 }),

• ({s(y 5 , t 5 )}, {y 5 →y 2 , t 5 →t 2 }),

• ({r(z 5 , t 5 )}, {z 5 →z 2 , t 5 →t 2 }),

• ({s(y 5 , t 5 ), r(z 5 , t 5 )}, {y 5 →y 2 , z 5 →z 2 , t 5 →t 2 }).

The element ({q 3 (t 3 , u 3 , v 3 )}, {t 3 →t 2 , u 3 →u 2 , v 3 →v 2 }) belongs to P 2 , and thus, we create a rule P 2 λ .P 3 ), where λ = {t 3 →t 2 } and P 3 contains the following elements:

• ({h(t 4 )}, {t 4 →t 2 }),
• ({h(t 5 )}, {t 5 →t 2 }).

At this point, we cannot create any new rule by Property 11. However, Property 13 may be used to derive an evolution of P 2 . Indeed, since P 2 λ .P 3 has been derived, we can derive P 2 P 2 with P 2 = Join u (P 2 , λ , P 3 ). Note that P 2 is a superset of P 2 that additionally contains the following elements:

• ({s(y 4 , t 4 ), h(t 4 )}, {y 4 →y 2 , t 4 →t 2 }),

• ({r(z 4 , t 4 ), h(t 4 )}, {z 4 →z 2 , t 4 →t 2 }),

• ({s(y 4 , t 4 ), r(z 4 , t 4 ), h(t 4 )}, {z 4 →z 2 , y 4 →y 2 , t 4 →t 2 }),

• ({s(y 5 , t 5 ), h(t 5 )}, {y 5 →y 2 , t 5 →t 2 }),

• ({r(z 5 , t 5 ), h(t 5 )}, {z 5 →z 2 , t 5 →t 2 }),

• ({s(y 5 , t 5 ), r(z 5 , t 5 ), h(t 5 )}, {y 5 →y 2 , z 5 →z 2 , t 5 →t 2 }),

• ({h(t 4 )}, {t 4 →t 2 }),

• ({h(t 5 )}, {t 5 →t 2 }).

By Property 16, the following sound rules can then be obtained:

• P b,c 1 λ .P 2 , • P c,e 1 λ .P 2 , • P g,g 1 λ .P 2 .
Applying once more Property 13 yields new sound rules such as:

P b,c 1 P b,c 1 ,
where P b,c 1 is a superset of P b,c 1 that additionally contains, among others, the following element:

({q 2 (x 4 , y 4 , z 4 ), r(z 4 , t 4 ), s(y 4 , t 4 ), h(t 4 )}, {x 4 →t 1 , y 4 →u 1 , z 4 →v 1 }).

Please note that in this case, π = {x 4 →t 1 , y 4 →u 1 , z 4 →v 1 } does not map every variable appearing in the corresponding subset of a rule body. Indeed, t 4 is not mapped, since its image by the homomorphism extending π does not belong to the terms relevant to the supporting bag.

We skip a part of the further development of this example. It can be checked that at some point, a rule P F P F is created, where P F contains the following elements:

({p 1 (x p ), i(x p )}, {x p →g}) ({p 2 (x q ), i(x q )}, {x q →g})
The following two creation rules are thus sound and relevant:

P 0 ∅.P i p P 0 ∅.P i q
where P i p contains in particular ({p 2 (x q ), i(x q )}, {x q →y p }) and P i q contains ({p 1 (x p ), i(x p )}, {x p →y q }). Since the body of R ex 6 belongs to P i p , a new creation rule is added: P i p {x p →y q }.P q .

s(b, t 1 ), r(c, t 1 ), q 2 (t 1 , u 1 , v 1 )

q 2 (x 2 , y 2 , z 2 ) q 2 (x 4 , y 4 , z 4 ) s(y 4 , t 4 ) s(y 5 , t 5 ) r(z 4 , t 4 ) r(z 5 , t 5 ) r(z 4 , t 4 ), s(y 4 , t 4 )
Atoms of the abstract bag: r(z 5 , t 5 ), s(y 5 , t 5 )

q 2 (x 2 , y 2 , z 2 ) q 2 (x 4 , y 4 , z 4 ) s(y 4 , t 4 ) s(y 5 , t 5 ) r(z 4 , t 4 ) r(z 5 , t 5 )
r(z 4 , t 4 ), s(y 4 , t 4 ) r(z 5 , t 5 ), s(y 5 , t 5 ) s(b, t 1 ), r(c, t 1 ), q 2 (t 1 , u 1 , v 1 ) Atoms of the abstract bag: x 4 ,y 4 ,z 4 ),r(z 4 ,t 4 ),s(y 4 ,t 4 ),h(t Likewise, since the body of R ex 7 belongs to P i q , a new creation rule is added: P i q {x q →y p }.P p . Last, two recursive rules are added: P p {x p →y q }.P q , P q {x q →y p }.P p .

c b t 1 u 1 v 1 c b u 1 t 1 v 1 q 2 (

Computation of the Full Blocked Tree

Given a fact, a set of gbts rules and their associated set of most informative rules, Algorithm 1 outputs a full blocked tree for F and R. We start by creating a bag with set of terms T 0 . This bag is the root of the full blocked tree. We maintain a list of blocked patterns: any bag that is of that pattern and that is not labeled as non-blocked is thus blocked. We then consider the most informative evolution rule having P F = P init (B(→ F, ∅)) (i.e., the initial abstract pattern of F ) as left-hand side, say P F → P * F . We label the root of the full blocked tree with the pattern P * F . 8 We mark this newly created root as being non-blocked. Then, as long as there exist a non-blocked bag B 1 and a most informative creation rule P 1 λ.P 2 with P 1 ∼ P (B 1 ) that has not been applied on B 1 , we apply that rule. To apply it, we add a child B 2 to B 1 such that P (B 2 ) ∼ P 2 and the induced link from B 2 to B 1 is λ. B 2 is considered blocked (i.e., is not marked non-blocked) if there is already a bag B 3 with P (B 2 ) ∼ P (B 3 ) in the built structure, and non-blocked otherwise. This procedure halts, since there is a finite number of non-equivalent patterns, and the maximal degree of the built tree is also bounded. It creates a sound blocked tree, since all creation and evolution Theorem 22. BCQ-Entailment for gbts is in 2ExpTime for combined complexity and in ExpTime for data complexity.

Proof. Let us recall that F, R |= Q holds exactly if F, R ∪ {Q → match} |= match, where match is a fresh, nullary predicate. Note that R∪{Q → match} is still gbts since Q → match is fg . F, R ∪ {Q → match} |= match can be easily checked given T * b (F, R ∪ {Q → match}) by checking if any of the abstract patterns associated to any of the bags contain some pattern (Q, π) for some π. The computation of the full blocked tree is polynomial in the size of the computed creation/evolution rule set. The number of such rules is polynomial in the number of patterns and in the maximum degree of a derivation tree. The number of patterns is doubly exponential in the data in the worst-case, while the degree is at most exponential. When the rule set (including the query) is fixed, the data complexity falls to ExpTime. Lower bounds for data complexity come from already known complexity results of weakly-guarded rules [START_REF] Calì | Taming the Infinite Chase: Query Answering under Expressive Relational Constraints[END_REF], for instance.

The algorithm we proposed is thus worst-case optimal both for combined and data complexities.

Querying the Full Blocked Tree

We considered in previous sections the query to be implemented via a rule. This trick allowed to have a conceptually easy querying operation, because it was sufficient to check if some bag of the full blocked tree was labeled by the query and an arbitrary mapping. However, this comes with two drawbacks. The first one is that the query is needed at the time of the construction of the full blocked tree. In scenarios where different queries are evaluated against the same data, one would like to process data and rules independently from the query, and then to evaluate the query on the pre-processed structure. This is not possible if we consider the query to be expressed via a rule. The second drawback of taking the query into account while building the full blocked tree is that it may prevent us from adapting this construction when assumptions are made on the set of rules: can we devise a better algorithm if we have additional knowledge concerning the rule set, for instance, if we know that it is guarded, and not only gbts?

This section is devoted to these issues. In the construction of the full blocked tree, we do not consider the query anymore. We still obtain a finite representation of arbitrarily deep patterned derivation trees for F and R, but we cannot just check if a bag is labeled by the query -since the query does not necessarily appear in the considered patterns anymore. A simple homomorphism check is not sufficient either, as can be seen in Example 17 below. To overcome this problem, we introduce a structure called atom-term partition tree (APT). Such a structure is meant to encode a decomposition of the query induced by a homomorphism from that query to a derivation tree. A possible algorithm to check the existence of a homomorphism from a query Q to a derivation tree would be to check if one of the APTs of Q is the structure induced by some homomorphism π, i.e. to validate this APT. APTs and their validation in a derivation tree will be formalized in Section 4.5.1. We are well aware that this definition is more involved than the simple definition of homomorphism. However, our goal will be to validate APTs, not in the potentially ever-growing derivation trees, but in the finite full blocked tree. In that case, APTs will still be used, but we will have to adjust their validation process (Section 4.5.2). Let us first stress why the usual homomorphism check is not a suitable operation for querying a full blocked tree. To simplify the presentation, we will restrict the running example in the following way: we only consider rules R ex 1 = p 1 (x p ) ∧ i(x p ) → r(x p , y p ) ∧ p 2 (y p ) ∧ i(y p ) and R ex 2 = p 2 (x q ) ∧ i(x q ) → s(x q , y q ) ∧ p 1 (y q ) ∧ i(y q ) (this set will be denoted by R ex ), and the initial fact is restricted to i(c) ∧ p 1 (c) ∧ p 2 (c) (denoted by F ex ).

p 1 (c), p 2 (c), i(c) r(c, y 1 ), p 2 (y 1 ), i(y 1 ) s(c, z 1 ), p 1 (z 1 ), i(z 1 ) s(y 1 , y 2 ), p 1 (y 2 ), i(y 2 ) r(z 1 , z 2 ), p 2 (z 2 ), i(z 2 ) r(y 2 , y 3 ), p 2 (y 3 ), i(y 3 ) s(z 2 , z 3 ), p 1 (z 3 ), i(z 3 ) B 0 B 1 B 2 B 3 B 4 B 5 B 6
Example 17. Let us consider the following query Q i :

Q i = p i (x) ∧ s(x, y) ∧ r(y, z) ∧ s(z, t) ∧ r(t, u) ∧ r(x, v).
If we only look for a homomorphism with atoms belonging to the full blocked tree associated with R ex and F ex and displayed in Figure 8, we do not find any answer to this query. However, B 2 is equivalent to B 6 , and by considering a derivation tree where B 3 would have a corresponding bag below B 6 (as B 7 in Figure 9), one would find a (correct) mapping of

Q i . p 1 (c), p 2 (c), i(c) r(c, y 1 ), p 2 (y 1 ), i(y 1 ) s(c, z 1 ), p 1 (z 1 ), i(z 1 ) s(y 1 , y 2 ), p 1 (y 2 ), i(y 2 ) r(z 1 , z 2 ), p 2 (z 2 ), i(z 2 )
r(y 2 , y 3 ), p 2 (y 3 ), i(y 3 ) s(z 2 , z 3 ), p 1 (z 3 ), i(z 3 )

B 0 B 1 B 2 B 3 B 4 B 5 B 6 r(z 3 , z 4 ), p 2 (z 4 ), i(z 4 ) B 7
Figure 9: A tree generated by the full blocked tree of Figure 8. B 7 is a copy of B 3 under B 6 .

Validation of an APT in a Derivation Tree

Let π be a homomorphism from Q to the atoms of some derivation tree T = DT (S). From π, let us build an arbitrary mapping π a T (out of the many possible ones), defined as follows: for every atom a = p(t 1 , . . . , t k ) of Q, let us choose a bag B of T with π(a) = p(π(t 1 ), . On another note, it will turn out to be important, given a term t of Q, to keep track of the bag of T in which the term π(t) appeared first. We note π t T (t) = (B, π(t)) when the term π(t) appears first in the bag B of T . Similar to above, π t T gives rise to a partitioning of the terms of Q into term bags Bags t (Q) = {Q t 1 , . . . , Q t m }, where two terms u and v of Q are in the same term bag Q t i if and only if there exists a bag B with π t T (u) = (B, π(u)) and

π t T (v) = (B, π(v)).
From π a T and π t T , we then obtain the function π T mapping elements of Bags a (Q) ∪ Bags t (Q) to bags of T such that

π T = Q a → B where π a T (a) = (B, π(a)) for any a ∈ Q a Q t → B where π t T (a) = (B , π(t)) for any t ∈ Q t
We can now define the atom-term bags of Q (induced by π a T ) denoted by Bags at (Q). If an atom bag Q a and a term bag Q t have the same image under π T , we obtain an atom-term bag Q at = Q a ∪ Q t . If an atom bag Q a (or a term bag Q t ) has an image different from the image of any other term bag (or atom bag, respectively) of Q, then it is an atom-term bag by itself.

Finally, we provide these atom-term bags with a tree structure induced by the tree structure of T . Let Q at 1 and Q at 2 be two atom-term bags of

Q. Then Q at 2 is a child of Q at 1 iff (i) π T (Q at 2
) is a descendant of of π T (Q at 1 ) and (ii) there is no atom-term bag

Q at 3 of Q such that π T (Q at 3 ) is a descendant of of π T (Q at 1 ) and π T (Q at 2 ) is a descendant of of π T (Q at 3
). Note that since we only consider connected queries, the structure so created is indeed a tree (it could be a forest with disconnected queries). In what follows, we define an atom-term tree decomposition of a query by such a tree of atom-term bags, independently from T and π.

Definition 34 (APT of a Query). Let Q be a query. An atom-term partition of Q is a partition of atoms(Q) ∪ terms(Q) (these sets being called atom-term bags). An atom-term partition tree (APT) of Q is a tree whose nodes form an atom-term partition of Q. Definition 35 ((Valid) APT-Mapping). Let Q be an APT of Q. Let T be a derivation tree. An APT-mapping of Q to T is a tuple Γ = (Π, π 1 , . . . , π k ) where Π is an injective mapping from the atom-term bags of Q to the bags of T and, for each atom-term bag Q at i of Q, π i is a substitution from the terms of Q at i (by this, we mean the terms of Q at i , not the terms appearing in the atoms of Q at i ) to the terms that were created in the atoms of Π(Q at i ). Remark that if u is a term of Q, then u appears in only one atom-term bag Q at i of Q. We can thus define π Γ = 1≤i≤k π i .

x p i (x)

y s(x, y) z r(y, z) t s(z, t) u r(t, u) v r(x, v) Q at 0 Q at 1 Q at 2 Q at 3 Q at 4 Q at 5 Figure 10: An atom-term partition of Q i = p i (x) ∧ s(x, y) ∧ r(y, z) ∧ s(z, t) ∧ r(t, u) ∧ r(x, v)
Finally, we say that (Π, π 1 , . . . , π k ) is valid when π Γ is a homomorphism from Q to the atoms of T .

Example 18 (APT-Mapping). We now present a valid APT-Mapping of the APT pictured Figure 10 to the derivation tree represented in Figure 9.

We let

Π = {Q at 0 →B 0 , Q at 1 →B 4 , Q at 2 →B 5 , Q at 3 →B 6 , Q at 4 →B 7 , Q at 5 →B 1 }.
The corresponding mappings are: π 0 = {x →c}, π 1 = {y →z 1 }, π 2 = {z →z 2 }, π 3 = {t →z 3 }, π 4 = {u →z 4 }, and π 5 = {v →y 1 }. Then, (Π, π 1 , π 2 , π 3 , π 4 , π 5 ) is a valid APT-mapping of the APT from Figure 10 to the derivation tree from Figure 9.

Property 23 (Soundness and Completeness). Let F be a fact, R be a set of gbts rules, and Q be a query. Then F, R |= Q if and only if there exists a derivation sequence S from F to F k , an APT Q of Q, and a valid APT-mapping from Q to DT (S).

Proof. We successively prove both directions of the equivalence.

(⇐) Let us suppose that there exists a valid APT-mapping from Q to DT (S). From Definition 35, it follows that there is a homomorphism π from Q to the atoms of DT (S), i.e. a homomorphism π from Q to F k .

(⇒) If F, R |= Q, then there is a homomorphism π from Q to some F k obtained by means of a derivation S from F . As in the construction given before Definition 34, we can choose some mapping π a T of the atoms of Q, and build from this mapping an APT Q of Q. We can then build an APT-mapping (Π, π 1 , . . . , π k ) as follows: Π = π T , and for each Q at i of Q, π i is the restriction of π to the terms of Q at i . This APT-mapping is valid. This rather long and unnecessarily complicated way to prove the existence of a homomorphism will now be put to good use when querying the full blocked tree, without resorting to its potentially infinite development.

Validation of an APT in a blocked tree

Hence, let us now consider a blocked tree T b and some tree (T, f ) ∈ G(T b ) generated by it. Let us assume that we have an APT Q of a query Q that corresponds to a mapping to (T, f ). Thus, each bag Q at i of the APT is mapped to a bag B of T. Intuitively, we represent this mapping on the full blocked tree by mapping Q at i to B rep such that B rep = f (B) (i.e., B has been generated by copying B rep ). We can enumerate all such mappings: the question is then to validate such a mapping, that is, to check that it actually corresponds to a valid APT-mapping in a tree generated by the full blocked tree.

Definition 36 (Valid APT Mapping to a Blocked Tree). Let Q be an APT of a query Q and Γ = (Π, π 1 , . . . , π k ) be an APT-mapping from Q to a blocked tree T b (where Π maps atom-term bags of Q to bags of the blocked tree). Then Γ is said to be valid if there exists a tree (T, f ) ∈ G(T b ) generated from T b and a mapping Ξ from the atom-term bags of Q to the bags of (T, f ) (we then call ((T, f ), Ξ) a proof of Γ) such that:

• if Q at is the root of Q, then Ξ(Q at ) = Π(Q at ); • if Q at is a child of Q at in Q, then f (Ξ(Q at )) = Π(Q at ) and Ξ(Q at ) is a descendant of Ξ(Q at );
• The ADT mapping (Ξ, π 1 , . . . , π k ) is valid in T, where for every atom-term bag

Q at j in Q with Ξ(Q at j ) = B i , we define π j = ψ f (B i )→B i • π j .
Example 19 (APT-Mapping to a Blocked Tree). We now present a valid APT-Mapping of the APT represented Figure 10 to the derivation tree represented in Figure 9. We define

Π = {Q at 0 →B 0 , Q at 1 →B 4 , Q at 2 →B 5 , Q at 3 →B 6 , Q at 4 →B 3 , Q at 5 →B 1 }.
Here, the only difference with the previous APT-mapping is the image of Q at 4 , which is not B 7 (which does not exist in the blocked tree), but B 3 . This is reflected in the definition of the π i : π 0 = {x →c}, π 1 = {y →z 1 }, π 2 = {z →z 2 }, π 3 = {t →z 3 }, π 4 = {u →y 2 }, and π 5 = {v →y 1 }. Then, (Π, π 1 , π 2 , π 3 , π 4 , π 5) is a valid APT-mapping of the APT from Figure 10 to the blocked tree from Figure 8, as witnessed by the derivation tree of Figure 9, where the bag B 7 has been generated by B 3 .

Property 24 (Soundness and Completeness). Let F be a fact, R be a set of gbts rules, and Q be a query. Then F, R |= Q if and only if there exists an APT Q of Q, and a valid APT-mapping from Q to the full blocked tree of F and R.

Proof. We successively prove both directions of the equivalence.

(⇐) Let us suppose that there exists a valid APT-mapping from Q to the full blocked tree T b of F and R. From Definition 36, there exists a valid APT mapping from Q to a (T, f ) generated from T b , i.e., by Definition 22 a valid APT-mapping from Q to some derivation tree T having T as a prefix. We can conclude thanks to Property 23.

(⇒) If F, R |= Q, then there is a homomorphism π from Q to some F k obtained by means of a derivation S from F with derivation tree T = DT (S). As in the construction given before Definition 34, we can chose some mapping π a T of the atoms of Q, and build from this mapping an APT Q of Q. Now, in this particular π, the root of Q can be mapped to any bag B of the derivation tree DT (S). Since B has an equivalent bag B in the full blocked tree T b , there exists another homomorphism π from Q to some F k obtained by means of a derivation S . Let us recompute an APT Q (the same result might be obtained). Then (see proof of Property 23), there is a valid APT mapping Γ = (Π, π 1 , . . . , π k ) from Q to DT (S ), since DT (S) is a prefix tree of some T generated from T b . Γ is thus a valid APT mapping from Q to T.

Now let us define the mapping Ξ as follows

: if Q at is the root of Q, then Ξ(Q at ) = Π(Q at ), otherwise Ξ(Q at ) = f (Π(Q at )). For each term t in the atom term bag Q at i of Q such that Ξ(Q at i ) = B j , we define π i (t) = ψ B j →f (B j ) • π i . Let us consider the APT mapping Γ = (Ξ, π 1 , . . . , π k ) from Q to T b . It is immediate to check that Γ is valid.

A bounded validation for APT-mappings

Although Property 24 brings us closer to our goal to obtain an algorithm for gbts deduction, there is still the need to guess the generated tree (T, f ) used to validate an APT-mapping (Definition 36). We will now show that such a generated tree can be built in a backtrackfree manner by an exploration of the APT of the query. Then we establish an upper bound for each validation step (i.e., if we have validated an initial segment Q of the APT Q of Q, and Q at is a child of some bag Q at in Q , how do we validate Q ∪ {Q at }?).

Property 25. Let Q be an APT of Q, and Γ be a valid APT-mapping from Q to a blocked tree T b . Let Q be a prefix tree of Q, and Γ be the restriction of Γ to Q . Note that Γ is a valid APT-mapping from Q to T b .

Consider now any proof ((T , f ), Ξ ) of Γ (see Definition 36).9 Then, there exists a proof ((T , f ), Ξ ) of Γ such that ((T , f ), Ξ ) is a subproof of ((T , f ), Ξ ).

Proof. Let us consider a proof ((T , f ), Ξ ) of Γ . As shown in the proof of Property 24, this proof corresponds to a homomorphism π of Q to (T , f ). Now consider any leaf bag Q at of Q , that is the root of a tree in Q. Γ and Γ can map Q at to different bags in (T , f ) and (T, f ). However, these bags are equivalent (according to Definition 18) to the same bag in T b . So anything that can be mapped under one of these bags can be mapped in the same way under the other. In particular, the subtree rooted in Q at can be mapped in the same way under the bag of (T , f ). This construction leads to a homomorphism π from Q to some (T , f ) that extends π . Using again the proof of Property 24, this homomorphism can be used to build a proof ((T , f ), Ξ ) of Γ, that is a superproof of ((T , f ), Ξ ).

This latter property provides us with a backtrack-free algorithm for checking the validity of an APT-mapping. Basically, Algorithm 2 performs a traversal of the APT Q, while verifying whether Γ "correctly joins" each bag of Q with its already "correctly joined" parent.

Algorithm 2: ValidateAPT

Data: A blocked tree T b , an APT Q, and an APT-mapping Γ from Q to T b .

Result: yes if Γ is valid, no otherwise. Explored := ∅;

for i = 1 to |Q| do Q at := some bag of Q s.t. either (parent(Q at ), -) ∈ Explored, or Q at is the root of Q; if joins(Γ, Q at ) = ∅ then Explored := Explored ∪{(Q at , joins(Γ, Q at ))}; else return no;
return yes;

It remains now to explain the procedure joins that checks whether a valid APT-mapping of a subtree Q of Q can be extended to a child Q at ∈ Q \ Q of some bag of Q . Let us consider a proof ((T , f ), Ξ ) of Γ = (Π, π 1 , . . . , π k ) being a valid APT-mapping of Q . According to Def. 36 and Prop. 24, it is sufficient to:

• find a bag B n that can be obtained by a bag copy sequence B 1 , . . . , B n where B 1 = Ξ (parent(Q at )), B n is a bag equivalent to Π(Q at ), and for 1 < i ≤ n, B i is obtained by a bag copy (see Definition 20) under B i-1 . Since Π(Q at ) and B n are equivalent, there is a bijection from the terms of Π(Q at ) to the terms of B n , that we denote by ψ.

• it remains now to check that for every term t appearing in an atom of Q at , t is a term that belongs to a bag Q at in the branch from the root of Q to Q at , and Ξ (t) = ψ(π(t)) (where π is the mapping defined in the APT-mapping from the terms of Q at to those of Π(Q at )). In that case, the call to joins returns ψ • π, ensuring that we are able to evaluate the joins of the next bags.

We last prove that there exists a "short" proof of every valid APT-mapping.

Property 26. Let Q be an APT of Q, and Γ be a valid APT-mapping from Q to a blocked tree T b . There exists a proof ((T, f ), Ξ) of Γ such that for any two bags Q at i and Q at j from Q where Q at i is a child of Q at j , the distance between Ξ(Qat i ) and Ξ(Qat j ) in T is at most p×f f , where p is the number of abstract patterns, and f the maximum size of a rule frontier.

Proof. We prove the result by induction on the number of atom-term bags in Q. If Q has only one atom-term bag, the property is trivially true. Let us assume the result to be true for any APT-mapping whose APT is of size n, and let Q be a APT of size n + 1, and Γ be a valid APT-mapping of Q. Let Q at c be an arbitrary leaf of Q, let Q be equal to Q \ {Q c }, and let Γ be the restriction of Γ to Q . By induction assumption, there exists a proof ((T , f ), Ξ ) of Γ fulfilling the claimed property. By the proof of Property 25, this proof can be extended to a proof ((T, f ), Ξ), such that Q at c is mapped to a descendant of Ξ(Q at p ), where Q at p is the parent of Q at c in Q. Moreover, the provided construction allows to ensure that there are no two distinct bags B i and B j on the path from Ξ(Q at p ) to Ξ(Q at c ) fulfilling the following two conditions:

• f (B i ) = f (B j ); • ∀x ∈ X s , ψ B i →f (B i ) (x) = ψ B j →f (B j ) (x)
, where X s is the image of the set of variables that appear both in Q at c and Q .

Then the distance between Ξ(Q at p ) and Ξ(Q at c ) has to be less than p × f f . Indeed, X s should belong to the frontier of Ξ(Q at c ), by the running intersection property of T. There is at most f f ways of arranging these terms, thus providing the claimed upper-bound.

Complexity Analysis and Worst-Case Optimal Adaptation to Subclasses

We provide a worst-case complexity analysis of the proposed algorithm, and present some small modifications that can be adopted in order to make the algorithm worst-case optimal for relevant subclasses of rules. Table 3 provides a summary of the notation used for the complexity analysis. The overall algorithm deciding whether F, R |= Q can now be sketched as follows:

• build the full blocked tree T b of (F, R) (note that this is done independently of the query)

• for every APT Q of Q, for every APT-mapping Γ of Q to T b , if ValidateAPT returns yes, return yes (and return no at the end otherwise).

The first step is done linearly in the number of evolution and creation rules. There are at most p 2 evolution rules, and p 2 × b f creation rules. We thus need to upper-bound the number of abstract patterns. There are at most |R| × 2 a B subsets of rule bodies, and b t B For weakly guarded rules, we change the definition of pattern. Indeed, with this kind of rules, a rule application necessarily maps all the terms of a rule body to terms occurring in a single bag. This holds since every initial term belongs to every bag, and every variable of the rule body that could map to an existentially quantified variable is argument of the guard of the body of the rule. Thus, by storing all the possible mappings of a rule body atom (instead of all partial homomorphisms of a subset of a rule body), we are able to construct any homomorphism from a rule body to the current fact. The equivalence between patterns and the blocking procedure remains unchanged. Since there are at most b w such homomorphisms for an atom, the number of abstract patterns is bounded by 2 b w , which is a simple exponential since w is bounded. The algorithm thus runs in exponential time for weakly guarded rules with bounded arity.

If we consider only guarded frontier-one rules, the number of possible homomorphisms decreases. Indeed, the set of atoms whose terms are included in a given bag is upper-bounded by a H + s.t H : the atoms that have been created at the creation of the bag, plus atoms that may be created afterwards. However, these atoms must be of the from r(x, . . . , x), since the considered rules are frontier-one, hence at most s.t H . This results in a simply exponential number of patterns, which provides the claimed upper-bound.

For frontier-guarded rules (and its subclasses), we slightly modify the construction of the decomposition tree. Indeed, in the original construction, every term of the initial fact is put in every bag of the decomposition tree. However, by putting only the constants appearing in a rule head as well as every instantiation of terms of the head of the rule creating the bag (that is, we do not put all initial terms in every bag), a correct tree decomposition would also be built, and the size of the bags (except for the root) would not be dependent of the initial fact any more. The number of patterns is then upper-bounded by 1 + 2 |R|×2 a B ×t t B H . When R is fixed, this number is polynomial in the data. Given that Q is fixed, we get the PTime upper-bound.

Matching Lower Complexity Bounds for gbts Subclasses

We now provide the missing hardness results to fully substantiate all complexity results displayed in Figure 1 and Table 1.

Data Complexity of Guarded Frontier-One Rules is PTime-hard

PTime hardness for gfr1 rules is not hard to establish and follows from known results (for instance, the description logic EL is subsumed by gfr1 rules and known to have PTime-hard data complexity). For the sake of self-containedness, we will give a direct reduction from one of the prototypical PTime problems: entailment in propositional Horn logic.

Theorem 28. CQ entailment under constant-free gfr1 rules is PTime-hard for data complexity.

Proof. Given a set H of propositional Horn clauses, we introduce for every propositional atom a occurring therein a constant c a . We also introduce one additional constant nil . Moreover, for every Horn clause C ∈ H with C = a 1 ∧ . . . ∧ a n → a, we introduce constants b C,1 , . . . , b C,n and let F consist of entails(b C,1 , c a ), first(b C,i , c a i ) for all i ∈ {1, . . . , n}, as ⇒ Assume to the contrary that F T ∪ F p 1 p 2 , R fix |= match does not hold, thus we find a model of F T ∪ F p 1 p 2 , R fix where match is false. We then can use this model to construct a model of T not satisfying ∀x(p 1 (x) → p 2 (x)) using the following defining equation for every p i ∈ Pr 1 :

∀x(p i (x) ↔ in(x, c p i )).
It can be readily checked that this model indeed satisfies T . Moreover it satisfies p 1 (a) but not p 2 (a), therefore ∀x(p 1 (x) → p 2 (x)) does not hold.

⇐ Assume to the contrary that T |= ∀x(p 1 (x) → p 2 (x)) does not hold, i.e. we find a model of T not satisfying ∀x(p 1 (x) → p 2 (x)) (i.e., in this model there must be one element e in the extension of p 1 but not of p 2 ). We now use this model to define a model of F T ∪ F p 1 p 2 , R fix by adding to the domain a new element c p i for every p i ∈ Pr 1 and let the interpretation function on the eponymous constants be the identity. The interpretation of the predicates typeA, . . . , typeE is as explicitly stated in F T , the interpretation of the in predicate is defined as the minimal set such that

∀x(p i (x) ↔ in(x, c p i ))
holds for all p i ∈ Pr 1 . Finally, we let sub hold for c p 1 , we let super hold for c p 2 , and we let test hold for a, where the constant a is mapped to the domain element e mentioned above. Then it can be easily checked that the obtained model satisfies all of F T ∪ F p 1 p 2 , R fix but not match.

Theorem 33 (Data Complexity of wgfr1 Rules). BCQ-Entailment under constant-free wgfr1 rules is ExpTime-hard for data complexity.

Proof. By Theorem 29, unary subsumption checking for reduced normalized Horn-ALC [Pr 2 ] terminologies is ExpTime-hard. By Lemma 32 and thanks to Proposition 31, any such problem can be polynomially reduced to a CQ entailment problem F, R |= q for uniform R and q. Consequently, the data complexity of conjunctive query entailment under wgfr1 rules must be ExpTime-hard as well.

Combined Complexity of Frontier-One Rules is 2ExpTime-hard

In this section, we show that fr1 rules are 2ExpTime-hard for combined complexity no matter whether predicate arity is bounded or not. Our proof reuses the general strategy and many technical tricks from a construction used to show 2ExpTime-hardness for CQ entailment in the DL ALCI from [START_REF] Lutz | Inverse roles make conjunctive queries hard[END_REF]. Still, many adaptations were done in order to make the construction fit our language fragment and to simplify unnecessarily complicated parts.

We prove the desired result via a reduction of CQ entailment w.r.t. fr1 rules to the word problem of an alternating Turing machine with exponential space, which will be formally introduced next.

Definition 39. An alternating Turing machine M, short ATM, is a quadruple (Q, Γ, q 0 , ∆) where:

• Q is the set of states10 , which can be partitioned into existential states Q ∃ and universal states Q ∀ .

• Γ is a finite alphabet, containing the blank symbol ,

• q 0 ∈ Q is the initial state,

• ∆ ⊆ Q × Σ × Q × Σ × {L, R} is the transition relation.
A configuration of an ATM is a word wqw where w, w ∈ Γ * and q ∈ Q. The successor configurations ∆(wqw ) of a configuration wqw are defined as:

∆(wqw ) = {vq γ γ v | w = vγ , w = γv , (γ, q, γ , q , L) ∈ ∆} ∪ {wγ q v | w = γv , (γ, q, γ , q , R) ∈ ∆} ∪ {wγ q | w = , ( , q, γ , q , R) ∈ ∆}.
The set of indirect successors of a configuration wqw is the smallest set of configurations that contains wqw and that is closed under the successor relation.

A halting configuration is of the form wqw with ∆(wqw ) = ∅. The set of accepting configurations is the smallest set of configurations such that:

• wqw is accepting if there exists vq v ∈ ∆(wqw ) is accepting in case of q ∈ Q ∃ ,
• wqw is accepting if all vq v ∈ ∆(wqw ) are accepting in case of q ∈ Q ∀ .

An ATM is said to accept a word w ∈ Γ * , if q 0 w is accepting. An ATM is exponentially space bounded if for any w ∈ Γ * , every indirect successor vqv of q 0 w satisfies that |vv | < 2 |w| .

According to (Chandra, Kozen, & Stockmeyer, 1981b), there is an exponentially space bounded ATM M * , whose word problem is 2ExpTime-hard. In order to simplify our argument, we will, however, not directly simulate a run of this Turing machine on a word w. Rather, given M * and a word w it is straightforward to construct an ATM M * w such that M * accepts w exactly if M * w accepts the empty word .11 Clearly, the size of M * w is polynomially bounded by n = |w|.

In the following, we will thus show how, given an exponentially space bounded ATM M and a word w, we can construct a fact F , rule set R and query Q -the size of all being polynomially bounded by n -such that F, R |= q iff M * w = (Q, Γ, q 0 , ∆) accepts the empty word. Thereby, the minimal model of F and R will contain elements representing the initial and all its (indirect) successor configurations. These configurations will themselves be endowed with a tree structure that stores the content of the exponentially bounded memory. The most intricate task to be solved will be to model memory preservation from one configuration to its successors.

We start by introducing some predicates and their intuitive meaning:

• conf : unary predicate to distinguish elements representing configurations from other elements;

• firstconf : unary predicate to denote the initial configuration;

• trans δ with δ ∈ ∆: set of binary predicates. trans δ connects a configuration with its successor configuration that was introduced due to δ;

• state q with q ∈ Q: set of unary predicates indicating the state of the configuration wqw ;

• symbol γ with γ ∈ Γ: set of unary predicates indicating the symbol at the heads current position, i.e. symbol γ holds for the configuration wqγw ;

• accepting: unary predicate indicating if a configuration is accepting;

• wire binary predicate used later for memory operations;

• fw unary predicate used later for memory operations.

We are now ready to provide first constituents of the fact F and of the rule set R. We let F contain the facts: {conf (init), firstconf (init), state q 0 (init)}.

(

) 1
For every δ = (q, γ, q , γ , D) ∈ ∆ (with D ∈ {L, R}), let R contain:

state q (x)∧symbol γ (x) → trans δ (x, y)∧wire(x, u)∧fw (u)∧wire(u, v)∧fw (v)∧wire(v, y) (2)

trans δ (x, y) → conf (y)∧state q (y) (3)
Clearly, by means of these rules, we create the successor configurations y reached from a transition predicate from given configuration x. The additionally introduced sequence " wire -→ u wire -→ v wire -→" between x and y will come handy later for memory preservation purposes. Figure 11 displays the structure of the configuration tree thus constructed.

Next we take care of the implementation of the acceptance condition for configurations. For every q ∈ Q ∃ and every δ = (q, γ, q , γ , D) ∈ ∆, we add the rule:

trans δ (x, y) ∧ accept(y) → accept(x). (4)
For every q ∈ Q ∀ and γ ∈ Γ, we add the rule: δ=(q,γ,q ,γ ,D)∈∆ trans δ (x, y δ ) ∧ accept(y δ ) → accept(x).

(

This way, as required, acceptance is propagated backward from successors to predecessors.

Consequently, the query to be posed against the "computation structure" described by our rule set should ask if the initial configuration is accepting, i.e.:

Q = accept(init). (6)
Next, we prepare the implementation of the memory access. To this end, we encode the position of the head (that is, the length of the word w) in a configuration wqw as an n-digit binary number (note that this allows us to address 2 n positions which is sufficient for the required exponential memory). We will use unary predicates hbit k , lbit k with 1 ≤ k ≤ n for the following purpose: hbit k holds for an element representing a configuration wqw , if the kth bit of the configuration's head position (i.e. the number |w|) expressed in binary format is 1. If the bit is 0, then lbit k holds instead.

Clearly, the initial position of the head is 0 (as we start from configuration q 0 w), thus for the initial configuration (represented by init) all bits must be 0. Hence we let F M,w contain lbit k (init) for all 1 ≤ k ≤ n.

In the course of a state transition δ = (q, γ, q , γ , D) ∈ ∆, the head's position may be increased by one (in case D = R) or decreased by 1 (in case D = L). The next rules implement this behavior, hence given a configuration's head position, they effectively compute the head position of this configuration's direct successors. For every δ = (q, γ, q , γ , D) ∈ ∆ with D = R we let R M,w contain the rules (where k ranges from 1 to n and m ranges from 1 to k):

trans δ (x, y) ∧ l≤k hbit l (x) → lbit k (y) (7) trans δ (x, y) ∧ lbit k (x) ∧ l<k hbit l (x) → hbit k (y) (8) trans δ (x, y) ∧ lbit k (x) ∧ lbit m (x) → lbit k (y) (9) trans δ (x, y) ∧ hbit k (x) ∧ lbit m (x) → hbit k (y) (10)
and for every δ = (q, γ, q , γ , D) ∈ ∆ with D = L we let R M,w contain the rules (ranges of k and m as above):

trans δ (x, y) ∧ l≤k lbit l (x) → hbit k (y) (11) trans δ (x, y) ∧ hbit k (x) ∧ l<k lbit l (x) → lbit k (y) (12) trans δ (x, y) ∧ hbit k (x) ∧ hbit m (x) → hbit k (y) (13) trans δ (x, y) ∧ lbit k (x) ∧ hbit m (x) → lbit k (y) (14)
In the next steps, we need to implement the exponential size memory of our Turing machine. At the same time, the memory should be "accessible" by polynomial size rule bodies. Thus we organize the memory as a binary tree of polynomial depth having exponentially (that is 2 n ) many leaves. Thus, for every configuration element, we create a tree of depth n having the configuration element as root and where the configuration's tape content is stored in the leaves. We use the following vocabulary:

• level k with 0 ≤ k ≤ n: set of unary predicates stating for each node inside the memory tree its depth.

• leftchild , rightchild : the two (binary) child predicates of the memory tree.

• child : a (binary) predicate subsuming the two above.

• entry γ with γ ∈ Γ: set of unary predicates indicating for every leaf of the memory tree the symbol stored there.

We now create the memory tree level by level (with k ranging from 1 to n):

conf (x) → level 0 (x) (15)
level k-1 (x) → leftchild (x, y) ∧ child (x, y) ∧ wired (x, y) ∧ wired (y, x) ∧ level k (y) ( 16) The leaf nodes of the memory tree thus created (i.e., the elements satisfying level n ) will be made to carry two types of information: (a) the current symbol stored in the corresponding tape cell and (b) the tape cell's "address" in binary encoding. The latter will be realized as follows: if the kth bit of the binary representation of the address is clear, the leaf node ν will be extended by a structure containing two newly introduced elements ν 1 and ν 2 which will be connected with ν via the following binary predicates: start k (ν, ν), wired (ν, ν 1 ), wired (ν 1 , ν 2 ), and end k (ν 2 , ν). In case the kth bit is set, we will also introduce new elements ν 1 and ν 2 but they will be connected with ν in a different way, namely: start k (ν, ν 1 ), wired (ν 1 , ν), wired (ν, ν 2 ), and end k (ν 2 , ν). The reason for this peculiar way of encoding the address information will become apparent in the sequel. Figure 12 depicts the structure of the memory tree constructed under each configuration tree.

level k-1 (x) → rightchild (x, y) ∧ child (x,
The following rules realize the aforementioned address representation, exploiting the fact that the kth address bit will be 0 if the considered leaf node's ancestor on level k -1 is connected with the ancestor on level k via leftchild and it will be 0 if the connection is via rightchild . Hence we let R M,w contain the rules (with k ranging from 1 to n as above):

leftchild (x k-1 , x k ) ∧ n i=k+1 (child (x i-1 , x i )) ∧ level n (x n ) → start k (x n , x n ) ∧ wired (x n , x n ) ∧ wired (x n , x n ) ∧ end k (x n , x n ) (19) rightchild (x k-1 , x k ) ∧ n i=k+1 (child (x i-1 , x i )) ∧ level n (x n ) → start k (x n , x n ) ∧ wired (x n , x n ) ∧ wired (x n , x n ) ∧ end k (x n , x n ) (20)
One of the purposes of the previous construction is to mark in each memory tree the leaf corresponding to the current head position by a unary predicate head and all other leaves by another unary predicate nohead . To this end, we encode the head position stored in the configuration elements via the predicates lbit k and hbit k in a "structural way", similar to our encoding in the leaves:

lbit k (x) → rootstart k (x, x) (21) hbit k (x) → rootstart k (x, x ) ∧ wired (x , x) (22)
For the assignment of head and nohead to leaf nodes, we now exploit two facts. First, the kth bit of the head address -stored in a configuration element ν c -and the kth bit of the address of a leaf node ν l of the same configuration element coincide, if there are nodes ν 1 , . . . , ν n-1 such that there is a path

ν c rootstart k -→ ν 1 wired -→ . . . wired -→ ν n-1 end k -→ ν l ;
moreover, no other two nodes are connected by such a path. Secondly, the kth bit of the two nodes differ if there are nodes ν 1 , . . . , ν n such that there is a path

ν c rootstart k -→ ν 1 wired -→ . . . wired -→ ν n end k -→ ν l ;
moreover, no other two nodes are connected by such a path (to see this, note that wired goes both ways inside the tree whence it is possible to make a back-and-forth step where necessary).

This allows us to assign head to all leaf nodes where a path of the first kind exists for every k as expressed by the following rule: 23) Likewise, we can assign nohead to all leaf nodes where a path of the second kind exists for some k, thus we add for every k ranging from 1 to n a separate rule of the following kind:

n k=1 rootstart k (x, x k,1 ) ∧ n-2 i=1 wired (x k,i , x k,i+1 ) ∧ end k (x k,n-1 , y) → head (y). (
rootstart k (x, x 1 ) ∧ n-1 i=1 wired (x i , x i+1 ) ∧ end k (x n , y) → nohead (y). ( 24
)
Now that we have an indicator of the head position in the memory tree, we can enforce that every configuration element is indeed assigned the symbol γ predicate whenever the symbol γ is found at the current head position:

n-1 i=0 child (x i , x i+1 ) ∧ symbol γ (x n ) ∧ head(x n ) → symbol γ (x 0 ). ( 25
)
The last bit of the alternating Turing machine functionality that needs to be taken care of is memory evolution: a symbol stored in memory changes according to the transition relation if and only if the head is at the corresponding position. In our encoding this means that for all nohead -assigned leaf nodes of a configuration's memory tree, their stored symbol has to be propagated to the corresponding leaf nodes of all direct successors' memory trees. Again we exploit structural properties to connect the corresponding leaf nodes of two subsequent configurations' memory trees:

Let ν c and ν c be two configuration elements such that ν c represents a direct successor of ν c . Let ν l be a leaf node of ν c 's memory tree and let ν l be a leaf node of ν c 's memory tree. Let the kth bit of ν l 's address and the kth bit of ν l 's address coincide. Then -and only then -there are nodes ν 1 , . . . , ν 2n+6 such that there is a path

ν l start k -→ ν 1 wired -→ . . . wired -→ ν 2n+6 end k -→ ν l
where fw holds for ν n+3 .

This justifies to transfer the stored symbol from any non-head-leaf to all leaf nodes to which it is simultaneously connected by such paths for every k:

n k=1 start k (x, x k,1 ) ∧ 2n+5 i=1 wired (x k,i , x k,i+1 ) ∧ end k (x k,2n+6 , y) ∧ n k=1 fwd (x k,n+3 ) ∧ symbol γ (x) ∧ nohead (x) → symbol γ (y). (26)
Of course, we also need to take care to assign the proper symbol (which is determined by the transition by which the current configuration has been reached) to the leaf node of the previous configuration's head position. To this end, we add for every δ = (q, γ, q , γ , D) ∈ ∆ the rule

head (x) ∧ n k=1 start k (x, x k,1 ) ∧ 2n+5 i=1 wired (x k,i , x k,i+1 ) ∧ end k (x k,2n+6 , z n ) ∧ n k=1 fwd (x k,n+3 ) ∧ trans δ (z, z 0 ) ∧ n-1 i=0 child (z i , z i+1 ) → symbol γ (z n ). (27)
Finally, we have to ensure that the initial configuration and its memory tree carry all the necessary information. We have to initialize the head position address to 0 by adding to F the facts {lbit 1 (init), . . . , lbit n (init)}.

(28)

Moreover, all tape cells initially contain the blank symbol , which we achieve by extending R by the rule

firstconf (x 0 ) ∧ n-1 k=0 child (x k , x k+1 ) → symbol (x n ). ( 29
)
Concluding, we have just built F , R and Q with the desired properties. Moreover, R consists of only fr1 rules and does not contain any constant. This concludes our argument that the combined complexity of CQ entailment over fr1 rules is 2ExpTime-hard, even in the case where no constants show up in the rules.

Theorem 34. Conjunctive query entailment for constant-free fr1 rules with bounded predicate arity is 2ExpTime-hard.

Combined Complexity of Weakly Guarded Frontier-One Rules is 2ExpTime-hard

Our last hardness result will be established along the same lines as the preceding one, namely by a reduction from the word problem of an alternating Turing machine with exponential space. In fact, we will also reuse part of the reduction and arguments presented in the previous section. In particular, we assume everything up to formula (14) as before except for the following modifications:

• Remove from Rule (2) all atoms built from the predicates wire and fw .

• Replace the Rule ( 5) with the following rules:

for every δ = (q, γ, q , γ , D) ∈ ∆ the rule

trans δ (x, y) ∧ accept(y) → accept δ (x) -the rule δ=(q,γ,q ,γ ,D)∈∆ accept δ (x) → accept(x)
Thereby, we introduce a fresh predicate accept δ for every δ = (q, γ, q , γ , D) ∈ ∆.

Clearly this set of rules has the same consequences as the previous Rule ( 5), however it consists merely of gfr1 rules.

This puts the ATM's "state space" and transition relations into place. Now we turn to the task of encoding the exponential tape. As opposed to the previous encoding, we now exploit that we can use predicates of arbitrary arity. Thus, for every γ ∈ Γ we introduce an n+1-ary predicate ontape γ where the first n positions are used for the binary encoding of a tape address and the n+1st position contains the configuration element that this tape information refers to. Our encoding will ensure that the first n positions of these predicates are non-affected. Likewise we will use n+1-ary predicates head and nohead to store for each tape position of a configuration if the ATM's head is currently in that position or not. For this purpose, we introduce auxiliary constants to encode whether address bits are high, low, or unknown. Thus we add to F the following atoms: high(1), bit [START_REF](z 1 , z 2 ) ∧ in(x, z 1 ) → in[END_REF], low(0), bit(0). Now, for every k we introduce a binary predicate bit k (whose second position is nonaffected) with the intention to let bit k (x, 0) hold whenever lbit k (x) holds and to also have hbit k (x) imply bit k (x, 1), which is achieved by the following two rules:

lbit k (x) ∧ low(z) → bit k (x, z), hbit k (x) ∧ high(z) → bit k (x, z).
Moreover, we make sure that the binary encoding of the head position's address that we find attached to the configuration elements through the bit k predicates is transferred into the head predicate as stated above:

conf (x) ∧ n k=1 bit k (x, z k ) → head(z 1 , . . . , z n , x).
Additionally, we make sure that for all other binary addresses z 1 . . . z n the according nohead atoms hold, by adding for every i in the range from 1 to n the rule conf (x) ∧ bit i (x, w) ∧ other(w, z i ) n k=1 bit(z k ) → nohead(z 1 , . . . , z n , x).

Furthermore, we have to ensure that the symbol γ found at any configuration's head position (expressed by the corresponding ontape γ atom) is also directly attached to that configuration by the according unary symbol γ atom:

head(z 1 , . . . , z n , x) ∧ ontape γ (z 1 , . . . , z n , x) → symbol γ (x).
Also, the symbol γ written to the tape at the previous configuration's head position as a result of some transition δ can be realized easily:

head(z 1 , . . . , z n , x) ∧ trans δ (x, y) → ontape γ (z 1 , . . . , z n , x)
On the other hand, all previous nohead-positions of the tape will keep their symbol, as made sure by the rules (for all γ ∈ Γ): nohead(z 1 , . . . , z n , x) ∧ ontape γ (z 1 , . . . , z n , x) ∧ trans δ (x, y) → ontape γ (z 1 , . . . , z n , y).

To ensure that the initial configuration and its tape carry all the necessary information, we initialize the head position address to 0 by adding to F , as in the previous section, the facts: {lbit 1 (init), . . . , lbit n (init)}.

(30)

To make sure that all tape cells initially contain the blank symbol , we extend R by the rule:

firstconf (x) ∧ n k=1 bit(z k ) → ontape (z 1 , . . . , z n , x). (31)
Concluding, we have just built F , R and Q with the desired properties. Moreover, R consists of only wgfr1 rules. Thus we arrive at the desired theorem.

Theorem 35. The combined complexity of CQ entailment over constant-free wgfr1 rules of unbounded arity is 2ExpTime-hard.

Body-Acyclic fg and fr1 Rules

In this section, we study the complexity of frontier-guarded rules with an acyclic body. The acyclicity notion considered here is a slight adaptation of hypergraph acyclicity stemming from database theory. We will show that body-acyclic fg rules coincide with guarded rules: indeed, a body-acyclic fg rule can be linearly rewritten as a set of guarded rules, and a guarded rule is a special case of body-acyclic rule.

Let us consider the hypergraph naturally associated with a set of atoms S: its set of nodes is in bijection with terms(S) and its multiset of hyperedges is in bijection with S, with each hyperedge being the subset of nodes assigned to the terms of the corresponding atom.

To simplify the next notions, we first proceed with some normalization of a set of fg rules, such that all rules have an empty frontier (so-called "disconnected rules" [START_REF] Baget | Walking the Decidability Line for Rules with Existential Variables[END_REF]) or a "variable-connected" body:

1. Let R be a fg rule with a non-empty frontier and let B be the hypergraph associated with body(R). Split each node in B assigned to a constant into as many nodes as hyperedges it belongs to (thus each constant node obtained belongs to a single hyperedge); let B be the hypergraph obtained; let C f be the connected component of B that contains the frontier guard(s); if there are several frontier guards, they are all in C f .

Let

R 0 = B \ C f → p 0 , where p 0 is a new nullary predicate. 3. Let R f = C f ∪ {p 0 } → head(R).
Let (F, R, Q) be an instance of the entailment problem, where R is a set of fg rules. All non-disconnected rules from R are processed as described above, which yields an equivalent set of fg rules. Let us denote this set by R disc ∪ R , where R disc is the set of disconnected rules, i.e., initial disconnected rules and obtained rules of form R 0 . The rules in R disc are integrated into F as described in [START_REF] Baget | Walking the Decidability Line for Rules with Existential Variables[END_REF], which can be performed with |R disc | calls to an oracle solving the entailment problem for fg rules. Briefly, for each

R d = (B d , H d ) ∈ R disc , it is checked whether F, R |= B d : if yes, H d is added to F and R d is removed from R disc ; the process is repeated until stability of R disc . Let F the fact obtained: for any BCQ Q, F, R |= Q iff F , R |= Q.
From now on, we thus assume that all fg rules have a non-empty frontier and their body is "variable-connected", i.e., the associated hypergraph is connected and cannot be disconnected by the above step 1.

The acyclicity of a hypergraph H is usually defined with respect to its so-called dual graph, whose nodes are the hyperedges of H and edges encode non-empty intersections between hyperedges of H. We define below a notion close to the dual graph, that we call decomposition graph of a set of atoms. In a decomposition graph, guarded atoms are grouped together with one of their guard into a single node, and constants are not taken into account in atom intersections (it follows that the associated acyclicity notion is slightly more general than hypergraph acyclicity).

Definition 40 (Decomposition Graph). Let S be a set of atoms. A decomposition graph of S is an undirected labeled graph D S = (V, E, atoms, vars), where V is the set of nodes, E is the set of edges, atoms and vars are labeling mappings of nodes and of edges respectively, such that:

• Let {C 1 , . . . C p } be a partition of S such that in each C i there is an atom that guards the other atoms of C i , with p being minimal for this property. Then V = {v 1 , . . . v p } and for

1 ≤ i ≤ p, atoms(v i ) = C i . • For 1 ≤ i, j ≤ p, i = j, there is an edge v i v j if C i and C j share a variable; vars(v i v j ) = vars(C i ) ∩ vars(C j ).
Several decomposition graphs can be assigned to S, however they have all the same structure and the same labeling on edges. The only difference between them comes from the choice of a guard when an atom is guarded by several guards with incomparable sets of variables. Now, considering the decomposition graph instead of the dual graph, the acyclicity of a set of atoms is then defined similarly to that of a hypergraph.

Definition 41 (Acyclicity of an Atom Set, Body-Acyclic fg Rule). Let S be a set of atoms and D S be a decomposition graph of S. An edge v i v j in D S is said to be removable if there is another path λ between v i and v j in D S such that for each each edge v k v l in λ, vars(v i v j ) ⊆ vars(v k v l ). An acyclic covering of S is a forest obtained from D S by removing removable edges only. S is said to be acyclic if has an acyclic covering. An fg rule R is said to be body-acyclic (ba) if body(R) is acyclic.

Example 20. Let S = {p 1 (x), p 2 (x, u), p 2 (y, z), p 3 (y, z, u), p 2 (u, v), p 3 (u, v, x)}. D S has set of nodes {v 1 , v 2 , v 3 }, with atoms(v 1 ) = {p 1 (x), p 2 (x, u)}, atoms(v 2 ) = {p 2 (y, z), p 3 (y, z, u)} and atoms(v 3 ) = {p 2 (u, v), p 3 (u, v, x)},
and all edges between these nodes, with vars(v

1 v 2 ) = vars(v 2 v 3 ) = {u} and vars(v 1 v 3 ) = {x, u}. An acyclic covering of S is obtained by removing edge v 1 v 2 or v 2 v 3 .
Let us point out that a set of atoms is acyclic according to the above definition if and only if the associated existentially closed conjunctive formula belongs to the guarded fragment of first-order logic (see acyclic guarded covering in [START_REF] Kerdiles | Saying it with Pictures: a logical landscape of conceptual graphs[END_REF] and [START_REF] Chein | Graph-based Knowledge Representation and Reasoning-Computational Foundations of Conceptual Graphs[END_REF] for details about this equivalence). Note also that the decomposition graph associated with the body of a guarded rule is restricted to a single node. Thus, guarded rules are trivially ba-fg rules.

Given a set of atoms S, checking whether it is acyclic, and if so, outputing one of its acyclic coverings can be performed in linear time (from [START_REF] Maier | The Theory of Relational Databases[END_REF] about the computation of a join tree in databases).

Let R be a variable-connected ba-fg rule and let T be an acyclic covering of body(R), which is thus a tree. Let {v 1 , ..., v p } be the nodes in T and let v r be a node such that atoms(v r ) contains a frontier guard. T is considered as rooted in v r , which yields a direction of its edges from children to parents: a directed edge (v i , v j ) is from a child to its parent. R is translated into a set of guarded rules {R 1 , . . . R p } as follows:

• To each edge (v i , v j ) is assigned the atom a i = q i (vars(v i v j )), where q i is a new predicate;

• To each node v i , i = r, is assigned the rule:

R i = atoms(v i ) ∪ {a k |v k child of v i } → a i • To the node v r is assigned the rule: R r = atoms(v r ) ∪ {a k |v k child of v r } → head(R)
Note that this translation is the identity on guarded rules.

Example 20

(Contd.) Let R = p 1 (x) ∧ p 2 (x, u) ∧ p 2 (y, z) ∧ p 3 (y, z, u) ∧ p 2 (u, v) ∧ p 3 (u, v, x) → head(R
= p 1 (x) ∧ p 2 (x, u) → q 1 (x, u) R 2 = p 2 (y, z) ∧ p 3 (y, z, u) → q 2 (u) R 3 = p 2 (u, v) ∧ p 3 (u, v, t) ∧ q 1 (x, u) ∧ q 2 (u) → head(R)
Property 36. Guarded rules and ba-fg rules are semantically equivalent in the following sense: a guarded rule is a ba-fg rule and any set of ba-fg rules can be translated into a semantically equivalent set of guarded rules.

The above translation is polynomial in the size of the rule and arity-preserving. Thus, complexity results on guarded rules apply to ba-fg rules. In particular ba-fg rules are ExpTime-complete for bounded-arity combined complexity, while fg rules are 2ExpTimecomplete.

Actually the ExpTime lower bound already holds for combined complexity with arity bounded by 2. Indeed, standard reasoning in the much weaker description logic reduced normalized Horn-ALC (cf. Section 5.2), which is a fragment of ba-gfr1 rules with maximal arity of 2, is already ExpTime-Hard, as cited in Theorem 29. It follows that ba-gfr1 rules are ExpTime-Hard for bounded-arity in combined complexity. One could have expected bafrontier-1 rules to be simpler than ba-fg rules. In fact, they have the same data complexity and the same bounded-arity combined complexity. The only remaining question, for which we have no answer yet, is whether they are simpler in the unbounded arity case.

Finally, let us point out that the acyclicity of rule bodies alone is not enough to guarantee a lower complexity, and even decidability: that the head of a rule shares variables with only one node of the decomposition graph (thus, that the frontier is guarded) is crucial. Without this assumption, the entailment problem remains undecidable. 12

Related Work

In this section, discuss the relationship of the existential rule fragments considered here with another major paradigm in logic-based knowledge representation: description logics. Also, we will point out similarities of the techniques applied in the presented algorithm with reasoning approaches established for other logics.

Relationships to Horn Description Logics and their Extensions

The relationship of description logics and existential rules has often been recognized. In particular Horn-DLs [START_REF] Hustadt | Data complexity of reasoning in very expressive description logics[END_REF][START_REF] Krötzsch | Complexity Boundaries for Horn Description Logics[END_REF][START_REF] Krötzsch | Complexities of Horn description logics[END_REF]) share many properties with existential rules such as the existence of a (homomorphically unique) canonical model. Crucial differences between the two approaches are that (1) as opposed to DLs, existential rules allow for predicates of arity greater than two as well as for the description of non-tree shaped terminological information and (2) as opposed to existential rules, expressive DLs allow for a tighter integration of cardinality constraints to a degree (at least currently) unachieved by existential rules.

In the following, we will point out which Horn-DLs are subsumed by which existential rules fragments. We will refrain from providing full translations and restrict ourselves to examples that provide the underlying intuition.

The description logic EL essentially allows for encoding implications of tree-shaped substructures in a model. For instance the statement "Everybody who has a caring mother and a caring father has a nice home" can be expressed by the EL axiom ∃hasMother .Caring ∃hasFather .Caring ∃hasHome.Nice which is equivalent to the existential rule hasMother (x, y) ∧ Caring(y) ∧ hasFather (x, z) ∧ Caring(z) → hasHome(x, w) ∧ Nice(w).

Horn-ALC is more expressive than EL in that it allows to express some sort of universal quantification such as in "Whenever some caring person has children, all of them are happy" denoted by Caring ∀hasChild which corresponds to the existential rule Caring(x) ∧ hasChild (x, y) → Happy(y).

It is not hard to see that the Horn-DLs EL and Horn-ALC are captured by fr1 rules; they can even be linearly rewritten into gfr1 rules when auxiliary predicates are allowed (as it is often done when normalizing DL knowledge bases). This still holds when these DL languages are extended by inverses (indicated by adding an I to the name of the DL: ELI, Horn-ALCI) and/or nominals (indicated by adding an O). In the latter case, constants must occur in the rules). For instance, the ELIO proposition "Everybody who is born in Germany likes some soccer team which has a member who is also a member of the the German national team", written in DL notation ∃bornin.{germany} ∃likes.(SoccerTeam ∃hasM ember.∃hasM ember -.{gnt})

, in existential rules form bornin(x, germany) → likes(x, y)∧SoccerTeam(y)∧hasM ember(y, z)∧hasM ember(gnt, z)

Role hierarchies (H), allow to express generalization/specialization relationships on binary predicates (such as fatherOf implying parentOf ). Adding this feature to any of the abovementioned description logics requires to use rules with frontier size 2 and leads outside the frontier-one fragment. Still a linear translation into g rules remains possible. 13 . Going further to DLs that feature functionality or transitivity of binary predicates leads to existential rule fragments which are not longer guarded in any way considered here. The definition of existential rule fragments capturing these expressive description logics is subject of ongoing research.

Diverse proposals have been made to overcome the structural restrictions of DLs, i.e. to allow to express non-tree-shaped relationships in the terminological knowledge. Description graphs [START_REF] Motik | Representing ontologies using description logics, description graphs, and rules[END_REF]) constitute one of these endeavors, where the existentially quantified structure in the head of a DL axiom is allowed to be arbitrarily graph-shaped and, additionally, there are datalog rules operating locally on these graph structures. It is straight-forward that the extension of any DL up to Horn-ACLHIO by description graphs can be coded into g existential rules.

Another suggestion made to allow for non-tree shaped structures in both body and head of a DL axiom is to introduce DL-safe variables, that is, variables that are only allowed to be bound to "named individuals" (i.e., domain elements denoted by constants). In a setting where each statement can carry either exclusively safe variables or exclusively non-safe ones, this can be captured by the notion of DL-safe rules [START_REF] Motik | Query answering for OWL DL with rules[END_REF]. A more liberal approach is that of the so-called nominal schemas [START_REF] Krötzsch | A better uncle for owl: nominal schemas for integrating rules and ontologies[END_REF][START_REF] Krötzsch | Nominal schemas in description logics: Complexities clarified[END_REF], where the two types of variables can occur jointly in the same statement. In both cases, the wg fragment captures these extensions when applied to DLs up to Horn-ALCHIO. Note that there is a direct correspondence between non-affected positions in existential rules and DL-safe variables: both can only carry domain elements corresponding to elements present in the initial data.

Pattern-or Type-Based Reasoning

For many logics, reasoning algorithms as well as related complexity arguments are based on the notion of types. On an intuitive level, types represent "configurations" which may occur in a model. In the easiest case (as in some description logics), such configurations might be sets of unary predicates {p 1 , . . . , p n }, where {p 1 , . . . , p n } occurring in a model just means that there is an individual a that is in the extension of every p i . More complex notions of types may refer to more than just one individual, leading to notions like 2-types, also known as dominoes [START_REF] Rudolph | Type-elimination-based reasoning for the description logic SHIQb s using decision diagrams and disjunctive datalog[END_REF]), star-types (Pratt-Hartmann, 2005), mosaics (Blackburn, van Benthem, & Wolter, 2006), or types based on trees [START_REF] Rudolph | Nominals, inverses, counting, and conjunctive queries or: Why infinity is your friend![END_REF]. Often, reasoning in a logic can be carried out by only considering the (multi-)set of types that are realized in a model. Typical reasoning strategies may then compute the set of these types bottom-up (as in tableaux with anywhere-blocking ), topdown (as in type-elimination-based procedures), or describe their multiplicity by means of equational systems. The applicability of such strategies guarantees decidability whenever the overall set of possible types is finite. It is not hard to see that, in our case, abstract patterns can be seen as "graph types" where the bound on the tree-width and the finiteness of the vocabulary guarantee the finiteness of the set of types, and therefore the effectiveness of the applied blocking strategy.

Consequence-Driven Reasoning

Our idea of the saturation of pattern rules in Section ... has many similarities with the approach of consequence-driven reasoning in description logics. In both cases, logical sentences that are consequences of a given theory are materialized. To see this, one should be aware that every evolution rule P 1 P 2 corresponds to an existential rule It can then be readily checked that the deduction calculus presented in Fig. 5 is indeed sound. As such, the presented algorithm has indeed similarities with type-based consequence driven reasoning approaches as, e.g., layed out by [START_REF] Kazakov | Consequence-driven reasoning for horn-SHIQ ontologies[END_REF] and [START_REF] Ortiz | Worst-case optimal reasoning for the Horn-DL fragments of OWL 1 and 2[END_REF][START_REF] Rudolph | Foundations of description logics[END_REF]. The crucial difference here is that the mentioned works use only 1-types, whereas the patterns defined characterize larger "clusters" of elements.

Tableaux and Blocking

It is well-known that the chase known from databases has many commonalities with the semantic tableau method in FOL [START_REF] Beth | Semantic entailment and formal derivability[END_REF][START_REF] Smullyan | First-order logic[END_REF], which has also been used in many other logics, most notably DLs [START_REF] Baader | An overview of tableau algorithms for description logics[END_REF][START_REF] Horrocks | A tableau decision procedure for SHOIQ[END_REF]. Note that the generic semantic tableaux for first order logic only gives rise to a semidecision procedure. In order to obtain a decision procedure for a restricted logic, termination needs to be guaranteed, typically through establishing a tree(-like) model property and the detection of repetitions in the course of the tableaux construction, leading to the idea of blocking as soon as repeating types occur (depending on the expressivity of the logic, 1-types, 2-types or even larger types have to be considered). Clearly, the blocking technique used by us in the construction of the full blocked tree can be seen as a pattern-based anywhere blocking.

Relationships to other work on guarded existential rules

As already mentioned, guarded and weakly-guarded rules were introduced in [START_REF] Calì | Taming the Infinite Chase: Query Answering under Expressive Relational Constraints[END_REF][START_REF] Calì | A General Datalog-Based Framework for Tractable Query Answering over Ontologies[END_REF]Calì, Gottlob, & Kifer, 2013). A fundamental notion used to bound the depth of the breadth-first saturation (with a bound depending on R and Q) is that of the type of a guard atom in the saturation (a guard atom in α ∞ (F, R) is the image of a rule guard by a rule application, and the type of an atom a is the set all atoms in α ∞ (F, R) with arguments included in terms(a)). This notion has some similarities with our bag patterns, without being exactly the restriction of bag patterns to the guarded case.

The notion of affected position/variable was refined into that of jointly affected position/variable in [START_REF] Krötzsch | Extending Decidable Existential Rules by Joining Acyclicity and Guardedness[END_REF]. This yields the new classes of jointly guarded rules and jointly frontier-guarded rules, which respectively generalize wg rules and wfg rules. Since these new classes are gbts, our results apply to them. In particular, the data and combined complexities of jointly frontier-guarded rules directly follow from those of gbts and wfg : ExpTime-complete data complexity, and 2ExpTime-complete combined complexity (in both bounded and unbounded predicate arity cases). Since wg rules have the same complexities as wfg rules for data complexity and combined complexity with bounded arity, these complexities also apply to jointly guarded rules; for combined complexity with unbounded arity, the bounds are not tight (ExpTime-hardness from the result on wg and 2ExpTime-membership from the result on wfg ). Note that [START_REF] Krötzsch | Extending Decidable Existential Rules by Joining Acyclicity and Guardedness[END_REF]) also provides a further generalization, namely glut frontier-guarded, which is bts, but not gbts nor fes.

Combinations of the gbts family with other families of rules have been proposed, by restricting possible interactions between rules of the different kinds. In (Baget et al., 2011), conditions expressed on the strongly connected components of a graph of rule dependencies allow to combine gbts, fes and fus sets of rules. In [START_REF] Gottlob | Combining decidability paradigms for existential rules[END_REF], a notion called tameness allows to combine guarded rules with sticky rules (an expressive fes concrete class of rules) by restricting the interactions between the sticky rules and the guard atoms in the guarded rules.

Finally, let us cite some very recent work related to the guarded family of existential rules. The expressiveness of the wg and wfg fragments was studied in [START_REF] Gottlob | Expressiveness of guarded existential rule languages[END_REF]. Other work has analyzed the complexity of entailment with guarded rules extended with disjunction [START_REF] Bourhis | The impact of disjunction on query answering under guarded-based existential rules[END_REF] or with stable negation [START_REF] Gottlob | Stable model semantics for guarded existential rules and description logics[END_REF].

Combined Approach

The combined approach [START_REF] Lutz | Conjunctive Query Answering in the Description Logic EL Using a Relational Database System[END_REF][START_REF] Kontchakov | The combined approach to query answering in DL-lite[END_REF], designed for EL and the DL-Lite familly, share some similarities with our approach. The combined approach is a two-step process. First, some materialization is performed. In order to ensure finiteness of this step, an over-specialization of the canonical model is thus computed. This over-specialization requires thus a rewriting of the query, in order to recover soundness. This rewriting may require the ontology. By comparison, our approach computes a materialization that is less specific than the saturation. It is thus the completeness that has to be recovered, through a change of the querying operation, which is not a simple homomorphism anymore, but is based on the notion of APT-homomorphism.

Conclusion

We have introduced the notion of greedy bounded-treewidth sets of existential rules that subsumes guarded rules, as well as their known generalizations, and gives rise to a generic and worse-case optimal algorithm for deciding conjunctive query entailment. Moreover, we have classified known gbts subclasses with respect to their combined and data complexities.

The existential rule framework is young and combines techniques from different research fields (such as databases, description logics, rule-based languages). A lot of work is still to be done to deepen its understanding, design efficient algorithms and develop its applications.

It remains an open question whether gbts is recognizable. We conjecture that the answer is yes. However, even if this question is interesting from a theoretical viewpoint, we recall that gbts is not more expressive than wfg , and furthermore, any gbts set of rules can be polynomially translated into a wfg set of rules, while preserving entailment (Section 3). Moreover, we built a reduction from the entailment problem, where R is fg and constantfree, to the problem of checking if some rule set R is gbts (this reduction is not included in this paper, since it is only one step in the study of the recognizability issue). Hence, we know that determining if some rule set is gbts is significantly harder than for wfg , where this check can be done in polynomial time.

Future work will aim at adding rules expressing restricted forms of equality and of useful properties such as transitivity into this framework, while preserving decidability, and the desirable PTime data complexity of fg rules.

We have shown in Section 4.6 that the PatSat algorithm can be adapted to run with optimal worst-case complexity for fragments of the gbts family. An important research line is the optimization, implementation and practical evaluation of this algorithm and its variants. To the best of our knowledge, currently existing prototypes processing existential rules follow a backward chaining approach, which involves rewriting the query into a union of CQs; hence, termination of the query rewriting process is ensured on fus rules (Gottlob, Orsi, & Pieris, 2014a;[START_REF] König | Sound, complete and minimal ucq-rewriting for existential rules[END_REF]

Figure 1 :

 1 Figure 1: Existential rule fragments, their relative expressiveness, and complexities.

Property 4 . 2 }

 42 For any set R of existential rules, τ (R) is wfg . Proof. R same \ {R same is guarded. R same 2 is fg . No rule affects the position in the unary predicate initial , thus all affected variables in R same 2 are guarded by the atom with predicate samebag, hence τ (R) is wfg .

Figure 4 :

 4 Figure 4: The derivation tree associated with Example 8

  e., atoms(B c ). If b i is not empty, by definition of the initial pattern, P init (B c ) contains (b i , π c ), where π c is the restriction of π to terms(b i ). If b i-1 is not empty, by hypothesis (completeness of P (B p ) w.r.t. F i-1 ), P p contains (b i-1 , π p ), where π p is the restriction of π |b i-1 to the inverse image of terms(B p ). If b i-1 or b i is empty, (sb R , π ) belongs to J(P init (B c ), P (B p )). Otherwise, consider J((b i , π c ), (b i-1 , π p )): it is equal to (sb R , π ). Property 9 (Completeness of Join-Based Propagation). Assume that (DT (S), P ) is complete w.r.t. F i-1 , and P (B c ) is computed by J(P init (B c ), P (B p )). Let d(B) denote the distance of a bag B to B c in (DT (S), P ). Updating a bag B consists in performing J(P (B), P (B )), where B is the neighbor of B s.t. d(B ) < d(B). Let (DT (S), P ) be obtained from (DT (S), P ) by updating all patterns by increasing value of d of the corresponding bags. Then (DT (S), P ) is complete w.r.t. F i .

  a bag in T, and B = f (B); let B r be the representative of the ∼-class containing B (i.e., B r = B if B is blocked) and let B c be a child of B r . If B has no child mapped to B c by f , let T new be obtained from T by copying B c under B (according to ψ B r →B ), which yields a new bag B c . Then (T new , f ∪ (B c →B c )) belongs to G(T b ).

Figure 5 :

 5 Figure 5: Deduction calculus for the pattern saturation rules. For the first deduction rule, R ∈ R ∪ {→ F }, π is a homomorphism from fr(R) to terms(support(P)) such that (body(R), π) ∈ P, and σ is the fusion of fr(R) induced by π.

Figure 6 : 1 •

 61 Figure 6: A graphical representation of P b,c 1

1 Figure 7 :

 17 Figure 7: Graphical representation of the rule P b,c 1

Figure 8 :

 8 Figure 8: The full blocked tree associated with F ex and R ex . B 2 and B 6 are equivalent, as well as B 3 and B 5 .

  . . , π(t k )) ∈ B, and define π a T (a) = (B, π(a)). Then π a T gives rise to a partitioning of the atoms of Q into atom bags Bags a (Q) = {Q a 1 , . . . , Q a n }, where two atoms a and b of Q are in the same atom bag Q a i if and only if there exists a bag B of T with π a T (a) = (B, π(a)) and π a T (b) = (B, π(b)).

Figure 10

 10 Figure 10 represents an APT of the example query Q i .

Figure 11 :

 11 Figure 11: Structure of the configuration tree in the constructed model.

Figure 12 :

 12 Figure 12: Structure of the memory tree in the constructed model.

  ), with fr(R) = {u, v}. Consider the acyclic covering with set of nodes {v 1 , v 2 , v 3 }, with atoms(v 1 ) = {p 1 (x), p 2 (x, u)}, atoms(v 2 ) = {p 2 (y, z), p 3 (y, z, u)} and atoms(v 3 ) = {p 2 (u, v), p 3 (u, v, x)}, and set of edges {v 1 v 3 , v 2 v 3 }. On has vars(v 1 v 3 ) = {u} and vars(v 1 v 3 ) = {x, u}. v 3 is the root. The obtained guarded rules are: R 1

Table 1 :

 1 Considered classes with syntactic properties.

	syntactic	non-affected non-frontier at most one
	properties	variables	variables	frontier
		must be	must be	variable that
	class (abbrv)	guarded	guarded	needs guarding
	guarded frontier-one rules (gfr1)	yes	yes	yes
	guarded rules (g )	yes	yes

Table 2 :

 2 Combined and Data Complexities

	Class	arity	arity	Data
		unbounded bounded	Complexity
	Datalog ExpTime	NP	PTime
	gfr1	ExpTime	ExpTime	PTime
	g	2ExpTime	ExpTime	PTime
	fr1	2ExpTime	2ExpTime	PTime
	fg	2ExpTime	2ExpTime	PTime
	wgfr1	2ExpTime	ExpTime	ExpTime
	wg	2ExpTime	ExpTime	ExpTime
	wfr1	2ExpTime	2ExpTime	ExpTime
	wfg	2ExpTime	2ExpTime	ExpTime
	gbts	2ExpTime	2ExpTime	ExpTime

class. Section 4 is devoted to an algorithm for entailment with gbts and to the associated complexity results. The next sections consider increasingly simpler classes, namely fg and fr1 (Section 5) and body-acyclic fg /fr1 rules (Section 6); several reductions are provided, which provide tight lower bounds and allow to completely classify these classes for data and combined complexities. Related work is reviewed in Section 7.

  which is both in terms(B 0 ) and terms(B 1 ), B 2 is thus added as a child of the highest bag, i.e., B 0 . R can be applied again, with homomorphisms π 3 = {x →b, y →z 1 } and π 4 = {x →d, y →z 2 }, which leads to create two bags, B 3 and B 4 , under B 1 and B 2 respectively. Clearly, applications of R can be repeated indefinitely.

  3: Illustration of Example 6 Property 2. Let S = F 0 . . . , F k be a greedy derivation. Then DT (S) is a tree decomposition of F k of width bounded by |vars(F )| + |C| + max(|vars(head(R))| R∈R ).The class gbts is a strict subclass of bts and does not contain fes (e.g., in Example 4: R is fes but not gbts). It is nevertheless an expressive subclass of bts since it contains wfg : Property 3. Any set of wfg rules is gbts.

	Definition 8 (Greedy Bounded-Treewidth Set of Rules (gbts)). R is said to be a greedy
	bounded-treewidth set (gbts) if (for any fact F ) any R-derivation (of F ) is greedy.

  1 if P 1 P 2 .Lemma 18. Let P 1 and P 2 be two abstract patterns such that P 1 P 2 . For any rule P

			P	π |σ(fr(R)) .P init (B(R, σ))	Prop. 11
	P 1	P 1 λ.Join l (P 1 , λ, P 2 ) λ.P 2	Prop. 12		P 1	P 1 Join u (P 1 , λ, P 2 ) λ.P 2	Prop. 13
			P 1	P 2 P 2 P 1 P 3	P 3	Prop. 14
	P 1	P 2 P 1 P 2 λ.P 3	λ.P 3		Prop. 15	P 1	λ.P 2 P 2 P 1 λ.P 3	P 3	Prop. 16

1 P 1 (resp. P 1 λ.P 1 ) in the pattern saturation, there exists a rule P 2 P 2 (resp. P 2 λ.P 2 ) in the pattern saturation such that P 1 P 2 .

Table 3 :

 3 Notations used in the complexity analysis

	Notation	Signification
	b	upper-bound on the number of terms in any abstract pattern
	q	number of atoms plus number of terms in the query
	f	maximum size of a rule frontier
	a B	maximum number of atoms in a rule body
	a H	maximum number of atoms in a rule head
	t B	maximum number of terms in a rule body
	t H	maximum number of terms in a rule head
	|R|	number of rules
	p	number of abstract patterns
	w	maximum arity of a predicate
	s	number of predicates appearing in the rule set
	4.6.1 Complexity of the algorithm

In this paper, we reserve the term ontology to general domain knowledge-sometimes also called terminological knowledge-in order to clearly distinguish it from the factual data-or assertional knowledge.

2. CQ answering in the context of DLs was first mentioned by[START_REF] Levy | CARIN: A representation language combining Horn rules and description logics[END_REF], with the first publication focusing on that subject by[START_REF] Calvanese | On the decidability of query containment under constraints[END_REF].

Beside the profiles based on DL-Lite and EL, there is a third OWL 2 tractable profile, OWL 2 RL, which can be seen as a restriction of Datalog.

The DL constructor called existential restriction (∃R.C) is fundamental in these DLs. The logical encoding of an axiom that contains ∃R.C in its right-hand side requires an existentially quantified variable in the corresponding rule head. For instance, the rule from Example 1 can be seen as the logical translation of the DL axiom Human ∃hasP arent.Human.

Rudolph, Thomazo, Baget, & Mugnier

Note that hereby we generalize the classical notion of a (ground) fact in order to take existential variables into account. This is in line with the notion of a database instance in database theory, where the existentially quantified variables are referred to as labeled nulls.

Note that, technically, we abuse a abstract pattern as a non-abstract pattern here, but this is not a problem since no safe renaming is necessary for the (pattern of) bag F .

Note that this proof ((T , f ), Ξ ) is not necessarily a subproof of the existing proof ((T, f ), Ξ) of Γ (i.e., (T , f ) is not necessarily an initial segment of (T, f ) and Ξ is not necessarily the restriction of Ξ).

Q (with possible subscripts) is used for state sets in order to avoid a notational clash with conjunctive queries denoted by Q.

Such a machine can be easily obtained: add new states and transitions that first write w to the tape, second go back to the starting position, and third switch to the initial state of the original Turing machine.

See for instance[START_REF] Baget | The Complexity of Rules and Constraints[END_REF], which provides a reduction from the word problem in a semi-Thue system, known to be undecidable, to the CQ entailment problem with existential rules (in a conceptual graph setting): this reduction yields existential rules with predicate arity bounded by 2, a body restricted to a path and a frontier of size 2.

It might, however, be noteworthy that it is possible to come up with a polynomial translation into gfr1 rules by materializing the subsumption hierarchy of the binary predicates upfront and, whenever a binary atom is created by a rule "creating" all the subsumed atoms at the same time.

Acknowledgments

Michaël Thomazo aknowledges support from the Alexander von Humboldt foundation.

rules are sound. It also creates a complete blocked tree, and thus a full blocked tree, as will be proven below.

Intuitively, the following property states that for any derivation tree associated with an R-derivation of F , there exists an isomorphic tree generated by T * b (F, R).

Property 20. Let F be a fact, R be gbts. Let S be an R-derivation of F and let (DT(S), P )

be the according patterned derivation tree with root B root . Let T * b (F, R) be the corresponding full blocked tree with pattern-assigning function P T * b and root B root

Then there exists a tree decomposition T generated from T * b (F, R) via a mapping f , such that there exists a bijection g from the bags of (DT(S), P ) to the bags of T that satisfies the following conditions:

, i.e., g maps the root of (DT(S), P ) to the root of T * b (F, R);

)) for all bags B of (DT(S), P ); 3. for all bags B, B of (DT(S), P ) for which B is a child of B with induced link λ, g(B )

is a child of g(B) with induced link λ.

Proof. We prove the property by induction on the length of S.

• If S is the empty derivation, its derivation tree is restricted to a single bag labeled by F . Such a tree can be generated from T * b (F, R), and the pattern of B root

is the root of T, is by construction greater than the initial pattern of the original fact.

• Let us assume that the property is true for all derivations of length n ≥ 0, and let us show that it also holds for any derivation of length n + 1. Let S be a derivation of length n + 1, and let S n be its restriction to the n first rule applications. Let B n+1 be the bag newly created in DT(S), and B n its parent. By induction hypothesis, there exist g, T n and f n fulfilling the conditions from 1 to 3 for S n . Let us consider f n (B n ). By condition 2, we know that P (f n (g n (B n ))) is greater than P (B n ). By Lemma 18, f n (g n (B n )) has a child B * n+1 whose pattern includes that of B n+1 and has induced link λ with f n (g n (B n )). By definition of a tree generated from a blocked tree, it holds that T n+1 can be generated from T * b (F, R) via f n+1 , where:

-T n+1 is obtained from T n by copying B * n+1 under g(B n ); we additionally define this bag as being g(B n+1 );

By induction hypothesis, it holds that g(B root ) = B root T ; Condition 1 is thus fulfilled. By construction of g(B n+1 ), Condition 3 also. It remains to check Condition 2. This is not trivial, since the patterns of a bag in the fact associated with S n and with S may be non-equivalent (i.e., the pattern may have "grown"). Let us assume that there exists a bag B * such that P (B * )

Let us moreover assume that B * is (one of) the closest such bag to B n+1 . Let us first notice that it cannot be B n+1 . Indeed, P (B n+1 ) is obtained by performing a join operation between its initial pattern and P Sn (B n ). By induction hypothesis, P (B n )

). Thus, by Properties 11 and 12, the pattern saturation contains a rule allowing to create a child of g(B n ) whose pattern includes P S (B n+1 ) and having induced link λ. Thus B * is not B n+1 , and by Property 9, P (B * ) is obtained by performing a join between P Sn (B * ) and P (B * k ), where B * k is the unique bag on the path from B n+1 to B * that is either a child or a parent of B * . Let us consider the case where B * k is a parent of B * (the other case is similar). By induction hypothesis, P Sn (B * )

. By construction of T * b (F, R) and of its generated tree, there is a rule P 1 λ.P 2 in the pattern saturation with

. Moreover, since this rule is a most informative rule (by construction of T * b (F, R)), Join l (P 1 , λ, P 2 ) P (f (g(B * ))). However, by monotonicity of the join operation, this would imply that P (B * ) P T * b (f (g(B * ))), hence a contradiction.

By preceding observations and Property 20, we are now able to state that Algorithm 1 is correct, as expressed by the next theorem.

Theorem 21. Algorithm 1 outputs a full blocked tree.

Before turning to the more involved querying operation, let us stress that this first algorithm already provides a tight upper-bound for the combined complexity of query answering under gbts rules. Indeed, the problem is already known to be 2ExpTime-hard, since guarded rules -whose 2ExpTime combined complexity was already shown [START_REF] Calì | Taming the Infinite Chase: Query Answering under Expressive Relational Constraints[END_REF], are a particular case of gbts rules. mappings from terms of a rule body to terms of a bag. An abstract pattern being a subset of the cartesian product of these two sets, the number of abstract patterns is upper-bounded by

The first step is thus done in double exponential time, which drops to a single exponential when the set of rules is fixed. Note that only this first step is needed in the first version of the algorithm, where the query was considered as a rule, which yields the proof of Theorem 22.

The second step can be done in N Q × N Γ × N V where:

• N Q is the number of APTs of a query Q of size q, and N Q = O(q q ) (the number of partitions on the atoms and terms of Q, times the number of trees that can be built on each of these partitions);

• N Γ is the number of APT mappings from one APT (of size q) to the full blocked tree.

The size of the full blocked tree is O(pb f ) and thus

• N V is the cost of Algorithm 2 that evaluates the validity of the APT. It performs at most q joins, and each one generates at most O(p × f f ) bags (see Property 26).

The second step of our algorithm thus operates in O(q q × p q × b f q × q × p × f f ). The querying part is thus polynomial in p (the number of patterns), and simply exponential in q and in f . Since p is in the worst-case double exponential w.r.t. F and R, the algorithm runs in 2ExpTime. Last, given a (nondeterministically guessed) proof of Γ, we can check in polynomial time (if R and F are fixed) that it is indeed a valid one, yielding: Theorem 27. CQ entailment for gbts is NP-complete for query complexity.

Thereby, the lower bound comes from the well-known NP-complete query complexity of plain (i.e., rule-free) CQ entailment.

Adaptation to relevant subclasses

We now show how to adapt the algorithm to the subclasses of gbts that have smaller worstcase complexities. This is done by slightly modifying the construction of the full blocked tree, allowing its size to be simply exponential or even polynomial with respect to the relevant parameters. We consider three cases:

• (weakly) guarded rules, whose combined complexity in the bounded arity case drops to ExpTime,

• guarded frontier-one rules, whose combined complexity in the unbounded arity case drops to ExpTime,

• guarded, frontier-guarded and frontier-1 rules, whose data complexity drops down to PTime.

well as rest(b C,n , nil ), and rest(b C,i , b C,i+1 ) for all i ∈ {1, . . . , n -1}, also let F contain entailed (nil ). Then the propositional atom a is entailed by H exactly if F, R |= Q with Q = entailed(c a ) and R containing the rules:

first(y, z) ∧ entailed (z) ∧ rest(y, z ) ∧ entailed (z ) → entailed (y), entailed (y) ∧ entails(y, z) → entailed (z).

Combined Complexity of Guarded Frontier-One Rules is ExpTime-hard

We prove ExpTime-hardness of CQ entailment under gfr1 rules by showing that any standard reasoning task in the description logic Role-Bounded Horn-ALC, for which ExpTimehardness is known [START_REF] Krötzsch | Complexity Boundaries for Horn Description Logics[END_REF][START_REF] Thomazo | Conjunctive Query Answering Under Existential Rules-Decidability, Complexity, and Algorithms[END_REF], can be polynomially reduced to the considered problem. We start by defining this problem. In order to avoid syntactic overload, we will stick to first-order logic syntax and refrain from using the traditional description-logic-style notation.

Definition 37 (Role-Bounded Horn-ALC). Let Pr 1 an infinite set of unary predicates and let Pr 2 be a finite set of binary predicates. A reduced normalized Horn-ALC[Pr 2 ] terminology T is a set of rules having one of the following shapes (with p 1 , p 2 , p 3 ∈ Pr 1 and r ∈ Pr 2 ):

We refer to the problem of deciding if for some T and p 1 , p 2 ∈ Pr 1 holds T |= ∀x(p 1 (x) → p 2 (x)) as unary subsumption checking.

Theorem 29 [START_REF] Krötzsch | Complexities of Horn description logics[END_REF], Section 6.2.). There is a finite set Pr 2 such that unary subsumption checking for reduced normalized Horn-ALC [Pr 2 ] terminologies is ExpTimehard.

The following corollary is now a straightforward consequence.

Corollary 30. CQ entailment under constant-free gfr1 rules is ExpTime-hard for combined complexity.

Proof. Clearly, given a reduced normalized Horn-ALC[Pr 2 ] terminology T and p 1 , p 2 ∈ Pr 1 , the unary subsumption entailment T |= ∀x(p 1 (x) → p 2 (x)) is to be confirmed if and only if F, R |= Q with F = {p 1 (a)}, R = T and Q = p 2 (a). The latter can be conceived as a CQ entailment problem of the desired type, since T is a gfr1 rule set. Note that our line of argumentation actually does not require the set Pr 2 to be fixed, however, this will be a necessary precondition in the next section where we use the same logic, hence we have introduced the logic in this form from the beginning.

Data Complexity of Weakly Guarded Frontier-One Rules is ExpTime-hard

We will now show that the data complexity for deciding CQ entailment under wgfr1 rules is ExpTime-hard. Again, we obtain the result by showing that a Horn-ALC [Pr 2 ] reasoning problem can be reduced to CQ entailment under wgfr1 rules but this time even with fixed rule set and query.

Definition 38. Given a set Pr 2 , let R fix be the fixed wgfr1 rule set containing the following rules (where r ranges over all elements of Pr 2 ):