1 Introduction

The problem of answering conjunctive queries [1, 90] over logical constraints is at the heart of knowledge representation and database research. This problem can be reduced to that of Boolean conjunctive query (BCQ) answering by instantiating free variables in conjunctive queries with facts from databases. Problems in many fields of computer science such as constraint satisfaction problems [34, 63], homomorphism problems [26] and query evaluation and containment problems [26] can be recast as Boolean conjunctive query answering problems [91]. Our interest in this paper is to develop practical methods and inference systems that can provide the basis for the following problems:

  • answering BCQs for the guarded, the loosely guarded and the clique-guarded fragments, and

  • saturation-based rewriting of BCQs for these guarded fragments.

The guarded fragment (GF) and the loosely guarded fragment (LGF) are introduced in [3, 97] as generalised modal fragments of first-order logic (FOL). In a guarded formula the free variables of quantified formulas are ‘guarded’ by an atom. Strictly extended from GF, the loosely guarded fragment LGF, which is also known as the pairwise guarded fragment [4, 97], pairwise ‘guards’ the free variables of quantified formulas using a conjunction of atoms. This conjunction is called a loose guard where the variables form a ‘clique’. Further LGF has been extended to the clique-guarded fragment (CGF) [45], in which the ‘cliques’ are extended with branches. In [55, 65] CGF is called the packed fragment. A common characteristic of GF, LGF and CGF is that the free variables of quantified formulas need to be guarded; therefore we collectively refer to these fragments as the guarded quantification fragments. These fragments are decidable and have well-behaved computational properties [3, 28, 45, 46, 55, 56, 65, 97]. Figure 1 shows the relationship between the guarded quantification fragments, (negated) BCQs targeted in this paper and FOL.

Fig. 1
figure 1

The relationship of the guarded quantification fragments, (negated) BCQs and first-order logic

The computational complexity of the BCQ answering problem for GF is 2ExpTime-complete [12]. For LGF and CGF the complexity of the BCQ answering problem is also 2ExpTime-complete, as in both cases the problem is reducible to the satisfiability checking problem of the clique-guarded negation fragment [11].Footnote 1 Figure 2 lists important known properties of the guarded quantification fragments where ✓ and ✗ respectively denote positive and negative results. In the Satisfiability checking column of Fig. 2, we assume that the fragments have a fixed signature.

Fig. 2
figure 2

Known properties of the guarded quantification fragments

Resolution-based procedures have been devised for deciding satisfiability in GF in [29, 39] and for LGF in [29, 39, 98]. Tableau-based procedures have been devised for deciding satisfiability in GF [54] and CGF [53]. However, querying poses a major problem, since neither BCQ nor its negation belongs to the guarded quantification fragments (see Fig. 1). Indeed, so far it appears that there has been no effort to extend these methods to solving the BCQ answering problems for any of the guarded quantification fragments, even if the aforementioned complexity results mean that in theory, these querying problems are decidable. Introducing new techniques, this paper develops decision procedures to answer BCQs for all the guarded quantification fragments. Our initial work for solving the BCQ answering problem for Horn LGF was published in [98] and for GF was published in [99].

Figure 3 illustrates the idea of our query answering procedure. Given a set \(\varSigma \) of rules, a dataset D and a BCQ q, checking whether \(\varSigma \cup D \models q\) is equivalent to checking unsatisfiability of \(\{\lnot q\} \cup \varSigma \cup D\). To decide \(\{\lnot q\} \cup \varSigma \cup D\), we transform it into a clausal form. In particular, \(\varSigma \) and D are mapped to loosely guarded clauses and \(\lnot q\) to query clauses. To perform the saturation process we develop a novel top-variable inference system. This system ensures termination when we perform resolution inferences on loosely guarded clauses and query clauses.

Fig. 3
figure 3

Saturation-based BCQ answering processing of a set of guarded quantification formulas \(\varSigma \), a dataset D and a BCQ q

Conventional BCQ rewriting tasks aim to reduce a BCQ entailment problem to a model checking problem: one first compiles a BCQ q and a set \(\varSigma \) of formulas into a (function-free) first-order formula \(\varSigma _q\), and then applies a model checking algorithm to \(\varSigma _q\) over datasets [24, 32, 48]. If this reduction is possible, then q and \(\varSigma \) are called first-order (FOrewritable. Counter-examples in [13, 14] imply that this property does not hold for BCQs for any of the guarded quantification fragments. To address this problem, we introduce a new setting of saturation-based query rewriting. This rewriting reduces the query answering problem \(\varSigma \cup D \models q\) to the entailment problem \(D \models \varSigma _q\), where \(\varSigma _q\) is a first-order formula. Our query rewriting method pre-saturates the clausal form of \(\{\lnot q\} \cup \varSigma \) and does it in such a way that this pre-saturation can be restored to a first-order formula \(\varSigma _q\). Using our method, any dataset D can be tested against the pre-saturation, but it is also possible to use other reasoning methods such as the chase algorithm [2, 64] to solve the entailment checking of \(D \models \varSigma _q\). Figure 4 outlines our saturation-based query rewriting procedure, which applies the saturation process to the rules and the query but not the dataset, and back-translates the saturation to a first-order formula \(\varSigma _q\).

Fig. 4
figure 4

Saturation-based BCQ rewriting processing of a set of guarded quantification formulas \(\varSigma \) and a BCQ q

This result is of independent interest to automated reasoning, as back-translating a clausal set that includes inferred conclusions, to a first-order formula typically fails, as in general this problem is undecidable [37]. Using results established in [33] that a clausal set can be back-translated into a first-order formula if the clausal set satisfies certain properties, we devise a query rewriting procedure that ensures a successful back-translation. To distinguish our query rewriting setting from the traditional ones, we refer to our approach as saturation-based query rewriting.

To provide a basis for implementation, our query answering and rewriting approaches are devised in line with the resolution framework of [8], which provides the basis for powerful saturation-based theorem provers such as E [83], SPASS [95], Vampire [75] and Zipperposition [27] and a lot of work in automated reasoning [31, 73, 81, 84, 93].

In a nutshell, the contributions of this paper are:

  • Inference systems for deciding BCQ answering for GF, LGF and CGF, dedicated to provide the basis for practical decision procedures.

  • A novel saturation-based BCQ rewriting approach for GF, LGF and CGF.

  • Improvements on existing resolution-based decision approaches for GF and LGF, and the first resolution-based approach for deciding CGF.

  • Novel saturation-based resolution inference systems, namely a partial selection-based resolution system and a top-variable resolution system, with formal soundness and refutational completeness proofs for first-order clausal logic.

  • Our procedures are applicable to answer and rewrite BCQs for real-world ontological languages such as guarded, loosely guarded, and clique-guarded Datalog\(^\pm \) and the description logic \({\mathcal {ALCHOI}}\).

  • Novel aspects of our approach include but are not limited to: the separation rules, the partial selection-based and top-variable resolution rules, the clausification processes and the back-translation procedure. These techniques may allow decision and querying problems for other fragments to be solved in the future.

The remainder of this paper is organised as follows. Section 2 formally defines basic notions of first-order logic, the guarded quantification fragments and the research questions. Section 3 reduces the BCQ answering problem for the targeted guarded fragments to an unsatisfiability checking problem of loosely guarded clauses and query clauses. Section 4 presents the partial selection-based resolution system and the top-variable resolution system. Section 5 then proves that the top-variable system decides satisfiability of the class of loosely guarded clauses. Section 6 tackles query clauses by introducing the separation rules and formula renaming. Combining the results from the previous sections, Sect. 7 devises a BCQ answering procedure for the guarded quantification fragments. Section 8 develops a saturation-based BCQ rewriting procedure for these guarded fragments. Sections 9 and 10 discuss related work and conclude the paper, respectively.

2 Basic Notions, Guarded Fragments and the Querying Problems

2.1 Basic Notions

Let \(\texttt{C}\), \(\texttt{F}\) and \(\texttt{P}\) be countably infinite sets that are pairwise disjoint. The elements in \(\texttt{C}\)\(\texttt{F}\) and \(\texttt{P}\) are constant symbols (or constants), function symbols and predicate symbols. A predicate symbol of arity zero is a propositional variable. We refer the triple \((\texttt{C}, \texttt{F}, \texttt{P})\) as a signature. A term is either a constant, or a variable, or it has the form of \(f(t_1, \ldots , t_n)\) if i) f is a function symbol of arity n and ii) \(t_1, \ldots , t_n\) are terms. A compound term is a term that is neither a constant nor a variable. An atom is an expression \(P(t_1, \ldots ,t_n)\), where P is a n-ary predicate symbol distinct from \(\approx \) and \(t_1, \ldots , t_n\) are terms. A literal is an atom A or a negated atom \(\lnot A\). Given two terms (or atoms) \(E_1 = A(\ldots , t, \ldots )\) and \(E_2 = B(\ldots , s, \ldots )\), we say t pairs s if the argument position of t in \(E_1\) is the same as that of s in \(E_2\). If a signature allows the special predicate symbols \(\approx \) and \(\not \approx \), then the setting is first-order logic with equality. We use infix notation for positive and negative equational atoms: \(s \approx t\) and \(s \not \approx t\).

In a quantified first-order formula \(\forall x F\) or \(\exists x F\), x is the quantified variable and F is the scope of the quantified variable x. An occurrence of a variable x in a first-order formula F is a free variable of F if and only if x is not within the scope of quantified variables. A sentence (or closed formula) is a first-order formula without free variables. A first-order clause (or clause) is a multiset of literals, interpreted as a disjunction of literals. A positive (negative) clause is a clause that contains only positive (negative) literals. An expression can be a term, an atom, a literal, or a clause. The set of variables that occur in an expression E is denoted as \({{\,\textrm{var}\,}}(E)\). A variable-free expression is a ground expression. A clause is decomposable if it can be partitioned into two variable-disjoint subclauses, otherwise, the clause is indecomposable.

The depth of a term t is denoted \({{\,\textrm{dep}\,}}(t)\) and defined as: i) if t is a variable or a constant, then \({{\,\textrm{dep}\,}}(t) = 0\), ii) if t is a compound term \(f(t_1, \ldots , t_n)\), then \({{\,\textrm{dep}\,}}(t) = 1 + max(\{{{\,\textrm{dep}\,}}(t_i) \ | \ 1 \le i \le n \})\). The depth of an expression E is the depth of the deepest term in E, denoted as \({{\,\textrm{dep}\,}}(E)\). The width of an expression E is the number of distinct variables in E. If an expression E does not contain any term, then \({{\,\textrm{dep}\,}}(E) = 0\) and the width of E is 0.

A substitution of terms for variables is a set \(\{x_1 \mapsto t_1, \ldots , x_n \mapsto t_n\}\) where each \(x_i\) is a distinct variable and each \(t_i\) is a term, which is not identical to the respective variable \(x_i\). We use lower-case Greek letters \(\sigma , \theta , \eta \) to denote substitutions. We use \(E\sigma \) to denote the result of the application of a substitution \(\sigma \) to the expression E. It is also said to be an instance of E. A variable renaming is a substitution \(\sigma \) such that \(\sigma = \{x_1 \mapsto y_1, \ldots , x_n \mapsto y_n\}\) where \(x_1, \ldots , x_n, y_1, \ldots , y_n\) are variables and \(\sigma \) is bijective. An expression \(E_1\) is a variant of an expression E if there exists a variable renaming \(\sigma \) such that \(E_1 = E\sigma \). We consider two clauses \(C_1\) and \(C_2\) to be identical if \(C_1\) is a variant of \(C_2\). Given substitutions \(\sigma \) and \(\theta \), the composition \(\sigma \theta \) denotes that for each variable x, \(x\sigma \theta = (x\sigma )\theta \). A substitution \(\sigma \) is a unifier of a set \(\{E_1, \ldots , E_n\}\) of expressions if and only if \(E_1\sigma = \ldots = E_n\sigma \). The set \(\{E_1, \ldots , E_n\}\) is said to be unifiable if there is a unifier for it. A unifier \(\sigma \) of a set \(\{E_1, \ldots , E_n\}\) of expressions is a most general unifier (mgu) if and only if for each unifier \(\theta \) of the set, there is a substitution \(\eta \) such that \(\sigma = \theta \eta \). A unifier \(\sigma \) is a simultaneous mgu of two sequences \(E_1, \ldots , E_n\) and \(E_1^\prime , \ldots , E_n^\prime \) of expressions where \(n > 1\), if \(\sigma \) is an mgu for each pair \(E_i\) and \(E_i^\prime \). By \(\sigma = {{\,\textrm{mgu}\,}}(E \doteq E^\prime )\), we mean that \(\sigma \) is an mgu of expressions E and \(E^\prime \). By \(\sigma = {{\,\textrm{mgu}\,}}(E_1 \doteq E_1^\prime , \ldots , E_n \doteq E_n^\prime )\) where \(n > 1\), we mean that \(\sigma \) is a simultaneous mgu of two sequences \(E_1, \ldots , E_n\) and \(E_1^\prime , \ldots , E_n^\prime \) of expressions.

We distinguish rules in our paper in two types: i) the rules that are applied to a clausal set, and they are framed using bold lines; ii) the rules that are applies to clauses, namely inference rules, and they are framed using non-bold lines. When we refer to function symbols, we mean non-constant ones. In the rest of the paper, we use the following notational convention:

$$\begin{aligned} \begin{array}{lll} \bullet \ x,y,z,u,v,x_1, \ldots \text {for variables} &{} &{} \bullet \ a, b, c, a_1, \ldots \text {for constant symbols} \\ \bullet \ f, g, h, \ldots \text {for function symbols} &{} &{} \bullet \ P,P_1,A,B, \ldots \text {for predicate symbols} \\ \bullet \ p, p_1, \ldots \ \text {for propositional variables} &{} &{} \bullet \ F, F_1, \ldots \text {for formulas} \\ \bullet \ C, D, Q, C_1, \ldots \text {for clauses} &{} &{} \bullet \ s, t, u, \ldots \ \text {for terms} \\ \bullet \ L, L_1, \ldots \text {for literals} &{} &{} \bullet \ A, B, G, G_1, \ldots \ \text {for atoms} \end{array} \end{aligned}$$

2.2 Guarded Quantification Fragments

In the following definitions, constants are allowed but not equality.

Definition 1

The guarded fragment (GF) is a fragment of first-order logic without function symbols, inductively defined as follows:

  1. 1.

    \(\top \) and \(\bot \) belong to GF.

  2. 2.

    If A is an atom, then A belongs to GF.

  3. 3.

    GF is closed under Boolean connectives.

  4. 4.

    Let F be a guarded formula and G an atom. Then \(\exists \overline{x} (G \wedge F)\) and \(\forall \overline{x} (G \rightarrow F)\) belong to GF if all free variables of F occur in G.

Definition 2

The loosely guarded fragment (LGF) is a fragment of first-order logic without function symbols, inductively defined as follows:

  1. 1.

    \(\top \) and \(\bot \) belong to LGF.

  2. 2.

    If A is an atom, then A belongs to LGF.

  3. 3.

    LGF is closed under Boolean connectives.

  4. 4.

    Let F be a loosely guarded formula and \(\mathbb {G}\) a conjunction of atoms. Then \(\forall \overline{x} (\mathbb {G} \rightarrow F)\) and \(\exists \overline{x} (\mathbb {G} \wedge F)\) belong to LGF if

    1. (a)

      all free variables of F occur in \(\mathbb {G}\), and

    2. (b)

      for each variable x in \(\overline{x}\) and each variable y occurring in \(\mathbb {G}\) that is distinct from x, x and y co-occur in an atom of \(\mathbb {G}\).

Definition 3

The clique-guarded fragment (CGF) is a fragment of first-order logic without function symbols, inductively defined as follows:

  1. 1.

    \(\top \) and \(\bot \) belong to CGF.

  2. 2.

    If A is an atom, then A belongs to CGF.

  3. 3.

    CGF is closed under Boolean connectives.

  4. 4.

    Let F be a clique-guarded formula and \(\mathbb {G}(\overline{x}, \overline{y})\) a conjunction of atoms. Then \(\forall \overline{z} (\exists \overline{x} \mathbb {G}(\overline{x}, \overline{y}) \rightarrow F)\) and \(\exists \overline{z} (\exists \overline{x} \mathbb {G}(\overline{x}, \overline{y}) \wedge F)\) belong to CGF, if

    1. (a)

      all free variables of F occur in \(\overline{y}\), and

    2. (b)

      each variable in \(\overline{x}\) occurs in only one atom of \(\mathbb {G}(\overline{x}, \overline{y})\), and

    3. (c)

      for each variable z in \(\overline{z}\) and each variable y occurring in \(\mathbb {G}(\overline{x}, \overline{y})\) that is distinct from z, z and y co-occur in an atom of \(\exists \overline{x} \mathbb {G}(\overline{x}, \overline{y})\).

In 4. of Definitions 13, the atom G, the conjunctions of atoms \(\mathbb {G}\) and \(\exists \overline{x} (\mathbb {G}(\overline{x}, \overline{y}))\) are, respectively, the guard, the loose guard and the clique-guard for F. We say a formula is a guarded quantification formula if it belongs to either GF, or LGF and CGF. Definition 1 defines GF in the same way as [29, Definition 2.1] and [39, Definition 2.1] modulo equality. Definition 2 improves the previous definitions of LGF in [29, 39]: [29, Definition 4.1] misses Condition 4(a) of Definition 2, and Condition (ii) in the definition of LGF in [39] is amended in Condition 4(b) of Definition 2. Unlike the definitions of CGF in [53, 65], Definition 3 is defined in accordance with Definitions 12 and disallows equality symbols.

Among the following formulas, \(F_1, F_2, F_4, F_6\) and \(F_7\) are guarded formulas, but not the rest. The formula \(F_7\) is the standard translation [18, chapter 2] of the modal formula \(P \rightarrow \Diamond \Box P\) and the description logic axiom \(P \sqsubseteq \exists R. \forall R. P\). For the relationship between GF and modal logic see [18, Sect. 7.4], and for that between GF and description logic see [80].

$$\begin{aligned}&F_1 = A(x) \qquad \qquad \qquad F_2 = \forall x [A(x,y) \rightarrow B(x,y) ]\qquad \qquad \qquad F_3 = \forall x [A(x) ]\\&F_4 = \forall x [A(x,y) \rightarrow \bot ]\qquad \qquad \qquad \qquad \qquad \ \quad F_5 = \forall x [A(x,y) \rightarrow \exists y(B(y,z)) ]\\&F_6 = \exists x [A(x,y) \wedge \forall z (B(x,z) \rightarrow \exists u (R(z,u))) ]\\&F_7 = \forall x [P(x) \rightarrow \exists y (R(x,y) \wedge \forall z (R(y,z) \rightarrow P(z)))) ]\end{aligned}$$

Extended from GF, LGF allows a restricted form of a conjunction of atoms in the guard positions. For example, \(\forall z [(R(x,z) \wedge R(z,y)) \rightarrow P(z) ]\) and the first-order translation of a temporal logic formula \(A \ \texttt{until} \ B\):

$$\begin{aligned} \exists y [R(x,y) \wedge B(y) \wedge \forall z((R(x,z) \wedge R(z,y))\rightarrow A(z))) ], \end{aligned}$$

are loosely guarded formulas, but are not guarded. Extended from LGF, CGF allows existentially quantified variables in loose guards. In the clique-guarded formula

$$\begin{aligned} F = \forall x_1x_2 \left[\begin{array}{rll} G(x_1,x_2) \rightarrow &{} \forall x_3 ( &{} \\ &{} (\exists x_4x_5 (A(x_1,x_3,x_4) \wedge B(x_2,x_3,x_5)) \ ) \rightarrow &{} \\ &{} (\exists x_6 D(x_1,x_6) \wedge \top ) &{} ) \end{array} \right], \end{aligned}$$

\(\exists x_6 D(x_1,x_6)\), \(\exists x_4x_5 (A(x_1,x_3,x_4) \wedge B(x_2,x_3,x_5)) \ \text {and} \ G(x_1,x_2)\) are respectively the clique-guards of \(\exists x_6 D(x_1,x_6) \wedge \top \),

$$\begin{aligned}&\forall x_3 ( \exists x_4x_5 (A(x_1,x_3,x_4) \wedge B(x_2,x_3,x_5)) \rightarrow (\exists x_6 D(x_1,x_6) \wedge \top )) \ \text {and} \ F. \end{aligned}$$

The transitivity formula \(\forall xyz [(R(x,y) \wedge R(y,z)) \rightarrow R(x,z) ]\) is neither a guarded nor a loosely guarded nor a clique-guarded formula.

2.3 BCQ Answering and Saturation-Based BCQ Rewriting Problems

First, we give the formal definition of BCQs and unions thereof.

Definition 4

A Boolean conjunctive query (BCQ) is a first-order sentence of the form \(\exists \overline{x} \varphi (\overline{x})\), where \(\varphi (\overline{x})\) is a conjunction of atoms containing only constants and variables as arguments. A union of BCQs is a disjunction of BCQs.

This paper aims to answer the following question.

Question 1

Given a set \(\varSigma \) of formulas in GF, LGF and CGF, a set D of ground atoms and a union q of BCQs, can we devise a practical decision procedure to check whether \(\varSigma \cup D \models q\)?

In this paper, the above question is reduced to check whether \(\varSigma \models q\), since ground atoms D belong to the guarded quantification fragments \(\varSigma \). To answer this question, we use a saturation-based method, which computes the closure of a given set of formulas under a set of inference rules.

If we answer Question 1 positively, then we consider a follow-up question:

Question 2

Suppose \(\varSigma \) is a set of formulas in GF, LGF and CGF, D is a set of ground atoms and q is a union of BCQs. Further, suppose N is the saturation obtained by applying the procedure devised for Question 1 to \(\{\lnot q\} \cup \varSigma \). Can N be back-translated to a (Skolem-symbol-free) first-order formula \(\varSigma _q\) such that \(\varSigma \cup D \models q\) if and only if \(D \models \varSigma _q\)?

3 From Formulas to Clausal Sets

In this section, we formally define a clausal class to which the considered problems can be reduced, and then define our clausal normal form translation.

3.1 Loosely Guarded Clauses and Query Clauses

It is helpful to use the flatness, simpleness, compatibility and covering properties to formally define our clausal forms, namely loosely guarded clauses and query clauses.

A compound term is flat if each argument in it is either a constant or a variable. A literal is flat if each argument in it is either a constant or a variable. A clause is flat if the literals in it are flat. A clause is simple if each argument in it is either a variable or a constant or a flat compound term. A simple compound-term literal (clause), or plainly a compound-term literal (clause), is a simple literal (clause) containing at least one flat compound term. For example, \(\lnot A(f(x,y))\) is a compound-term literal, but not \(\lnot A(f(g(x),y))\) because of the presence of the nested compound term f(g(x), y). A clause C is covering if each compound term t in it satisfies \({{\,\textrm{var}\,}}(t)={{\,\textrm{var}\,}}(C)\). Two compound terms t and s are compatible if the argument sequences of t and s are identical. A clause C is compatible if in C, compound terms that are under the same function symbol are compatible. A clause is strongly compatible if all compound terms in it are compatible. For example, \(A_1(f(x,y)) \vee \lnot A_2(g(x,y)) \vee A_3(y,x)\) is covering and strongly compatible, and \(A_1(f(x,y)) \vee \lnot A_2(g(y,x))\) is covering and compatible, but not strongly compatible.

Definition 5

A query clause is a flat negative clause.

Definition 6

A loosely guarded clause C is a simple, covering and strongly compatible clause, satisfying the following conditions:

  1. 1.

    C is either ground, or

  2. 2.

    C contains a set of negative flat literals \(\lnot G_1, \ldots , \lnot G_n\) such that each pair of distinct variable in C co-occurs in at least one literal of \(\lnot G_1, \ldots , \lnot G_n\).

In 2. of Definition 6, \(\lnot G_1, \ldots , \lnot G_n\) is called a loose guard of C. When a clause contains only one variable, then it is a loosely guarded clause if it is simple, covering, strongly compatible, and it contains a flat negative literal that contains its variable. A loosely guarded clause is a guarded clause if its loose guards contain only one literal, which we call a guard of this clause. A Horn guarded clause is a guarded clause containing at most one positive literal. A clause is (loosely) guarded if it contains at least one (loose) guard.

Consider the clauses

$$\begin{aligned}&C_1 = \lnot A_1(x,y) \vee \lnot A_2(y,z) \vee \lnot A_3(z,x),\\&C_2 = \lnot B_1(x,y,a) \vee \lnot B_2(y,z,b) \vee \lnot B_3(z,x,w), \\&C_3 = \lnot A_1(x,y) \vee A_2(f(y,x),f(x,y)). \end{aligned}$$

The clause \(C_1\) is a loosely guarded clause; \(C_2\) is not as w and y do not co-occur in any negative flat literal; \(C_3\) is not a loosely guarded clause either since f(yx) and f(xy) are not compatible. A query clause is not necessarily loosely guarded or vice-versa. For example, \(C_1\) is a query clause; \(\lnot A(x,y) \vee B(f(x,y))\) is a (loosely) guarded clause but not a query clause; and \(\lnot A_1(x,y) \vee \lnot A_2(y,z)\) is a query clause, but not (loosely) guarded.

Fig. 5
figure 5

Relationships between the investigated clausal classes and fragments

We use LG to denote the class of loosely guarded clauses, and LGQ to denote the class of both query and LG clauses. The class of LG clauses is more expressive than the guarded quantification fragments. For example, \(\lnot G(x) \vee A(f(x))\) is an LG clause but it does not belong to the guarded quantification fragments. Figure 5 summarises the relationships between BCQs, the guarded quantification fragments and the considered clausal classes. In Fig. 5, an upper node is more expressive than the one linked below it.

3.2 Clausal Normal Form Translation

We use the formula renaming technique [69, Sect. 4] in our clausification processes. Let \(F[F_1(\overline{x})]\) denote a first-order formula F in which \(F_1\) is a subformula of F and \(\overline{x}\) are the free variables in \(F_1\). Using a predicate symbol P, say, not occurring in \(F[F_1(\overline{x})]\), formula renaming with positive literals transforms \(F[F_1(\overline{x})]\) to

$$\begin{aligned} F[P(\overline{x})] \wedge \forall \overline{x} (\lnot P(\overline{x}) \vee F_1(\overline{x})) \end{aligned}$$

and formula renaming with negative literals transforms \(F[F_1(\overline{x})]\) to

$$\begin{aligned} F[\lnot P(\overline{x})] \wedge \forall \overline{x} (P(\overline{x}) \vee F_1(\overline{x})), \end{aligned}$$

where every occurrence of \(F_1(\overline{x})\) in \(F[F_1(\overline{x})]\) are replaced by \(P(\overline{x})\) and \(\lnot P(\overline{x})\), respectively. In the above formula renaming with positive literals, \(F[P(\overline{x})]\) and \(\forall \overline{x} (\lnot P(\overline{x}) \vee F_1(\overline{x}))\) are called the replacement of \(F[F_1(\overline{x})]\) and the definition of P, respectively. In the above formula renaming with negative literals, \(F[\lnot P(\overline{x})]\) and \(\forall \overline{x} (P(\overline{x}) \vee F_1(\overline{x}))\) are called the replacement of \(F[F_1(\overline{x})]\) and the definition of P, respectively. If a formula F is the definition of a predicate symbol P, we say P defines F. For a comprehensive description of clausification techniques, we refer the reader to [6, 69].

Given a union \(q_1 \vee \ldots \vee q_n\) of BCQs and a set \(\varSigma \) guarded quantification formulas, we reduce the entailment checking problem of \(\varSigma \models q_1 \vee \ldots \vee q_n\) to the problem of checking unsatisfiability of \(\{\lnot q_1 \wedge \ldots \wedge \lnot q_n\} \cup \varSigma \). We assume that all free variables in \(\varSigma \) are existentially quantified as we are interested in satisfiability checking. We use Trans to denote our clausification process, detailed below.

  1. 1.

    Negate the union of BCQs to obtain a set of query clauses.

  2. 2.

    Clausify loosely guarded formulas following the steps below, illustrated on

    $$\begin{aligned} F = \exists y [R(x,y) \wedge B(y) \wedge \forall z((R(x,z) \wedge R(z,y))\rightarrow A(z))) ]. \end{aligned}$$
    1. (a)

      Add existential quantifiers to all free variables, equivalently express (double) implications as disjunctions and then perform negation normal form translation. From F we obtain

      $$\begin{aligned} F_1 = \exists xy [R(x,y) \wedge B(y) \wedge \forall z(\lnot R(x,z) \vee \lnot R(z,y) \vee A(z)) ]. \end{aligned}$$
    2. (b)

      Use formula renaming with positive literals for all universally quantified subformulas in the formula obtained in 2(a). From \(F_1\) we obtain

      $$\begin{aligned} F_2 = \left[\begin{array}{rll} \exists xy (&{} R(x,y) \wedge B(y) \wedge P_1(x,y) &{} ) \wedge \\ \forall xy ( &{} \lnot P_1(x,y) \vee \forall z (\lnot R(x,z) \vee \lnot R(z,y) \vee A(z)) &{} ) \end{array} \right], \end{aligned}$$

      where \(P_1\) is a fresh predicate symbol. We say that

      $$\begin{aligned}&\exists xy (R(x,y) \wedge B(y) \wedge P_1(x,y)) \ \text {is the }{replacement}~\text {of }F_1,\text { and} \\&\forall xy ( \lnot P_1(x,y) \vee \forall z (\lnot R(x,z) \vee \lnot R(z,y) \vee A(z)) \ \text {is the }{definition}~\text {of }P_1. \end{aligned}$$
    3. (c)

      Transform immediate subformulas of the formulas obtained in 2(b) that are connected by conjunctions to prenex normal form and then apply Skolemisation. By introducing Skolem constants a and b, from \(F_2\) we obtain

      $$\begin{aligned} F_3 = \left[\begin{array}{rll} &{} R(a,b) \wedge B(b) \wedge P_1(a,b) &{} \wedge \\ \forall xyz ( &{} \lnot P_1(x,y) \vee \lnot R(x,z) \vee \lnot R(z,y) \vee A(z) &{} ) \end{array} \right]. \end{aligned}$$
    4. (d)

      Drop universal quantifiers and then perform conjunctive normal form transformation to formulas obtained in 2(c). From \(F_3\) we obtain a set of LG clauses:

      $$\begin{aligned} R(a,b), \ B(b), \ P_1(a,b) \ \text {and} \ \lnot P_1(x,y) \vee \lnot R(x,z) \vee \lnot R(z,y) \vee A(z). \end{aligned}$$
  3. 3.

    Clausify clique-guarded formula following the steps below, illustrated on

    $$\begin{aligned} F^\prime = \forall x_1x_2 \left[\begin{array}{rll} G(x_1,x_2) \rightarrow &{} \forall x_3 ( &{} \\ &{} (\exists x_4x_5 (A(x_1,x_3,x_4) \wedge B(x_2,x_3,x_5)) \ ) \rightarrow &{} \\ &{} (\exists x_6 D(x_1,x_6) \wedge \top ) &{} ) \end{array} \right]. \end{aligned}$$
    1. (a)

      Add existential quantification for all free variables and simplify \(\top \) and \(\bot \). Unlike 2(a) we first apply the miniscoping rule [69] to existential quantified variables in clique-guards, and then perform the negation normal form transformation. From \(F^\prime \) we obtain

      $$\begin{aligned} F_1^\prime = \forall x_1x_2 \left[\begin{array}{rll} G(x_1,x_2) \rightarrow &{} \forall x_3 ( &{} \\ &{} (\exists x_4 A(x_1,x_3,x_4) \wedge \exists x_5 B(x_2,x_3,x_5) \ ) \rightarrow &{} \\ &{} (\exists x_6 D(x_1,x_6) \wedge \top ) &{} ) \end{array} \right]. \end{aligned}$$

      Then transform \(F_1^\prime \) to negation normal form and drop \(\top \), obtaining

      $$\begin{aligned} F_2^\prime = \forall x_1x_2 \left[\begin{array}{rll} \lnot G(x_1,x_2) \ \vee &{} \forall x_3 ( &{} \\ &{} (\forall x_4 (\lnot A(x_1,x_3,x_4)) \vee \forall x_5 (\lnot B(x_2,x_3,x_5)) \ ) &{} \vee \\ &{} \exists x_6 D(x_1,x_6) &{} ) \end{array} \right], \end{aligned}$$
    2. (b1)

      Apply formula renaming to all universally quantified subformulas in the formula obtained in 3(a). For universally quantified subformulas in the clique-guards, namely \(\forall x_4 (\lnot A(x_1,x_3,x_4))\) and \(\forall x_5 (\lnot B(x_2,x_3,x_5))\), we apply formula renaming with negative literals to them. From \(F_2^\prime \) we obtain an intermediate formula

      $$\begin{aligned} F_3^\prime = \left[\begin{array}{l} \forall x_1x_3 ( P_1(x_1, x_3) \vee \forall x_4 (\lnot A(x_1,x_3,x_4))) \wedge \\ \forall x_2x_3 ( P_2(x_2, x_3) \vee \forall x_5 (\lnot B(x_2,x_3,x_5))) \wedge \\ \forall x_1x_2 ( \lnot G(x_1,x_2) \vee \forall x_3 (\lnot P_1(x_1, x_3) \vee \lnot P_2(x_2, x_3) \vee \exists x_6 D(x_1,x_6))) \end{array} \right], \end{aligned}$$

      where \(P_1\) and \(P_2\) are the fresh predicate symbols.

    3. (b2)

      For the remaining universally quantified subformulas in the formula obtained in 3(a) and 3(b1), we apply formula renaming with positive literals. From \(F_3^\prime \) we eventually obtain

      $$\begin{aligned} F_4^\prime = \left[\begin{array}{l} p_1 \wedge \\ (\lnot p_1 \vee \forall x_1x_2 ( \lnot G(x_1,x_2) \vee P_3(x_1, x_2) )) \wedge \\ \forall x_1x_3 ( P_1(x_1, x_3) \vee \forall x_4 (\lnot A(x_1,x_3,x_4))) \wedge \\ \forall x_2x_3 ( P_2(x_2, x_3) \vee \forall x_5 (\lnot B(x_2,x_3,x_5))) \wedge \\ \forall x_1x_2 ( \lnot P_3(x_1, x_2) \vee \forall x_3 (\lnot P_1(x_1, x_3) \vee \lnot P_2(x_2, x_3) \vee \exists x_6 D(x_1,x_6))) \end{array} \right], \end{aligned}$$

      where \(p_1\) and \(P_3\) are the fresh predicate symbols. In \(F_4^\prime \), \(p_1\) is the replacement of \(F_2^\prime \) and the remaining four conjuncts respectively defines \(p_1\), \(P_1\), \(P_2\) and \(P_3\).

    4. (c)

      Transform immediate subformulas of the formulas obtained in 3(b2) that are connected by conjunctions to prenex normal form and then apply Skolemisation. Using a Skolem function symbol f, \(F_4^\prime \) is transformed into

      $$\begin{aligned} F_5^\prime = \left[\begin{array}{l} p_1 \wedge \\ (\lnot p_1 \vee \forall x_1x_2 ( \lnot G(x_1,x_2) \vee P_3(x_1, x_2) ) ) \wedge \\ \forall x_1x_3x_4 ( P_1(x_1, x_3) \vee \lnot A(x_1,x_3,x_4) ) \wedge \\ \forall x_2x_3x_5 ( P_2(x_2, x_3) \vee \lnot B(x_2,x_3,x_5) ) \wedge \\ \forall x_1x_2x_3 ( \lnot P_3(x_1, x_2) \vee \lnot P_1(x_1, x_3) \vee \lnot P_2(x_2, x_3) \vee D(x_1,f(x_1,x_2,x_3)) ) \\ \end{array} \right]. \end{aligned}$$
    5. (d)

      Transform the formula obtained in 3(c) to conjunctive normal form and then drop universal quantifiers. From \(F_5^\prime \) we obtain a set of LG clauses:

      $$\begin{aligned}&p_1, \qquad \qquad \qquad \qquad \qquad \ \lnot p_1 \vee \lnot G(x_1,x_2) \vee P_3(x_1, x_2), \\&P_1(x_1, x_3) \vee \lnot A(x_1,x_3,x_4), \qquad \ \ \ P_2(x_2, x_3) \vee \lnot B(x_2,x_3,x_5), \\&\lnot P_3(x_1, x_2) \vee \lnot P_1(x_1, x_3) \vee \lnot P_2(x_2, x_3) \vee D(x_1,f(x_1,x_2,x_3)). \end{aligned}$$

To sum up, the Trans process transforms unions of BCQs to query clauses, clausifies guarded formulas to a set of guarded clauses, and loosely guarded and clique-guarded formulas to a set of LG clauses.

By i) renaming universally quantified subformulas and ii) applying prenex normal form transformation and then Skolemisation to each conjunctively connected immediate subformulas, the Trans process intentionally introduces Skolem functions of a higher arity. More specifically, i)–ii) ensure that LG clauses have the covering and the strong compatibility properties. The covering property is essential to guarantee termination in our BCQ answering procedures, and the strong compatibility property makes the back-translation from an LG clausal set to a first-order formula possible.

The Trans process provides the most general and crucial clausification steps, but this can be further optimised in implementation. For example, in 3(c) of the Trans process, renaming the top-most formula \(\forall x_1x_2 (\lnot G(x_1,x_2) \vee P_1(x_1, x_2))\) is not critical. Another possible optimisation is using formula renaming to avoid the exponential blow-up of distributing disjunctions over conjunctions.

Lemma 7

i) Applying the Trans process to a (loosely) guarded formula transforms it into a set of (loosely) guarded clauses, and ii) applying the Trans process to a clique-guarded formula transforms it into a set of loosely guarded clauses.

Proof

i): Suppose F is a loosely guarded formula. Suppose \(F_2\) is a result of applying 2(a)–2(b) of Trans to F, and further suppose \(P_1, \ldots , P_n\) are the fresh predicate symbols introduced in 2(b). W.l.o.g. we say \(F_2 = F_{2,1} \wedge \ldots \wedge F_{2,n} \wedge F_{2,r}\) where \(F_{2,1}, \ldots , F_{2,n}\) are respectively the definitions of \(P_1, \ldots , P_n\) and \(F_{2,r}\) is the replacement of \(F_2\). We prove that Trans clausifies every conjunct of \(F_2\) to a set of LG clauses.

Consider \(F_{2,r}\). By 2(b), no universally quantified subformulas occur in \(F_{2,r}\), therefore \(F_{2,r}\) is a closed existentially quantified formula. The fact that \(F_{2,r}\) contains no compound terms implies that 2(c)–2(d) clausify \(F_{2,r}\) to a set of flat ground clauses, which are LG clauses.

Consider \(F_{2,1}, \ldots , F_{2,n}\). W.l.o.g. we take \(F_{2,1}\). By 2(b), \(F_{2,1}\) can be represented as

$$\begin{aligned} \forall \overline{x} (\lnot P_1(\overline{x}) \vee \forall \overline{y} (\lnot G_1(\overline{x_1}, \overline{y_1}) \vee \ldots \vee \lnot G_r(\overline{x_k}, \overline{y_k}) \vee F_{a})) \end{aligned}$$

where \(\forall \overline{y} (\lnot G_1(\overline{x_1}, \overline{y_1}) \vee \ldots \vee \lnot G_r(\overline{x_k}, \overline{y_k}) \vee F_{a})\) is a loosely guarded formula, \(F_{a}\) is a loosely guarded formula where all universal quantified formulas are abstracted (hence \(F_{a}\) is a formula containing no universal quantification but may contain existential quantifications), \(\overline{x_1}, \ldots , \overline{x_k} \subseteq \overline{x}\) and \(\overline{y_1}, \ldots , \overline{y_k} \subseteq \overline{y}\). By 2(c), \(F_{2,1}\) is converted to

$$\begin{aligned} \forall \overline{x} \overline{y} (\lnot P_1(\overline{x}) \vee \lnot G_1(\overline{x_1}, \overline{y_1}) \vee \ldots \vee \lnot G_r(\overline{x_k}, \overline{y_k}) \vee F_{a}). \end{aligned}$$

If \(F_{a}\) contains conjunctions, 2(c)–2(d) clausify \(F_{2,1}\) to a set of clauses, otherwise \(F_{2,1}\) is clausified to one clause. Suppose C is a clause obtained by applying 2(c)–2(d) to \(F_{2,1}\). We use \(C_1\) to denote the subclause \(\lnot P_1(\overline{x}) \vee \lnot G_1(\overline{x_1}, \overline{y_1}) \vee \ldots \vee \lnot G_r(\overline{x_k}, \overline{y_k})\). First, we prove that \(C_1\) is a loose guard of C. By the fact \({{\,\textrm{var}\,}}(F_{2,1}) = \overline{x} \overline{y}\), \({{\,\textrm{var}\,}}(C) = \overline{x} \overline{y}\). By 4 of Definition 2, \(C_1\) is flat and \({{\,\textrm{var}\,}}(C_1) = \overline{x} \overline{y}\). By 4(b) of Definition 2 and the fact that the free variables of \(\forall \overline{y} (\lnot G_1(\overline{x_1}, \overline{y_1}) \vee \ldots \vee \lnot G_r(\overline{x_k}, \overline{y_k}) \vee F_{a})\) are \(\overline{x}\), each pair of variables in \(\overline{x} \overline{y}\) co-occurs in at least one literal of \(C_1\). Hence \(C_1\) is a loose guard of C. Next, we prove that C satisfies the other properties of LG clauses. We distinguish two cases of whether \(F_{a}\) contains existential quantifications. Suppose \(F_{a}\) contains existential quantifications and suppose the existentially quantified variables in \(F_{a}\) are Skolemised to Skolem functions \(f_1, \ldots , f_k\). W.l.o.g. suppose \(f_1\) and \(f_2\) are two Skolem symbols occurring in C. By prenex normal form transformation, all compound terms in C that are under neither \(f_1\) or \(f_2\) have the same sequence of arguments \(\overline{x} \overline{y}\), therefore C is covering and strongly compatible. As no function symbol occurs in \(F_{a}\), no term in C is nested, and C is simple. Then, C is an LG clause. Suppose \(F_{a}\) contains no existentially quantified formulas. Immediately C is flat. Since we previously proved that \(C_1\) is a loose guard of C, C is an LG clause. That Trans converts guarded formulas to a set of guarded clauses is immediate since this is the case that a loose guard contains only one literal.

ii): Now we consider the clique-guarded formula. Unlike the clausification for loosely guarded formulas, the existentially quantified variables in clique-guards, mentioned in Condition 4(b) in the CGF definition, need to be handled. Suppose \(F^\prime \) is a clique-guarded formula, and w.l.o.g. suppose \(F_2^\prime \) is a result of applying 3(a) to \(F^\prime \). Further, suppose \(F_3^\prime \) is the result of applying 3(b1) to \(F_2^\prime \). Using the fresh predicate symbols \(P_{3,1}, \ldots , P_{3,n}\), we say \(F_3^\prime = F_{3,1}^\prime \wedge \ldots \wedge F_{3,n}^\prime \wedge F_{3,r}^\prime \) where \(F_{3,1}^\prime , \ldots , F_{3,n}^\prime \) are respectively the definitions of \(P_{3,1}, \ldots , P_{3,n}\) and \(F_{3,r}^\prime \) is the replacement of \(F_3^\prime \). Assume that \(F_4^\prime \) is the result of applying 3(b2) to \(F_{3,r}^\prime \). Using fresh predicate symbols \(P_{4,1}, \ldots , P_{4,m}\), we say \(F_4^\prime = F_{3,1}^\prime \wedge \ldots \wedge F_{3,n}^\prime \wedge F_{4,1}^\prime \wedge \ldots \wedge F_{4,m}^\prime \wedge F_{4,r}^\prime \) where \(F_{4,1}^\prime , \ldots , F_{4,m}^\prime \) are respectively the definitions of \(P_{4,1}, \ldots , P_{4,m}\) and \(F_{4,r}^\prime \) is the replacement of \(F_4^\prime \). We prove that by Trans every conjunct of \(F_4^\prime \) is clausified as a set of LG clauses.

Consider applying 3(b1) to \(F_2^\prime \), deriving \(F_3^\prime \), viz., \(F_{3,1}^\prime \wedge \ldots \wedge F_{3,n}^\prime \wedge F_{3,r}^\prime \). Suppose \(F_{2,1}^\prime \) is a subformula in \(F_2^\prime \) that contains universally quantified subformulas occurring in clique-guards. W.l.o.g. we assume that \(F_{3,1}^\prime \wedge \ldots \wedge F_{3,n}^\prime \wedge F_{3,r}^\prime \) is obtained by applying 3(b1) to \(F_{2,1}^\prime \) and w.l.o.g. we present \(F_{2,1}^\prime \) as

$$\begin{aligned} \forall \overline{z} (\forall \overline{x_1} \lnot G_1 (\overline{x_1}, \overline{y_1}) \vee \ldots \vee \forall \overline{x_k} \lnot G_t(\overline{x_k}, \overline{y_k}) \vee F_{a}^\prime ) \end{aligned}$$

where \(\overline{x_1}, \ldots , \overline{x_k}\) respectively only occur in \(\lnot G_1 (\overline{x_1}, \overline{y_1}), \ldots , \lnot G_t(\overline{x_k}, \overline{y_k})\) and \(F_{a}^\prime \) is a clique-guarded formula. W.l.o.g. we use \(P_{3,1}, \ldots , P_{3_t}\) such that \(t \le n\) to apply 3(b1) to \(F_{2,1}^\prime \), obtaining

$$\begin{aligned}&\forall \overline{z} (\lnot P_{3,1}(\overline{y_1}) \vee \ldots \vee \lnot P_{3,r}(\overline{y_k}) \vee F^{\prime \prime }_{a}) \wedge \\&\forall \overline{y_1} (P_{3,1}(\overline{y_1}) \vee \forall \overline{x_1} \lnot G_1(\overline{x_1}, \overline{y_1})) \wedge \ldots \wedge \forall \overline{y_k} (P_{3_t}(\overline{y_k}) \vee \forall \overline{x_n} \lnot G_t(\overline{x_k}, \overline{y_k})) \end{aligned}$$

where \(F^{\prime \prime }_{a}\) is a clique-guarded formula and no universal quantification occurs in its clique-guards (since 3(b1) abstracts universal quantified formulas in clique-guards). The subformula \(\forall \overline{z} (\lnot P_{3,1}(\overline{y_1}) \vee \ldots \vee \lnot P_{3,r}(\overline{y_k}) \vee F^{\prime \prime }_{a})\) is the replacement of \(F_{2,1}^\prime \). This replacement represents a conjunct in \(F_{3,r}^\prime \) and we consider \(F_{3,r}^\prime \) in the next paragraph. The subformulas

$$\begin{aligned}&\forall \overline{y_1} (P_{3,1}(\overline{y_1}) \vee \forall \overline{x_1} \lnot G_1(\overline{x_1}, \overline{y_1})), \ \ldots , \ \forall \overline{y_k} (P_{3_t}(\overline{y_k}) \vee \forall \overline{x_n} \lnot G_t(\overline{x_k}, \overline{y_k})). \end{aligned}$$

are the definitions of \(P_{3,1}, \ldots , P_{3_t}\) such that \(t \le n\), respectively. By 3(c)–3(d) these definitions are clausified to flat LG clauses consisting of two literals. Hence, 3(c)–3(d) clausify \(F_{3,1}^\prime \wedge \ldots \wedge F_{3,n}^\prime \) to a set of LG clauses.

Next consider \(F_{3,r}^\prime \). Since \(F_{3,r}^\prime \) contains no quantification in its clique-guard, by the definitions of LGF and CGF, \(F_{3,r}^\prime \) is a loosely guarded formula. Suppose applying 3(b2) to \(F_{3,r}^\prime \) derives \(F_4^\prime = F_{4,1}^\prime \wedge \ldots \wedge F_{4,m}^\prime \wedge F_{4,r}^\prime \). W.l.o.g. we discuss \(F_{4,1}^\prime \). The fact that no universal quantification occurs in clique-guards of \(F_{3,r}^\prime \) implies that \(F_{4,1}^\prime \) can be presented as

$$\begin{aligned} \forall \overline{x} (\lnot P_{4,1}(\overline{x}) \vee \forall \overline{y} (\lnot G_1(\overline{x_1}, \overline{y_1}) \vee \ldots \vee \lnot G_l(\overline{x_k}, \overline{y_k}) \vee F_{a}^{\prime \prime \prime }) \end{aligned}$$

where \(\forall \overline{y} (\lnot G_1(\overline{x_1}, \overline{y_1}) \vee \ldots \vee \lnot G_l(\overline{x_k}, \overline{y_k}) \vee F_{a}^{\prime \prime \prime })\) is a loosely guarded formula, \(F_{a}^{\prime \prime \prime }\) is a loosely guarded formula where all universal quantified formulas are abstracted (hence it is a formula containing no universal quantification but may contain existential quantifications) and \(\overline{x_1}, \ldots , \overline{x_k} \subseteq \overline{x}\) and \(\overline{y_1}, \ldots , \overline{y_k} \subseteq \overline{y}\). Note that \(F_{a}^{\prime \prime }\) is obtained by abstracting universally quantified subformulas in clique-guards in \(F_{2,1}^\prime \), and \(F_{a}^{\prime \prime \prime }\) is obtained by abstracting all universally quantified formulas in \(F_{3,r}^\prime \). By the result established in applying 2(c)–2(d) of Trans to \(F_{2,1}, \ldots , F_{2,n}\), 3(c)–3(d) of Trans clausify \(F_{4,1}^\prime \) to an LG clause or a set of LG clauses if \(F_{a}^{\prime \prime \prime }\) contains conjunctions. Finally consider \(F_{4,r}^\prime \). By the result established in applying 2(b) of Trans to \(F_{2,r}\), 3(c)–3(d) clausify \(F_{4,r}^\prime \) to a set of flat ground clauses, viz., LG clauses. \(\square \)

Theorem 8

The Trans process reduces the problem of BCQ answering for GF, LGF and CGF to that of deciding satisfiability of a set of LGQ clauses.

Proof

Suppose \(q_1 \vee \ldots \vee q_n\) is a union of BCQs, \(\varSigma \) is a set of guarded quantification formulas and D is a set of ground atoms. Since ground atoms D belong to GF, LGF and CGF, it suffices to reduce checking entailment of \(\varSigma \models q_1 \vee \ldots \vee q_n\) to checking unsatisfiability of \(\{\lnot q_1, \ldots , \lnot q_n\} \cup \varSigma \). By the definition of BCQ, \(\{\lnot q_1, \ldots , \lnot q_n\}\) is a set of query clauses. By Lemma 7, \(\varSigma \) is clausified to a set of LG clauses. \(\square \)

4 Top-Variable Inference System

In this section, we present three systems: a basic selection-based resolution system, a partial selection-based resolution system and a top-variable resolution system.

4.1 Basic Notions in the Saturation-Based Resolution Framework

In our systems, admissible orderings and selection functions are the two main parameters to refine and guide the inference process. The following notions are standard in the resolution framework of [8].

Let \(\succ \) be a strict ordering, called a precedence, on the symbols in \(\texttt{C}\), \(\texttt{F}\) and \(\texttt{P}\). An ordering \(\succ \) on expressions is liftable if \(E_1 \succ E_2\) implies \(E_1\sigma \succ E_2\sigma \) for any expressions \(E_1\), \(E_2\) and substitution \(\sigma \). An ordering \(\succ \) on literals is admissible, if the following conditions are satisfied.

  • It is liftable, well-founded and total on ground literals,

  • \(\lnot {A} \succ A\) for all ground atoms A,

  • if \(B \succ A\), then \(B \succ \lnot A\) for all ground atoms A and B.

Let \(\succ \) be an ordering and C a ground clause. A literal L in C is (strictly) maximal with respect to the ground clause C if and only if for all \(L^\prime \) in C, \(L \succeq L^\prime \) (\(L \succ L^\prime \)). A non-ground literal L is (strictly) maximal with respect to a clause C if and only if there exist some ground substitutions \(\sigma \) such that \(L\sigma \) is (strictly) maximal with respect to \(C\sigma \), that is, for all \(L^\prime \) in C, \(L\sigma \succeq L^\prime \sigma \) (\(L\sigma \succ L^\prime \sigma \)). A selection function maps a clause C to a multiset of negative literals in C. The literals in the range of selection functions are said to be selected. An eligible literal with respect to a clause is either a (strictly) maximal literal or a selected literal.

A ground clause C is redundant with respect to a ground clausal set N if there exist \(C_1, \ldots , C_n\) in N such that \(C_1, \ldots , C_n \models C\) and \(C \succ C_i\) for each i with \(1 \le i \le ~n\). Let N be a clausal set. Then a ground clause C is redundant with respect to N if there exists ground instances \(C_1\sigma , \ldots , C_n\sigma \) of clauses \(C_1, \ldots , C_n\) in N such that \(C_1\sigma , \ldots , C_n\sigma \models C\) and \(C \succ C_i\sigma \) for each i with \(1 \le i \le n\). A non-ground clause C is redundant with respect to N if every ground instance of C is redundant with respect to N. Let C and \(C_1, \ldots , C_n\) be premises and D a conclusion in an inference I. Then the inference I is redundant with respect to N if there exist clauses \(D_1, \ldots , D_k\) in N that are smaller than C such that \(C_1, \ldots , C_n,D_1, \ldots , D_k \models D\). A non-ground inference  I is redundant with respect to N if every ground instance of I is redundant in the ground instances of the clauses of N. A clausal set N is saturated up to redundancy with respect to an inference system R if all inferences in R with non-redundant premises in N are redundant with respect to N.

4.2 The S-Res System

In this section, we fine a selection-based resolution system, referred to as the S-Res system. This is a standard instance of the resolution framework in [8].

The S-Res system consists of two types of rules: the Deduce and Delete rules. New conclusions are derived using the Deduce rule.

figure a

To ensure decidability, we minimally need the following Delete rule.

figure b

The Factor rule is the positive factoring rule, defined by:

figure c

The S-Res rule is the selection-based resolution rule defined by

figure d

In the S-Res rule, the right-most premise is the main premise and the others are the side premises. Unlike the standard hyperresolution rule [76] (like the hyperresolution rule in [92]), the S-Res rule does not require the side premises to be positive and all negative literals in the main premise to be selected, e.g., D in the main premise is not nessarily positive. Standard hyperresolution is only applied when the selection function selects all negative literals in the premises of the S-Res rule. The binary resolution rule [8] is an instance of the S-Res rule whenever it only has one selected literal in the main premise.

The S-Res system is defined in the spirit of the resolution framework of [8], therefore, more sophisticated simplification and redundant elimination techniques, such as forward and backward subsumption elimination and condensation in [8, Sect. 4.3], can be freely added to the system.

Theorem 9

The S-Res system is sound and refutationally complete for general first-order clausal logic.

Proof

By the fact that the S-Res system strictly follows the principles of the resolution framework in [8]. \(\square \)

4.3 The P-Res System

Next, we describe a new partial selection-based resolution inference system, denoted as P-Res. This system is built on the top of the S-Res system, but the S-Res rule is replaced by the following partial selection-based resolution rule.

figure e

The P-Res rule is not a selection-based resolution rule where a sub-multiset of the negative literals in the main premise is selected. The literals \(\lnot A_1, \ldots , \lnot A_m\) are resolved not because they are selected, but because the application of the S-Res rule makes the inference on a sub-multiset of the S-Res side premises and the S-Res main premise possible. Condition 2b. stipulates the existence of an mgu between \(A_1, \ldots , A_n\) and \(B_1, \ldots , B_n\) as a pre-requisite for the application of the P-Res rule. This means that whenever the S-Res rule applies to

$$\begin{aligned} C_1 = B_1 \vee D_1, \ \ldots ,\ C_n = B_n \vee D_n \ \text {and} \ C = \lnot A_1 \vee \ldots \vee \lnot A_m \vee \ldots \vee \lnot A_n \vee D \end{aligned}$$

with \(\lnot A_1, \ldots , \lnot A_n\) selected, one can apply the P-Res rule with m of the side premises where \(1 \le m \le n\). We say that \(\lnot A_1, \ldots , \lnot A_m\) are the P-Res eligible literals with respect to an S-Res inference.

Unlike the S-Res rule, Condition 2b. in the P-Res rule includes the case of \(n=1\), meaning that the pre-requisites for Conditions 2a. and 2b. are not exclusive. Though when \(n = 1\), using either Condition 2a. or 2b. to the main premise derives the same conclusion, the mechanism is different: Condition 2a. considers the situation when the P-Res rule is reduced to a binary  S-Res rule, but Condition 2b. considers the partial inferences when the main premise contains only one P-Res eligible literal. Both mechanisms are useful in practice: for example, Condition 2a. is used when a main premise contains only one negative literal, but when a main premise contains multiple negative literals, Condition 2b. allows us to decide that among all these negative literals, the one we want to resolve, to derive a partial resolvent. This partial resolvent can have properties that the resolvent, when we resolve all the negative literals, does not have.

Although the S-Res rule has the advantage of avoiding intermediate resolvents that are derived by binary resolution rules, the S-Res resolvents can be difficult to tame as the rule is performed on a macro level. The P-Res rule, on the other hand, amends the S-Res rule by allowing one to resolve any non-empty and non-strict sub-multiset of the S-Res side premises with the S-Res main premise. This means that the P-Res rule provides new flexibility to capture the S-Res resolvents and thus generalises the S-Res rule. This flexibility is important to tame (and decide) the clausal class we consider.

Next, we show soundness and refutational completeness of the P-Res system. A P-Res inference with the main premise C and a sub-multiset of the side premises \(C_1, \ldots , C_n\) makes the S-Res inference on C and \(C_1, \ldots , C_n\) redundant. We first consider the ground case.

Lemma 10

Suppose N is a clausal set and \(C_1, \ldots , C_n, C\) are ground clauses occurring in N. Suppose I is an S-Res inference with \(C_1, \ldots , C_n\) the side premises and C the main premise. Further suppose \(R_p\) is the P-Res resolvent of applying the P-Res rule to a sub-multiset of \(C_1, \ldots , C_n\) and C. Then, I is redundant with respect to \(N \cup \{R_p\}\).

Proof

Suppose R is the resolvent of I and \(\succ \) is the applied admissible ordering. By the notion of redundant inferences for ground clauses, we prove that \(C \succ R_p\) and \(C_1, \ldots , C_n, R_p \models R\). W.l.o.g. suppose

$$\begin{aligned} C_1 = A_1 \vee D_1, \ldots , C_n = A_n \vee D_n \ \text {and} \ C = \lnot A_1 \vee \ldots \vee \lnot A_m \vee \ldots \vee \lnot A_n \vee D \end{aligned}$$

where \(1 \le m \le n\). Further suppose a P-Res inference is performed on C and \(C_1, \ldots , C_m\). By the definitions of the S-Res and P-Res rules,

$$\begin{aligned} R = D_1 \vee \ldots \vee D_n \vee D \ \text {and} \ R_p = \lnot A_{m+1} \vee \ldots \vee \lnot A_{n} \vee D_1 \vee \ldots \vee D_m \vee D. \end{aligned}$$

By Condition 1. of the S-Res and P-Res rules, \(A_1 \succ D_1, \ldots , A_m \succ D_m\), hence \(C \succ R_p\). Next, we prove \(C_1, \ldots , C_n, R_p \models R\) by contradiction. Let I be an arbitrary interpretation satisfying that

$$\begin{aligned}&I \models A_1 \vee D_1, \ldots , A_n \vee D_n, \lnot A_{m+1} \vee \ldots \vee \lnot A_{n} \vee D_1 \vee \ldots \vee D_m \vee D, \end{aligned}$$
(1)
$$\begin{aligned}&\text {but} \ I \not \models D_1 \vee \ldots \vee D_n \vee D. \end{aligned}$$
(2)

(2) implies \(I \not \models D_1, \ldots , I \not \models D_n\), therefore, considering (1) we get that

$$\begin{aligned} I \models A_1, \ldots , A_n, \lnot A_{m+1} \vee \ldots \vee \lnot A_{n} \vee D_1 \vee \ldots \vee D_m \vee D. \end{aligned}$$
(3)

(3) implies that \(I \models D_1 \vee \ldots \vee D_m \vee D\). As \(D_1 \vee \ldots \vee D_m \vee D\) is a subclause of \(D_1 \vee \ldots \vee D_n \vee D\), \(I \models D_1 \vee \ldots \vee D_n \vee D\), which refutes (2). Then, \(C_1, \ldots , C_n, R_p \models R\). By the facts that \(C \succ R_p\) and \(C_1, \ldots , C_n, R_p \models R\), I is redundant with respect to \(N \cup \{R_p\}\). \(\square \)

Lemma 10 shows that given an S-Res inference I on ground clauses of a clausal set N, computing a P-Res resolvent \(R_p\) with respect to I makes I redundant with respect to \(N \cup \{R_p\}\). Similar justifications can be found in [8, pp. 53–54] and [7, p. 28] described as ‘partial replacement strategy’.

Next, we generalise Lemma 10 to non-ground inferences.

Lemma 11

Suppose N is a clausal set and \(C_1, \ldots , C_n, C\) are general clauses occurring in N. Suppose I is an S-Res inference where \(C_1, \ldots , C_n\) are the side premises and C is the main premise. Further suppose \(R_p\) is the P-Res resolvent of applying the P-Res rule to a sub-multiset of \(C_1, \ldots , C_n\) and C. Then, every ground instance of I is redundant with respect to the ground instances of the clauses in \(N \cup \{R_p\}\).

Proof

Suppose R is the S-Res resolvent in I. W.l.o.g. suppose \(C_1, \ldots , C_m\) are side premises of applying the P-Res rule to C and \(C_1, \ldots , C_m\) and \(R_p\) is the resolvent, where \(1 \le m \le n\). Suppose \(\sigma \) is a ground substitution satisfying that applying the S-Res rule to \(C_1\sigma , \ldots , C_n\sigma \) as the side premises and \(C\sigma \) as the main premise derives \(R\sigma \). We use \(I_{gnd}\) to denote this ground S-Res inference. Since the P-Res rule only requires a sub-multiset of the S-Res side premises, the P-Res rule is applicable to \(C_1\sigma , \ldots , C_m\sigma \) as the side premises and \(C\sigma \) as the main premise, deriving \(R_p\sigma \). By Lemma 10, \(I_{gnd}\) is redundant with respect to the ground instances \(C_1\sigma , \ldots , C_n\sigma , R_p\sigma \) of the clauses in \(N \cup \{R_p\}\). Hence, every ground S-Res inference is redundant with respect to the ground instances of the clauses in \(N \cup \{R_p\}\). \(\square \)

The main result of this section is then as follows.

Theorem 12

The P-Res system is sound and refutationally complete for general first-order clausal logic.

Proof

By Lemma 10 and Theorem 9, the P-Res system is sound and complete for ground clauses. By the fact that the Factor rule is the positive factoring rule in the resolution framework of [8] and Lemma 11, the P-Res system is sound and refutational complete for general first-order clauses. \(\square \)

4.4 The T-Res System

Finally, we present the top-variable resolution inference system, referred to as the T-Res system. As a special case of the P-Res system, the T-Res system uses the customised admissible orderings, selection functions and a specific version of the P-Res rule, i.e., the top-variable resolution rule T-Res, particularly devised for deciding satisfiability of the LGQ clausal class.

First, we give the top-variable resolution rule T-Res. Suppose in an S-Res inference with \(C_1 = B_1 \vee D_1, \ldots , C_n = B_n \vee D_n\) the side premises and \(C = \lnot A_1 \vee \ldots \vee \lnot A_n \vee ~D\) the main premise with \(\lnot A_1, \ldots , \lnot A_n\) selected. The top-variable technique is applied to this inference by the following steps.

  1. 1.

    Without producing or adding the resolvent, compute an mgu \(\sigma ^\prime \) for \(C_1, \ldots , C_n\) and C such that \(\sigma ^\prime = {{\,\textrm{mgu}\,}}(A_1 \doteq B_1, \ldots , A_n \doteq B_n)\).

  2. 2.

    Compute the variable ordering \(>_v\) and \(=_v\) over the variables of \(\lnot A_1 \vee \ldots \vee \lnot A_n\). By definition, \(x >_v y\) and \(x =_v y\) with respect to \(\sigma ^\prime \), if \({{\,\textrm{dep}\,}}(x\sigma ^\prime ) > {{\,\textrm{dep}\,}}(y\sigma ^\prime )\) and \({{\,\textrm{dep}\,}}(x\sigma ^\prime ) = {{\,\textrm{dep}\,}}(y\sigma ^\prime )\), respectively.

  3. 3.

    Based on \(>_v\) and \(=_v\), the maximal variables in \(\lnot A_1 \vee \ldots \vee \lnot A_n\) are the top variables. The sub-multiset \(\lnot A_1, \ldots , \lnot A_m\) of \(\lnot A_1, \ldots , \lnot A_n\) (\(1 \le m \le n\)) are the top-variable literals if each literal in \(\lnot A_1, \ldots , \lnot A_m\) contains at least one top variable, and \(\lnot A_1 \vee \ldots \vee \lnot A_m\) is the top-variable subclause of C.

The top-variable resolution rule is defined by

figure f

Top variables, top-variable literals and top-variable subclauses are only in effect with respect to an S-Res inference, since the T-Res rule is a very specific application of the P-Res rule, built on the top of the S-Res rule. Suppose I is an S-Res inference with \(C_1, \ldots , C_n\) the side premises and C the main premise. As shown in the previous section, the P-Res rule allows one to perform an inference on C and any sub-multiset of \(C_1, \ldots , C_n\). Suppose I\(^\prime \) is a P-Res inference based on I. Then, in the computation of I\(^\prime \), the T-Res rule further specifies the sub-multiset N of \(C_1, \ldots , C_n\) by the top-variable technique. Let I\(^{\prime \prime }\) be a T-Res inference based on I\(^{\prime }\) in which C is the main premise and the side premises are clauses in N. To ensure that the clauses in N are the P-Res side premises in I\(^{\prime \prime }\), we use the complementary literals of the eligible literals of N to restrict the inference and name these literals the top-variable literals. Therefore, although the T-Res rule identifies the top-variable literals as per S-Res inference, the top-variable literals are not determined by a dynamic selection function, but by the presence of S-Res side premises. This top-variable technique provides the basis for our decision procedures discussed later. Since a T-Res inference is based on the existence of an S-Res inference, the mgu for the T-Res inference is ensured to exist, hence the top-variable literals in T-Res inferences can always be identified. To distinguish the mgus of the T-Res and the S-Res rules, we use \(\sigma \) and \(\sigma ^\prime \) to denote them, respectively.

Now we provide the customised admissible orderings and selection functions. As admissible orderings, we choose to use any lexicographic path ordering \(\succ _{lpo}\) with a precedence in which function symbols are larger than constants, which are larger than predicate symbols. This is a requirement also for any admissible ordering with the same precedence restriction. For selection functions, we require the selection function \({{\,\textrm{SelectNC}\,}}\) to select one of the negative compound-term literals in LGQ clauses containing negatively occurring compound-term literals.

Algorithm 1 details how the admissible ordering \(\succ _{lpo}\), the selection function \({{\,\textrm{SelectNC}\,}}\) and the T-Res rule are applied to LGQ clauses. The algorithm contains the following functions:

  • \({{\,\textrm{Max}\,}}(C)\) returns a (strictly) \(\succ _{lpo}\)-maximal literal with respect to the clause C.

  • \({{\,\textrm{SelectNC}\,}}(C)\) returns one of the negative compound-term literals in the clause C.

  • \({{\,\textrm{TRes}\,}}(N, C)\) performs a T-Res inference with clauses in N the side premises and C the main premise, returning

    1. 1.

      either all negative literals of the clause C, or

    2. 2.

      the top-variable literals of the clause C (with respect to this T-Res inference).

Algorithm 1
figure g

Find the eligible or the top-variable literals for LGQ clauses

Algorithm 2
figure h

The \({{\,\textrm{TRes}\,}}\) function

Algorithm 2 specifies the \({{\,\textrm{TRes}\,}}(N,C)\) function, describing the application of the T-Res rule to a non-ground flat LGQ clause C as the main premise and \(C_1, \ldots , C_n\) occurring in N as the side premises. In Algorithm 2, the \({{\,\textrm{ComT}\,}}(C_1, \ldots , C_n, C)\) function finds the top-variable literals in C with respect to the S-Res inference when \(C_1, \ldots , C_n\) are the side premises and C is the main premise. Algorithm 2 first tries to perform an S-Res inference on \(C_1, \ldots , C_n\) and C, and if it is possible, the S-Res inference is immediately replaced by a T-Res inference. In the algorithm Lines 2–3 check whether the S-Res rule applies to \(C_1, \ldots , C_n\) as the side premises and C as the main premise with all negative literals selected. If so, Line 5 uses the \({{\,\textrm{ComT}\,}}(C_1, \ldots , C_n, C)\) function to compute the top-variable literals in C with respect to this S-Res inference, ensuring that the T-Res rule is applicable to C and the sub-multiset of \(C_1, \ldots , C_n\) mapping to the top-variable literals in C. Otherwise, Line 6 returns all negative literals of C, meaning that no S-Res inference, hence no T-Res inference, is possible for \(C_1, \ldots , C_n\) and C. Though the T-Res rule does not require one to select all negative literals in the S-Res main premise, the \({{\,\textrm{TRes}\,}}\) function requires it because it is essential for deciding satisfiability of the LGQ clausal class.

The following sample derivation shows how the T-Res system decides an unsatisfiable set of LG clauses. Consider an unsatisfiable set N of LG clauses \(C_1, \ldots , C_9\):

$$\begin{aligned} C_1 = \ {}&\lnot A_1(x,y) \vee \lnot A_2(y,z) \vee \lnot A_3(z,x) \vee B(x,y,b), \\ C_2 = \ {}&A_3(x,f(x)) \vee \lnot G_3(x), \qquad \qquad \ \ \quad C_3 = A_2(f(x),f(x)) \vee \lnot G_2(x), \\ C_4 = \ {}&A_1(f(x),x) \vee D(g(x)) \vee \lnot G_1(x), \qquad \qquad \quad \qquad C_5 = \lnot B(x,y,b), \\ C_6 = \ {}&\lnot D(x), \ \ \quad C_7 = G_1(f(a)), \ \ \qquad C_8 = G_3(f(a)), \qquad C_9 = G_2(a). \end{aligned}$$

Suppose the precedence on which \(\succ _{lpo}\) is based is \(f> g> a> b> B> A_1> A_2> A_3> D> G_1> G_2 > G_3\). By \(\boxed {L}\) or \(L^*\) we mean that L is selected or L is a (strictly) maximal literal, respectively. In the T-Res system, \(C_1, \ldots , C_9\) are presented as:

$$\begin{aligned} C_1 = \ {}&\boxed {\lnot A_1(x,y)} \vee \boxed {\lnot A_2(y,z)} \vee \boxed {\lnot A_3(z,x)} \vee B(x,y,b), \\ C_2 = \ {}&A_3(x,f(x))^*\vee \lnot G_3(x), \qquad \qquad \quad \ \ \ C_3 = A_2(f(x),f(x))^*\vee \lnot G_2(x), \\ C_4 = \ {}&A_1(f(x),x)^*\vee D(g(x)) \vee \lnot G_1(x), \qquad \qquad \qquad \quad C_5 = \boxed {\lnot B(x,y,b)}, \\ C_6 = \ {}&\boxed {\lnot D(x)}, \ \ \quad C_7 = G_1(f(a))^*, \ \ \quad C_8 = G_3(f(a))^*, \quad \quad C_9 = G_2(a)^*. \end{aligned}$$

One can use any clause to start a derivation, w.l.o.g. we begin with \(C_1\). For each newly derived clause, Algorithm 1 is applied to determine the eligible or the top-variable literals of the clause.

  1. 1.

    By Algorithm 1 and the fact that \(C_1\) is a non-ground flat LG clause, the \({{\,\textrm{TRes}\,}}\) function is applied to \(C_1\) and clauses in N. In Algorithm 2, all negative literals in \(C_1\) are temporarily selected to check if the S-Res rule is applicable to \(C_1\).

  2. 2.

    As an S-Res inference step is applicable to \(C_2, C_3, C_4\) as the side premises and \(C_1\) as the main premise, the \({{\,\textrm{ComT}\,}}(C_2, C_3, C_4, C_1)\) function computes an mgu

    $$\begin{aligned} \sigma ^\prime = \{x \mapsto f(f(x^\prime )), y \mapsto f(x^\prime ), z \mapsto f(x^\prime )\} \end{aligned}$$

    for variables of \(C_1\). Hence x is the only top variable in \(C_1\) and therefore \(\lnot A_1(x,y)\) and \(\lnot A_3(z,x)\) are the top-variable literals. This means that based on the S-Res inference on C and \(C_2, C_3, C_4\), we intend to perform a special P-Res inference, viz., a T-Res inference, with C the main premise and \(C_2\) and \(C_4\) the side premises.

  3. 3.

    The T-Res rule is applied to \(C_2\) and \(C_4\) as the side premises and \(C_1\) as the main premise with an mgu \(\sigma = \{x \mapsto f(x^\prime ), y \mapsto x^\prime , z \mapsto x^\prime \}\), deriving

    $$\begin{aligned} C_{10} = \lnot A_2(x,x) \vee B(f(x),x,b)^*\vee D(g(x)) \vee \lnot G_1(x) \vee \lnot G_3(x), \end{aligned}$$

    with \(x^\prime \) renamed as x. No resolution step can be performed on \(C_3\) and \(C_{10}\) for the lack of complementary eligible literals, nonetheless a resolution inference step can be performed between \(C_{5}\) and \(C_{10}\).

  4. 4.

    By Algorithm 2, the S-Res rule is applicable to \(C_{5}\) as the main premise and \(C_{10}\) as the side premise. Since \(C_{5}\) contains only one negative literal, the literal is the top-variable literal in \(C_{5}\). Then applying the T-Res rule to \(C_{10}\) and \(C_{5}\) derives

    $$\begin{aligned} C_{11} = \lnot A_2(x,x) \vee D(g(x))^*\vee \lnot G_1(x) \vee \lnot G_3(x). \end{aligned}$$
  5. 5.

    By Algorithm 2, the T-Res rule is applicable to \(C_{11}\) as the side premise and \(C_{6}\) as the main premise with \(\lnot D(x)\) the top-variable literal, deriving

    $$\begin{aligned} C_{12} = \boxed {\lnot A_2(x,x)} \vee \boxed {\lnot G_1(x)} \vee \boxed {\lnot G_3(x)}. \end{aligned}$$
  6. 6.

    Due to the presence of \(C_3, C_7, C_8\) and \(C_{12}\) satisfy conditions of the \({{\,\textrm{TRes}\,}}\) function, the \({{\,\textrm{ComT}\,}}(C_3, C_7, C_8, C_{12})\) function finds that x is the only top variable in \(C_{12}\) with an mgu \(\sigma ^\prime = \{x \mapsto f(a)\}\). Hence all negative literals in \(C_{12}\) are the top-variable literals. Applying the T-Res rule to \(C_3, C_7, C_8\) as the side premises and \(C_{12}\) as the main premise derives \(C_{13} = \boxed {\lnot G_2(a)}\).

  7. 7.

    Applying the T-Res rule to \(C_9\) and \(C_{13}\) derives \(\bot \).

Recall that by the term depth of a clause, we mean the depth of the deepest term in that clause. As shown by the above example, the T-Res rule avoids term depth increase in resolvents of LGQ clauses. Suppose the \({{\,\textrm{ComT}\,}}(C_1, \ldots , C_n, C)\) function takes LGQ clauses \(C_1, \ldots , C_n\) and C as input and C is a non-ground flat LGQ clause. In the application of the top-variable technique to \(C_1, \ldots , C_n\) and C, Step 1. first computes an S-Res mgu of \(C_1, \ldots , C_n\) and C, and Steps 2.–3. then find the variable x in C that is unified to be the deepest term \(x\sigma ^\prime \) in \(C\sigma ^\prime \) as the top variable. As \(x\sigma ^\prime \) may become a nested term in the S-Res resolvent, the T-Res rule computes a partial resolvent, by only resolving the top-variable literals of C, to avoid this potential term depth increase caused by \(x\sigma ^\prime \). In the previous example, if an S-Res inference is computed on \(C_1\) as the main premise and \(C_2, C_3, C_4\) as the side premises, a nested compound term f(f(x)) will occur in the S-Res resolvent.

Now we give the main result of this section.

Theorem 13

The T-Res system is sound and refutationally complete for general first-order clausal logic.

Proof

By Theorem 12 and since T-Res is a special case of the P-Res system. \(\square \)

The definitions in the resolution framework of [8] and most resolution-based decision procedures [35] stipulate that eligibility, in particular (strict) maximality, of literals is determined on the instantiated premises with the mgus, i.e., a-posteriori eligibility is used. Instead, a-priori eligibility determines eligibility, in particular (strict) maximality, of literals on the non-instantiated premises. A-posteriori eligibility is more general and stronger than a-priori eligibility. However, a-priori eligibility is possible is more efficient, due to the overhead of pre-computing unifications.

The T-Res system uses a-posteriori eligibility, however, thanks to the covering and strong compatibility properties of the LGQ clausal class, one can use a-priori eligibility. This is briefly mentioned in deciding satisfiability of guarded clauses with equality in [39]. We now formally prove this claim.

Lemma 14

Let a covering clause C contain a compound-term literal \(L_1\) and a non-compound-term literal \(L_2\). Then \(L_1 \succ _{lpo} L_2\).

Proof

We distinguish two cases: i) Suppose \(L_1\) contains a ground compound term. By the covering property, C is ground. Then \(L_1 \succ _{lpo} L_2\) as \(L_1\) contains at least one function symbol but \(L_2\) does not.

ii) Suppose \(L_1\) contains a non-ground compound term t. By the covering property, \({{\,\textrm{var}\,}}(t) = {{\,\textrm{var}\,}}(L_1) = {{\,\textrm{var}\,}}(C)\). By the facts that \({{\,\textrm{var}\,}}(L_2) \subseteq {{\,\textrm{var}\,}}(L_1)\) and \(L_1\) contains at least one function symbol but \(L_2\) does not, \(L_1 \succ _{lpo} L_2\). \(\square \)

By the covering and the strong compatibility properties of LGQ clauses, a literal identified as eligible by a-posteriori eligibility is the same as the one identified by a-priori eligibility. This is formally stated as:

Lemma 15

When applying the refinement of the T-Res system to an LGQ clause C, if a literal L is (strictly) \(\succeq _{lpo}\)-maximal with respect to C, then \(L\sigma \) is (strictly) \(\succeq _{lpo}\)-maximal with respect to \(C\sigma \), for any substitution \(\sigma \).

Proof

In Algorithm 1, the maximality checking is done in either Lines 1–2 or 5–6.

For the case in Lines 1–2 the claim trivially holds as C is ground. Lines 5–6 mean that C contains compound-term literals. By Lemma 14, L is a compound-term literal. Suppose \(L^\prime \) is a literal in C distinct from L. First, suppose \(L^\prime \) is not a compound-term literal. By the covering property, \(L \succeq _{lpo} L^\prime \) implies \(L\sigma \succeq _{lpo} L^\prime \sigma \) for any substitution \(\sigma \). Next, suppose \(L^\prime \) is a compound-term literal. By the fact that C is strongly compatible, \(L \succeq _{lpo} L^\prime \) implies \(L\sigma \succeq _{lpo} L^\prime \sigma \) for any substitution \(\sigma \). Thus, \(L\sigma \) is (strictly) maximal with respect to \(C\sigma \). \(\square \)

Lemma 15 is generalisable to any covering and strongly compatible clause, as it is these properties that make a-priori eligibility determination possible. From now on we assume the use of a-priori eligibility to determine (strictly) maximal literals in the T-Res system. This also streamlines the discussions and simplifies proofs.

5 Deciding Satisfiability of the LG Clausal Class

Having shown in the previous section that the T-Res system is sound and refutational complete, now we prove the system decides the LG clausal class. Our goal is to show: given a finite signature, applying the conclusion-deriving Deduce rules in the T-Res system to a set of LG clauses only derives LG clauses that are of bounded depth and width. This claim is achieved by restricting that in an LG clause C, the eligible literals or the top-variable literals

  1. 1.

    have the same variables set as C, and

  2. 2.

    are the deepest literals in C.

First, we show 1.

Lemma 16

By the T-Res system, the eligible literals or the top-variable literals in an LG clause C have the same variable set as C.

Proof

Being led by Algorithm 1, we distinguish three cases:

Lines 1–2: When C is ground the statement trivially holds.

Lines 3–6: Suppose C is a non-ground compound-term LG clause and L is an eligible literal in C. Suppose L is positive. By the \({{\,\textrm{Max}\,}}\) function and \(\succ _{lpo}\), L is a positive compound-term literal. Next, suppose L is negative. By the \({{\,\textrm{SelectNC}\,}}\) function, L is a negative compound-term literal. In either case, by the covering property of LG clauses, \({{\,\textrm{var}\,}}(L) = {{\,\textrm{var}\,}}(C)\).

Lines 7: Suppose C is a non-ground flat LG clause and \(\mathbb {L}\) are the top-variable literals in C. Suppose x is a top variable in C. By 2. of Definition 6 and the definition of top-variable literals, x co-occurs with all other variables of C in \(\mathbb {L}\), therefore \({{\,\textrm{var}\,}}(\mathbb {L}) = {{\,\textrm{var}\,}}(C)\). \(\square \)

For 2, the T-Res system ensures that the deepest literals in LG clauses are eligible. Specifically Lines 3–6 of Algorithm 1 ensure that when an LG clause contains non-ground compound-terms, one of the compound-term literals is eligible.

Compound-term covering clauses have the following property.

Remark 17

Suppose C is a covering clause and contains ground compound terms. Then, C is ground.

Proof

By the definition of the covering property. \(\square \)

Next, we look at the unification for the eligible literals of LG clauses. We first investigate the pairing property of compound-term eligible literals. Recall the definition of pairing from Sect. 2: Given two atoms \(A(\ldots , s, \ldots )\) and \(B(\ldots , t, \ldots )\) with terms s and t, we say s pairs t if the argument position of s in \(A(\ldots , s, \ldots )\) is the same as that of t in \(B(\ldots , t, \ldots )\).

Lemma 18

Let \(A_1\) and \(A_2\) be two simple and covering compound-term atoms, and suppose \(A_1\) and \(A_2\) are unifiable using an mgu \(\sigma \). Then, compound terms in \(A_1\) pair only compound terms in \(A_2\) and vice-versa.

Proof

We distinguish three cases: i) The statement trivially holds when both \(A_1\) and \(A_2\) are ground atoms.

ii) Suppose one of \(A_1\) and \(A_2\) is a ground atom and the other one is a non-ground atom. By Remark 17, the non-ground atom in \(A_1\) and \(A_2\) contains no ground compound terms. Hence, in this case, a non-ground compound term pairs either a ground compound term or a constant. As unifying a non-ground compound term with a constant is not possible, a non-ground compound term must pair a ground compound term.

iii) Suppose both \(A_1\) and \(A_2\) are non-ground. W.l.o.g., \(A_1\) and \(A_2\) are represented as \(A_1(t,t^\prime ,\ldots )\) and \(A_2(u,u^\prime ,\ldots )\), respectively. By Remark 17 and the fact that \(A_1\) and \(A_2\) are non-ground atoms, if any of t, \(t^\prime \), u and \(u^\prime \) is a compound term, then it is a non-ground compound term.

Suppose t is a compound term. We prove that u is a compound term by contradiction. Then u can be either a constant or a variable. The case that u is a constant prevents the unification of \(t\sigma = u\sigma \). Now suppose u is a variable. As \(A_2\) is a compound-term literal, w.l.o.g., suppose \(u^\prime \) is a compound term in \(A_2\). Then \(t^\prime \) is not a constant as it prevents the unification of \(u^\prime \) and \(t^\prime \), therefore, \(t^\prime \) is a variable or a compound term. We distinguish the two cases of \(t^\prime \): 1) Suppose \(t^\prime \) is a variable. By the covering property, w.l.o.g., we use \(f(\ldots , x, \ldots )\), x, y and \(g(\ldots , y, \ldots )\) to represent t, \(t^\prime \), u and \(u^\prime \) respectively. Then \(A_1(t,t^\prime ,\ldots )\) and \(A_2(u,u^\prime ,\ldots )\) are represented as \(A_1(f(\ldots , x, \ldots ), x, \ldots )\) and \(A_2(y, g(\ldots , y, \ldots ), \ldots )\), respectively. The unification between these two atoms is impossible due to occur-check failure.

2) Suppose \(t^\prime \) is a compound term. By the covering property, w.l.o.g., we use \(f(\overline{x})\), \(g(\overline{x})\), y and \(g(\ldots , y, \ldots )\) to represent t, \(t^\prime \), u and \(u^\prime \) respectively. Then \(A_1(t,t^\prime ,\ldots )\) and \(A_2(u,u^\prime ,\ldots )\) are represented as \(A_1(f(\overline{x}), g(\overline{x}), \ldots )\) and \(A_2(y, g(\ldots , y, \ldots ), \ldots )\), respectively. Then there exists no unifier for these two atoms again due to occur-check failure. The fact that u is neither a constant nor a variable implies that u is a compound term. \(\square \)

The loose guard in the premise of Factor inferences or the loose guard in the side premise of T-Res inferences act as the loose guard of the conclusion. Formally:

Lemma 19

Let \(A_1\) and \(A_2\) be two simple and covering atoms, and suppose \(A_1\) and \(A_2\) are unifiable using an mgu \(\sigma \). Further suppose \(\mathbb {G}\) is a set of flat literals satisfying \({{\,\textrm{var}\,}}(A_1) = {{\,\textrm{var}\,}}(\mathbb {G})\). Then, if \(A_1\) is a compound-term atom, \({{\,\textrm{var}\,}}(A_1\sigma ) = {{\,\textrm{var}\,}}(\mathbb {G}\sigma )\) and all literals in \(\mathbb {G}\sigma \) are flat.

Proof

Since \({{\,\textrm{var}\,}}(A_1) = {{\,\textrm{var}\,}}(\mathbb {G})\), it is immediate that \({{\,\textrm{var}\,}}(A_1\sigma ) = {{\,\textrm{var}\,}}(\mathbb {G}\sigma )\).

We prove that \(\mathbb {G}\sigma \) is a set of flat literals by distinguishing two cases: i) Assume that \(A_2\) is flat. This implies that \(\sigma \) substitutes variables in \(A_1\) with either variables or constants. By the facts that \(\mathbb {G}\) is a set of flat literals and \({{\,\textrm{var}\,}}(A_1) = {{\,\textrm{var}\,}}(\mathbb {G})\), all literals in \(\mathbb {G}\sigma \) are flat.

ii) Assume that \(A_2\) is a compound-term literal. By Lemma 18, compound terms in \(A_1\) pair compound terms in \(A_2\) and vice-versa. Since \(A_1\) and \(A_2\) are simple, the mgu \(\sigma \) substitutes variables in \(A_1\) with either variables or constants. Since \(\mathbb {G}\) is a set of flat literals and \({{\,\textrm{var}\,}}(A_1) = {{\,\textrm{var}\,}}(\mathbb {G})\), all literals in \(\mathbb {G}\sigma \) are flat. \(\square \)

Lemmas 2021 below consider non-loose-guard literals in the conclusions of LG clauses. A similar result to Lemma 20 is Lemma 4.6 in [39], but a key ‘covering’ condition is not considered. First, we look at the depth of eligible literals.

Lemma 20

Suppose \(A_1\) and \(A_2\) are two simple and covering atoms, and they are unifiable using an mgu \(\sigma \). Then, \(A_1\sigma \) is simple.

Proof

If either of \(A_1\) and \(A_2\) is ground, or either of \(A_1\) and \(A_2\) is non-ground and flat, then immediately \(A_1\sigma \) is simple.

Let both \(A_1\) and \(A_2\) be compound-term atoms. By Lemma 18 and since \(A_1\) and \(A_2\) are simple, the mgu \(\sigma \) substitutes variables with either constants or variables. Then, the fact that \(A_1\) is simple implies that \(A_1\sigma \) is simple.\(\square \)

Next we study the depth and width of non-eligible literals in conclusions.

Lemma 21

Let \(A_1\) and \(A_2\) be two simple atoms satisfying \({{\,\textrm{var}\,}}(A_2) \subseteq {{\,\textrm{var}\,}}(A_1)\). Then given an arbitrary substitution \(\sigma \), these properties hold:

  1. 1.

    If \(A_1\sigma \) is simple, then \(A_2\sigma \) is simple.

  2. 2.

    \({{\,\textrm{var}\,}}(A_2\sigma ) \subseteq {{\,\textrm{var}\,}}(A_1\sigma )\).

Further suppose that t and u are, respectively, compound terms occurring in \(A_1\) and \(A_2\) satisfying \({{\,\textrm{var}\,}}(t) = {{\,\textrm{var}\,}}(u) = {{\,\textrm{var}\,}}(A_1)\). Then, \({{\,\textrm{var}\,}}(t\sigma ) = {{\,\textrm{var}\,}}(u\sigma ) = {{\,\textrm{var}\,}}(A_1\sigma )\).

Proof

By the assumption that \(A_1\) and \(A_1\sigma \) are simple, \(\sigma \) does not cause term depth increase in \(A_1\sigma \). By the facts that \({{\,\textrm{var}\,}}(A_2) \subseteq {{\,\textrm{var}\,}}(A_1)\) and \(A_2\) is simple, \(A_2\sigma \) is simple.

By the facts that \({{\,\textrm{var}\,}}(A_2) \subseteq {{\,\textrm{var}\,}}(A_1)\) and \({{\,\textrm{var}\,}}(t) = {{\,\textrm{var}\,}}(u) = {{\,\textrm{var}\,}}(A_1)\), it is immediate that \({{\,\textrm{var}\,}}(A_2\sigma ) \subseteq {{\,\textrm{var}\,}}(A_1\sigma )\) and \({{\,\textrm{var}\,}}(t\sigma ) = {{\,\textrm{var}\,}}(u\sigma ) = {{\,\textrm{var}\,}}(A_1\sigma )\), respectively. \(\square \)

Recall that a flat compound term is a compound term containing only variables and constants as arguments. We consider how the strong compatibility property holds in the conclusions.

Lemma 22

Let s, \(s^\prime \), t and \(t^\prime \) be flat compound terms. Suppose s and t are compatible with \(s^\prime \) and \(t^\prime \), respectively. Then, if \(s\sigma \doteq t\sigma \) with an arbitrary substitution \(\sigma \), the following conditions are satisfied.

  1. 1.

    \(s\sigma \) and \(s^\prime \sigma \) are compatible, and \(t\sigma \) and \(t^\prime \sigma \) are compatible.

  2. 2.

    s and t are compatible, and \(s\sigma \) and \(t\sigma \) are compatible.

  3. 3.

    \(s^\prime \sigma \) and \(t^\prime \sigma \) are compatible.

Proof

Since s and t are, respectively, compatible with \(s^\prime \) and \(t^\prime \), \(s\sigma \) and \(t\sigma \) are compatible with \(s^\prime \sigma \) and \(t^\prime \sigma \), respectively. Since s and t are unifiable by \(\sigma \), \(s\sigma \) and \(t\sigma \) are compatible. Then, 1. implies that \(s^\prime \sigma \) and \(t^\prime \sigma \) are compatible. \(\square \)

A compound-term LG clause with a compound-term literal removed is still an LG clause. We generalise this claim with applications of substitutions.

Lemma 23

Suppose \(C = D \vee B\) is an LG clause with B a compound-term literal. Further, suppose \(\sigma \) is a substitution that substitutes all variables in C with either constants or variables. Then, \(D\sigma \) is an LG clause.

Proof

If \(\sigma \) is a ground substitution, the lemma trivially holds. Suppose \(\sigma \) is a non-ground substitution. We prove that \(D\sigma \) is simple, covering, strongly compatible and contains a loose guard. Since C is an LG clause and D is a subclause of C, D is simple. Because \(\sigma \) substitutes variables with either constants or variables, \(D\sigma \) is simple. Let s and t be two arbitrary compound terms in D. That C is covering implies that \({{\,\textrm{var}\,}}(t) = {{\,\textrm{var}\,}}(C)\), hence \({{\,\textrm{var}\,}}(t) = {{\,\textrm{var}\,}}(D)\), and therefore \({{\,\textrm{var}\,}}(t\sigma ) = {{\,\textrm{var}\,}}(D\sigma )\). Then \(D\sigma \) is covering. Since C is strongly compatible, s and t are compatible. By 2. of Lemma 22, \(s\sigma \) and \(t\sigma \) are compatible, hence \(D\sigma \) is strongly compatible. Suppose \(\mathbb {G}\) is a set of flat literals that acts as a loose guard of C. Then \(\mathbb {G}\) is a loose guard of D. Since \(\sigma \) substitutes variables with either constants or variables and all literals in \(\mathbb {G}\) are flat, all literals in \(\mathbb {G}\sigma \) are flat. Since \({{\,\textrm{var}\,}}(\mathbb {G}) = {{\,\textrm{var}\,}}(C)\) and D is a subclause of C, \({{\,\textrm{var}\,}}(\mathbb {G}\sigma ) = {{\,\textrm{var}\,}}(D\sigma )\). By the facts that \(\sigma \) substitutes variables with either constants or variables and \(\mathbb {G}\) is a loose guard of D, each pair of variables of \(D\sigma \) co-occurs in a literal of \(\mathbb {G}\sigma \). Hence \(\mathbb {G}\sigma \) is a loose guard of \(D\sigma \). Therefore, \(D\sigma \) is an LG clause. \(\square \)

We establish properties of applying the T-Res rule to a flat clause and LG clauses.

Lemma 24

Suppose a T-Res inference happens to LG clauses as the side premises and a non-ground flat clause as the main premise, with Condition 2b. of the T-Res rule satisfied. Then, the top variables in the main premise pair constants or compound terms in the side premises, and the non-top variables in the main premise pair constants or variables in the side premises.

Proof

Assuming that a-priori eligibility is applied, the T-Res rule is simplified to:

provided the following conditions are satisfied.

  1. 1.

    No literal is selected in \(D_1, \ldots , D_n,D\) and \(B_1, \ldots , B_n\) are strictly \(\succ _{lpo}\)-maximal with respect to \(D_1, \ldots , D_n\), respectively.

  2. 2a.

    If \(n = 1\), then i) either \(\lnot A_1\) is selected, or nothing is selected in \(\lnot A_1 \vee D\) and \(\lnot A_1\) is \(\succ _{lpo}\)-maximal with respect to D, and ii) \(\sigma = {{\,\textrm{mgu}\,}}(A_1 \doteq B_1)\) or

  3. 2b.

    there must exist an mgu \(\sigma ^\prime \) such that \(\sigma ^\prime = {{\,\textrm{mgu}\,}}(A_1 \doteq B_1, \ldots , A_n \doteq B_n)\), then \(\lnot A_1, \ldots , \lnot A_m\) are the top-variable literals of \(\lnot A_1 \vee \ldots \vee \lnot A_{m} \vee \ldots \vee \lnot A_n \vee D\) and \(\sigma = {{\,\textrm{mgu}\,}}(A_1 \doteq B_1, \ldots , A_m \doteq B_m)\) where \(1 \le m \le n\).

  4. 3.

    All premises are variable disjoint.

W.l.o.g. suppose \(\lnot A_t(\ldots , x, \ldots , y, \ldots )\) is a literal in \(\lnot A_1, \ldots , \lnot A_m\), x is a top variable and y is a non-top variable (if it exists). Further suppose \(\sigma ^\prime \) is the S-Res mgu that \(\sigma ^\prime = {{\,\textrm{mgu}\,}}(A_1 \doteq B_1, \ldots , A_n \doteq B_n)\). Suppose \(C_t = B_t(\ldots , t_1, \ldots , t_2, \ldots ) \vee D_t\) is the side premise such that \(A_t(\ldots , x, \ldots , y, \ldots )\sigma ^\prime = B_t(\ldots , t_1, \ldots , t_2, \ldots )\sigma ^\prime \), and \(t_1\) and \(t_2\) pair x and y, respectively.

We prove that \(t_1\) is either a constant or a compound term and \(t_2\) is either a constant or a variable by distinguishing two cases of \(C_t\). i) Suppose \(C_t\) is ground. Then, immediately \(t_1\) is either a constant or a ground compound term. We prove that \(t_2\) is a constant by contradiction. Assume that \(t_2\) is a ground compound term. The fact that \(C_t\) is simple implies \({{\,\textrm{dep}\,}}(t_2) \ge {{\,\textrm{dep}\,}}(t_1)\). Since \(t_1\) and \(t_2\) are ground, \({{\,\textrm{dep}\,}}(t_2\sigma ^\prime ) \ge {{\,\textrm{dep}\,}}(t_1\sigma ^\prime )\), and \({{\,\textrm{dep}\,}}(y\sigma ^\prime ) \ge {{\,\textrm{dep}\,}}(x\sigma ^\prime )\), which contradicts that y is not a top variable. Therefore, \(t_2\) is a constant.

ii) Suppose \(C_t\) is non-ground. Then Lines 3–7 in Algorithm 1 are used to check eligibility in \(C_t\). By the fact that the eligible literal in \(C_t\) is positive, Lines 5–6 are applied to \(C_t\), hence \(C_t\) is a non-ground compound-term clause and \(B_t(\ldots , t_1, \ldots , t_2, \ldots )\) is the \(\succ _{lpo}\)-strictly maximal with respect to \(C_t\). By Lemma 14, \(B_t\) is a compound-term literal. We prove that \(t_1\) is a compound term by contradiction. Assume \(t_1\) is either a variable or a constant. Since \(B_t\) is a compound-term literal, there exists a compound term in \(B_t\). W.l.o.g., we suppose t is a compound term in \(B_t\) and suppose z is the variable in \(A_t\) that t pairs. The covering property of \(C_t\) implies \({{\,\textrm{var}\,}}(t_1) \subseteq {{\,\textrm{var}\,}}(t)\). The fact that \({{\,\textrm{dep}\,}}(t_1) < {{\,\textrm{dep}\,}}(t)\) implies \({{\,\textrm{dep}\,}}(t_1\sigma ^\prime ) < {{\,\textrm{dep}\,}}(t\sigma ^\prime )\), therefore \({{\,\textrm{dep}\,}}(x\sigma ^\prime ) < {{\,\textrm{dep}\,}}(z\sigma ^\prime )\), which contradicts that x is a top variable. Then, \(t_1\) is a compound term. Next, we prove that \(t_2\) is either a constant or a variable again by contradiction. Assume \(t_2\) is a compound term. Since \(C_t\) is covering, \({{\,\textrm{var}\,}}(t_1) = {{\,\textrm{var}\,}}(t_2)\). Since \({{\,\textrm{dep}\,}}(t_1) = {{\,\textrm{dep}\,}}(t_2)\), \({{\,\textrm{dep}\,}}(t_1\sigma ^\prime ) = {{\,\textrm{dep}\,}}(t_2\sigma ^\prime )\), and therefore \({{\,\textrm{dep}\,}}(x\sigma ^\prime ) = {{\,\textrm{dep}\,}}(y\sigma ^\prime )\), which contradicts that y is not a top variable. Hence, \(t_2\) is either a variable or a constant. \(\square \)

Lemma 24 allows us to analyse unification in T-Res inferences, formally stated in the following corollary.

Corollary 25

In an application of the T-Res rule to LG clauses as the side premises and a non-ground flat clause as the main premise, with Condition 2b. of the T-Res rule satisfied, the following conditions hold.

  1. 1.

    An mgu \(\sigma \) substitutes top variables x with either constants or the compound term pairing x modulo variable renaming and grounding, and substitutes non-top variables with either constants or variables.

  2. 2.

    An mgu \(\sigma \) substitutes variables in the eligible literals of the side premises with either constants or variables.

Proof

1: By the pairing property established in Lemma 24.

2: Suppose \(B(\ldots , x, \ldots )\) is an eligible literal in one of the side premises, and suppose x is a variable argument in \(B(\ldots , x, \ldots )\). By Lemma 24 and the fact that the main premise is a non-ground flat clause, x pairs either a constant or a variable, therefore \(\sigma \) substitutes x with either a constant or a variable. \(\square \)

If a top-variable pairs a constant, the way a T-Res inference is performed is clear.

Lemma 26

Suppose a T-Res inference happens to LG clauses as the side premises and a non-ground flat clause as the main premise, with Condition 2b. of the T-Res rule satisfied. Then, if a top variable x pairs a constant, then i) all negative literals in the main premise are selected and ii) the mgu is a ground substitution instantiating all variables in the eligible literals and the top-variable literals with only constants.

Proof

Suppose \(\sigma ^\prime \) is the mgu of the S-Res inference that ensures this application of the T-Res rule. By the definition of the top-variable technique, for any non-top variable y in the main premise, \({{\,\textrm{dep}\,}}(x\sigma ^\prime ) > {{\,\textrm{dep}\,}}(y\sigma ^\prime )\). The fact that x pairs a constant indicates that \({{\,\textrm{dep}\,}}(x\sigma ^\prime ) = 0\), therefore \({{\,\textrm{dep}\,}}(y\sigma ^\prime ) = 0\). Then, all variables in the main premise are top variables and they pair either constants or variables. By Lemma 24, these top variables pair constants. Hence, \(\sigma ^\prime \) is a ground substitution that substitutes all variables with only constants. \(\square \)

Next, we formally show that the T-Res rule prevents term depth increase in the T-Res resolvents of a non-ground flat clause and LG clauses.

Lemma 27

In an application of the T-Res rule to LG clauses as the side premises and a non-ground flat clause as the main premise, with Condition 2b. of the T-Res rule satisfied, the T-Res resolvent is no deeper than at least one of its premises.

Proof

By 1.–2. of Corollary 25. \(\square \)

Finally, we investigate the applications of the Factor and T-Res rules to LG clauses, starting with the Factor rule.

Lemma 28

In the application of the Factor rule in the T-Res system to LG clauses, the factors are LG clauses.

Proof

Assuming a-priori eligibility, the Factor rule simplifies to:

if the following conditions are satisfied.

  1. 1.

    Nothing is selected in \(C \vee A_1 \vee A_2\).

  2. 2.

    \(A_1\) is \(\succ _{lpo}\)-maximal with respect to C.

  3. 3.

    \(\sigma = {{\,\textrm{mgu}\,}}(A_1 \doteq A_2)\).

Suppose \(C^\prime = C \vee A_1 \vee A_2\) and the premise \(C^\prime \) is an LG clause. By the definition of the Factor rule, \(A_1\) is the eligible literal and it is positive. Since Lines 3–4 and Line 7 in Algorithm 1 select negative literals of LG clauses as the eligible or the top-variable literals, either Lines 1–2 or Lines 5–6 in Algorithm 1 are applicable to \(C^\prime \). We distinguish these cases:

Suppose \(C^\prime \) satisfies Lines 1–2. Then the premise \(C^\prime \) is a ground LG clause, and it is immediate that the factor \((C \vee A_1)\sigma \) is a ground LG clause.

Suppose \(C^\prime \) satisfies Lines 5–6. Then \(C^\prime \) is a non-ground LG clause containing positive compound-term literals, but no negative compound-term literals. By Lemma 14 and the fact that \(C^\prime \) is covering, \(A_1\) is a compound-term literal. By Remark 17 and the fact that \(C^\prime \) is not ground, \(A_1\) is a non-ground compound-term literal. By the covering property of \(C^\prime \), \({{\,\textrm{var}\,}}(A_2) \subseteq {{\,\textrm{var}\,}}(A_1)\). We prove that \(A_2\) is a compound-term literal by contradiction. Suppose \(A_2\) is a flat literal. Because \({{\,\textrm{var}\,}}(A_2) \subseteq {{\,\textrm{var}\,}}(A_1)\) and \(A_1\) is a compound-term literal, a compound term t in \(A_1\) pairs either a variable that occurs in t, or a constant. Due to occur-check failure, in neither case \(A_1\) and \(A_2\) are unifiable, which refutes the fact that \(A_1\) and \(A_2\) are unifiable. Hence, \(A_2\) is a compound-term literal. The fact that \(C^\prime \) is covering implies that \({{\,\textrm{var}\,}}(A_2) = {{\,\textrm{var}\,}}(A_1)\). By Lemma 18 and the fact that \(C^\prime \) is covering, the mgu \(\sigma \) substitutes variables with either variables or constants. By Lemma 23 and since \(C^\prime \) is a compound-term LG clause, the factor \((C \vee A_1)\sigma \) is an LG clause. \(\square \)

Lemma 29

In the application of the T-Res rule to LG clauses, the resolvents are LG clauses.

Proof

We consider T-Res inferences by distinguishing all possible cases of the main premise. Suppose an LG clause \(C = \lnot A_1 \vee D\) is the T-Res main premise. In Algorithm 1, C satisfies either Lines 1–4 or Line 7.

First, we consider the cases where the main premise satisfies either Lines 1–2 or Lines 3–4 in Algorithm 1. In these cases, the eligible literal in the main premise C is either selected or is maximal with respect to C. Then Condition 2a. of the T-Res rule is applied to the main premise and the T-Res inference is reduced to a binary T-Res inference without using the top-variable technique. W.l.o.g., suppose in a T-Res inference, an LG clause \(C_1 = B_1 \vee D_1\) is the side premise and the resolvent \(R = (D_1 \vee D)\sigma \) where \(\sigma \) the mgu of \(B_1\) and \(A_1\). Further, suppose C satisfies either Lines 1–2 or Lines 3–4 in Algorithm 1. Since the eligible literal in \(C_1\) is positive, \(C_1\) satisfies either Lines 1–2 or Lines 5–6 in Algorithm 1.

Suppose C satisfies Lines 1–2. Then C is a ground LG clause. We distinguish the cases of \(\lnot A_1\).

1) Suppose \(\lnot A_1\) is a ground flat literal. The fact that no selection function in the T-Res system selects negative ground literals implies that the eligibility of \(\lnot A_1\), because \(\lnot A_1\) is maximal with respect to C, therefore C is a flat clause. The facts that \(A_1\) and \(B_1\) are unifiable and \(A_1\) is a flat ground literal imply that \(B_1\) is a flat literal. The fact that \(B_1\) is strictly \(\succ _{lpo}\)-maximal with respect to \(C_1\) implies that \(C_1\) is a flat clause. Since the eligible literal \(B_1\) in the flat LG clause \(C_1\) is a flat literal, \(C_1\) is a ground clause satisfying Lines 1–2 in Algorithm 1. Since both C and \(C_2\) are flat ground clauses, the resolvent R is a flat ground clause. Hence, R is an LG clause.

2) Next, suppose \(\lnot A_1\) is a ground compound-term literal. By Remark 17, C is a ground compound-term LG clause. Since \(C_1\) is an LG clause, \(B_1\) is either a compound-term literal or a flat literal. Since \(B_1\) is maximal with respect to \(C_1\), the assumption that \(B_1\) is flat implies that \(B_1\) is ground, otherwise, negative literals in \(C_1\) will be selected. However, if \(B_1\) is ground, the unification between \(A_1\) and \(B_1\) is impossible due to a clash. Then, \(B_1\) is a compound-term literal. Suppose \(B_1\) is ground. By Remark 17\(C_1\) is a ground compound-term LG clause. The fact that C and \(C_1\) are both ground compound-term LG clauses implies that applying the T-Res rule to C and \(C_1\) derives a ground LG clause. Next, suppose \(B_1\) is a non-ground compound-term literal. By Lemma 18 and since \(A_1\) and \(B_1\) are unifiable by the mgu \(\sigma \), the mgu \(\sigma \) substitutes the variables in \(B_1\) with constants. By Lemma 16 and because \(B_1\) is the eligible literal in \(C_1\), \(\sigma \) substitutes all variables in \(C_1\) with constants, therefore \(C_1\sigma \) is a ground compound-term LG clause. Since C is ground, applying the T-Res rule to C and \(C_1\) derives the same resolvent as applying the T-Res rule to C and \(C_1\sigma \). The fact that C and \(C_1\sigma \) are ground compound-term LG clauses implies that applying the T-Res rule to C and \(C_1\sigma \) derives a ground LG clause. Hence, the resolvent R is an LG clause.

Suppose C satisfies Lines 3–4. Then C contains negative compound-term literals. By Remark 17 and since C is not ground, the literal \(\lnot A_1\) contains non-ground compound terms, and therefore \(\lnot A_1\) is selected by the \({{\,\textrm{SelectNC}\,}}\) function. We now distinguish the possible cases of \(B_1\).

i) Suppose \(B_1\) is a flat literal. Similar to the proof in 2) that \(B_1\) cannot be a flat literal, the assumption that \(B_1\) is flat implies that \(B_1\) is ground. This makes the unification between \(A_1\) and \(B_1\) impossible due to a clash. Hence, \(B_1\) cannot be flat.

ii) Suppose \(B_1\) is a compound-term literal. We distinguish two cases of \(B_1\).

ii)-i) First, consider \(B_1\) as a ground compound-term literal. By Lemma 18 and the fact that \(A_1\) and \(B_1\) are unifiable, the mgu \(\sigma \) substitutes all variables in \(A_1\) with constants. By the fact that \(A_1\) is a compound-term literal of \(C_1\) and the covering property of the LG clauses, \(\sigma \) substitutes all variables in \(C_1\) with constants, therefore \(C_1\sigma \) is a ground compound-term LG clause. As C is ground, applying the T-Res rule to C and \(C_1\) derives the same resolvent as the one when applying the T-Res rule to C and \(C_1\sigma \). The fact that C and \(C_1\sigma \) are ground compound-term LG clauses implies that applying the T-Res rule to C and \(C_1\sigma \) derives a ground LG clause. Hence, the resolvent R is an LG clause.

ii)-ii) Next, suppose \(B_1\) is a non-ground compound-term literal. By Lemma 18 and the fact that \(A_1\) and \(B_1\) are two unifiable simple compound-term literals, the \(\sigma \) substitutes the variables in \(A_1\) and \(B_1\) with variables or constants. By Lemma 16\(\sigma \) substitutes the variables in C and \(C_1\) with variables or constants. If the mgu \(\sigma \) is a ground substitution, then both \(C\sigma \) and \(C_1\sigma \) are ground LG clauses, therefore applying the T-Res rule to \(C\sigma \) and \(C_1\sigma \) derives a ground LG clause. Suppose \(\sigma \) is a non-ground substitution. First, we prove that there is a loose guard in the resolvent R. Suppose \(\mathbb {G}\) is a set of flat literals that act as a loose guard of \(C_1\). By Lemma 19 and because \(A_1\) and \(B_1\) are covering, simple and unifiable by the mgu \(\sigma \), \({{\,\textrm{var}\,}}(A_1\sigma ) = {{\,\textrm{var}\,}}(\mathbb {G}\sigma )\). By Lemma 16, \({{\,\textrm{var}\,}}(A_1\sigma ) = {{\,\textrm{var}\,}}(C\sigma )\) and \({{\,\textrm{var}\,}}(B_1\sigma ) = {{\,\textrm{var}\,}}(C_1\sigma )\), therefore, \({{\,\textrm{var}\,}}(\mathbb {G}\sigma ) = {{\,\textrm{var}\,}}(C_1\sigma ) = {{\,\textrm{var}\,}}(C\sigma )\). Then \({{\,\textrm{var}\,}}(\mathbb {G}\sigma ) = {{\,\textrm{var}\,}}(R)\). By the variable co-occurrence property of LG clauses and because \(\mathbb {G}\) is a loose guard of \(C_1\), each pair of variables in \(C_1\) co-occurs in a literal of \(\mathbb {G}\). Since \({{\,\textrm{var}\,}}(\mathbb {G}\sigma ) = {{\,\textrm{var}\,}}(C_1\sigma ) = {{\,\textrm{var}\,}}(R)\) and \(\sigma \) substitutes the variables in \(C_1\) and C with variables and constants, each pair of variables in R co-occurs in a literal of \(\mathbb {G}\sigma \) and all literals in \(\mathbb {G}\sigma \) are flat. Hence, \(\mathbb {G}\sigma \) is a loose guard of the resolvent R. Next, we prove that R is simple. Suppose L is a literal in either C or \(C_1\). By Lemma 16, either \({{\,\textrm{var}\,}}(L) \subseteq {{\,\textrm{var}\,}}(A_1)\) or \({{\,\textrm{var}\,}}(L) \subseteq {{\,\textrm{var}\,}}(B_1)\). Because \(\sigma \) substitutes the variables in either \(A_1\) or \(B_1\) with either variables or constants, \(A_1\sigma \) and \(B_1\sigma \) are simple. By 1. in Lemma 21\(L\sigma \) is simple. Hence, the resolvent R is simple. Next, we prove that R is covering. Because the mgu \(\sigma \) substitutes the variables in \(C_1\) and C with variables and constants, the compound terms in R come from compound terms in either \(C_1\) or C. Suppose t is a compound term in either C or \(C_1\). By Remark 17 and since both C and \(C_1\) are non-ground, t is a non-ground compound term literal. By Lemma 21 and the covering property of LG clauses, either \({{\,\textrm{var}\,}}(t\sigma ) = {{\,\textrm{var}\,}}(A_1\sigma )\) or \({{\,\textrm{var}\,}}(t\sigma ) = {{\,\textrm{var}\,}}(B_1\sigma )\). The fact that either \({{\,\textrm{var}\,}}(A_1\sigma ) = {{\,\textrm{var}\,}}(R)\) or \({{\,\textrm{var}\,}}(B_1\sigma ) = {{\,\textrm{var}\,}}(R)\) implies that \({{\,\textrm{var}\,}}(t\sigma ) = {{\,\textrm{var}\,}}(R)\), therefore the resolvent R is covering. Finally, we prove that R is strongly compatible. By the fact that \(\sigma \) substitutes the variables in C and \(C_1\) with variables and constants, the compound terms in the resolvent R are inherited from compound terms that exist in C or \(C_1\). W.l.o.g. suppose s and t are respectively compound terms in \(A_1\) and \(B_1\), and s pairs t. Further, suppose \(s_1\) is a compound term in C that is distinct from s, and \(t_1\) is a compound term in \(C_1\) that is distinct from t. By 3. of Lemma 22 and the fact that s and t are unifiable by the mgu \(\sigma \), \(s_1\sigma \) is compatible with \(t_1\sigma \). Then all compound terms in the resolvent R are compatible. Hence, R is strongly compatible. Because R is simple, covering, strongly compatible and R contains a loose guard, R is an LG clause.

Next, we consider the case when a T-Res main premise satisfies Line 7. This means that the premise is a non-ground flat LG clause. These T-Res inferences happen when the main premise satisfies Condition 2b. and hence the top-variable technique is applied. Assume that in an T-Res inference, LG clauses \(C_1 = B_1 \vee D_1, \ldots , C_n = B_n \vee D_n\) are the side premises, an LG clause \(C = \lnot A_1 \vee \ldots \vee \lnot A_{m} \vee \ldots \vee \lnot A_n \vee D\) is the main premise with \(\lnot A_1 \vee \ldots \vee \lnot A_{m}\) the top-variable subclause and the resolvent is \(R = (D_1 \vee \ldots \vee D_m \vee \lnot A_{m+1} \vee \ldots \vee \lnot A_{n} \vee D)\sigma \), where \(\sigma \) is the the mgu such that \(\sigma = {{\,\textrm{mgu}\,}}(A_1 \doteq B_1, \ldots , A_m \doteq B_m)\) where \(1 \le m \le n\). Suppose C is a non-ground flat LG clause. By Corollary 25, the mgu \(\sigma \) substitutes the top variables in C with constants or compound terms, it substitutes non-top variables in C with constants or variables and it substitutes all variables in \(C_1, \ldots , C_m\) with constants or variables. We distinguish two possible cases of the mgu \(\sigma \):

1. Suppose \(\sigma \) substitutes a top variable with a constant. By Lemma 26, all variables in the top-variable subclause \(\lnot A_1 \vee \ldots \vee \lnot A_{m}\) are substituted with constants. Hence, \(B_1, \ldots , B_n\) are flat literals. Since the strictly \(\succ _{lpo}\)-maximal literal \(B_i\) with respect to \(C_i\) is flat, \(C_i\) is a flat ground clause, for each i such that \(1 \le i \le n\). By Lemma 16 and since C is an LG clause, \(\sigma \) substitutes all variables in C with constants. Applying the T-Res rule to flat ground LG clauses \(C_1, \ldots , C_m\) and C derives the same conclusions as applying the T-Res rule to \(C_1, \ldots , C_m\) and \(C\sigma \). Since applying the T-Res rule to \(C_1, \ldots , C_m\) and \(C\sigma \) derive a flat ground clause, applying the T-Res rule to \(C_1, \ldots , C_m\) and C also derives flat ground clauses. Hence, the resolvent R is an LG clause.

2. Next, suppose the mgu \(\sigma \) substitutes no top variables with constants. First, we establish intermediate results of unification on top variables. Suppose x is a top variable and \(\lnot A_t\) is the literal in \(\lnot A_1, \ldots \lnot A_m\) where x occurs. Further, suppose \(B_t\) is a literal in the side premises satisfying \(B_t\sigma \doteq A_t\sigma \). W.l.o.g. suppose \(C_t\) is a side premise in \(C_1, \ldots , C_m\) and \(C_t = B_t \vee D_t\). By the assumption that the mgu \(\sigma \) substitutes no top variables with constants and \(B_t\) pairs the top-variable literal \(A_t\), \(B_t\) is a compound-term literal. Suppose t is the compound term in \(B_t\) that pairs x. The fact that \(B_t\sigma \doteq A_t\sigma \) implies that \({{\,\textrm{var}\,}}(B_t\sigma ) = {{\,\textrm{var}\,}}(A_t\sigma )\). By the covering property of LG clauses and the fact that t is a compound term, \({{\,\textrm{var}\,}}(t) = {{\,\textrm{var}\,}}(B_t)\), therefore \({{\,\textrm{var}\,}}(t\sigma ) = {{\,\textrm{var}\,}}(B_t\sigma )\). The fact that x pairs t implies that \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}(t\sigma )\), therefore \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}(B_t\sigma )\). Since \({{\,\textrm{var}\,}}(B_t\sigma ) = {{\,\textrm{var}\,}}(A_t\sigma )\), \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}(A_t\sigma )\). By the variable co-occurrence property of LG clauses, x co-occurs with all other variables in C. Because x is a top-variable, in the literals of \(\lnot A_1, \ldots , \lnot A_m\), x co-occurs with all other variables in C. Suppose y is a variable in \(\lnot A_1, \ldots , \lnot A_m\), and w.l.o.g. suppose x and y co-occurs in \(A_1\). The fact that \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}(A_t\sigma )\) implies that \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}(A_1\sigma )\), therefore \({{\,\textrm{var}\,}}(y\sigma ) \subseteq {{\,\textrm{var}\,}}(x\sigma )\). Hence for each variable y in \(\lnot A_1, \ldots , \lnot A_m\), \({{\,\textrm{var}\,}}(y\sigma ) \subseteq {{\,\textrm{var}\,}}(x\sigma )\). Then, for each \(A_i\) in \(A_1, \ldots , A_m\), \({{\,\textrm{var}\,}}(A_i\sigma ) = {{\,\textrm{var}\,}}(x\sigma )\). By the covering property of the LG clauses, for each \(B_i\) in \(B_1, \ldots , B_m\), \({{\,\textrm{var}\,}}(B_i) = {{\,\textrm{var}\,}}(D_i)\). Since \(A_i\) and \(B_i\) are unifiable using the mgu \(\sigma \), \({{\,\textrm{var}\,}}(A_i\sigma ) = {{\,\textrm{var}\,}}(B_i\sigma )\) for each i such that \(1 \le i \le m\). Then \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}(B_i\sigma )\), and therefore \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}(D_i\sigma )\) for each i such that \(1 \le i \le m\). By Lemma 16, \({{\,\textrm{var}\,}}(\lnot A_1 \vee \ldots \vee \lnot A_m) = {{\,\textrm{var}\,}}(C)\). Hence, \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}((\lnot A_{m+1} \vee \ldots \vee \lnot A_{n} \vee D)\sigma )\). Then, \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}(t\sigma ) = {{\,\textrm{var}\,}}(R)\).

Following 2. we also need to prove that the resolvent R contains a loose guard. Suppose \(C_i = B_i \vee D_i\) is a side premise in \(C_1, \ldots , C_m\), t is a compound term in \(B_i\), x is the top-variable that t pairs. Further, suppose \(\mathbb {G}\) is a set of negative flat literals acting as a loose guard of \(C_i\). By 2. of Corollary 25, all literals in \(\mathbb {G}\) are flat. By the definition of LG clauses, \({{\,\textrm{var}\,}}(\mathbb {G}) = {{\,\textrm{var}\,}}(t)\). By the result established in the previous paragraph and as \({{\,\textrm{var}\,}}(\mathbb {G}\sigma ) = {{\,\textrm{var}\,}}(t\sigma )\), \({{\,\textrm{var}\,}}(\mathbb {G}\sigma ) = {{\,\textrm{var}\,}}(R)\). By the variable co-occurrence property of LG clauses, each pair of variables in \(\mathbb {G}\sigma \) co-occurs in a literal of \(\mathbb {G}\sigma \), therefore each pair of variables in \(\mathbb {G}\sigma \) co-occurs in a literal of R. The fact that all literals in \(\mathbb {G}\sigma \) are flat implies that \(\mathbb {G}\sigma \) act as a loose guard of the resolvent R. Next, we prove that R is covering. The fact that C is a flat clause implies that all compound terms in R come from the side premises. Suppose \(C_i = B_i \vee D_i\) is a side premise in \(C_1, \ldots , C_m\) and t is a compound term in \(B_i\). W.l.o.g. further suppose s is a compound term in \(D_i\). By the covering property of LG clauses, \({{\,\textrm{var}\,}}(s) = {{\,\textrm{var}\,}}(t)\) and \({{\,\textrm{var}\,}}(s\sigma ) = {{\,\textrm{var}\,}}(t\sigma )\) with \(\sigma \) as the mgu. By the result established in the previous paragraph, \({{\,\textrm{var}\,}}(s\sigma ) = {{\,\textrm{var}\,}}(R)\). Then, the resolvent R is covering. Next, we prove that R is strongly compatible. Again, we consider compound terms in the side premises since all compound terms in R come from the side premises. Suppose \(t_1\) and \(t_2\) are two flat compound terms in \(D_1, \ldots , D_m\). We prove that R is strongly compatible by showing that \(t_1\sigma \) and \(t_2\sigma \) are compatible. Suppose \(C_1 = B_1 \vee D_1\) and \(C_2 = B_2 \vee D_2\) are two side premises in \(C_1, \ldots , C_m\) and w.l.o.g. suppose \(t_1\) and \(t_2\) occur in \(D_1\) and \(D_2\), respectively. By the assumption that the mgu \(\sigma \) substitutes no top variables with constants and the fact that \(B_1\) and \(B_2\) pair the top-variable literals, \(B_1\) and \(B_2\) are compound-term literals. W.l.o.g. suppose \(s_1\) and \(s_2\) are two flat compound terms in \(B_1\) and \(B_2\), respectively. Further suppose \(s_1\) and \(s_2\) pair top variables \(x_1\) and \(x_2\), respectively. By the variable co-occurrence property of LG clauses, \(x_1\) and \(x_2\) co-occur in at least one literal in \(\lnot A_1, \ldots , \lnot A_m\). W.l.o.g. suppose \(\lnot A_3\) is a literal where‘\(x_1\) and \(x_2\) co-occur. Suppose \(C_3 = B_3 \vee D_3\) is a side premise and \(A_3\sigma \doteq B_3\sigma \). Further suppose \(u_1\) and \(u_2\) are flat compound terms in \(B_3\) that pair \(x_1\) and \(x_2\), respectively. By the strong compatibility property of LG clauses, \(u_1\sigma \) is compatible with \(u_2\sigma \), therefore, \(x_1\sigma \) is compatible with \(x_2\sigma \). Since \(x_1\) pairs \(s_1\) and \(x_2\) pairs \(s_2\), \(s_1\sigma \) is compatible with \(s_2\sigma \). By the strong compatibility property of LG clauses, \(s_1\) and \(s_2\) are compatible with \(t_1\) and \(t_2\), respectively. Hence \(s_1\sigma \) and \(s_2\sigma \) are compatible with \(t_1\sigma \) and \(t_2\sigma \), respectively. By the fact that \(s_1\sigma \) is compatible with \(s_2\sigma \), \(t_1\sigma \) is compatible with \(t_2\sigma \), therefore all compound terms in the resolvent R are compatible. Then, R is strongly compatible. Finally, we prove that the resolvent R is a simple clause. By 1. of Corollary 25, the mgu \(\sigma \) substitutes the variables in \(\lnot A_{m+1} \vee \ldots \vee \lnot A_{n} \vee D\) with either variables, constants or flat compound terms. By 2. of Corollary 25, the mgu \(\sigma \) substitutes the variables in \(D_1, \ldots , D_m\) with either variables or constants. Because \(\lnot A_{m+1} \vee \ldots \vee \lnot A_{n} \vee D\) is a flat clause and \(D_1, \ldots , D_m\) are simple clauses, the resolvent \((D_1 \vee \ldots \vee D_m \vee \lnot A_{m+1} \vee \ldots \vee \lnot A_{n} \vee D)\sigma \) is a simple clause. Then, the resolvent R is an LG clause.\(\square \)

Lemmas 2829 prove that applying the Factor and T-Res rules to LG clauses derive LG clauses. The derived LG clauses are of bounded depth as the clauses are simple. We now investigate the width of the derived clauses. Recall that by the width of a clause, we mean the number of distinct variables in the clause.

Lemma 30

In applications of the T-Res system to LG clauses, the derived LG clause is no wider than at least one of its premises.

Proof

We distinguish the applications of the Factor rule and the T-Res rule: i) By Lemma 28, the conclusions of applying Factor to LG clauses are LG clauses. The proof in Lemma 28 shows that the loose guard of the factor is from the loose guard of the premise (modulo variable renaming and ground instantiations). The fact that a loose guard contains all variables of an LG clause implies that the factor of an LG clause is no wider than its premise.

ii) By Lemma 29, the conclusions of applying T-Res to LG clauses are LG clauses. The proof in Lemma 29 shows that the loose guard of the derived LG clauses is inherited from one of the T-Res side premises (modulo variable renaming and ground instantiation), therefore any derived LG clause is no wider than at least one of its T-Res side premises. \(\square \)

Finally, we give the main result of this section.

Theorem 31

The T-Res system decides satisfiability of the LG clausal class.

Proof

By Lemmas 2829, applying the T-Res system to LG clauses derives LG clauses with bounded depth. By Lemma 30, the derived LG clauses have bounded width. As no fresh symbols are introduced in the derivation, the T-Res system decides the LG clausal class. \(\square \)

6 Handling Query Clauses

6.1 Basic Notions of Query Clauses

Recall that a query clause is a negative flat clause. Since there is no restriction on the occurrences of the variables in query clauses, analysing the conclusions of these clauses is non-trivial. To better manipulate and study query clauses, we introduce the notions of surface literal, chained variables and isolated variables.

Definition 32

Let Q be a query clause. Then, a literal L is a surface literal in Q if there exists no distinct literal \(L^\prime \) in Q such that \({{\,\textrm{var}\,}}(L) \subset {{\,\textrm{var}\,}}(L^\prime )\). Let \(L_1\) and \(L_2\) be two surface literals in Q such that \({{\,\textrm{var}\,}}(L_1) \not = {{\,\textrm{var}\,}}(L_2)\). Then, x is a chained variable in Q if x belongs to \({{\,\textrm{var}\,}}(L_1) \cap {{\,\textrm{var}\,}}(L_2)\). The other non-chained variables are the isolated variables in Q.

For example, the literals \(\lnot A_1(x_1,x_2), \lnot A_2(x_2,x_3), \lnot A_3(x_3, x_4, x_5), \lnot A_4(x_5, x_6)\) in

$$\begin{aligned} Q_1 = \ {}&\lnot A_1(x_1,x_2) \vee \lnot A_2(x_2,x_3) \vee \lnot A_3(x_3, x_4, x_5) \vee \lnot A_4(x_5, x_6) \vee \lnot A_5(x_3, x_4), \end{aligned}$$

are surface literals, but the literal \(\lnot A_5(x_3, x_4)\) is not as \({{\,\textrm{var}\,}}(A_5) \subset {{\,\textrm{var}\,}}(A_3)\). Then, the variables \(x_2, x_3, x_5\) are the chained variables and \(x_1, x_4, x_6\) are the isolated variables in \(Q_1\). In

$$\begin{aligned} Q_2 = \ {}&\lnot A_1(x_1,x_2,x_3) \vee \lnot A_2(x_3,x_4,x_5) \vee \lnot A_3(x_5, x_6, x_7) \vee \\&\lnot A_4(x_1, x_7,x_8) \vee \lnot A_5(x_3, x_4, x_9), \end{aligned}$$

all literals are surface literals, therefore, the variables \(x_1, x_3, x_4, x_5, x_7\) are the chained variables and \(x_2, x_6, x_8, x_9\) are the isolated variables in \(Q_2\).

A hypergraph is used to represent a flat clause, formally defined as follows.

Definition 33

Suppose C is a flat clause, and \(\mathcal {H}(V, E)\) is a hypergraph which consists of a set V of vertices and a set E of hyperedges. Then \(\mathcal {H}(V, E)\) is the hypergraph associated with C if the set V of vertices consists of all variables in C, and the set E of hyperedges contains, for each literal L in C, the set of variables that appear in L.

We use rectangles and variable symbols to represent the hyperedges and the vertices of the hypergraph associated with a flat clause, respectively. Dotted-line and solid-line rectangles respectively represent positive and negative literals and negation symbols are omitted. Figure 6 displays the hypergraphs associated with the query clauses \(Q_1\) and \(Q_2\) above.

Definition 34

A chained-only query clause and an isolated-only query clause are respectively query clauses containing only chained and only isolated variables.

For example, the query clause \(\lnot A(x_1,x_2) \vee \lnot A_2(x_2,x_3) \vee \lnot A_3(x_3,x_1)\) is a chained-only query clause and \(\lnot A_1(x_1) \vee \lnot A_2(x_1,x_2,x_3)\) is an isolated-only query clause.

Fig. 6
figure 6

Hypergraphs associated with of \(Q_1\) and \(Q_2\)

6.2 The Separation Rules

We define the separation rules we need and prove their soundness.

The separation rule Sep replaces a clause \(C \vee D\) by two clauses in which the subclauses C and D have been separated by a fresh predicate symbol [82], formally:

figure i

The Sep rule is introduced in [82] to decide satisfiability of fluted logic, and the rule is referred to as ‘splitting through new predicate symbols’ in [60, Sect. 3.5.6].

The Sep rule preserves satisfiability equivalence. This proof can be found in Theorem 3 of the technical report version of [82]. Formally:

Lemma 35

The Sep premise \(N \cup \{C \vee D\}\) is satisfiable if and only if the Sep conclusion \(N \cup \{C \vee P(\overline{x}), \lnot P(\overline{x}) \vee D\}\) is satisfiable.

The following are separation rules, customised for separating decomposable and indecomposable query clauses. Recall that a clause is decomposable if it can be partitioned into two variable-disjoint subclauses, otherwise, the clause is indecomposable.

figure j
figure k

The SepDeQ rule can be seen as either a form of formula renaming with positive literals introduced in Sect. 3 or a form of the splitting rule with propositional symbols [68, 74]. Unlike splitting [94], the SepDeQ rule does not create a new branch in the derivation, thus no back-tracking is needed. Due to the introduction of the fresh predicate symbols in the SepDeQ conclusions, one cannot use the subsumption elimination technique to eliminate the SepDeQ premise by the SepDeQ conclusions, whereas splitting can take the advantage of the subsumption elimination technique as no fresh predicate symbols are needed in the splitting process.

Inspired by the Sep rule, the SepDeQ and SepIndeQ rules are specifically developed for separating query clauses. For example, in applications of the SepDeQ and SepIndeQ rules to query clauses, the polarity of the literals using the fresh predicate symbol is assigned in a way such that the SepDeQ and SepIndeQ conclusions are either query clauses or guarded clauses. The Sep rule is stronger than the SepDeQ and SepIndeQ rules with respect to separating query clauses. Given a query clause

$$\begin{aligned} Q = \ {}&\lnot A(z,x_1) \vee \lnot A(x_1,x_2) \vee \lnot A(x_2,x_3) \vee \lnot A(x_3,z) \vee \\&\lnot B(z,y_1) \vee \lnot B(y_1,y_2) \vee \lnot B(y_2,y_3) \vee \lnot B(y_3,z), \end{aligned}$$

the Sep rule separates it into

$$\begin{aligned}&\lnot A(z,x_1) \vee \lnot A(x_1,x_2) \vee \lnot A(x_2,x_3) \vee \lnot A(x_3,z) \vee P(z),\\&\lnot B(z,y_1) \vee \lnot B(y_1,y_2) \vee \lnot B(y_2,y_3) \vee \lnot B(y_3,z) \vee \lnot P(z) \end{aligned}$$

using a fresh predicate symbol P. Yet neither SepDeQ nor SepIndeQ is applicable to Q as Q is an indecomposable chained-only query clause.

Though the Sep rule is stronger and more general than the SepDeQ and SepIndeQ rules, our separation rules provide a clear view of how a query clause is separated in a goal-oriented way. Consider the SepIndeQ rule. Each application of the SepIndeQ rule removes a surface literal and the subclause it guards, viz., \(C \vee \lnot A(\overline{x}, \overline{y})\), from the premise \(C \vee \lnot A(\overline{x}, \overline{y}) \vee D\). On the other hand, the application of the Sep rule to query clauses is complicated and difficult to analyse. Most importantly, applying the Sep rule to query clauses can derive conclusions that do not belong to the LGQ clausal class, making the conclusions difficult to handle. For example, applying the Sep rule to the above query clause Q guarantees deriving a non-LGQ clause \(\lnot A(z,x_1) \vee \lnot A(x_1,x_2) \vee \lnot A(x_2,x_3) \vee \lnot A(x_3,z) \vee P(z)\).

Now we prove the soundness of the SepIndeQ rule by showing the connection between the rule and the Sep rule, formally stated as:

Lemma 36

Suppose \(N \cup \{C \vee \lnot A(\overline{x}, \overline{y}) \vee D\}\) is a SepIndeQ premise. Then, applying the Sep rule can derive \({N \cup \{C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x}), \lnot P(\overline{x}) \vee D\}}\) using a fresh predicate symbol P.

Proof

First, we prove that the Sep rule is applicable to \(N \cup \{C \vee \lnot A(\overline{x}, \overline{y}) \vee D\}\). We distinguish four conditions of the Sep rule.

1) We prove that both \(C \vee \lnot A(\overline{x}, \overline{y})\) and D are non-empty subclauses. The case when \(C \vee \lnot A(\overline{x}, \overline{y})\) is empty makes the application of the SepIndeQ rule to \(N \cup \{C \vee \lnot A(\overline{x}, \overline{y}) \vee D\}\) void. We prove that D is not empty by contradiction. Suppose D is empty. By the fact that \({{\,\textrm{var}\,}}(C) \subseteq \overline{x} \cup \overline{y}\), all variables in \(C \vee \lnot A(\overline{x}, \overline{y})\) are isolated variables, therefore the SepIndeQ rule is not applicable to \(C \vee \lnot A(\overline{x}, \overline{y})\). Hence, D is a non-empty subclause.

2) We prove that \({{\,\textrm{var}\,}}(C \vee \lnot A(\overline{x}, \overline{y})) \not \subseteq {{\,\textrm{var}\,}}(D)\) and \({{\,\textrm{var}\,}}(D) \not \subseteq {{\,\textrm{var}\,}}(C \vee \lnot A(\overline{x}, \overline{y}))\). The fact that \(\overline{y} \cap {{\,\textrm{var}\,}}(D) = \emptyset \) implies \({{\,\textrm{var}\,}}(C \vee \lnot A(\overline{x}, \overline{y})) \not \subseteq {{\,\textrm{var}\,}}(D)\). We prove \({{\,\textrm{var}\,}}(D) \not \subseteq {{\,\textrm{var}\,}}(C \vee \lnot A(\overline{x}, \overline{y}))\) by contradiction. Suppose \({{\,\textrm{var}\,}}(D) \subseteq {{\,\textrm{var}\,}}(C \vee \lnot A(\overline{x}, \overline{y}))\). As \({{\,\textrm{var}\,}}(C) \subseteq \overline{x} \cup \overline{y}\), we also have \({{\,\textrm{var}\,}}(D) \subseteq \overline{x} \cup \overline{y}\). Then \(\{\overline{x} \cup \overline{y}\} = {{\,\textrm{var}\,}}(C \vee \lnot A(\overline{x}, \overline{y}) \vee D) = {{\,\textrm{var}\,}}(\lnot A(\overline{x}, \overline{y}))\). Hence, \(\lnot A(\overline{x}, \overline{y})\) is a surface literal of \(C \vee \lnot A(\overline{x}, \overline{y}) \vee D\), and therefore for any other surface literals L in \(C \vee \lnot A(\overline{x}, \overline{y}) \vee D\), \({{\,\textrm{var}\,}}(L) = {{\,\textrm{var}\,}}(\lnot A(\overline{x}, \overline{y}))\). Then all variables in \(C \vee \lnot A(\overline{x}, \overline{y}) \vee D\) are isolated variables, which contradicts that \(\overline{x}\) are the chained variables of \(C \vee \lnot A(\overline{x}, \overline{y}) \vee D\).

3) By the result established in 2) and the fact that the chained variables \(\overline{x}\) occur in both subclauses \(C \vee \lnot A(\overline{x}, \overline{y})\) and D, \(\overline{x} = {{\,\textrm{var}\,}}(C \vee \lnot A(\overline{x}, \overline{y})) \cap {{\,\textrm{var}\,}}(D)\).

4) This is the same condition as 5. of the SepIndeQ rule.

By the results established in 1)–4), applying the Sep rule to \(N \cup \{C \vee \lnot A(\overline{x}, \overline{y}) \vee D\}\) derives either

$$\begin{aligned}&{N \cup \{C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x}), \lnot P(\overline{x}) \vee D\}} \ \text {or} \ {N \cup \{C \vee \lnot A(\overline{x}, \overline{y}) \vee \lnot P(\overline{x}), P(\overline{x}) \vee D\}}. \end{aligned}$$

using a fresh predicate symbol P. \(\square \)

The SepDeQ and SepIndeQ rules are sound, formally stated as:

Lemma 37

The SepDeQ and SepIndeQ premises are satisfiable if and only if the SepDeQ and SepIndeQ conclusions are satisfiable, respectively.

Proof

It is immediate that the statement holds for the SepDeQ rule since the rule performs formula renaming. By Lemma 36, applying the SepIndeQ rule or the Sep rule to the same premise derives the same conclusions. Hence, each application of the SepIndeQ rule can be seen as an application of the Sep rule. By Lemma 35, the SepIndeQ rule is sound. \(\square \)

Now we extend the T-Res system with the SepDeQ and SepIndeQ rules. Resolution systems in line with the framework of [8] follow the principle that a conclusion is always smaller than the premises. To satisfy this condition, we make the fresh predicate symbols introduced in the applications of the SepDeQ and SepIndeQ rules \(\succ _{lpo}\)-smaller than the predicate symbols in the SepDeQ and SepIndeQ premises. With this restriction and the fact that the SepDeQ and SepIndeQ rules are replacement rules, we regard the SepDeQ and SepIndeQ rules as the simplification rules in the T-Res system. We use T-Res\(^+\) to denote the T-Res system combined with the SepDeQ and SepIndeQ rules.

When infinitely many fresh predicate symbols are introduced in the saturation process of the T-Res\(^+\) system, the system may lose refutational completeness. Hence, the main result of this section is formulated as follows.

Theorem 38

Provided that the SepDeQ and SepIndeQ rules introduce finitely many fresh predicate symbols, the T-Res\(^+\) system is sound and refutationally complete for first-order clausal logic.

Proof

By Theorem 13, Lemma 37 and the assumption that the fresh predicate symbols introduced in the applications of the SepDeQ and SepIndeQ rules are \(\succ _{lpo}\)-smaller than the predicate symbols in the SepDeQ and SepIndeQ premises. \(\square \)

6.3 Separating Query Clauses

In this section, we investigate application of the SepDeQ and SepIndeQ rules to query clauses. We start with the SepDeQ rule.

Lemma 39

Suppose Q is a decomposable query clause. Then, the SepDeQ rule separates Q into narrower query clauses and narrower guarded clauses.

Proof

By the definitions of query clauses and guarded clauses. \(\square \)

Next, we consider the SepIndeQ rule.

Remark 40

Suppose Q is an indecomposable query clause. Then, the SepIndeQ rule applies to Q if and only if there exists a surface literal in Q containing both isolated variables and chained variables.

Proof

By the definition of the SepIndeQ rule. \(\square \)

Based on the observation of Remark 40, we look at how the SepIndeQ rule is applied to indecomposable query clauses.

Lemma 41

Suppose Q is an indecomposable query clause, and Q has a surface literal containing both chained variables and isolated variables. Then, SepIndeQ can separate Q into narrower query clauses and narrower Horn guarded clauses.

Proof

Suppose \(C_1 = C \vee \lnot A(\overline{x}, \overline{y}) \vee D\) is an indecomposable query clause, and suppose \(\lnot P(\overline{x}) \vee D\) and \(C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x})\) are the SepIndeQ conclusions of \(C_1\).

First, consider \(\lnot P(\overline{x}) \vee D\). As D is a query clause, \(\lnot P(\overline{x}) \vee D\) is a query clause. By the facts that all variables in \(\lnot P(\overline{x}) \vee D\) occur in \(C \vee \lnot A(\overline{x}, \overline{y}) \vee D\) and \(\lnot P(\overline{x}) \vee D\) does not contain \(\overline{y}\), \(\lnot P(\overline{x}) \vee D\) is narrower than \(C \vee \lnot A(\overline{x}, \overline{y}) \vee D\).

Next consider \(C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x})\). The fact that \({{\,\textrm{var}\,}}(C) \subseteq {{\,\textrm{var}\,}}(\lnot A(\overline{x}, \overline{y}))\) implies \({{\,\textrm{var}\,}}(\lnot A(\overline{x}, \overline{y})) = {{\,\textrm{var}\,}}(C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x}))\). By the fact that all literals in \(C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x})\) are flat, \(\lnot A(\overline{x}, \overline{y})\) is a guard for \(C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x})\), therefore \(C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x})\) is a guarded clause. Because \(P(\overline{x})\) is the only positive literal in \(C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x})\), the clause is a Horn guarded clause. We prove that \(C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x})\) is narrower than \(C \vee \lnot A(\overline{x}, \overline{y}) \vee D\) by contradiction. Suppose \({{\,\textrm{var}\,}}(C \vee \lnot A(\overline{x}, \overline{y}) \vee D) \subseteq {{\,\textrm{var}\,}}(C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x}))\). The fact that \({{\,\textrm{var}\,}}(D) \cap \overline{y} = \emptyset \) implies \({{\,\textrm{var}\,}}(D) \subseteq \overline{x}\), which contradicts that \(\overline{x}\) are chained variables in \(C \vee \lnot A(\overline{x}, \overline{y}) \vee D\). Hence, \(C \vee \lnot A(\overline{x}, \overline{y}) \vee P(\overline{x})\) is narrower than \(C \vee \lnot A(\overline{x}, \overline{y}) \vee D\). \(\square \)

The SepIndeQ rule is devised to remove the isolated variables from a query clause through separating i) the surface literal containing both the isolated variables and chained variables and ii) the literals guarded by this surface literal from the query clause. By ‘a literal \(L_1\) is guarded by a literal L’, we mean that L acts as a guard of \(L_1\), viz., the literal L is a negative flat literal and \({{\,\textrm{var}\,}}(L_1) \subseteq {{\,\textrm{var}\,}}(L)\).

An isolated variable satisfies the following condition:

Remark 42

Suppose Q is a query clause, and x is an isolated variable in Q. Further suppose \(L_1\) and \(L_2\) are x-occurring surface literals in Q. Then, \({{\,\textrm{var}\,}}(L_1) = {{\,\textrm{var}\,}}(L_2)\).

Proof

We prove the claim by contradiction. Suppose \({{\,\textrm{var}\,}}(L_1) \ne {{\,\textrm{var}\,}}(L_2)\). The facts that \(x \in {{\,\textrm{var}\,}}(L_1) \cap {{\,\textrm{var}\,}}(L_2)\) and \(L_1\) and \(L_2\) are surface literals imply that x is a chained variable, which contradicts the assumption that x is an isolated variable. \(\square \)

Lemmas 39 and 41 claim that applying the SepDeQ and SepIndeQ rules to a query clause derives new query clauses, therefore the separation rules can be recursively applied to query clauses. We use Q-Sep to denote the procedure of recursively applying the SepDeQ and SepIndeQ rules to a query clause.

Consider an application of the Q-Sep procedure to the query clause

Since \(Q_1\) is indecomposable and contains surface literals where both isolated variables and chained variables occur, the SepIndeQ rule is applicable to the clause. All literals in \(Q_1\) are the surface literals containing both isolated variables and chained variables, except \(\lnot A_2(x_2,{x_3})\). To better show how the SepIndeQ rule separates a query clause, we colour the isolated variables and the surface literal and the literals guarded by it .

Fig. 7
figure 7

The Q-Sep procedure separates \(Q_1\) into Horn guarded clauses \(C_1, C_2, C_3\) and an indecomposable isolated-only query clause \(Q_3^\prime \). The removed isolated variables are and the separated surface literal and the literals guarded by it are

The Q-Sep procedure separates \(Q_1\) by the following steps:

  1. 1.

    W.l.o.g. we begin with removing the isolated variable \(x_1\) from \(Q_1\). This means we separate the surface literal \(\lnot A_1({x_1},{x_2})\) from \(Q_1\). Using a fresh predicate symbol \(P_1\), applying the SepIndeQ rule to \(Q_1\) derives:

  2. 2.

    As \(C_1\) is a guarded clause, it is not separable. In \(Q_1^\prime \) the surface literal \(\lnot A_2({x_2},{x_3})\) guards the literal \(\lnot P_1({x_2})\). To remove the isolated variable \(x_2\) from \(Q_1^\prime \), we use the SepIndeQ rule to separate \(\lnot P_1({x_2}) \vee \lnot A_2({x_2},{x_3})\) from \(Q_1^\prime \). Using a fresh predicate symbol \(P_2\), \(Q_1^\prime \) is separated into:

  3. 3.

    No separation rule is applicable to \(C_2\). We separate the isolated variable \(x_3\) from \(Q_2^\prime \): find that \(\lnot A_3({x_3}, {x_4}, x_5)\) is the \(x_3\)-occurring surface literal in \(Q_2^\prime \), and then separate this literal and the literals guarded by it, viz., \(\lnot P_2({x_3})\) and \(\lnot A_5({x_3}, {x_4})\). Using a fresh predicate symbol \(P_3\), \(Q_2^\prime \) is separated into:

  4. 4.

    The conclusions \(C_3\) and \(Q_3^\prime \) are not separable. Finally, \(Q_1\) is replaced by the Horn guarded clauses \(C_1, C_2, C_3\) and the indecomposable isolated-only query clause \(Q_3^\prime \).

Though Step 3. aims to remove the isolated variable \(x_3\) from \(Q_2^\prime \), it turns out that both the isolated variables \(x_3\) and \(x_4\) are removed from \(Q_2^\prime \). This is because \(x_4\) occurs in the \(x_3\)-occurring surface literal \(\lnot A_3({x_3}, {x_4}, x_5)\), therefore by Remark 40, Step 3. also removes all \(x_4\)-occurring literals from \(Q_2^\prime \). Figure 7 shows how the Q-Sep procedure separates \(Q_1\) into \(C_1, C_2, C_3\) and \(Q_3^\prime \), framed in the green box.

The indecomposable isolated-only query clauses, for example, \(Q_3^\prime \) from the previous example, are indeed Horn guarded clauses. Analysis of these two clausal classes reveals the following property:

Lemma 43

An indecomposable isolated-only query clause is a Horn guarded clause.

Proof

Suppose Q is an indecomposable isolated-only query clause. Recall that if Q contains two surface literals \(L_1\) and \(L_2\) such that \({{\,\textrm{var}\,}}(L_1) \not = {{\,\textrm{var}\,}}(L_2)\) and \(x \in {{\,\textrm{var}\,}}(L_1) \cap {{\,\textrm{var}\,}}(L_2)\), then x is a chained variable in Q. Since Q contains no chained variables, it is the case that either i) Q contains only one surface literal, or ii) Q contains multiple surface literals and each pair \(L_1\) and \(L_2\) of surface literals satisfies either \({{\,\textrm{var}\,}}(L_1) = {{\,\textrm{var}\,}}(L_2)\) or \({{\,\textrm{var}\,}}(L_1) \cap {{\,\textrm{var}\,}}(L_2) = \emptyset \). We distinguish these two cases:

i) The indecomposable isolated-only query clause Q is flat, negative and contains only one surface literal L. By the definition of surface literals, \({{\,\textrm{var}\,}}(L) = {{\,\textrm{var}\,}}(Q)\). Then, Q is a Horn guarded clause with a guard L.

ii) If any pair \(L_1\) and \(L_2\) of surface literals in Q satisfies \({{\,\textrm{var}\,}}(L_1) = {{\,\textrm{var}\,}}(L_2)\), then it is the same case as i) but \(L_1\) and \(L_2\) are both guards of Q. If there exists a pair \(L_1\) and \(L_2\) of surface literals satisfying \({{\,\textrm{var}\,}}(L_1) \cap {{\,\textrm{var}\,}}(L_2) = \emptyset \), then Q is decomposable, which contradicts the assumption. \(\square \)

A chained variable in the SepIndeQ premise may become an isolated variable in the SepIndeQ conclusion, but not vice-versa. For example, in Step 1. of the previous example, the chained variable \(x_2\) in \(Q_1\) becomes isolated in \(Q_1^\prime \), due to the removal of the isolated variable \(x_1\) in \(Q_1\). However, since the SepIndeQ rule does not introduce new connections between variables in the conclusions, an isolated variable in the SepIndeQ premise cannot turn into a chained variable in the SepIndeQ conclusion. Since the Q-Sep procedure continuously removes isolated variables in the SepIndeQ conclusions, the procedure handles the freshly converted isolated variables.

Next, we look at another query clause

To remove the isolated variables \(x_2, x_4, x_6, x_8\) and \(x_9\) from \(Q_2\), we apply the SepIndeQ rule to \(Q_2\) five times. Using fresh predicate symbols \(P_4\), \(P_5\), \(P_6\), \(P_7\) and \(P_8\), the Q-Sep procedure separates \(Q_2\) into Horn guarded clauses

$$\begin{aligned}&\lnot A_1(x_1, x_2, x_3) \vee P_4(x_1, x_3), \quad \quad \lnot A_4(x_1, x_7, x_8) \vee P_5(x_1, x_7), \\&\lnot A_3(x_5 ,x_6 ,x_7) \vee P_6(x_5, x_7), \quad \quad \lnot A_5(x_3 ,x_4 ,x_9) \vee P_7(x_3, x_4), \\&\lnot A_2(x_3, x_4, x_5) \vee \lnot P_7(x_3, x_4) \vee P_8(x_3, x_5), \end{aligned}$$

and an indecomposable chained-only query clause

$$\begin{aligned} Q_3 = \lnot P_4(x_1, x_3) \vee \lnot P_8(x_3, x_5) \vee \lnot P_6(x_5, x_7) \vee \lnot P_5(x_1, x_7). \end{aligned}$$

Figure 8 shows how the Q-Sep procedure separates \(Q_2\) into the above Horn guarded clauses and the above indecomposable chained-only query clause. We see that each application of the SepIndeQ rule separates a coloured surface literal.

Unlike the Q-Sep conclusions of \(Q_1\), applying the Q-Sep procedure to \(Q_2\) derives the indecomposable chained-only query clause, c.f. \(Q_3\). By Remark 40, the procedure of recursively applying the SepIndeQ rule to an indecomposable query clause terminates if either an indecomposable chained-only query clause or an indecomposable isolated-only query clause is derived. We use the notion of ICQ to denote indecomposable chained-only query clauses.

Fig. 8
figure 8

The Q-Sep procedure separates \(Q_2\) into Horn guarded clauses and an indecomposable chained-only query clause

The main result of this section is given as follows.

Lemma 44

Applying the Q-Sep procedure to a query clause replaces it with narrower guarded clauses and optionally narrower ICQ clauses.

Proof

i) By Lemma 39, recursively applying the SepDeQ rule to a decomposable query clause replaces it with narrower guarded clauses and narrower indecomposable query clauses. ii) By Remark 40 and Lemmas 41 and 43, recursively applying the SepIndeQ rule to an indecomposable query clause, in which a surface literal contains both isolated variables and chained variables, replaces it by narrower Horn guarded clauses and narrower ICQ clauses. iii) Suppose Q an indecomposable query clause that the SepIndeQ rule cannot separate. By Remark 40, Q is an indecomposable query clause containing either only chained variables or only isolated variables. Then Q is either an indecomposable chained-only query clause, viz., an ICQ clause, or an indecomposable isolated-only query clause, viz., a Horn guarded clause, thanks to Lemma 43. By i)–iii), the claim holds.\(\square \)

Following Lemma 44, we analyse the number of fresh predicate symbols that may be introduced in an application of the Q-Sep procedure to a query clause.

Lemma 45

In the application of the Q-Sep procedure to a query clause, finitely many fresh predicate symbols are introduced.

Proof

Suppose Q is a query clause and n is the width, viz., the number of distinct variables, in Q. By Lemma 39, recursively applying the SepDeQ rule to Q terminates in at most \(n-1\) steps. The fact that each application of the SepDeQ rule to Q introduces two fresh predicate symbols implies that at most \(2*(n-1)\) fresh predicate symbols are needed. Similarly, by Lemma 41, recursively applying the SepIndeQ rule to Q requires at most \(n-1\) fresh predicate symbols. In total at most \(3*(n-1)\) fresh predicate symbols are needed in separating Q. \(\square \)

Depending on the surface literal one picks, applying the Q-Sep procedure to a query clause may derive distinct sets of guarded clauses and ICQ clauses.

Regarding a query clause as a hypergraph, the Q-Sep procedure is a process of ‘cutting the branches off’ the hypergraph. Interestingly, this procedure handles query clauses like the GYO-reduction in [41, 47, 96]. Using the notion of cyclic queries [16], the GYO-reduction identifies cyclic conjunctive queries by recursively removing branches, viz., ‘ears’ in the hypergraph of the queries. This method reduces a conjunctive query to an empty formula if the query is acyclic, otherwise, the query is cyclic. In our definition, an ‘ear’ is the surface literal containing both isolated variables and chained variables, and it is separated from the query clause using the Q-Sep procedure. Hence, the Q-Sep procedure can be regarded as an implementation of the GYO-reduction: if a query clause can be separated into guarded clauses, then, that query clause is acyclic, otherwise it is cyclic. However, the Sep rule, which is the basis of the Q-Sep procedure, is more general than the GYO-reduction as its applicability is for any first-order clause. The fact that an acyclic conjunctive query is expressible as a guarded formula is also reflected in [36, 42].

6.4 Handling Indecomposable Chained-Only Query Clauses

In this section, we show how the term depth increase problem is avoided when the T-Res rule is performed on ICQ clauses and LG clauses, and we devise a formula renaming technique to manage the T-Res resolvents, which are not necessarily in the LGQ clausal class.

In an ICQ clause

$$\begin{aligned} Q_3 = \lnot P_4(x_1, x_3) \vee \lnot P_8(x_3, x_5) \vee \lnot P_6(x_5, x_7) \vee \lnot P_5(x_1, x_7), \end{aligned}$$

the chained variables \(x_1, x_3, x_5\) and \(x_7\) form a ‘cycle’ through the literals \(P_4\), \(P_5\), \(P_6\) and \(P_8\), as shown by the hypergraph representation given in the top-right corner in Fig. 8. The application of the S-Res rule can lead to nested compound terms in the resolvents. Consider a set N of the LGQ clause \(Q_3\) and the following LG clauses:

$$\begin{aligned} C_1 = \,&P_4(x, g(x,y,z_1,z_2))^*\vee \lnot G_1(x,y,z_1,z_2), \\ C_2 = \,&\lnot G_2(x,y,z_1,z_2) \vee P_8(g(x,y,z_1,z_2), x)^*\vee A(h(x,y,z_1,z_2)), \\ C_3 = \,&P_6(f(x), x)^*\vee \lnot G_3(x) \ \text {and} \ C_4 = P_5(f(x), x)^*\vee \lnot G_4(x). \end{aligned}$$

Applying the S-Res rule to \(C_1, \ldots , C_4\) as the side premises and \(Q_3\) as the main premise with all negative literals selected derives the S-Res resolvent:

$$\begin{aligned} R_1 =&\ \lnot G_3(x) \vee \lnot G_4(x) \vee \lnot G_1(f(x),y,z_1,z_2) \vee \\&\lnot G_2(f(x),y,z_1,z_2) \vee A(h(f(x),y,z_1,z_2)). \end{aligned}$$

The nested compound term in the literal \(A(h(f(x),y,z_1,z_2))\) occurs in \(R_1\). Applying the binary S-Res rule to \(C_3\) and \(Q_3\) with \(\lnot P_6(x_5, x_7)\) selected derives

$$\begin{aligned} R_2 = \lnot P_4(x_1, x_3) \vee \boxed {\lnot P_8(x_3, f(x))} \vee \lnot G_3(x) \vee \lnot P_5(x_1, x). \end{aligned}$$

Then applying the binary S-Res rule to \(C_2\) and \(R_2\) with \(\lnot P_8(x_3, f(x))\) selected derives

$$\begin{aligned} R_3 = \lnot P_4(x_1, x_3) \vee \lnot G_3(x) \vee \lnot P_5(x_1, x) \vee \lnot G_2(f(x),y,z_1,z_2) \vee A(h(f(x),y,z_1,z_2)), \end{aligned}$$

in which, again, a nested compound-term occurs in the literal \(A(h(f(x),y,z_1,z_2))\). The result is predictable since an application of the S-Res rule can be seen as successive applications of the binary S-Res rule.

Now we show how the top-variable technique handles this term depth increase. In Algorithms 1–2, the T-Res rule is applied to \(Q_3\) and \(C_1 \ldots , C_4\) as follows.

  1. 1.

    The \({{\,\mathrm{T-Res}\,}}(N, Q_3)\) function first selects all negative literals in \(Q_3\), and then seeks the S-Res side premises for \(Q_3\), which are \(C_1, \ldots , C_4\).

  2. 2.

    The S-Res mgu of \(C_1, \ldots , C_4\) and \(Q_3\) is

    $$\begin{aligned} \{x_1 \mapsto f(x), x_5 \mapsto f(x), x_7 \mapsto x, x_3 \mapsto g(f(x),y,z_1,z_2)\} \end{aligned}$$

    for the variables in \(Q_3\). Hence \(x_3\) is the only top variable in \(Q_3\).

  3. 3.

    The literals \(\lnot P_4(x_1, x_3)\) and \(\lnot P_8(x_3, x_5)\) in \(Q_3\) are therefore the top-variable literals. A T-Res inference is performed on \(C_1\), \(C_2\) and \(Q_3\), deriving:

    Notice that R contains no nested compound terms.

  4. 4.

    No further inference is possible for \(N \cup \{R\}\), hence \(N \cup \{R\}\) is saturated.

Though the T-Res resolvent R is free of nested compound terms, it is wider than any of its premises; moreover, it is neither a query clause due to the occurrence of the compound term \(h(x,y,z_1,z_2)\) nor an LG clause since R contains no loose guard. The resolvent R is formed with the remainders of \(C_1\), \(C_2\) and \(Q_3\) coloured in , and above, respectively. Observe that: i) the remainders of \(C_1\) and \(C_2\) are LG clauses and the remainder of \(Q_3\) is a query clause, and ii) due to the covering property of LG clauses, after unification, the remainders of \(C_1\) and \(C_2\) form an LG clause in R. Based on this observation, we devise a formula renaming technique which introduces a fresh predicate symbol \(P_9\) to abstract the remainders of \(C_1\) and \(C_2\) from R and replaces R by its equisatisfiable set of LGQ clauses:

where \(C_5\) is an LG clause and \(Q_4\) is an indecomposable query clause. Since the SepIndeQ rule is applicable to \(Q_4\), one can remove the isolated variable \(x_7\) from \(Q_4\) via separating the literals \(\lnot P_7(x, x_7)\) and \(\lnot P_6(x, x_7)\) from \(Q_4\). Using a new predicate symbol \(P_{10}\), one separates \(Q_4\) into the Horn guarded clauses:

$$\begin{aligned}&C_6 = \lnot P_7(x, x_7) \vee \lnot P_6(x, x_7) \vee \lnot P_{10}(x) \ \text {and} \ C_7 = \lnot P_9(x,y,z_1,z_2) \vee P_{10}(x). \end{aligned}$$

Figure 9 shows how the Q-Sep procedure separates \(Q_4\) into \(C_6\) and \(C_7\). Then, the T-Res resolvent R is replaced by the LG clauses \(C_5, C_6\) and \(C_7\). To sum up, i) given an LGQ clausal set \(\{Q_3, C_1, \ldots , C_4\}\), a saturated LGQ clausal set \(\{Q_3, C_1, \ldots , C_7\}\) is derived, and ii) the newly derived clauses \(C_5, C_6\) and \(C_7\) are no wider than the T-Res side premises \(C_1\) and \(C_2\).

Fig. 9
figure 9

Applying the Q-Sep procedure to \(Q_4\) separates it into Horn guarded clauses. The removed isolated variables are coloured in and the separated literals are coloured in

The other challenge in applying the T-Res rule to an ICQ clause and LG clauses is that the T-Res resolvents may have a wider variable cycle than the T-Res main premise. For example, applying the T-Res rule to the LG clauses

$$\begin{aligned} C_1^\prime =&\lnot A_1(x_1, x_2) \vee \lnot A_1(x_2, x_3) \vee \lnot A_1(x_3, x_1) \vee P_4(x_1, x_3), \\ C_2^\prime =&\lnot A_1(x_3, x_4) \vee \lnot A_1(x_4, x_5) \vee \lnot A_1(x_5, x_3) \vee P_8(x_3, x_5), \\ C_3^\prime =&\lnot A_1(x_5, x_6) \vee \lnot A_1(x_6, x_7) \vee \lnot A_1(x_7, x_5) \vee P_6(x_5, x_7), \\ C_4^\prime =&\lnot A_1(x_1, x_4) \vee \lnot A_1(x_4, x_7) \vee \lnot A_1(x_7, x_1) \vee P_5(x_1, x_7) \end{aligned}$$

as the side premises and \(Q_3\) as the main premise derives the ICQ clause

$$\begin{aligned}&\lnot A_1(x_1, x_2) \vee \lnot A_1(x_2, x_3) \vee \lnot A_1(x_3, x_1) \vee \lnot A_1(x_3, x_4) \vee \lnot A_1(x_4, x_5) \vee \lnot A_1(x_5, x_3) \vee \\&\lnot A_1(x_5, x_6) \vee \lnot A_1(x_6, x_7) \vee \lnot A_1(x_7, x_5) \vee \lnot A_1(x_1, x_4) \vee \lnot A_1(x_4, x_7) \vee \lnot A_1(x_7, x_1) \end{aligned}$$

in which the variable cycle is significantly wider than the one in the query clause \(Q_3\). However, the T-Res system avoids this T-Res inference by selecting all negative literals in \(C_1^\prime , C_2^\prime , C_3^\prime \) and \(C_4^\prime \), forcing these clauses to act as the main premises in the resolution inferences. Specifically, the T-Res system restricts that only ground simple clauses and non-ground compound-term clauses can be side premises for ICQ clauses. Without introducing wider variable cycles, the application of the T-Res rule to \(Q_3\) and \(C_1, \ldots , C_4\) breaks the variable cycle in \(Q_3\). This is due to the covering property of the LG clauses in the T-Res side premises, ensuring that the variables in the side premises are simultaneously unified, therefore the new variable relations in the remainders of the side premises, occurring in the T-Res resolvent, remain controlled by the loose guards of the LG side premises.

Transforming the T-Res resolvent of an ICQ clause and LG clauses to the smallest number of LGQ clauses is not straightforward. We use the notions of connected top variables and closed top-variable subclauses to identify the LG subclauses in the T-Res resolvents.

Definition 46

In a T-Res inference on an ICQ clause as the main premise with the top-variable subclause C, and LG clauses as the side premises,

  1. 1.

    top variables \(x_i\) and \(x_j\) are connected in C if there exists a sequence of top variables \(x_i, \ldots , x_j\) in C such that each pair of adjacent variables co-occurs in a top-variable literal, and

  2. 2.

    the clause \(C^\prime \) is a closed top-variable subclause of C if

    1. (a)

      each pair of top variables in \(C^\prime \) are connected, and

    2. (b)

      the top variables in \(C^\prime \) do not connect to the top variables that are in C but not in \(C^\prime \).

Suppose \(Q_{icq}\) is an ICQ clause and \(N_{lg}\) are LG clauses. Further, suppose \(Q_{icq}\) is the main premise and \(N_{lg}\) are the side premises in a T-Res inference. Then, each closed top-variable subclause in \(Q_{icq}\) is resolved with a subset \(N_{lg}^\prime \) of \(N_{lg}\), and the disjunction of the remainders of all clauses in \(N_{lg}^\prime \) forms an LG clause in the T-Res resolvent. In the previous example, the top-variable subclause \(\lnot P_5(x_1, x_3) \vee \lnot P_9(x_3, x_5)\) in \(Q_3\) is the only closed top-variable subclause in \(Q_3\), since \(x_3\) is the only top variable in \(Q_3\). The fact that the T-Res side premises of \(\lnot P_5(x_1, x_3)\) and \(\lnot P_9(x_3, x_5)\) are \(C_1\) and \(C_2\) implies that the disjunction of remainders of \(C_1\) and \(C_2\) forms an LG clause

$$\begin{aligned} C_{lg}^\prime = \lnot G_1(x,y,z_1,z_2) \vee \lnot G_2(x,y,z_1,z_2) \vee A(h(x,y,z_1,z_2)) \end{aligned}$$

in the T-Res resolvent

$$\begin{aligned} R = \lnot G_1(x,y,z_1,z_2) \vee \lnot G_2(x,y,z_1,z_2) \vee A(h(x,y,z_1,z_2))^*\vee \lnot P_7(x, x_7) \vee \lnot P_6(x, x_7). \end{aligned}$$

In the previous example, we abstracted \(C_{lg}^\prime \) from R by introducing a fresh predicate symbol \(P_9\), obtaining an LG clause \(C_5\) and a query clause \(Q_4\).

The T-Res resolvents of an ICQ clause and LG clauses is handled by the following formula renaming:

figure u

Applying the T-Trans rule to a T-Res resolvent of an ICQ clause and LG clause replaces it with a set of LGQ clauses and preserves satisfiability equivalence. Formally:

Lemma 47

Let R be a T-Res resolvent of an ICQ clause \(Q_{icq}\) as the main premise and LG clauses \(N_{lg}\) as the side premises. Then, the following properties hold.

  1. 1.

    Applying the T-Trans rule to R replaces it by a set \(N_{lg}^\prime \) of LG clauses and a query clause \(Q_r\).

  2. 2.

    Applying the Q-Sep procedure to \(Q_r\) separates it into a set \(N_{g}\) of guarded clauses and optionally a set \(N_{icq}\) of ICQ clauses.

  3. 3.

    For each clause \(C^\prime \) in \(N_{lg}^\prime \), there exists a clause C in \(N_{lg}\) such that \(C^\prime \) is no wider than C.

  4. 4.

    For each clause \(C^\prime \) in \(N_{g}\), it is the case that either \(C^\prime \) is narrower than \(Q_{icq}\), or there exists a clause C in \(N_{lg}\) such that \(C^\prime \) is not wider than C.

  5. 5.

    For each clause \(Q_{icq}^\prime \) in \(N_{icq}\), \(Q_{icq}^\prime \) is narrower than \(Q_{icq}\).

  6. 6.

    Suppose N is a clausal set. Then, \(N \cup \{R\}\) is satisfiable if and only if \(N \cup N_{lg}^\prime \cup N_{g} \cup N_{icq}\) is satisfiable.

Proof

Recall the T-Res rule with a-priori eligibility.

if the following conditions are satisfied.

  1. 1.

    No literal is selected in \(D_1, \ldots , D_n,D\) and \(B_1, \ldots , B_n\) are strictly \(\succ _{lpo}\)-maximal with respect to \(D_1, \ldots , D_n\), respectively.

  2. 2a.

    If \(n = 1\), i) either \(\lnot A_1\) is selected, or nothing is selected in \(\lnot A_1 \vee D\) and \(\lnot A_1\) is \(\succ _{lpo}\)-maximal with respect to D, and ii) \(\sigma = {{\,\textrm{mgu}\,}}(A_1 \doteq B_1)\) or

  3. 2b.

    there must exist an mgu \(\sigma ^\prime \) such that \(\sigma ^\prime = {{\,\textrm{mgu}\,}}(A_1 \doteq B_1, \ldots , A_n \doteq B_n)\), then \(\lnot A_1, \ldots , \lnot A_m\) are the top-variable literals of \(\lnot A_1 \vee \ldots \vee \lnot A_{m} \vee \ldots \vee \lnot A_n \vee D\) and \(\sigma = {{\,\textrm{mgu}\,}}(A_1 \doteq B_1, \ldots , A_m \doteq B_m)\) where \(1 \le m \le n\).

  4. 3.

    All premises are variable disjoint.

Suppose \(Q_{icq} = \lnot A_1 \vee \ldots \vee \lnot A_{m} \vee \ldots \vee \lnot A_n\) is the T-Res main premise and an ICQ clause, and \(C_1 = B_1 \vee D_1, \ldots , C_m = \ B_m \vee D_m, \ldots , C_n = B_n \vee D_n\) are the T-Res side premises and LG clauses. Further suppose R is the T-Res resolvent \((D_1 \vee \ldots \vee D_m \vee \lnot A_{m+1} \vee \ldots \vee \lnot A_{n})\sigma \) of \(C_1, \ldots , C_n\) and C. The variables occurring in the T-Trans rule are omitted in this proof.

Suppose \(C_i\) is a clause in \(C_1, \ldots , C_m\). By Algorithm 1, \(C_i\) is either a ground flat clause or a compound-term clause. Suppose \(C_i\) is a ground flat clause. This means that a top variable in \(Q_{icq}\) pairs a constant in \(C_i\). By Lemma 26, \(C_1, \ldots , C_m\) are ground flat clauses and all negative literals in \(Q_{icq}\) are selected. Hence, the T-Res resolvent R is a ground flat clause, viz., an LG clause, and the case of applying the T-Trans rule to R is trivial. Hence, \(C_1, \ldots , C_m\) are compound-term clauses. We now prove 1.–6. by in sequential order.

1.-1: We first prove that \((\lnot A_{m+1} \vee \ldots \vee \lnot A_{n})\sigma \) is a query clause. By 1. of Corollary 25, the mgu \(\sigma \) substitutes all variables in \(\lnot A_{m+1} \vee \ldots \vee \lnot A_{n}\) with either variables or constants. Then, \((\lnot A_{m+1} \vee \ldots \vee \lnot A_{n})\sigma \) is a query clause. When \(m=n\) the statement trivially holds.

1.-2: We prove that \((D_1 \vee \ldots \vee D_m)\sigma \) is a disjunction of LG clauses, and each disjunct maps to a closed top-variable subclause. This is done by proving:

  1. i

    The subclause \(D_i\sigma \) is an LG clause for each i such that \(1 \le i \le m\).

  2. ii

    Suppose \(\lnot A_i\) and \(\lnot A_j\) are two distinct literals containing connected top variables where \(1 \le i \le m\) and \(1 \le j \le m\). Then, \((D_i \vee D_j)\sigma \) is an LG clause.

  3. iii

    Suppose \(\lnot A_{i_1} \vee \ldots \vee \lnot A_{i_k}\) is a closed top-variable subclause of \(\lnot A_1 \vee \ldots \vee \lnot A_{m}\), and suppose \(D_i^\prime \) represents \(D_{i_1} \vee \ldots \vee D_{i_k}\). Then, \((D_1 \vee \ldots \vee D_m)\sigma \) can be represented as \((D_1^\prime \vee \ldots \vee D_t^\prime )\sigma \) where \(1 \le t \le m\).

1.-2-i: By Lemma 14 and the fact that \(C_i\) is a compound-term clause, the eligible literal \(B_i\) in \(C_i\) is a compound-term literal. By the covering property of LG clauses, \({{\,\textrm{var}\,}}(B_i) = {{\,\textrm{var}\,}}(C_i)\). By 2. of Corollary 25, the mgu \(\sigma \) substitutes variables in \(C_i\) with variables and constants. By the fact that \(C_i\) is an LG clause and Lemma 23, \(D_i\sigma \) is an LG clause.

1.-2-ii: Suppose x and y are top variables in \(\lnot A_i\) and \(\lnot A_{j}\), respectively. Further suppose x and y are connected. By the definition of connected top variables, there exists a sequence of top variables \(x, \ldots , y\) in C such that each pair of adjacent variables co-occurs in a top-variable literal. By Lemma 24, \(x, \ldots , y\) only pair compound terms. Suppose \(x^\prime \) and \(y^\prime \) are two adjacent top variables in \(x, \ldots , y\). W.l.o.g. suppose \(\lnot A_t\) is a top-variable literal in C where \(x^\prime \) and \(y^\prime \) co-occur. Suppose \(B_t\) is the compound-term literal in the T-Res side premises that resolves \(\lnot A_t\), satisfying that \(A_t\sigma \doteq B_t\sigma \). Further suppose \(s^\prime \) and \(t^\prime \) are the compound terms in \(B_t\) that \(x^\prime \) and \(y^\prime \) pair, respectively. By 1. of Corollary 25 and the covering property of LG clauses, \({{\,\textrm{var}\,}}(s^\prime \sigma ) = {{\,\textrm{var}\,}}(t^\prime \sigma )\), therefore \({{\,\textrm{var}\,}}(x^\prime \sigma ) = {{\,\textrm{var}\,}}(y^\prime \sigma )\). Hence, \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}(y\sigma )\). By the strong compatibility of LG clauses, \(s^\prime \sigma \) is compatible with \(t^\prime \sigma \), therefore \(x^\prime \sigma \) is compatible with \(y^\prime \sigma \). Hence, \(x\sigma \) is compatible with \(y\sigma \). W.l.o.g. suppose x pairs a compound term t in \(B_i\) and y pairs a compound term s in \(B_j\). By the result established in 1.-2-ii, \(D_i\sigma \) and \(D_j\sigma \) are LG clauses, The fact that \({{\,\textrm{var}\,}}(x\sigma ) = {{\,\textrm{var}\,}}(y\sigma )\) implies \({{\,\textrm{var}\,}}(s\sigma ) = {{\,\textrm{var}\,}}(t\sigma )\). By the covering property of LG clauses, \({{\,\textrm{var}\,}}(D_i\sigma ) = {{\,\textrm{var}\,}}(D_j\sigma )\), therefore \(D_i\sigma \vee D_j\sigma \) is covering. Since \(x\sigma \) is compatible with \(y\sigma \), \(s\sigma \) is compatible with \(t\sigma \). By the strong compatibility property of LG clauses, the compound terms in \(D_i\sigma \) and \(D_j\sigma \) are compatible, therefore \(D_i\sigma \vee D_j\sigma \) are strongly compatible. The fact that \(D_i\sigma \) and \(D_j\sigma \) are LG clauses implies that \(D_i\sigma \vee D_j\sigma \) is a simple clause. Since \(D_i\sigma \) is an LG clause, \(D_i\sigma \) contains a loose guard. By the fact that \({{\,\textrm{var}\,}}(D_i\sigma ) = {{\,\textrm{var}\,}}(D_j\sigma )\), \(D_i\sigma \vee D_j\sigma \) contains a loose guard. Hence, \(D_i\sigma \vee D_j\sigma \) is an LG clause.

1.-2-iii: Suppose \(\lnot A_{i_1} \vee \ldots \vee \lnot A_{i_k}\) is a closed top-variable subclause of \(\lnot A_1 \vee \ldots \vee \lnot A_{m}\). Further suppose \(D_i^\prime \) represents \(D_{i_1} \vee \ldots \vee D_{i_k}\) where \(\sigma = {{\,\textrm{mgu}\,}}(A_{i_1} \doteq B_{i_1}, \ldots , A_{i_k} \doteq B_{i_k})\). We first prove that \(D_i^\prime \) is an LG clause. Suppose \(C^\prime \) is the top-variable subclause \(\lnot A_1 \vee \ldots \vee \lnot A_{m}\). By the fact that each literal in \(C^\prime \) contains at least one top variable, and 2b. of Definition 46 that each pair of closed top-variable subclauses of \(C^\prime \) has no connected top variables, one can partition \(C^\prime \) into a set of closed top-variable subclauses. We use \(C_1^\prime , \ldots , C_t^\prime \) to denote this set of subclauses. W.l.o.g. we use \(C_i^\prime \) to represent \(\lnot A_{i_1} \vee \ldots \vee \lnot A_{i_k}\). By 2a. of Definition 46, each pair of top variables in \(C_i^\prime \) is connected. By the result established in 1.-2-ii, \((D_{i_1} \vee \ldots \vee D_{i_k})\sigma \) is an LG clause, therefore \(D_i^\prime \) is an LG clause. We represent \((D_1 \vee \ldots \vee D_m)\sigma \) as \((D_1^\prime \vee \ldots \vee D_t^\prime )\sigma \) where each \(D_i^\prime \) in \(D_1^\prime , \ldots , D_t^\prime \) maps to a closed top-variable subclause \(C_i^\prime \). Now we can present the T-Res resolvent as follows.

$$\begin{aligned} R = (D_1^\prime \vee \ldots \vee D_t^\prime \vee \lnot A_{m+1} \vee \ldots \vee \lnot A_{n})\sigma \end{aligned}$$

Applying the T-Trans rule to R transforms it into

$$\begin{aligned} D_1^\prime \sigma \vee P_1, \ \ldots , \ D_t^\prime \sigma \vee P_t, \ Q_r = (\lnot A_{m+1} \vee \ldots \vee \lnot A_{n})\sigma \vee \lnot P_1 \vee \ldots \vee \lnot P_t. \end{aligned}$$

We prove that \(D_i^\prime \sigma \vee P_i\) is an LG clause for all i such that \(1 \le i \le t\). The case is trivial when \(D_i^\prime \sigma \) is ground. Now assume that \(D_i^\prime \sigma \) is non-ground. By 1.-2-iii, \(D_i^\prime \sigma \) is an LG clause. By the definition of the T-Trans rule, \(P_i\) is a flat literal and \({{\,\textrm{var}\,}}(D_i^\prime \sigma ) = {{\,\textrm{var}\,}}(P_i)\), hence \(D_i^\prime \sigma \vee P_i\) is an LG clause. Next, we prove that \(Q_r\) is a query clause. By the definition of the T-Trans rule, \(\lnot P_1 \vee \ldots \vee \lnot P_t\) is a negative flat clause. By the result established in 1.-1, \(Q_r\) is a query clause.

2.: This is a consequence of Lemma 44.

3.: We prove that for each clause \(D_i^\prime \sigma \vee P_i\) in \(D_1^\prime \sigma \vee P_1, \ \ldots , D_t^\prime \sigma \vee P_t\), there exists a T-Res side premise C in \(C_1, \ldots , C_m\) such that \(D_i^\prime \sigma \vee P_i\) is no wider than C. By 1.-2-i, the loose guard \(\mathbb {G}\sigma \) in \(D_i^\prime \sigma \) is inherited from a loose guard \(\mathbb {G}\) in \(C_1, \ldots , C_m\). W.l.o.g. suppose a side premise C contains the loose guard \(\mathbb {G}\). The fact that a loose guard contains all variables of an LG clause implies that \({{\,\textrm{var}\,}}(D_i^\prime \sigma \vee P_i) = {{\,\textrm{var}\,}}(\mathbb {G}\sigma )\) and \({{\,\textrm{var}\,}}(C) = {{\,\textrm{var}\,}}(\mathbb {G})\). Then, \({{\,\textrm{var}\,}}(D_i^\prime \sigma \vee P_i) = {{\,\textrm{var}\,}}(C\sigma )\). By 2. of Corollary 25, the mgu \(\sigma \) substitutes all variables in \(\mathbb {G}\) with either constants or variables, therefore C contains no less distinct variables than \(D_i^\prime \sigma \vee P_i\).

4.: Suppose \(C^\prime \) is a guarded clause obtained by applying the Q-Sep procedure to

$$\begin{aligned} Q_r = \lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \vee \lnot P_1 \vee \ldots \vee \lnot P_t. \end{aligned}$$

Then, \(C^\prime \) can only be derived due to the fact that a surface literal in \(Q_r\) is separated by the Q-Sep procedure. We prove that

  1. 1

    if the separated surface literal belongs to \(\lnot A_{m+1}\sigma , \ldots , \lnot A_{n}\sigma \), then \(C^\prime \) is narrower than \(Q_{icq}\), or

  2. 2

    if the separated surface literal belongs to \(\lnot P_1, \ldots , \lnot P_t\), then there exists a T-Res side premise C in \(C_1, \ldots , C_m\) such that \(C^\prime \) is no wider than C.

4.-1: Suppose \(C^\prime \) is a guarded clause that is obtained by separating a surface literal in \(Q_r\) belonging to \(\lnot A_{m+1}\sigma , \ldots , \lnot A_{n}\sigma \). The fact that \(\lnot A_{m+1} \vee \ldots \vee \lnot A_{n}\) contains only non-top variables implies that \(\lnot A_{m+1} \vee \ldots \vee \lnot A_{n}\) is narrower than \(Q_{icq}\). By 1. of Corollary 25, the mgu \(\sigma \) substitutes the variables in \(\lnot A_{m+1} \vee \ldots \vee \lnot A_{n}\) with either variables or constants, hence \(\lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \) is narrower than \(Q_{icq}\). By Lemma 44, \(C^\prime \) is narrower than \(\lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \), hence \(C^\prime \) is narrower than \(Q_{icq}\).

4.-2: W.l.o.g. suppose \(\lnot P_1\) is a surface literal in \(\lnot P_1, \ldots , \lnot P_t\) that is separated from \(Q_r\) and suppose \(D_1^{\prime }\sigma \) is the subclause that \(P_1\) defines. Further, suppose \(C^\prime \) is the guarded clause obtained by separating \(\lnot P_1\) from \(Q_r\). By the definition of the T-Trans rule, \({{\,\textrm{var}\,}}(P_1) = {{\,\textrm{var}\,}}(D_1^{\prime }\sigma )\). By 1.-2-iii, \(D_1^{\prime }\sigma \) is a disjunction of the remainders from the T-Res side premises that map to a closed top-variable clause. W.l.o.g. suppose \(D_1\) is one of those remainders and \(D_1\sigma \) is a disjunct in \(D_1^{\prime }\sigma \). Suppose C is the T-Res side premise where \(D_1\) occurs. By 2. of Corollary 25, the mgu \(\sigma \) substitutes variables in the T-Res side premises with variables and constants, therefore \(D_1\sigma \) is no wider than \(D_1\). By 1.-2-ii, \({{\,\textrm{var}\,}}(D_1\sigma ) = {{\,\textrm{var}\,}}(D_1^{\prime }\sigma )\). Hence, \(D_1^{\prime }\sigma \) is no wider than \(D_1\), thus \(D_1^{\prime }\sigma \) is no wider than C. The fact that \({{\,\textrm{var}\,}}(P_1) = {{\,\textrm{var}\,}}(D_1^{\prime }\sigma )\) implies that \(P_1\) is no wider than C. Since the guarded clause \(C^\prime \) is obtained by separating the surface literal \(\lnot P_1\) from \(Q_r\), \(\lnot P_1\) acts as a guard in \(C^\prime \), hence \({{\,\textrm{var}\,}}(P_1) = {{\,\textrm{var}\,}}(C^\prime )\). Then, \(C^\prime \) is no wider than C.

5.: Suppose applying the Q-Sep procedure to

$$\begin{aligned} Q_r = \lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \vee \lnot P_1 \vee \ldots \vee \lnot P_t \end{aligned}$$

derives a set \(N_{icq}\) of ICQ clauses, and \(Q_{icq}^\prime \) is an ICQ clause in \(N_{icq}\). W.l.o.g. we assume that the mgu \(\sigma \) substitutes the variable arguments in the T-Res side premises \(C_1, \ldots , C_m\) with the variable arguments in the T-Res main premise \(Q_{icq}\). We prove that \(Q_{icq}^\prime \) is narrower than \(Q_{icq}\) by showing that \(Q_{icq}^\prime \) contains only the non-top-variables from \(Q_{icq}\). The following three steps prove this claim.

5.-1: First we prove that the chained variables (in \(Q_r\)) occurring in \(\lnot P_1, \ldots , \lnot P_t\) belong to the non-top-variables from \(Q_{icq}\). W.l.o.g. suppose \(\lnot P_1\) and \(\lnot P_2\) are two surface literals in \(Q_r\) that have common variables. Suppose \(D_1^{\prime }\sigma \) and \(D_2^{\prime }\sigma \) are the subclauses that \(P_1\) and \(P_2\) define, respectively. Further suppose \(D_1\) is a disjunct in \(D_1^{\prime }\) and \(D_2\) is a disjunct in \(D_2^{\prime }\). Suppose \(C_1 = B_1 \vee D_1\) and \(C_2 = B_2 \vee D_2\) are T-Res side premises. By 1.-2-ii, \({{\,\textrm{var}\,}}(D_1\sigma ) = {{\,\textrm{var}\,}}(D_1^{\prime }\sigma )\) and \({{\,\textrm{var}\,}}(D_2\sigma ) = {{\,\textrm{var}\,}}(D_2^{\prime }\sigma )\). By the definition of the T-Trans rule, \({{\,\textrm{var}\,}}(P_1) = {{\,\textrm{var}\,}}(D_1^{\prime }\sigma )\) and \({{\,\textrm{var}\,}}(P_2) = {{\,\textrm{var}\,}}(D_2^{\prime }\sigma )\), therefore \({{\,\textrm{var}\,}}(P_1) = {{\,\textrm{var}\,}}(D_1\sigma )\) and \({{\,\textrm{var}\,}}(P_2) = {{\,\textrm{var}\,}}(D_2\sigma )\). Hence, the overlapping variables between \(\lnot P_1\) and \(\lnot P_2\) are the same as those of \(D_1\sigma \) and \(D_2\sigma \). Now we consider how the mgu \(\sigma \) substitutes the variables in \(D_1\) and \(D_2\). W.l.o.g suppose \(\lnot A_1\) and \(\lnot A_2\) are top-variable literals in \(Q_{icq}\) satisfying \(A_1\sigma = B_1\sigma \) and \(A_2\sigma = B_2\sigma \). To understand how the mgu \(\sigma \) substitutes the variables in \(D_1\) and \(D_2\) is to understand how \(\sigma \), respectively, unifies the pair \(A_1\) and \(B_1\) and the pair \(A_2\) and \(B_2\). By 2. in Corollary 25 and the assumption that the mgu \(\sigma \) substitutes the variable arguments in \(B_i\) with that in \(A_i\), \(\sigma \) substitutes all variable arguments in \(B_1\) and \(B_2\) with either non-top-variables or constants from \(Q_{icq}\). Hence, the overlapping variables between \(B_1\sigma \) and \(B_2\sigma \) are non-top-variables in \(Q_{icq}\). Then, the overlapping variables between \(D_1\sigma \) and \(D_2\sigma \), and the ones between \(P_1\) and \(P_2\), are non-top-variables from \(Q_{icq}\). By the definition of chained variables and the assumption that \(\lnot P_1\) and \(\lnot P_2\) are the surface literals in \(Q_r\), the overlapping variables of \(P_1\) and \(P_2\) are the chained variables in \(Q_r\). Hence, the chained variables occurring in \(\lnot P_1, \ldots , \lnot P_t\) come from the non-top variables in \(Q_{icq}\).

5.-2: Next we prove that the chained variables occurring in \(\lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \) are the non-top-variables from \(Q_{icq}\). By 1. in Corollary 25, the fact that \(\lnot A_{m+1} \vee \ldots \vee \lnot A_{n}\) contains only non-top-variables and the assumption that the mgu \(\sigma \) substitutes the variable arguments in \(C_1, \ldots , C_m\) with the variable arguments in \(Q_{icq}\), the variables in \(\lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \) are the non-top-variables in \(Q_{icq}\). Hence, the chained variables in \(\lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \) belong to the non-top-variables in \(Q_{icq}\).

5.-3: By 5.-1 and 5.-2 and the fact that applying the Q-Sep procedure to a query clause does not introduce new chained variables to the query clause in the conclusions, \(Q_{icq}^\prime \) contains no more distinct variables than the non-top-variables in \(Q_{icq}\). Since the top variables in \(Q_{icq}\) do not occur in \(Q_{icq}^\prime \), \(Q_{icq}^\prime \) is narrower than \(Q_{icq}\).

6.: By Lemma 37, the Q-Sep procedure is sound. The fact that the T-Trans rule is formula renaming implies that the rule itself is sound. Hence, satisfiability equivalence is preserved.\(\square \)

Fig. 10
figure 10

Overview of handling query clauses

We use Q-IC to denote the procedure of applying our rules to ICQ clauses. This procedure consists of the following steps:

  1. 1.

    Apply the T-Res rule to an ICQ clause as the main premise and LG clauses as the side premises, deriving the T-Res resolvent R.

  2. 2.

    Apply the T-Trans rule to R, deriving a query clause Q and LG clauses.

  3. 3.

    Apply the Q-Sep procedure to Q, deriving guarded clauses and optionally ICQ clauses.

Figure 10 gives an overview of the query handling process for LG clauses presented in this section.

The idea behind the Q-IC procedure is: whenever the T-Res resolvent R of an ICQ clause Q and LG clauses \(C_1, \ldots , C_n\) is derived, we use the T-Trans rule and the Q-Sep procedure to replace R by a set N of LGQ clauses, which can be decided by the T-Res\(^+\) system that we introduced above Theorem 38. Most importantly, for each clause C in N, there exists a clause \(C^\prime \) in \(Q, C_1, \ldots , C_n\) satisfying that C is no wider than \(C^\prime \). Another optional implementation for 2.–3. of the Q-IC procedure is to devise a customised separation rule that separates the T-Res resolvent R into LGQ clauses in one step. This implementation is feasible due to the analysis of the variable relations of R, as explored in Lemma 47.

The main result of this section is given as follows.

Lemma 48

In the application of the Q-IC procedure to an ICQ clause \(Q_{icq}\) and LG clauses \(N_{lg}\), the Q-IC conclusions satisfy the following conditions.

  1. 1.

    They are a set \(N_{lg}^\prime \) of LG clauses and optionally a set \(N_{icq}\) of ICQ clauses.

  2. 2.

    For each clause \(C^\prime \) in \(N_{lg}^\prime \), it is the case that either \(C^\prime \) is narrower than \(Q_{icq}\), or there exists a clause C in \(N_{lg}\) such that \(C^\prime \) is no wider than C.

  3. 3.

    For each clause \(Q_{icq}^\prime \) in \(N_{icq}\), \(Q_{icq}^\prime \) is narrower than \(Q_{icq}\).

  4. 4.

    The replacement of \(\{Q_{icq}\} \cup N_{lg}\) by \(N_{lg}^\prime \cup N_{icq}\) preserves satisfiability equivalence.

Proof

By Lemma 47 and the fact that the guarded clauses are LG clausal clauses. \(\square \)

7 Answering BCQs for the Guarded Quantification Fragments

In Sect. 4 we introduce the top-variable inference system, in Sect. 5 we show that this system decides loosely guarded clauses, and in Sect. 6 we show how we handle query clauses. Now we combine the results from these sections and we are ready to describe a concrete saturation-based procedure for answering BCQ s for the guarded quantification fragments.

We use the notation Q-Ans to denote this procedure. To show that the Q-Ans procedure is suitable for implementation in modern saturation-based first-order theorem provers, we devise the procedure in accordance with the given-clause algorithm [66, 94] in Algorithm 3.

Algorithm 3
figure v

The Q-Ans algorithm for answering BCQs for the guarded quantification fragments

The functions in Algorithm 3 are listed below.

  1. 1.

    \({{\,\textrm{Trans}\,}}(\varSigma , q)\) applies the Trans process to a set \(\varSigma \) of guarded quantification formulas and a union q of BCQs, returning a set \(N_{lg}\) of LG clauses and a set \(N_{q}\) of query clauses.

  2. 2.

    \({{\,\textrm{Sep}\,}}(Q)\) applies the Q-Sep procedure to a query clause Q, and returns a set \(N_g\) of guarded clauses and optionally a set \(N_{icq}\) of ICQ clause.

  3. 3.

    \({{\,\textrm{Pick}\,}}(N)\) picks and then removes a clause from a clausal set N.

  4. 4.

    \({{\,\mathrm{T-Res}\,}}(C, N)\) eagerly applies the T-Res rule to a clause C and clauses in N, and returns the T-Res resolvent \(R_{tres}\).

  5. 5.

    \({{\,\mathrm{T-Trans}\,}}(R_{tres})\) applies the T-Trans rule to the T-Res resolvents \(R_{tres}\), returning a set \(N_{lg}\) of LG clauses and a query clause Q.

  6. 6.

    \({{\,\textrm{Factor}\,}}(C)\) applies the Factor rule (of the T-Res system) to a clause C, and returns the factor of C.

  7. 7.

    \({{\,\textrm{Smp}\,}}(N_1, N_2)\) returns all clauses from \(N_1\) that are not redundant with respect to clauses in \(N_2\).

The derivation in Algorithm 3 needs to guarantee fairness. Let N be a set of clauses. Then, a derivation \(N = N_0, N_1, \ldots \), with limit \(N_{\infty } = \bigcup _{j} \bigcap _{k \ge j} N_k\) is fair if the conclusion of the non-redundant premises in \(N_{\infty }\) is contained in \(\bigcup _{j} N_j\). Intuitively fairness means that no inference in the derivation is delayed indefinitely. To ensure fairness, the \({{\,\textrm{Pick}\,}}(N)\) function should guarantee that every clause in N will eventually be picked. We refer the reader to [8, p. 36] for a precise definition of fairness.

As a given-clause algorithm, Algorithm 3 splits input clauses into a worked-off clausal set \( workedOff \) storing the clauses that have already been picked as given clauses, and a clausal set \( usable \) with clauses needed to be considered for further inferences. For each clause C in \( usable \), we remove it from \( usable \), and then add C, all non-redundant conclusions for C and the non-redundant clauses in \( workedOff \) to \( usable \). In the inference loop, reduction rules are applied to guarantee termination.

Algorithm 3 consists of the following stages.

  • Lines 1–7 transform a union of BCQs, guarded quantification formulas into a set of LG clauses and ICQ clauses.

  • Lines 9–22 saturate the class of LG clauses and ICQ clauses.

  • Lines 24–25 output the answer to the given BCQs.

Lines 1–3 initialise the \( workedOff \) and \( usable \) clausal sets. Lines 4–6 transform a union of BCQ into a set of ICQ and guarded clauses, and then add these clauses to the \( usable \) clausal set. Line 7 performs the input reduction that removes redundancy in \( usable \).

The while-loop in Lines 9–22 terminates if either \( usable \) is empty or it contains an empty clause \(\bot \). Lines 10–11 pick a clause, namely \( given \), from the \( usable \) causal set and then add \( given \) to the \( workdedOffs \) causal set. Lines 12–18 derive new conclusions. Lines 12–16 say that if \( given \) is an ICQ clause, then the Q-IC procedure is applied to this ICQ clause and LG clauses in the \( workedOff \) clausal set, deriving a set of ICQ clauses and LG clauses. These newly derived clauses are denoted as \( new \). As ICQ clauses are negative clauses, the positive factoring rule Factor does not apply to them. Lines 17–18 say that if \( given \) is an LG clause, then the T-Res or the Factor rules are applied to that clause, deriving new LG clauses, denoted as \( new \). Finally Lines 19–22 are the inter-reduction steps that removes redundancy in the \( new \), the \( workdedOff \) and the \( usable \) clausal sets.

Lines 24–25 output the answer to the given BCQ. Suppose \(q = q_1 \vee \ldots \vee q_n\) is a union of BCQs and \(\varSigma \) is a set of the guarded quantification formulas. An empty \( usable \) clausal set implies that \(\{\lnot q_1, \ldots , \lnot q_n\} \cup \varSigma \) is satisfiable. Hence, the answer to q is ‘No’. If the \( usable \) clausal set contains an empty clause, then \(\{\lnot q_1, \ldots , \lnot q_n\} \cup \varSigma \) is unsatisfiable. In this case, the answer to q is ‘Yes’.

Since new predicate symbols are iteratively introduced in the derivation, one needs to ensure that only finitely many new predicate symbols are required. The introduced new predicate symbol will be reused whenever one needs to define a clause that has been defined before. This approach is formally stated as:

Remark 49

In the Q-Ans procedure, suppose a predicate symbol P is used to define an LGQ clause C at one step in the derivation. Then, in any further step whenever a predicate symbol is needed for defining C, we reuse the symbol P.

We show that for the fragments we consider the Q-Ans procedure requires a finite number of predicate symbols.

Lemma 50

In the application of the Q-Ans procedure to the BCQ answering problem for GF, LGF and CGF, only finitely many predicate symbols are introduced.

Proof

In the Q-Ans procedure, new predicate symbols are introduced in Line 2, Lines 4–6 and Lines 14–15 in Algorithm 3. We distinguish these cases:

Line 2: Since the Trans process is applied to formulas before the saturation process, this introduces finitely many new predicate symbols.

Lines 4–6: A union of BCQs is transformed into a finite number of query clauses. By Lemma 45, only finitely many new predicate symbols are needed for separating the input query clauses.

Lines 14–15: This step uses new predicate symbols to transform the T-Res resolvents R of an ICQ clause and LG clauses by a set of LGQ clauses. Since we reuse the introduced predicate symbols (Remark 49), we need to prove that given an LGQ clausal set, the number of different T-Res resolvents R is finitely bounded, and therefore the number of predicate symbols needed to transform the T-Res resolvents R to LGQ clauses is finitely bounded.

W.l.o.g. suppose the T-Res rule is applied to an ICQ clause \(Q_{icq} = \lnot A_1 \vee \ldots \vee \lnot A_{m} \vee \ldots \vee \lnot A_n\) as the main premise and LG clauses \(C_1 = B_1 \vee D_1, \ldots , C_m = \ B_m \vee D_m\) as the side premises, deriving the T-Res resolvent

$$\begin{aligned} R = D_1\sigma \vee \ldots \vee D_m\sigma \vee \lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma , \end{aligned}$$

where \(\sigma = {{\,\textrm{mgu}\,}}(A_1 \doteq B_1, \ldots , A_m \doteq B_m)\). By 1. of Lemma 47, \(D_1\sigma , \ldots , D_m\sigma \) are LG clauses and \(\lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \) is a query clause. By 1. of Corollary 25 and the fact that the variables in \(\lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \) are the non-top variables from \(Q_{icq}\), \(\lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \) is narrower than \(Q_{icq}\). By 3. of Lemma 47, the clauses in \(D_1\sigma , \ldots , D_m\sigma \) are no wider than the clauses in \(C_1, \ldots , C_m\). Hence the T-Res resolvent R is indeed a disjunction of a query clause (narrower than the query clause in the T-Res main premise) and LG clauses (that are no wider than the LG clauses in the T-Res side premises). We use the terminology R-type clauses to refer to the T-Res resolvents of an ICQ clause and LG clauses.

We first prove that in the application of the Q-Abs procedure to LGQ clauses, the number of R-type clauses is finite. Suppose N is an LGQ clausal set. Then, by applying the Q-Sep procedure to the query clauses in N, as shown in Lines 4–6 of Algorithm 3, N is transformed into a set of LG clauses and a set of ICQ clauses. Suppose \(N_1\) and \(N_2\) are sets of LG and ICQ clauses, respectively. W.l.o.g. suppose \(N = N_1 \cup N_2\). We distinguish the inferences performed on \(N_1\) and \(N_2\).

i: Suppose \(N_1^\prime \) is the union of \(N_1\) and the LG clauses derived by applying the T-Res\(^+\) system to N. By Lemma 30 and the property that LG clauses contain no nested compound terms, \(N_1^\prime \) consists of finitely many clauses. Suppose \(N_1^{\prime \prime }\) is the set of LG clauses (after condensation and modulo variable renaming) built using the signature of \(N_1^\prime \), and no clause \(N_1^{\prime \prime }\) is wider than the maximal width of the clauses in \(N_1^\prime \). By the fact that the clauses in \(N_1^{\prime \prime }\) are of bounded depth and width, the number of clauses in \(N_1^{\prime \prime }\) is finitely bounded. Suppose C is an LG clause that is a subclause in the R-type clause when applying the T-Res rule to N. By 3. of Lemma 47, C is no wider than the clauses in \(N_1^\prime \), therefore C belongs to \(N_1^{\prime \prime }\). By the fact that the number of clauses in \(N_1^{\prime \prime }\) is bounded, the number of clauses that are built using LG subclauses is bounded, hence, using the signature in \(N_1\), there are finitely many \(D_1\sigma \vee \ldots \vee D_m\sigma \) clauses.

ii: Suppose \(N_2^\prime \) is the set of query clauses (after condensation and modulo variable renaming) built using the signature of \(N_2\), and the clauses in \(N_2^\prime \) are narrower than the maximal width of the clauses in \(N_2\). Since clauses in \(N_2^\prime \) are of bounded depth and width, there are finitely many clauses in \(N_2^\prime \). Suppose \(Q_r\) is the query clause occurring in the R-type clause in applying the T-Res rule to N. Then, \(Q_r\) is narrower than the clauses in \(N_2^\prime \), hence \(Q_r\) belongs to \(N_2^\prime \). Hence, using the signature in \(N_2\), there are finitely many \(\lnot A_{m+1}\sigma \vee \ldots \vee \lnot A_{n}\sigma \) clauses.

By the results established in i and ii, given an LGQ clausal set N, the number of R-type clauses that can be derived from N is finitely bounded. Then, for each R-type clause, only a finite number of new predicate symbols is needed. Since we reuse the introduced predicate symbols as stated in Remark 49, the total number of new predicate symbols for transforming R-type clauses is finitely bounded. Then, Lines 14–15 only require a finitely bounded number of new predicate symbols. \(\square \)

Next, we prove that the Q-Ans procedure guarantees termination.

Theorem 51

The Q-Ans procedure guarantees termination of deciding satisfiability for the LGQ clausal class.

Proof

By Theorem 31, the Q-Ans procedure is guaranteed to terminate on the LG clausal class. By Lemmas 44 and 48, applying the Q-Ans procedure to query clauses and LG clauses derives LGQ clauses that are no wider and no deeper than the premises. By Lemma 50, applying the Q-Ans procedure to LGQ clauses requires finitely many new predicate symbols. Therefor, the Q-Ans procedure decides satisfiability of the LGQ clausal class. \(\square \)

Finally, the next theorem positively answers Question 1.

Theorem 52

The Q-Ans procedure is a decision procedure for answering BCQs for GF, LGF and CGF.

Proof

By Theorems 8, 38 and 51. \(\square \)

8 Saturation-Based BCQ Rewriting for the Guarded Quantification Fragments

In this section, we turn our attention to investigating the saturation-based BCQ rewriting problem for the guarded quantification fragments.

Question 2

Suppose \(\varSigma \) is a set of formulas in GF, LGF and CGF, D is a set of ground atoms and q is a union of BCQs. Further, suppose N is the saturation obtained by applying the procedure devised for Question 1 to \(\{\lnot q\} \cup \varSigma \). Can N be back-translated to a (Skolem-symbol-free) first-order formula \(\varSigma _q\) such that \(\varSigma \cup D \models q\) if and only if \(D \models \varSigma _q\)?

Unlike the previous setting of BCQ answering, the BCQ rewriting problem depends only on the rules \(\varSigma \) and the query q. As guarded quantification formulas are free of function symbols, the function symbols in the saturation of \(\{\lnot q\} \cup \varSigma \) are Skolem symbols, hence the obtained formula \(\varSigma _q\) should also be function-free.

8.1 Basic Notions and Rules for Back-Translation

That a clausal set N can be back-translated into a first-order formula if N is globally consistent, globally linear, normal and unique is shown in [33, chapter 5]. To avoid ambiguity, we replace the word consistency with compatibility in this paper.

Now we formally define the above notions, starting with global compatibility. The compatibility property of a clause in Sect. 3 is extended to that of a clausal set. Recall that two compound terms t and s are compatible if the argument sequences of t and s are identical. A clause C is compatible if, in C, compound terms that are under the same function symbol are compatible.

Definition 53

(Compatibility) A clausal set N is locally compatible if all clauses in N are compatible. A clausal set N is globally compatible if compound terms in N that are under the same function symbol are compatible.

Definition 54

(Linearity) A pair of compound terms t and s is linear if the set of arguments in t is a subset of that in s or vice-versa. A clause C is linear if in C, each pair of compound terms that are under different function symbols, is linear.

A clausal set N is locally linear if all clauses in N are linear. A clausal set N is globally linear if each pair of compound terms in N that are under different function symbols is linear.

Definition 55

(Normality) A clause is normal if the compound terms in it contain only variables as arguments. A clausal set is normal if each clause in it is normal.

Definition 56

(Uniqueness) A compound term \(f(t_1, \ldots , t_n)\) is unique if \(t_1, \ldots , t_n\) are distinct variables. A clausal set N is unique if every compound term in N is unique.

A first-order clausal set N can be back-translated into a first-order formula if N satisfies all the aforementioned properties.

Theorem 57

([33, chapter 5]) Suppose N is a normal, unique, globally linear and globally compatible first-order clausal set. Then, N can be back-translated into a first-order formula without Skolem symbols.

Next, we introduce the basic rules for back-translation. We use the notation C(t) to denote that C(t) is a clause and t is a term that possibly occurs in C(t). We use \(C_n(f(\overline{x^n_m}))\) to denote that \(f(\overline{x^n_m})\) is a flat compound term and \(\overline{x^n_m}\) is a variable sequence \(x_1, \ldots , x_m\) occurring in the clause \(C_n\).

A term is abstracted from a clause using:

figure w

Variables are renamed using:

figure x

A clausal set is unskolemised to a first-order formula using:

figure y

The challenge of applying the Unsko rule to a clausal set N is not only about computing a correct result, but it is about ensuring that N is normal, unique, globally linear and globally compatible. Given a clausal set N that is obtained by saturating a set of clausified formulas, the Unsko rule restores first-order quantifications for N by eliminating the Skolem symbols in N. We refer the reader to [33, chapter 5] and [37, pp. 63–69] for more details on unskolemisation.

Lemma 58

([37, Sect. 5]) The Abs, the Rena and the Unsko rules preserve logical equivalence.

Next, we devise a back-translation procedure for LGQ clausal sets. This procedure first transforms an LGQ clausal set N to a normal, unique, globally linear and globally compatible clausal set \(N_1\), and then unskolemises \(N_1\) into a Skolem-symbol-free first-order formula. The following LGQ clausal set

$$\begin{aligned} N = \left\{ \begin{array}{l} \lnot G_1(x_1,a) \vee A_1(f(x_1,a),x_1) \vee A_2(g(x_1,a),x_1), \\ \lnot G_2(x_2,x_3) \vee A_3(f(x_2,x_3),x_2) \vee A_4(g(x_2,x_3),x_2),\\ \lnot G_3(b,x_4) \vee A_5(g(b,x_4),b)\\ \lnot G_4(x_5, c, c) \vee A_6(h(c,c,x_5)) \vee A_7(h(c,c,x_5))\\ \lnot B_1(x_8, x_6) \vee \lnot B_2(x_6, x_7) \vee \lnot B_3(x_7, x_8) \end{array} \right\} \end{aligned}$$

will be used as a running example, in which a and c are non-Skolem constants and b is a Skolem constant.

8.1.1 Transforming LGQ Clausal Sets to Normal and Unique Clausal Sets

In this section, we transform an LGQ clausal set into a normal, unique, locally linear and locally compatible clausal set. First, we introduce two variations of the Abs rule.

Constants in compound terms are abstracted using:

figure z

Duplicate variables in compound terms are abstracted using:

figure aa

We use Q-Abs to denote the procedure of applying the ConAbs and the VarAbs rules to an LGQ clausal set. The Q-Abs procedure ensures that an LGQ clausal set is transformed into a normal and unique clausal set. Using the LGQ clausal set N as an example, the Q-Abs procedure is applied to N by the following steps.

  1. 1.

    Recursively apply the ConAbs rule to each clause in an LGQ clausal set. From N we obtain

    $$\begin{aligned} N_1 = \left\{ \begin{array}{l} \lnot G_1(x_1,y_1) \vee A_1(f(x_1,y_1),x_1) \vee A_2(g(x_1,y_1),x_1) \vee y_1 \not \approx a, \\ \lnot G_2(x_2,x_3) \vee A_3(f(x_2,x_3),x_2) \vee A_4(g(x_2,x_3),x_2),\\ \lnot G_3(y_2,x_4) \vee A_5(g(y_2,x_4),y_2) \vee y_2 \not \approx b,\\ \lnot G_4(x_5, y_3, y_3) \vee A_6(h(y_3,y_3,x_5)) \vee A_7(h(y_3,y_3,x_5)) \vee y_3 \not \approx c \\ \lnot B_1(x_8, x_6) \vee \lnot B_2(x_6, x_7) \vee \lnot B_3(x_7, x_8) \end{array} \right\} . \end{aligned}$$
  2. 2.

    For each clause in the clausal set obtained in 1., recursively apply the VarAbs rule to it. From \(N_1\) we obtain

    $$\begin{aligned} N_2 = \left\{ \begin{array}{l} \lnot G_1(x_1,y_1) \vee A_1(f(x_1,y_1),x_1) \vee A_2(g(x_1,y_1),x_1) \vee y_1 \not \approx a, \\ \lnot G_2(x_2,x_3) \vee A_3(f(x_2,x_3),x_2) \vee A_4(g(x_2,x_3),x_2),\\ \lnot G_3(y_2,x_4) \vee A_5(g(y_2,x_4),y_2) \vee y_2 \not \approx b,\\ \lnot G_4(x_5, y_3, y_4) \vee A_6(h(y_3,y_4,x_5)) \vee A_7(h(y_3,y_4,x_5)) \vee y_3 \not \approx c \vee y_4 \not \approx y_3\\ \lnot B_1(x_8, x_6) \vee \lnot B_2(x_6, x_7) \vee \lnot B_3(x_7, x_8) \end{array} \right\} . \end{aligned}$$

We use the notation LGQ\(_\textsf {nu}\) to denote the clausal set obtained by applying the Q-Abs procedure to an LGQ clausal set.

Lemma 59

Let N be a set of LGQ\(_\textsf {nu}\) clauses. Then, i) all clauses in N are strongly compatible, and ii) N is normal, unique, locally compatible and locally linear.

Proof

W.l.o.g. suppose \(N_1\) is an LGQ clausal set satisfying such that applying Q-Abs procedure to \(N_1\) derives N. Further, suppose C is a clause in \(N_1\).

By the strong compatible property of LGQ clauses and the fact that the ConAbs and the VarAbs rules simultaneously abstract variables or constants from C, applying the Q-Abs procedure to C derives a strongly compatible clause. Hence, the clauses in N are strongly compatible, therefore N is locally compatible and locally linear.

That C is simple implies that the arguments in compound terms of C are either variables or constants. Suppose \(C^\prime \) is the clause obtained by recursively applying the ConAbs rule to C. Since each application of the ConAbs rule to C abstracts a constant occurring in the compound terms of C, no constants occur in compound terms in \(C^\prime \), hence \(C^\prime \) is normal. Suppose \(C^{\prime \prime }\) is the clause obtained by recursively applying the VarAbs rule to \(C^\prime \). Since each application of the VarAbs rule to \(C^\prime \) abstracts a duplicate variable occurring in the compound terms of \(C^\prime \), no duplicate variables occur in compound terms in \(C^{\prime \prime }\), therefore \(C^{\prime \prime }\) is unique. The fact that \(C^\prime \) is normal implies that \(C^{\prime \prime }\) is normal. Then, N is normal and unique. \(\square \)

Note that an LGQ\(_\textsf {nu}\) clause may not belong to the LGQ clausal class due to the presence of equality literals.

8.1.2 Renaming LGQ \(_\textsf {nu}\) Clausal Sets for Unskolemisation

In this section, we transform an LGQ\(_\textsf {nu}\) clausal set into a normal, unique, globally compatible and globally linear clausal set, preparing the set for unskolemisation.

Given an LGQ\(_\textsf {nu}\) clausal set N, one needs to locate the LGQ\(_\textsf {nu}\) clauses in N that have common Skolem function symbols, so that we can simultaneously unskolemise these clauses. We introduce the notions of connectedness, inter-connectedness and closed clausal set to define clauses that have identical function symbols.

Definition 60

(Inter-connected clausal set) Two clauses are connected if they contain at least one common function symbol. Two clausal sets are connected if they contain at least one common function symbol, otherwise, they are unconnected.

A clausal set N is an inter-connected clausal set if for any pair of clauses C and \(C^\prime \) in N, there exists a sequence of clauses \(C, C_1, \ldots , C_n, C^\prime \) in N such that each pair of adjacent clauses in \(C, C_1, \ldots , C_n, C^\prime \) is connected.

Recall that a flat clause is a clause containing no function symbols. We say that a clausal set is flat if the set contains only flat clauses. We partition an LGQ\(_\textsf {nu}\) clausal set N into clausal sets \(N_1, \ldots , N_n\) such that i) each \(N_i\) is either an inter-connected clausal set or a flat clausal set, and ii) each pair of clausal sets in \(N_1, \ldots , N_n\) are unconnected. Then, \(N_1, \ldots , N_n\) are closed clausal sets in N.

An inter-connected LGQ\(_\textsf {nu}\) clausal set has the following useful property.

Lemma 61

Let N be an inter-connected LGQ\(_\textsf {nu}\) clausal set. Then, all compound terms in N have the same arity.

Proof

In a clausal set, compound terms that are under the same function symbol have the same arity. By i) of Lemma 59, the compound terms in an LGQ\(_\textsf {nu}\) clause have the same arity. Hence, all compound terms in an inter-connected LGQ\(_\textsf {nu}\) clausal set have the same arity. \(\square \)

Given a closed LGQ\(_\textsf {nu}\) clausal set N, the Rena rule does not apply to it if N is a flat clausal set. Variables in an inter-connected LGQ\(_\textsf {nu}\) clausal set are renamed using the following rule:

figure ab

We use Q-Rena to denote the procedure of applying the VarRe rule to an inter-connected LGQ\(_\textsf {nu}\) clausal set. The Q-Rena procedure transforms an LGQ\(_\textsf {nu}\) clausal set to a normal, unique, globally compatible and globally linear clausal set, detailed below.

  1. 1.

    Partition an LGQ\(_\textsf {nu}\) clausal set to closed LGQ\(_\textsf {nu}\) clausal sets. We use the LGQ\(_\textsf {nu}\) clausal set \(N_2\) from the previous section as an example. Partition \(N_2\) into closed LGQ\(_\textsf {nu}\) clausal sets

    $$\begin{aligned}&N_2^\prime = \left\{ \begin{array}{l} \lnot G_1(x_1,y_1) \vee A_1(f(x_1,y_1),x_1) \vee A_2(g(x_1,y_1),x_1) \vee y_1 \not \approx a, \\ \lnot G_2(x_2,x_3) \vee A_3(f(x_2,x_3),x_2) \vee A_4(g(x_2,x_3),x_2),\\ \lnot G_3(y_2,x_4) \vee A_5(g(y_2,x_4),b) \vee y_2 \not \approx b \end{array} \right\} , \\&N_2^{\prime \prime } = \left\{ \begin{array}{l} \lnot G_4(x_5, y_3, y_4) \vee A_6(h(y_3,y_4,x_5)) \vee A_7(h(y_3,y_4,x_5)) \vee y_3 \not \approx c \vee y_4 \not \approx y_3 \end{array} \right\} , \\&\text {and} \ N_2^{\prime \prime \prime } = \{\lnot B_1(x_8, x_6) \vee \lnot B_2(x_6, x_7) \vee \lnot B_3(x_7, x_8)\}. \end{aligned}$$
  2. 2.

    Apply the VarRe rule to the inter-connected LGQ\(_\textsf {nu}\) clausal sets obtained in 1. Using a sequence of new variables x and y, applying the VarRe rule to \(N_2^\prime \) derives

    $$\begin{aligned} N_3^\prime = \left\{ \begin{array}{l} \lnot G_1(x,y) \vee A_1(f(x,y),x) \vee A_2(g(x,y),x) \vee y \not \approx a, \\ \lnot G_2(x,y) \vee A_3(f(x,y),x) \vee A_4(g(x,y),x),\\ \lnot G_3(x,y) \vee A_5(g(x,y),x) \vee x \not \approx b \end{array} \right\} . \end{aligned}$$

    Using new variables \(x_1, y_1, z_1\), applying the VarRe rule to \(N_2^{\prime \prime }\) transforms it into

    $$\begin{aligned} N_3^{\prime \prime } = \left\{ \begin{array}{l} \lnot G_4(x_1, y_1, z_1) \vee A_6(h(y_1,z_1,x_1)) \vee A_7(h(y_1,z_1,x_1)) \vee y_1 \not \approx c \vee z_1 \not \approx y_1 \end{array} \right\} . \end{aligned}$$

    Finally, from \(N_2\) we obtain the clausal set \(N_3^\prime \cup N_3^{\prime \prime } \cup N_2^{\prime \prime \prime }\).

We use the notation of LGQ\(_\textsf {nucl}\) to denote the clausal set obtained by applying the Q-Rena procedure to an LGQ\(_\textsf {nu}\) clausal set.

Lemma 62

Let N be an LGQ\(_\textsf {nucl}\) clausal set. Then, N is normal, unique, globally compatible and globally linear.

Proof

Suppose \(N_1\) is an inter-connected LGQ\(_\textsf {nu}\) clausal set, and \(N_2\) is a flat LGQ\(_\textsf {nu}\) clausal set. As \(N_2\) is a flat clausal set, it is trivially is normal, unique, globally compatible and globally linear.

We prove that applying the Q-Rena procedure to \(N_1\) transforms it to a normal, unique, globally compatible and globally linear clausal set. Suppose \(N_1^\prime \) is the clausal set obtained by applying the Q-Rena procedure to \(N_1\). By Lemma 59, \(N_1^\prime \) is normal and unique. By Lemma 61, the Q-Rena procedure renames the variables in \(N_1\) so that the variable arguments in all compound terms of \(N_1\) are renamed with an identical variable sequence. Then, \(N_1^\prime \) is globally compatible and globally linear. Since \(N_2\) is normal, unique, globally compatible and globally linear, N is normal, unique, globally compatible and globally linear. \(\square \)

8.1.3 Unskolemising LGQ \(_\textsf {nucl}\) Clausal Sets

In this section, we unskolemise an LGQ\(_\textsf {nucl}\) clausal set to a first-order formula without Skolem symbols. Two variations of the Unsko rule, respectively, are devised for inter-connected LGQ\(_\textsf {nucl}\) clausal sets and flat LGQ\(_\textsf {nucl}\) clausal sets.

An inter-connected LGQ\(_\textsf {nucl}\) clausal set is unskolemised using:

figure ac

A flat LGQ\(_\textsf {nucl}\) clausal set is unskolemised using:

figure ad

We use Q-Unsko to denote the procedure of applying the UnSkI and the UnSkF rules to an LGQ\(_\textsf {nucl}\) clausal set. Using the LGQ\(_\textsf {nucl}\) clausal set \(N_2^{\prime \prime \prime } \cup N_3^\prime \cup N_3^{\prime \prime }\) as an example, we show what the Q-Unsko procedure does.

  1. 1.

    For inter-connected LGQ\(_\textsf {nucl}\) clausal sets, the UnSkI rule is applied to them. Applying the UnSkI rule to \(N_3^\prime \) and \(N_3^{\prime \prime }\), respectively, derives

    $$\begin{aligned} F_1 = \exists z^\prime \forall x y \exists x^\prime y^\prime \left[\begin{array}{ll} (\lnot G_1(x,y) \vee A_1(x^\prime ,x) \vee A_2(y^\prime ,x) \vee y \not \approx a) &{} \wedge \\ (\lnot G_2(x,y) \vee A_3(x^\prime ,x) \vee A_4(y^\prime ,x)) &{} \wedge \\ (\lnot G_3(x,y) \vee A_5(y^\prime ,x) \vee x \not \approx z^\prime ) &{} \end{array} \right]\ \text {and} \\ F_2 = \forall y_1 z_1 x_1 \exists x_1^\prime \left[\begin{array}{l} \lnot G_4(x_1, y_1, z_1) \vee A_6(x_1^\prime ) \vee A_7(x_1^\prime ) \vee y_1 \not \approx c \vee z_1 \not \approx y_1 \end{array} \right]. \end{aligned}$$
  2. 2.

    For flat LGQ\(_\textsf {nucl}\) clausal sets, the UnSkF rule is applied to them. Applying the UnSkF rule to \(N_2^{\prime \prime \prime }\) unskolemise it into

    $$\begin{aligned} F_3 = \forall x_6 x_7 x_8 \left[\begin{array}{l} \lnot B_1(x_8, x_6) \vee \lnot B_2(x_6, x_7) \vee \lnot B_3(x_7, x_8) \end{array} \right]. \end{aligned}$$
  3. 3.

    Conjunctively connect the outputting formulas of 1. and 2. The running sample N is hence back-translated to a Skolem-symbol-free first-order formula \(F_1 \wedge F_2 \wedge F_3\).

Lemma 63

The back-translation defined by applying the Q-Unsko procedure to an LGQ\(_\textsf {nucl}\) clausal set is a Skolem-symbol-free first-order formula (with equality).

Proof

By Lemma 62, Theorem 57 and the definition of the Q-Unsko procedure. \(\square \)

The result of our back-translation procedure is summarised as follows.

Lemma 64

Let N be an LGQ clausal set. Then, i) successively applying the Q-Abs, the Q-Rena and the Q-Unsko procedures to N back-translates it into a Skolem-symbol-free first-order formula F, and ii) F is logically equivalent to N.

Proof

By ii) of Lemma 59, Lemmas 62 and 63, N is ensured to be back-translated to a Skolem-symbol-free first-order formula. That the ConAbs and the VarAbs rules are special cases of the Abs rule, the VarRe rule is a special case of the Rena rule, the UnSkI and the UnSkF rules are special cases of the Unsko rule and Lemma 58 imply that F and N are logically equivalent. \(\square \)

Figure 11 summarises our back-translation procedure for the LGQ clausal class.

Fig. 11
figure 11

The back-translation process for LGQ clausal sets

Returning to Question 2, let a first-order formula \(\varSigma _q\) be computed such that \(D \models \varSigma _q\) if and only if \(\varSigma \cup D \models q\). The final step in our procedure is to negate the first-order formula form of the saturation of \(\varSigma \cup \{\lnot q\}\). In our example, we need negate \(F_1 \wedge F_2 \wedge F_3\) to obtain as \(\varSigma _q\):

$$\begin{aligned}&\forall z^\prime \exists x y \forall x^\prime y^\prime \left[\begin{array}{ll} (G_1(x,y) \wedge \lnot A_1(x^\prime ,x) \wedge \lnot A_2(y^\prime ,x) \wedge y \approx a) &{} \vee \\ (G_2(x,y) \wedge \lnot A_3(x^\prime ,x) \wedge \lnot A_4(y^\prime ,x)) &{} \vee \\ (G_3(x,y) \wedge \lnot A_5(y^\prime ,x) \wedge x \approx z^\prime ) &{} \end{array} \right]\bigvee \\&\exists y_1 z_1 x_1 \forall x_1^\prime \left[\begin{array}{l} G_4(x_1, y_1, z_1) \wedge \lnot A_6(x_1^\prime ) \wedge \lnot A_7(x_1^\prime ) \wedge y_1 \approx c \wedge z_1 \approx y_1 \end{array} \right]\vee \\&\exists x_6x_7x_8 [ B_1(x_8, x_6) \wedge B_2(x_6, x_7) \wedge B_3(x_7, x_8)]. \end{aligned}$$

Let N be an LGQ clausal set. We use Q-Rew to denote the procedure of successively applying the Q-Abs, the Q-Rena and the Q-Unsko procedures to N, deriving a first-order formula F, and then negating F.

Finally, we positively answer Question 2.

Theorem 65

Suppose \(\varSigma \) is a set of guarded quantification formulas, D is a set of ground atoms and q is a union of BCQs. Further, suppose N is a saturation obtained by applying Q-Ans to \(\{\lnot q\} \cup \varSigma \). Then, applying the Q-Rew procedure to N produces a Skolem-symbol-free first-order formula \(\varSigma _q\) such that \(\varSigma \cup D \models q\) if and only if \(D \models \varSigma _q\).

Proof

By Lemma 64. \(\square \)

Comparing the signature in \(\varSigma _q\) and that in \(\varSigma \) and q, \(\varSigma _q\) may contain predicate and equality symbols not occurring in q and \(\varSigma \), since these symbols may have been introduced by the Q-Ans and the Q-Abs procedures, respectively.

9 Related Work

9.1 Resolution-Based Decision Procedures

The basis of our BCQ answering and rewriting approaches is saturation-based resolution, which provides a practical and powerful method for developing decision procedures, as is evidenced in [9, 29, 35, 38, 57, 59, 60, 82].

The P-Res rule is inspired by the ‘partial replacement’ strategy in [7, 8] and the ‘partial conclusion’ of the ‘Ordered Hyper-Resolution with Selection’ rule in [39]. Even though [39] claims that the idea of ‘partial conclusion’ can be easily generalised in the framework of [8], it does not show how and no proof is provided. In [7] and [8], the ‘partial replacement’ strategy seems to be what is behind ‘partial conclusions’, and it is proved that for ground clauses the ‘partial replacement’ strategy makes the application of a selection-based resolution rule, viz., the S-Res rule, redundant. In this paper, we formalise ‘partial replacement’ in the P-Res system with the P-Res rule as the core rule. We have proved the system is generally sound and refutationally complete for full first-order clausal logic.

The P-Res rule adds high-level flexibility to the approach of an S-Res inference step, as one can choose any sub-multiset of the S-Res side premises as the P-Res side premises. This means that the P-Res rule gives us the option to choose a desirable resolvent from the possible ‘partial resolvents’. This technique is critical in our methods to querying for the guarded quantification fragments, allowing a choice of the ‘partial resolvent’ that can be expressed in the same clausal class as the P-Res premises.

Motivated by the ‘MAXVAR’ technique in [29], we devised the top-variable technique. The ‘MAXVAR’ technique and the top-variable technique are also used in [39] and [98], respectively. A detailed example to demonstrate how the ‘MAXVAR’ technique works is given in [39], and the reader is referred to the manuscript [29] for the formal definitions and proofs. [29] uses the ‘MAXVAR’ technique to avoid term depth increase in the resolvents of the loosely guarded clauses with nested compound terms. The presentation of the ‘MAXVAR’ technique in [29] is complicated: one needs to identify the depth of a sequence of variables, and then apply a specially devised unification algorithm to find ‘MAXVAR’. Moreover, the ‘MAXVAR’ technique requires the use of non-liftable orderings, which are not compatible with the framework of [8].

We introduce the top-variable technique as a variation and simplification of the ‘MAXVAR’ technique in the conference paper [98], which considers the LG clausal class with no nested compound terms. The top-variable technique is generalised to apply to query clauses and already uses liftable orderings, so that it fits into the framework of [8]. However, in [98], the pre-conditions of the top-variable technique, so-called query pairs, cannot be immediately applied in our general querying setting.

Improving on [29, 39, 98], in the present paper, we first give a clean approach to compute top variables, viz., the \({{\,\textrm{ComT}\,}}\) function, and we then encode the top-variable technique in the \({{\,\textrm{TRes}\,}}\) function, as given in Algorithm 2. We formally prove that the T-Res rule can be used in any saturation-based resolution inference system following principles of the framework of [8]. We further generalise the premises of the T-Res rule to non-ground flat clauses and LG clauses, with detailed formal proofs given in Lemma 24, Corollary 25 and Lemma 26.

The T-Res system extends the resolution systems for the guarded fragment in [29, 39, 60] and the loosely guarded fragment in [29, 39, 98]. Although [60] is not interested in the loosely guarded fragment, it points out that the guarded clauses have the property that all compound terms have the same sequence of variables, i.e., the strongly compatible property, which is an essential observation for our saturation-based rewriting procedure. Nonetheless, in [60], this property is only used in analysing the complexity of its resolution decision procedure for the guarded fragment. [39] includes a discussion of refinement for the loosely guarded fragment, but does not give a formal description of the refinement or relevant proofs. A detailed refinement for the loosely guarded fragment is given in [29] with proofs, but [29] uses non-liftable orderings, which are not compatible with the framework of [8]. The resolution framework in [8] provides a powerful system unifying many different resolution refinement strategies that exist in different forms, such as standard resolution, ordered resolution, hyper-resolution and selection-based resolution, and it provides vigorous simplification rules and redundancy elimination techniques, and forms the basis of the most state-of-the-art first-order theorem provers, such as SPASS [95], Vampire [75], E [83], and Zipperposition [27]. Our initial work in [98] gives a resolution-based procedure in line with the resolution framework of [8] for deciding satisfiability of LGF and querying for LGF, but only solves the BCQ answering problem for the Horn fragment of LGF.

In this paper, we formally define and thoroughly investigate partial resolution and the top-variable resolution techniques and develop detailed proofs. We then show that these techniques can be used and extended to decide satisfiability, BCQ answering and saturation-based BCQ rewriting for the guarded quantification fragments.

These are significant improvements and extensions over [29, 39, 60, 98]. Moreover, our methods provide the basis for BCQ answering and new saturation-based BCQ rewriting procedures for all the guarded quantification fragments.

9.2 BCQ Answering Problem

The chase algorithms [20], which can be viewed as a form of forward chaining [79] or semantic tableau [49], is the state-of-the-art methods in solving BCQ answering problems in database and knowledge representation. These methods are applied on the ground data and \(\varSigma \)-rules in implication normal form. Unlike chase, our saturation-based query answering procedure does not require the grounding of clauses, which significantly reduces the number of clauses that need to be generated and handled. In our procedures, the inferences are performed differently, in particular, we are not limited to forward chaining and instead the \(\varSigma \)-clauses can be saturated first and then data can be added. Not only do our procedures avoid grounding, but they can simulate grounding by performing inferences on data first.

The following ontology-based data access [24, 30, 52, 71] scenario further motivates the saturation-based methods to address query answering problems: given a set \(\varSigma \) of guarded quantification formulas, a BCQ q and datasets D, checking whether \(\varSigma \cup D \models q\) is equivalent to checking unsatisfiability of \(\{\lnot q\} \cup \varSigma \cup D\).

Suppose both q and \(\varSigma \) are fixed. We pre-saturate \(\{\lnot q\} \cup \varSigma \) and use N to denote this pre-saturation. Then, independent of the datasets D, the saturation N can be reused in checking satisfiability of \(N \cup D\). This prevents having to recompute numerous inferences of \(\{\lnot q\} \cup \varSigma \) unnecessarily.

Previous works investigate the BCQ answering problem for Datalog\(^\pm \) [22] and description logics, such as guarded Datalog\(^\pm \) rules [20, 21, 23] and fragments of the description logic \(\mathcal {ALCHOI}\) [24, 62, 67, 77]. Constraints in relational databases and ontological languages in knowledge bases are widely formalised in rules of Datalog\(^\pm \), therefore devising automated querying procedures for Datalog\(^\pm \) is important.

A Datalog\(^\pm \) rule is a first-order formula in the form

$$\begin{aligned} F = \forall \overline{x} \overline{y} (\varphi (\overline{x}, \overline{y}) \rightarrow \exists \overline{z} \phi (\overline{x}, \overline{z})), \end{aligned}$$

where \(\varphi (\overline{x}, \overline{y})\) and \(\phi (\overline{x}, \overline{z})\) are conjunctions of atoms. Although answering BCQs for Datalog\(^\pm \) rules is undecidable [17], answering BCQs for the guarded fragment of Datalog\(^\pm \), viz., guarded Datalog\(^\pm \) rules, is 2ExpTime-complete [21]. The above Datalog\(^\pm \) rule F is a guarded Datalog\(^\pm \) rule if there exists an atom in \(\varphi (\overline{x}, \overline{y})\) that contains all free variables of \(\exists \overline{z} \phi (\overline{x}, \overline{z})\). Guarded Datalog\(^\pm \) can be extended to the so-called loosely guarded and clique-guarded Datalog\(^\pm \) by adopting the definition of the loosely guarded and the clique-guarded fragments, respectively. For example,

$$\begin{aligned} \forall xyz (\textsf {Siblings}(x,y) \wedge \textsf {Siblings}(y,z) \wedge \textsf {Siblings}(z,x) \rightarrow \exists u (\textsf {Mother}(u,x,y,z))) \end{aligned}$$

is a loosely guarded Datalog\(^\pm \) rule. Guarded, loosely guarded and clique-guarded Datalog\(^\pm \) rules can be seen as belonging to the Horn fragments of GF, LGF and CGF, respectively. Therefore our methods apply and lay the theoretical foundation for the first practical decision procedure of answering BCQs for guarded, loosely guarded and clique-guarded Datalog\(^\pm \) rules. Note that there are guarded Datalog\(^\pm \) rules that are not expressible in GF [10, p. 103], however, the Trans process transforms these Datalog\(^\pm \) rules into Horn guarded clauses.

The fragments of expressive description logic \(\mathcal {ALCHOI}\) [5] are prominent ontological languages in semantic web [50]. Query answering approaches for fragments of \(\mathcal {ALCHOI}\) have been extensively studied in the literature [24, 40, 62, 67, 77]. A key technique in this area is transforming BCQs into knowledge bases; see the rolling-up technique in [87] and the tuple graph technique in [25]. Interestingly, our Q-Sep procedure also achieves encoding of a query clause into the knowledge base of LG clauses. By the standard translation [18, chapter 2], axioms in the description logic \(\mathcal {ALCHOI}\) can be translated into guarded formulas needing only unary and binary predicate symbols. Hence, our Q-Ans procedure can also be used as a practical decision procedure for BCQ answering for the expressive description logic \(\mathcal {ALCHOI}\).

The squid decomposition technique analyses the complexity for answering BCQs over weakly guarded Datalog\(^\pm \) [21]. In squid decompositions, a BCQ is regarded as a squid-like graph in which branches are ‘tentacles’ and variable cycles are ‘heads’. Squid decomposition finds ground atoms that are complementary in the squid head, and then uses ground unit resolution to eliminate the heads. In contrast, our approach uses the separation rules to first cut ‘tentacles’ and then uses the T-Res rule to resolve cycles in ‘heads’. Our approach produces compact saturations of BCQs and the guarded quantification formulas, thus avoiding the significant overhead of grounding.

9.3 BCQ Rewriting Problem

Standard BCQ rewriting settings consider the following problem: given a union q of BCQs, a set \(\varSigma \) of first-order formulas and a dataset D, can we produce (function-free) first-order formulas \(\varSigma _q\), so that the entailment checking problem of \(D \cup \varSigma \models q\) is reduced to the model checking problem of \(D \models \varSigma _q\). If there exists such a \(\varSigma _q\), \(\varSigma \) and q are said to be first-order rewritable [24]. Problems on the first-order rewritability property have been extensively studied in [19, 24, 51, 88, 89] for different description logics, and in [14, 23, 43, 51] for fragments of Datalog\(^\pm \) rules. However, it is known that BCQ answering for none of the guarded quantification fragments are first-order rewritable. Another interesting saturation-based rewriting approach is [58], in which one first saturates axioms of the description logic \(\mathcal {SHIQ}\), presenting the saturation as a set of disjunctive Datalog rules, and then deductive databases are used to check entailment of BCQs over the disjunctive Datalog rules.

Unlike the idea of the first-order rewritability, saturation-based BCQ rewriting regards \(D \models \varSigma _q\) as an entailment checking problem. Unlike [58], in our query rewriting, queries are included in the reasoning process to obtain a saturation. Our saturation-based query rewriting is advantageous in ontology-based data access scenarios: Having a function-free first-order formula \(\varSigma _q\) such that \(D \cup \varSigma \models q\) if and only if \(D \models \varSigma _q\), we can check \(\varSigma _q\) over different datasets \(D_1, \ldots , D_n\). More importantly, to check whether \(D_i \models \varSigma _q\), we can use reasoning methods other than resolution, e.g., the chase algorithm, as \(\varSigma _q\) is free of Skolem symbols. This combines different reasoning tools can potentially accelerate query answering processes. Moreover, devising this rewriting procedure is interesting and challenging in its own right, as it required a new investigation and new techniques to back-translate a first-order clausal set into a function-free first-order formula, which in general is an undecidable problem.

10 Conclusion and Discussion

Considering the problem of query answering for the guarded quantification fragments, we present three sound and refutationally complete saturation-based resolution inference systems for general first-order clausal logic. Based on the top-variable inference system and customised separation rules, we establish the theoretical foundation for the first practical decision procedures of BCQ answering for the guarded, the loosely guarded, and the clique-guarded fragments. By extending the BCQ answering procedures with the back-translation techniques, we have devised a novel saturation-based BCQ rewriting procedure for these fragments.

We are confident that our procedures provide a solid foundation for practical implementations. We claim the procedures can be implemented in any saturation-based theorem prover, as they are devised in line with the resolution framework in [8]. Compared to the framework in [8], novel techniques are i) the SepDeQ and the SepIndeQ rules, ii) the P-Res and the T-Res rules and iii) the rules in the Q-Rew procedure.

i) Given a query clause Q, the application of the SepDeQ or the SepIndeQ rules to Q can be implemented by the following steps.

  1. 1.

    Find the surface literals in Q. By regarding each literal L in Q as a multiset in which the elements are the variable arguments of L, one can implement a multiset ordering \(\succ _m\) for the literals in Q. The \(\succ _m\)-maximal literals in Q are the surface literals in Q.

  2. 2.

    Identify the separable surface literals in Q. Check whether two surface literals in Q have overlapping variables.

  3. 3.

    Identify the separable subclauses in Q. Suppose \(L_1\) and \(L_2\) are two separable surface literals in Q. To separate \(L_1\) from Q, one needs to find the literals in Q that are \(\succ _m\)-smaller than \(L_1\), namely the literals guarded by \(L_1\). The literals guarded by \(L_1\) are a separable subclause in Q.

  4. 4.

    Separate the subclause guarded by \(L_1\) from Q. Following the conditions defined in the SepDeQ or the SepIndeQ rule, apply formula renaming with negative literals to replace the literals guarded by \(L_1\) by a fresh predicate symbol containing the only overlapping variables of \(L_1\) and \(L_2\).

ii) A possible implementation of the P-Res or the T-Res rule is: Suppose in a selection-based resolution (S-Res) inference, \(C_1, \ldots , C_n\) are the side premises, and C is the main premise with the negative literals \(\lnot A_1, \ldots , \lnot A_n\) selected. Then, one can use the selection-based resolution (S-Res) to implement a P-Res or a T-Res resolvent of C and \(C_1, \ldots , C_n\) as follows.

  1. 1.

    Without deriving any resolvent, compute an mgu \(\sigma ^\prime \) between C and \(C_1, \ldots , C_n\).

  2. 2.

    Unselect the literals \(\lnot A_1, \ldots , \lnot A_n\) in C, and then select a sub-multiset \(\lnot A_1, \ldots , \lnot A_m\) of \(\lnot A_1, \ldots , \lnot A_n\) where \(1 \le m \le n\), performing the P-Res rule on \(C_1, \ldots , C_m\) and C with \(\lnot A_1, \ldots , \lnot A_m\) selected. For the case of the T-Res inference, \(\lnot A_1, \ldots , \lnot A_m\) are the top-variable literals computed using the variable ordering \(\succ _v\) and \(\sigma ^\prime \).

  3. 3.

    When the P-Res or the T-Res resolvent is derived, unselect \(\lnot A_1, \ldots , \lnot A_m\).

iii) The Abs, the Rena and the Unsko rules have been used in eliminating second-order quantifiers tasks, as implemented in the SCAN system [70].

One next step is implementing the Q-Ans and the Q-Rew procedures and evaluating them on real-world ontologies. For example, we could focus on ontologies that are composed by the fragments of the description logic \(\mathcal {ALCHOI}\) and guarded, loosely guarded and clique-guarded Datalog\(^\pm \), since the number of GF problems in the TPTP first-order theorem proving benchmark [85] is rather small.

Two other interesting questions for future work are: 1) Extend our saturation-based procedures to support the tasks of BCQ answering and saturation-based BCQ rewriting for the guarded negation and the clique-guarded negation fragments [11]. This will require equality reasoning which we conjecture can be handled by extensions of the procedures presented in this paper with paramodulation or superposition. Whether our saturation-based methods can be refined to decide satisfiability of other variations of the guarded fragment such as the guarded fragment with transitive guards [86], the triguarded fragment [61, 78], the two-variable guarded fragment with counting quantifiers [72] and the forward guarded fragment [15], and querying for other guard-related fragments such as the monadic fragment of the two-variable guarded fragment with transitive guards [44] and the forward guarded fragment [15] remains to be investigated.

2) In our Q-Rew procedure, the rewritten queries are expressible in LGF and BCQs, but with equality. It would be interesting to know whether in the setting of the saturation-based BCQ rewriting problem for the guarded quantification fragments with equality, one can translate the saturated clausal set back into BCQs and formulas in these guarded quantification fragments with equality. The answer is not straightforward, as we first need to develop a decision procedure for the problem of the BCQ answering for these equality-occurring fragments.