LTCS-Report Finite Herbrand Models for Restricted First-Order Clauses

We call a Herbrand model of a set of (cid:12)rst-order clauses (cid:12)nite , if each of the predicates in the clauses is interpreted by a (cid:12)nite set of ground terms. We consider (cid:12)rst-order clauses with the signature restricted to unary predicate and function symbols and one variable. Deciding the existence of a (cid:12)nite Herbrand model for a set of such clauses is known to be Exp-Time -hard even when clauses are restricted to an anti-Horn form. Here we present an ExpTime algorithm to decide if a (cid:12)nite Herbrand model exists in the more general case of arbitrary clauses. Moreover, we describe a way to generate (cid:12)nite Herbrand models, if they exist. Since there can be in-(cid:12)nitely many minimal (cid:12)nite Herbrand models, we propose a new notion of acyclic Herbrand models. If there is a (cid:12)nite Herbrand model for a set of restricted clauses, then there are (cid:12)nitely many (at most triple-exponentially many) acyclic Herbrand models. We show how to generate all of them.


Introduction
We consider the problem of existence of the so called finite Herbrand model for a set of restricted first-order clauses.This is a special case of the problem of satisfiability a set of the first order formulas in FOL which continues to be a great area of research in logic, computer science, automated deduction.The problem is in general undecidable, not even semi-decidable.Hence the focus is on finding models for restricted classes of clauses.Our restrictions consists of allowing only unary predicates, unary function symbols, one constant and only one variable. 1uch sets of clauses can be seen as skolemized versions of Ackermann formulas, for which satisfiability is known to be decidable [8; 11].If a set of such clauses is satisfiable, then it has a Herbrand model.This model may not be finite, i.e. the predicates may be interpreted by infinite sets of the first order elements from Herbrand universe.
We search for the finite Herbrand models, i.e. the models in which each predicate is interpreted by a finite set of terms.In other words, we search for a special kind of ground atomic representation of a Herbrand model in the terminology of [5]. 2 Hyperresolution-based methods have been proposed, cf.[4; 9], but its precise complexity is still unclear.We prove that the problem of deciding whether a finite Hebrand model of a given set of first-order clauses exists, is ExpTime-complete, provided that the signature is restricted as mentioned above.
This restricted class of clauses came to our focus, while looking for methods of solving certain language equations or unification for description logics [1].We have found that these problems may be reduced to finding finite Herbrand models for a set of anti-Horn clauses restricted in this way, [2].As a continuation of that research, we show a generalization of the methods used there to the set of all clauses under the same restrictions.It is interesting that this more general problem is in the same complexity class as in the case of anti-Horn clauses.In future one can attempt to further generalize this class by lifting some of the restrictions.
Our solution to the problem is given by an algorithm that is not based on resolution techniques nor is an enumeration procedure explicitly constructing a model in a bottom-up fashion.Instead it follows a top-down approach, starting from the largest terms that appear in the model.However, we also demonstrate how to use our approach to actually construct models, and discuss how to find all so-called acyclic Herbrand models of a given set of clauses.
Our methods may be relevant to problems like that of (i) termination in logic programming with function symbols [10] and (ii) acyclicity for existential rules [7].While in (i) also Herbrand models are of chief interest, the setting (ii) usually considers arbitrary first-order structures, but the so-called Skolem chase, related to Herbrand models, is sometimes investigated in the context of finding approximating criteria for termination [13].However, there are two main differences to our setting.First, termination requires that all (minimal) models must be finite, instead of just one (as in our case).Only in the case of Horn clauses, our algorithm is a decision procedure for termination, because in this case there is a unique minimal Herbrand model.Second, usually predicates and functions of arbitrary arity are allowed, whereas we restrict ourselves to the unary case.
The problem of finding one finite Herbrand model is related to finite model finding [12], and useful for explaining to a user why a consequence does not hold since such a finite Herbrand model is relatively easy to understand due to its tree-like structure.Our construction can also be used for finding one terminating computation of a disjunctive logic program, which cannot be guaranteed to terminate for all possible computation paths [6].
In the next section, we introduce propagation rules as a class of first-order clauses and discuss the problem of finding finite Herbrand models.In Section 3, we introduce a characterization of such models via so-called shortcuts, and use them in Section 4 to decide the existence of finite Herbrand models.Finally, in Section 5 we discuss how to actually construct such models.Detailed proofs can be found in the accompanying technical report [3].

Clauses and Herbrand models
Let P be a set of unary predicate symbols, F be a set of unary function symbols, a be a constant symbol, and x be a variable.We consider first-order clauses c of the form where P 1 , . . ., P k , Q 1 , . . ., Q ∈ P and the terms t 1 , . . ., t k , s 1 , . . ., s are constructed over F, a, and x.The single variable x is considered to be universally quantified.Since all function symbols are unary, we usually denote such terms without parentheses, e.g. as f ga for f, g ∈ F. The height |t| of a term t is defined as the number of occurrences of function symbols it contains.The left-hand side of c is called its body, and the right-hand side is the head.The set of all predicates in the body of c is denoted by b(c), and h(c) is the set of all predicates in the head of c.Note that the body may be empty, in which case we denote it by , and similarly write ⊥ for an empty head.
We call such clauses (extended) propagation rules [2].In the following, we consider a set C of such clauses, and are looking for a finite Herbrand model H of C, i.e. essentially a finite subset of the Herbrand universe over P, F and a.By "finite" we mean that each predicate symbol is interpreted by a finite set of ground terms, i.e. objects of the Herbrand universe.We will use two equivalent representations for Herbrand interpretations H, depending on which is more convenient for our arguments: either H specifies sets of ground terms P H for each P ∈ P, or alternatively it can be seen as a single set of ground atoms of the form P (t), specifying exactly which atoms are true in H.

Normalization
Before we check for the existence of a finite Herbrand model, we first normalize the set C. Definition 1.A set of propagation rules is in normal form iff it consists of only • one positive ground clause of the form → A(a) such that A does not occur in the head of any other clause,

and
• increasing and decreasing clauses of the forms respectively, where Q f is a unique predicate, i.e. for every Q ∈ P and f ∈ F, there can be at most one Q f ∈ P for which the above two clauses exist (and then they must both exist).

Although technically
→ A(a) can also be seen as a flat clause (as it involves only a single term of a fixed height, instead of multiple terms with different heights), we do not consider it part of the flat clauses, due to its special status as the only ground clause.
In order to transform C into normal form, we first identify possibly existing pairs of increasing and decreasing clauses, then flatten the remaining clauses by introducing more increasing and decreasing clauses.Afterwards, we have to eliminate the clauses that are mixed, i.e. contain both a and x.We do this by guessing for each predicate P , whether P (a) will be true or not, and replacing P (a) in all clauses by or ⊥, respectively.In this process, we also eliminate all ground clauses and replace them with the single ground clause → A(a).
In more detail, we do the following.
N1 For any Q ∈ P and f ∈ F, if there is a unique P ∈ P such that C contains the clauses P (x) → Q(f x) and Q(f x) → P (x), then rename P to Q f (which we assume to be fresh).Initially, these are the only increasing and decreasing clauses.
N2 Do the following until all clauses are either increasing, decreasing, or flat (but possibly mixed): For any non-flat clause c ∈ C that has not been identified as increasing or decreasing, choose an atom P (f t) in c and replace it by P f (t).Add the increasing and decreasing clauses P f (x) → P (f x) and P (f x) → P f (x) to C if they do not already exist.
N3 Introduce a fresh predicate A and the clause → A(a).
Guess a set P a ⊆ P \ {A}.For every P ∈ P, do the following: N4 Remove all clauses from C that contain ⊥ in the body or in the head.
Remove from the body of all clauses, and ⊥ from the head of all clause.
N5 If there remains any clause except → A(a) that has an empty body ( ), then the normalization fails.
• Step N1 does not apply, because there are no clauses that we could identify as increasing or decreasing.
• In Step N2, we replace the atom P 2 (ga) by an atom P g 2 (a) and the atom P 1 (f (a)) by P f 1 (a), where P g 2 and P f 1 are new predicates.We add the corresponding increasing and decreasing clauses, and now the set of clauses has the following form: • In Step N3, we add → A(a).Then we have to guess P a ⊆ P. Let us guess that P g 2 ∈ P a and P 1 , P 2 , P f 1 / ∈ P a .P g 2 (a) will be replaced by and P f 1 (a) will be replaced by ⊥.We add the clause A(x) → P g 2 (x) and corresponding clauses for the other predicates.The set of clauses is now of the following form: ), clauses: P 2 (g(x)) → P g 2 (x), P f 1 (x) → P 1 (f (x)), P 1 (f (x)) → P f 1 (x).
• In Step N4, we remove and ⊥ from one flat clause and obtain the normalized set of clauses: • Since there are no flat clauses with on the left, Step N5 does not apply, hence the normalization succeeds.
Obviously, a successful normalization process will terminate with a set of propagation rules in normal form.It is correct in the following sense.• Initially, we set H := H, which is a model of the initial set of clauses.
• In Step N1, we simply replace some predicates by fresh predicates.If P is renamed to Q f , we set (Q f ) H := P H , which preserves the property that H is a Herbrand model of the resulting set of clauses. • Step N2 consists of flattening the clauses and creating new predicates on the way.Each new predicate is of the form P f for some already existing predicate P and a function symbol f .We define the interpretation of these new predicates recursively: if P H is defined, we set (P f ) Under this modification, it is clear that the atoms P (f t) and P f (t) are equivalent in H , and hence H remains a model of the flattened clauses, and also satisfies the new increasing and decreasing clauses.
• In Step N3 we define a special predicate A and we guess P a ⊆ P \ {A}.
We define A H := {a}, which satisfies the new clause → A(a).We can further guess P a := {P ∈ P \ {A} | a ∈ P H }. Thus, for every P ∈ P a , A(x) → P (x) is satisfied by H , and for every P / ∈ P a except A, A(x) ∧ P (x) → ⊥ is satisfied.
• The transformations in Step N4 clearly do not affect the satisfaction of the remaining clauses.
• The failure condition in Step N5 cannot apply, because any remaining nonground clause with on the left-hand side would mean that H is infinite, which implies by the above constructions that H is infinite.
(⇐): Assume that the normalization process did not fail, so we have guessed a set P a to obtain C , and that H is a finite Herbrand model of C .We show that H is also a model of C if we extend it with interpretations for the predicates that were renamed in the first step, i.e. if Q f is the renamed version of P in C , then we extend H by defining P H := (Q f ) H .To show this, we demonstrate that H satisfies the set of clauses as it was before each normalization step, by going through the steps in reverse order.
• Step N5 does not apply due to our assumption that the normalization did not fail.
• Regarding Step N4, the removed clauses are trivially satisfied by any Herbrand interpretation, and the addition of to the body or ⊥ to the head does not affect the satisfaction of a clause.
• For Step N3, observe that for any P ∈ P a we have a ∈ P H since H satisfies → A(a) and A(x) → P (x), i.e.P (a) is equivalent to in H. Similarly, for P ∈ P a , the clause A(x) ∧ P (x) → ⊥ ensures that a / ∈ P H .
• In Step N2 the new increasing and decreasing clauses ensure that the replaced atoms are equivalent to the original ones under H.
• Finally, the original clauses before Step N1 are satisfied by H due to our initial extension of H to the renamed predicates.
In the following, we always assume C to be normalized.

Finding Finite Herbrand Models: A Naive Algorithm
To guide our procedure for finding a finite Herbrand model, we first consider a naive model construction approach.We start with the small Herbrand interpretation H 0 = {A(a)} that satisfies the only ground clause in C, and nondeterministically add atoms that are required to satisfy the clauses in C, in order to extend the interpretation to H 1 , H 2 , H 3 , . . . .If this process terminates, we have found a finite Herbrand model H m .
Formally, we follow the following steps to construct each H i+1 from H i , as long as there are still unsatisfied clauses.Definition 4. Let H i be a finite Herbrand interpretation.
• Choose an arbitrary clause c from C and an arbitrary ground term t to substitute for the variable x, such that If c is flat or increasing, we say that the term t is active in The set of all pairs (t, c) such that t is active at c in H i is denoted by act(H i ).
• Choose an arbitrary disjunct Q(t ) from the head of c (where t is either x or f x for some f ∈ F) and set We call this the expansion rule, and denote by H i c,t,Q −−→ H i+1 the application of this rule for the clause c, active term t and predicate Q (if it is applicable).The expansion step H i H i+1 denotes that the above relation holds for some c, t and Q.Given a Herbrand interpretation H 0 , an expansion sequence (starting in in which case the expansion rule is not applicable anymore.We say that C terminates if it has a terminating expansion sequence starting in H 0 = {A(a)}.
Termination is obviously equivalent to C having a finite Herbrand model.
Example 5. Let our set of propagation rules C be the following: The choice of P a is obviously: to the interpretation.If we choose Q 1 (f a) we will not get a terminating expansion sequence: At this moment c 7 is not satisfied and we have no way to satisfy it.Hence since H 6 is not a model, the sequence does not terminate.Nevertheless another choice in expanding H 5 leads to termination.
Here is another example.

Example 6. Let the set of predicates
Let our set of propagation rules C be the following with some clauses added by the choice of P a omitted.
We start with H 0 = {A(a)} and construct an expansion sequence, by choosing c 1 , a and P f : }. Now the increasing clauses are not satisfied, hence we have to create term f (a) in the interpretation of P and Q 2 .
The expansion steps are in the following table.
Now, because of the clause 3, which cannot be satisfied, we cannot terminate this sequence.Nevertheless there is a sequence that terminates.It differs from the above one by taking different order in satisfying the increasing and flat clauses.
At this moment all clauses are satisfied.The sequence terminates.
There are two reasons for an expansion sequence starting in H 0 to be nonterminating: • It may be impossible to avoid a contradiction, i.e. a clause with an active ground term and an empty head (⊥).
• Any expansion sequence that avoids such contradictions is forced into a cycle of producing atoms with higher and higher ground terms.
The main idea of our decision procedure is based on an obvious observation that in order for a sequence to terminate, the atoms added in the expansion sequence must contain terms of a bounded height.Moreover we can trace expansion steps independently for each of these terms, because of the restrictions on the signature.
The simplest terminating sequence would be one which avoids applying the expansion rule to increasing clauses completely (if that is possible), i.e. that never involves terms other than a.Since there are only finitely many predicates, such a flat sequence must be terminating.

Taking Shortcuts
Let us consider a terminating expansion sequence H 0 H 1 . . .H m .We want to divide it into subsequences that can serve as building blocks for the whole sequence.Here is an informal description of how this is done.
As observed above, the terms that appear in the atoms are of bounded height.We first consider a term of maximal height, e.g.f t. 3 Hence it was created by an expansion rule applied to an increasing clause with a predicate P f .Let X = {P | P f (t) ∈ H i } for some interpretation H i in the original sequence.Now we can reconstruct an expansion sequence starting with H 0 = {P (f t) | P ∈ X } following the way the term f t was deactivated in the clauses C, in the original expansion sequence.We say that the expansion sequence for f t obtained in this way has height 0, because f t is of maximal height and no bigger term is created.Now, consider t, the subterm of f t.Let us assume that t = gt .Such term had to be created by an increasing clause with a predicate Q g .We repeat the process to extract an expansion sequence for the term gt setting X = {Q | Q g (t ) ∈ H j } for some interpretation H j and starting with H 0 = {Q(gt ) | Q ∈ X }.Now, the sequence has height 1, because for the bigger terms (of maximal height), we have already extracted expansion sequences of heights 0.
We can proceed in the same way for the term t , extracting an expansion sequence of height 2, etc., until we come to the term a.For this term the original sequence is reconstructed by starting with H 0 = {A(a)}, and following the way a is deactivated in the original sequence, while the bigger terms are taken care of by the already extracted subsequences.
In order to capture these ideas, we define the notion of a shortcut that represents an extracted expansion subsequence of an assumed terminating sequence.It is easy to check that, whenever there is a sequence satisfying S1-S4, then there is a similar sequence for all ground terms t.This is because, without applying the expansion rule to decreasing clauses with active term t, the term t cannot be decomposed, and all other applications of expansion rules can only extend t by more function symbols.For this reason, shortcuts (X , Y) do not have to refer to a specific term, because the definition is satisfied either for all terms or for none.
There always exists the trivial shortcut (∅, ∅), which corresponds to a trivially empty expansion sequence.This shortcut does not have a well-defined height, so we just fix it to −1 (which is impossible for any other shortcut).
Obviously, C is terminating iff there is a shortcut of the form ({A}, Y), because a can never be active at decreasing clauses.We can thus try to construct an expansion sequence as in S1-S4 for ({A}, Y), by composing it from smaller sequences.We could try to use a bottom-up approach: if we have to add the atom P (f a) due to an increasing clause in C, we can try to deal with this atom by finding a shortcut of the form ({P }, Y ) and apply it to f a. Once we have found this shortcut, we can apply the expansion rule to any atoms Q(f a), Q ∈ Y , for which a matching decreasing clause Q(f x) → Q f (x) exists, thereby adding the smaller term a to the interpretation of Q f , which then may lead to more atoms over a.
Any time we produce a new term t in this process, we look for a shortcut that we can use for t in a recursive manner.This bottom-up approach can easily lead to a large complexity algorithm.
Here we will instead compute shortcuts of increasing height in a top-down manner, using the following observations.If there is a shortcut ({A}, Y) of height 0, it is quite simple to find it, because it is not necessary to produce terms of height > 0 using increasing clauses.Hence, we simply have to find a way to satisfy all flat clauses without the expansion rule becoming applicable for any increasing clauses.Now consider a shortcut ({A}, Y) of height larger than 0, and let t be a term of maximal height in the corresponding expansion sequence for a.Then we can extract a sub-sequence for t, starting with the atoms P (t) that were initially produced by increasing clauses, applying the expansion rule only to flat clauses using t (since t is maximal), and ending with some atoms Q(t), where the term t is active only at decreasing clauses.We can extract in this way a shortcut (X , Y) of height 0.
Since the original shortcut was of positive height, we know that t = f t for some f ∈ F, and that t was produced by increasing clauses P f (x) → P (f x) with P ∈ X .Hence, can similarly extract a sub-sequence for t , by again starting with the atoms P (t ) produced by increasing clauses, and ending with only atoms Q(t ) active at decreasing clauses, such that whenever we produce a term of larger height, we can employ a shortcut of height 0 that we had extracted in the previous step.The shortcut corresponding to the resulting sub-sequence will be of height 1.In this way, we can eventually compose the expansion sequence for ({A}, Y) from expansion sequences of smaller height.
Example 8. Let the following be C, , with some of the clauses obtained from guessing P a are omitted.
A terminating expansion sequence is the following (some of the steps are omitted, because of the absent clauses): The term of maximal height is f a.It was produced by c 5 = P f (x) → P (f x).
After f a has been created, it is active at . We see that it was deactivated in the expansion sequence by adding Q 2 (f a) to the next interpretation.This has activated the decreasing clause, c 8 .
In this way we can extract the shortcut ({P }, {P, Q 2 }) for height 0 from the terminating expansion sequence.This shortcut will correspond to the following expansion sequence: Of course, this shortcut and expansion sequence can be used with an arbitrary term, t.
Having this shortcut, we can present the original expansion sequence in the following way: S n ← nextShortcuts(C, S n−1 ) 6: if there exists ({A}, Y) ∈ S n then 7: return true 8: Notice that the atoms P (f a), Q 2 (f a) are not visible in the final interpretation, because they are hidden in the shortcut.When we reconstruct a model, we have to put them back there.But in constructing a shortcut we are interested only in the atoms containing terms of small height.In this case, constants.
At this point our algorithm will check if there exists a shortcut of the form ({P, Q 2 }, Y) and it will discover that all flat and increasing clauses are satisfied for {P (f a), Q 2 (f a)} hence there is a shortcut ({P, Q 2 }, {P, Q 2 }) as required. 4n this way we have obtained the shortcut ({A}, {A, P f , Q f 2 , Q 1 }) of height 1 based on the shortcut of height 0.

Detecting the Existence of a Finite Herbrand Model
As explained above, in order for a finite Herbrand model of C to exist, there must be a shortcut of the form ({A}, Y), that corresponds to a terminating expansion sequence.We are not given such a sequence from which we can extract all or some shortcuts.Instead we compute all possible shortcuts for C. If a shortcut ({A}, Y) for some Y ⊆ P is in this set of shortcuts, then we can be sure that a terminating expansion sequence exists.
This idea is formalized in Algorithm 1.
We describe next the procedure nextShortcuts(C, S n−1 ), which computes all possible shortcuts of height at most n based on all shortcuts of height at most n − 1.

Possibilities
The algorithm for computing shortcuts is using a procedure for the so called possibilities.Possibilities are just different ways of extending an expansion sequence with a term t with respect to flat clauses in C, whereas the bigger terms required by the increasing clauses are dealt with using the already computed shortcuts.Finally, for X ⊆ P, we set possibilities(X ) := possibilities(C| X ), where C| X is defined as the set of all flat clauses c from C with b(c) ⊆ X .
This definition is basically the same as in [2].Intuitively, possibilities(. ..) describes all possibilities of deactivating a given term at the involved clauses (either a single clause, a set of clauses, or the specific set of clauses activated by X ).If there are no predicates on the right-hand side of c, then possibilities(c) = ∅, and if such a c belongs to C, then possibilities(C) = ∅.In contrast, if C| X = ∅, then possibilities(X ) = possibilities(∅) = {∅}, i.e. there is exactly one possibility, which is to do nothing, since no terms are active and thus no action is required.
Example 10.Let us look at some clauses in Example 8.
Now, let us compute possibilities for some sets of predicates.
• possibilities({P }) = {{Q 1 }, {Q f 2 }}, which corresponds to a choice we have when deactivating a term at a clause c 2 .
• Notice that possibilities({Q 1 , Q 2 }) = ∅, hence we cannot terminate a sequence if we reach these two predicates with the same term.
In the presence of shortcuts, we can extend the notion of possibilities to the increasing clauses, the predicates labeled with a function symbol, and sets of such predicates that include them.Notice that if P f ∈ X and there are no shortcuts of the form ({P }, Y), we don't know what to do with the bigger terms with the prefix f and then if we take increasing clauses into consideration, possibilities(X ) = ∅.If S is a set of shortcuts, the extended possibilities( The extended notion of possibilities is defined in the Algorithm 2.
For convenience, given a set X ⊆ P and a function symbol f ∈ F, we define the following abbreviations to translate back and forth between the predicates P and P f : Notice that if a predicate is in X +f , it has the form P f .Hence if P (f t) is in an interpretation, then P f (t) must be there too.Hence the term f t is decomposed in P f .Notice too that not all predicates in X has the form P f defined in the set P. Similarly, if a predicate is in X −f , it has the form P , where P f ∈ X .We know that if P f (t) is in an interpretation, then P (f t) must be there too.
Algorithm 2 computes all possibilities for a set of predicates X , with respect to a set of shortcuts S, and a set of clauses C. Hence it has two parts: computing possibilities for increasing clauses with the available shortcuts and computing possibilities for flat clauses.
Notice that since (∅, ∅) is always a shortcut, if the set X −f is empty, then in Line 3 the set P is not changed.In contrast, if there is no shortcut of the form (X −f , Y) ∈ S, then P will become empty.In Line 7, if P is already empty, then it will stay empty; if it is not, it can become empty in case = 0. Algorithm 2 can be optimized, because in the present formulation it produces many unuseful possibilities, i.e. it includes predicates even if a clause is already satisfied.Nevertheless, all productive possibilities are included in P. At the beginning the set of possibilities P is initialized to the set containing empty set, which means that no extension is required.Since {A} does not contain any predicates of the form P f , for each f ∈ F, hence for each f ∈ F, the empty shortcut (∅, ∅) is used and thus we add the empty set to the empty possibility in P, hence the set of possibilities remains unchanged (line 4).
In the for-loop for the flat clauses, the algorithm considers c 1 = A(x) → P f (x).Inside the body of this loop, the set of possibilities is redefined to P = {{A, P f }}.Since no other flat clauses satisfy the conditions in the if-condition, the algorithm will return P = {{A, P f }}, i.e. there is only one possibility for {A}, which is {A, P f }. 5If we want to compute possibilities for {A, P f }, we will get ∅ as a result.This is because there is no shortcut of the form ({P }, W) in S = {(∅, ∅)}.Since there is no W +f available, P becomes empty (Line 3).It will stay empty through the loop for flat clauses too (there is no Z available in Line 7).
The following lemma shows that Algorithm 2 is sound.
Lemma 12. Assume that for every (X , W) ∈ S there is a shortcut (X , Y) for C of height ≤ n with Y ⊆ W, and let Z be an element of possibilities(C, S, X ).Then, for every ground term t, there is an expansion sequence H 0 . . .H m of height ≤ n + 1 satisfying S1, S2 (see Definition 7), and the following conditions.S3 X ∪Z ⊇ {P | P (t) ∈ H m }, i.e.H m contains the term t only in the predicates from X ∪ Z.
S4 For every (t , c) ∈ act(H m ) we have t = t and, if c is not decreasing, then b(c) X . 6roof.We construct the required expansion sequence, initializing H 0 to the set {P (t) | P ∈ X }, as required for S1.We then have act( We proceed to deactivate t at all such increasing and flat clauses; the decreasing clauses are allowed to have t active due to Condition S4 . Consider first the increasing clauses with active term t.We follow the computation of Algorithm 2 that led to Z.By Line 3, for each f ∈ F, there must be a pair (X −f , W) ∈ S with W +f ⊆ Z.By assumption, there is a shortcut (X −f , Y) of height ≤ n with Y ⊆ W. Such a shortcut induces an expansion sequence of height ≤ n starting with the term f t in the predicates X −f .This sequence uses only terms with suffix f t and ends with f t active only at decreasing clauses P (f x) → P f (x) with P ∈ Y ⊆ W.
We hence start constructing our expansion sequence for t by expansion steps for all increasing clauses with active term t, followed by the sequences of height ≤ n that exist due to the pairs (X −f , W) ∈ S as described above.We then add expansion steps for the decreasing clauses with active term f t, which induces new atoms of the form P f (t) with P f ∈ W +f ⊆ Z.After this, t is still the only active term, and it is not active anymore at any increasing clauses c with b(c) ⊆ X .
, by Line 7 we must have Q ∈ Z for some i ∈ {1, . . ., m}.Hence, we can add the appropriate expansion step to deactivate t at c.The final Herbrand interpretation H m clearly satisfies S2 and S3 .Moreover, the term t is only active at flat or increasing clauses whose body contains at least one predicate from Z \ X , as well as possibly some decreasing clauses.Hence, Condition S4 is also satisfied.Finally, the obtained expansion sequence for t is of height ≤ n + 1 since it is composed only of expansion steps for flat clauses with active term t, as well as expansion sequences of height ≤ n for terms f t with f ∈ F (and associated steps for increasing and decreasing clauses translating between t and f t) Next we explain in more detail, but still informally, how computing possibilities is used for obtaining a shortcut.

Shortcuts of Height 0
To construct a shortcut of height 0 starting from a set X of predicates, we need to choose from possibilities(X ) in such a way that no predicates of the form P f are reached.One way to realize this is to assume for now that possibilities(c) = ∅ for all increasing clauses c, and extend Definition 9 accordingly, obtaining an empty set of possibilities whenever an increasing clause is involved [2].We will relax this assumption later, when we consider shortcuts of larger height (see Algorithm 2).
In order to compute all possible shortcuts of height 0 for X , we must then consider until there are no new possibilities, i.e.P n = P n−1 .
Intuitively, we iteratively expand the set X by new possibilities Z (which are sets of predicates), until nothing more needs to be added. 7Each of the final possibilities represents one way of using the expansion rule to deactivate a given term t at all flat clauses, assuming that we start with the atoms P (t) for all P ∈ X .Hence, each Z ∈ P n yields a kind of extended shortcut (X , Y) of height 0 with Y ⊆ X ∪ Z.Note that Z may contain superfluous predicates that are not necessary to form a shortcut, because some clauses are considered multiple times during the computation, and a different possibility may be chosen each time.

Shortcuts of larger height
We proceed to compute shortcuts by induction on their height: assuming that we know all possible shortcuts of height (at most) n, we use them to construct new shortcuts of height n + 1.In an expansion sequence of height n + 1, we now allow a term t to become active at increasing clauses P f (x) → P (f x), but only if we know a shortcut for {P }, or more generally for a set predicates X that all contain the higher term f t.Assuming that (X , Y) is such a shortcut of height ≤ n (which we have already computed before), the corresponding expansion sequence may cause f t to become active at decreasing clauses which forces us to add t to each such Q f .Essentially, we can now extend the definition of possibilities(c) for increasing clauses c by considering shortcuts to deal with the propagation of the produced higher terms.

Computing shortcuts
The above ideas are formalized in Algorithm 3 which uses Algorithm 2 to compute all shortcuts of height ≤ n + 1 from the already known shortcuts of height ≤ n.
The algorithm works with a set T of triples of the form (X , R X , V X ) with X ⊆ R X and V X ⊆ R X , where X represents the starting predicates, R X is the set of

Algorithm 3 (nextShortcuts(C, S))
Input: A set C of propagation rules and a set S of shortcuts Output: A set of shortcuts for the next height for all Z ∈ possibilities(C, S, R X ) do end for 7: end while predicates that have already been reached from X by choosing some possibilities, and V X is a set of predicates for which we have already computed the possibilities.While R X \ V X = ∅, there are still some new predicates that need to be processed using Algorithm 2. The form of the initial triples in Line 1 reflects the kind of shortcuts that we need: first, a shortcut starting from {A} (to show termination of C), and, second, shortcuts for any combination of predicates X which may contain a common term f t due to increasing clauses for X +f being applied to the shallower term t.The latter case also covers the trivial shortcut (∅, ∅), which is always included in the output of Algorithm 3. 8Example 13.Consider Example 8.If the algorithm newShortcuts is used with the empty set of shortcuts, i.e. S 0 = {(∅, ∅)}, one of the triples initialized in Line 1 is ({A}, {A}, ∅).This triple is an element of the set T.
It is removed from there in the while-loop starting at Line 2. Now, possibilities for {A} are computed, and as we have already seen in Example 11, the only possibility for {A} is {A, P f }.Hence a new triple ({A}, {A, P f }, {A}) is added to T. 9In the next execution of the while-loop, this triple is again removed from T. The possibilities for {A, P f } are computed.But as we have already seen in Example 11, there are no possibilities for this set.Hence nothing is added to T in Line 5.There are no shortcut of the form ({A}, Y) if S is empty.
In the same run of the algorithm newShortcuts, another triple ({P }, {P }, ∅) is considered.Inside the while-loop it is removed from T, and possibilities for {P } are being computed.The only clause relevant for P is c 2 = P (x) → Q 1 (x)∨Q 2 (x).Hence possibilities for P computed by Algorithm 2 is the set {{P, Q 1 }, {P, Q 2 }}.
The soundness of the procedure is stated in the following lemma.Lemma 14.If for every (X , W) ∈ S n there is a shortcut (X , Y) for C of height ≤ n with Y ⊆ W, then for every (X , R X ) ∈ nextShortcuts(C, S), there is a shortcut (X , Y) for C of height ≤ n + 1 with Y ⊆ R X .
Proof.We consider an arbitrary ground term t and a triple (X , R X , V X ) as it appears in the final set T in Line 8 of Algorithm 3. We follow this triple through the whole computation, starting with an initial triple (X , X , ∅) in Line 1, and show that the following invariant remains satisfied: there exists an expansion sequence H 0 . . .H m of height ≤ n + 1 that satisfies S1, S2, and the following conditions.S3 R X ⊇ {P | P (t) ∈ H m }, i.e.H m contains the term t only in the predicates from R X .
S4 For every (t , c) ∈ act(H m ), we have t = t and, if c is not decreasing, then b(c) V X .
This condition is satisfied for the initial triple (X , X , ∅) since we can simply choose H 0 = H m according to S1.Now assume that such a sequence H 0 . . .H m exists for the triple (X , R X , V X ) with R X \V X = ∅ in Line 2 and that the next triple (X , R X , V X ) = (X , R X ∪ Z, R X ) is obtained via Z ∈ possibilities(C, S, R X ) in Line 5. By Lemma 12, there is an expansion sequence of height ≤ n + 1 that deactivates t at all clauses c with b(c) ⊆ R X , thereby adding t to the interpretation of some predicates from Z. From this expansion sequence, we can reuse all steps that deactivate terms at clauses that were not already deactivated in H m .
In the resulting Herbrand interpretation, we have the term t only in the predicates from R X = R X ∪ Z, and, except for decreasing clauses, t can only be active at clauses c with b(c) V X = R X .This shows that Conditions S3 and S4 remain satisfied.
For the final triple (X , R X , V X ) with V X = R X , these conditions yield an expansion sequence satisfying S1-S4 for the set Y := {P | P (t) ∈ H m }, because (t, c) ∈ act(H m ) with b(c) V X = R X is impossible when only the predicates from R X can contain t in H m .Since we have used Lemma 12 only w.r.t. the term t, the constructed expansion sequence is of height at most n + 1, which shows that (X , Y) is a shortcut for C of height ≤ n + 1.
In subsequent steps, the set R X is further expanded by possibilities for R X until no new predicates are reached.The corresponding possibilities output by Algorithm 2 can be obtained as above, by considering the extended set R X as starting point for our sub-sequence.This may involve a lot of the expansion steps that were already considered for the previous possibilities, but is always correct in the sense that the computed possibility Z represents a set of predicates that contains t in H m .In the end, the set Y = {P | P (t) ∈ H m } can furthermore not contain any predicates that are not in R X since any such predicates must have been added by the expansion rule due to an active term in other predicates, and this rule can only be applied if it is really necessary to deactivate a term at a clause.This means that we obtain a triple (X , R X , R X ) with R X = Y, and thus Algorithm 3 returns the shortcut (X , Y) when called with S n as input, i.e. we have (X , Y) ∈ S n+1 .
We can now examine the complexity of our algorithm.
Lemma 17.Let n > 0 be such that S n was computed by Algorithm 1. Then S n−1 ⊆ S n .
Proof.For n = 1, it suffices to observe that Algorithm 3 (with the help of Algorithm 2) always produces the empty shortcut if the input set S contains it.Now assume S n−1 ⊆ S n , and consider the computation steps in these two algorithms when given either S n−1 or S n .Since all pairs from S n−1 are also included in S n , all possibilities w.r.t.S n−1 are still possibilities w.r.t.S n , i.e. possibilities(C, S n−1 , X ) ⊆ possibilities(C, S n , X ) holds for all X (see Line 3 of Algorithm 2).Due to this, all triples computed by Algorithm 3 on input S n−1 are also computed when given S n as input (see Line 4 of Algorithm 3).Hence, S n = nextShortcuts(C, S n−1 ) ⊆ nextShortcuts(C, S n ) = S n+1 .
Lemma 18. Algorithm 1 terminates after time at most exponential in the size of C.
Proof.Since the number of relevant predicates is linear, there are at most exponentially many possible shortcuts.Hence, the main loop of Algorithm 1 may be executed at most exponentially many times.
In each iteration, the execution of Algorithm 3 can be seen as a construction of a set of trees with the roots (X , X , ∅) and leaves of the form (X , Y, Y).There are exponentially many such trees, because we create them for every set of the form X −f .The height of each tree is at most polynomial, because in each round of the loop the third component of the triple (X , R X , V X ) grows.The branching factor is bounded exponentially, because we can add different possibilities Z to the second component of the triple in each step.Hence, each tree contains at most exponentially many nodes, and thus each call of nextShortcuts(C, S n ) can take only exponential time.
In conclusion, Algorithm 1 needs at most exponentially many iterations, each taking exponential time.
Theorem 19.Deciding whether a finite set of propagation rules has a finite Herbrand model is ExpTime-complete.
Proof.Algorithm 1 is a deterministic algorithm that decides termination in exponential time.The problem is ExpTime-hard since this is the case already for anti-Horn propagation rules [2].

Acyclic Herbrand Models
In the previous sections of this paper we were designing algorithms for detecting existence of a finite Herbrand model for a set of restricted clauses C. In this section we study the problem of generating such models.The soundness lemma (Lemma 15) suggests the possibility of reconstructing a finite Herbrand model from a set of shortcuts.
The question then arises whether every finite Herbrand model can be reconstructed in this way.The answer is negative.We can reconstruct the models which are obtained by terminating expansion sequences.If a model does not have such a sequence, this can be caused by an atom added to the interpretation in an arbitrary way, when it is not required by an unsatisfied clause.Such an atom can contain a term which is not constructed by increasing/decreasing clauses, hence we cannot know what form it has.Thus we cannot reconstruct the model that contains such atoms.
One can see from the proof of completeness (Lemma 16) that given a finite Herbrand model, our algorithms compute a model that is a subset of this one.Hence, the next question is: can we reconstruct all minimal finite Herbrand models?Consider finite Herbrand models M 1 , M 2 of a set of clauses C. We say that M 1 is smaller than M 2 iff M 1 ⊆ M 2 , and it is minimal if there is no smaller model of C. First let us notice that since a set of clauses C may contain some non-Horn clauses, there may be multiple minimal finite Herbrand models.In fact there can be an infinite number of them.
Example 20.Let P (x) → P f (x) ∨ Q g (x) be the only flat clause in C. Then there are infinitely many minimal Herbrand models of the form {P (a), P (f a), . . ., P (f n a), Q(gf n a)}, where n > 0 and atoms of P f , Q g are omitted.
Hence if we want to output all minimal finite Herbrand models, the process would not terminate in some cases.An obvious idea to reduce the number of computed models would be to restrict ourselves to those models containing atoms with terms of minimal height.But this would leave out some models which can be of interest, as illustrated in the following example.
Example 21.Let the set C contain the following flat clauses: Then a finite Herbrand model of minimal height will contain {A(a), Q(ga)}.But another one, containing {A(a), R(f a), S(hf a)} is not of minimal height, although it represents an alternative way of satisfying the clauses.
Example 20 shows that an infinite number of finite models is generated because of some cycle in the process of constructing terms in atoms.We would like to avoid computing such models, since they just repeat constructing new terms following the same pattern.For that we define acyclic Herbrand models.In this case, we say that (X 1 , Y 1 ) requires (depends on) (X 2 , Y 2 ), denoted by (X 1 , Y 1 ) f → (X 2 , Y 2 ).We call this relation the dependency relation between shortcuts.
In Section 3 we describe how to extract shortcuts of height n from a terminating expansion sequence.For each such sequence H 0 . . .H m , we now define a dependency tree that is composed of dependency relations between shortcuts.There must be an initial shortcut of the form ({A}, Y) that corresponds to the whole sequence and will be the root of this tree.Then, for every f ∈ F for which Y −f is not empty, there is a unique shortcut (X f , Y f ) that ({A}, Y) depends on and corresponds to a subsequence of H 0 . . .H m .We thus add the edges ({A}, Y) f → (X f , Y f ) to the tree.Continuing this process, we obtain a finite dependency tree that describes the dependency relations between the shortcuts used in the sequence.
Notice that for a given shortcut there may be multiple expansion sequences, and hence there can be different dependency trees with the same root.Given a terminating expansion sequence, we say that this sequence is acyclic if the dependency tree of shortcuts extracted from this sequence is acyclic, i.e. there is no repetition of shortcuts on any branch of the tree.A finite Herbrand model is called acyclic if there is an acyclic terminating expansion sequence for this model.
Example 23.In Example 8, we show how to extract a shortcut ({P }, {P, Q 2 }) of height 0 from an expansion sequence.This shortcut is required by the shortcut ({A}, {A.P f , Q f 2 , Q 1 }) of height 1.To be more precise, ({A}, {A.P f , Q f 2 , Q 1 }) requires the shortcut ({P, Q 2 }, {P, Q 2 }). 10ence, from that example, we can extract a small dependency tree: From any acyclic dependency tree rooted in a shortcut ({A}, Y), we can easily define an acyclic Herbrand model H in the following way.For each shortcut (X , Y) in the tree, the path from the root uniquely defines a term t, and we add all atoms P (t) to H where P ∈ Y.For a given set of propagation rules C, we can thus compute all possible acyclic Herbrand models, by first computing all shortcuts using Algorithm 1, and from these all acyclic dependency trees.
The above constructions justify the following theorem.
Theorem 24.If a set of propagation rules C has a finite Herbrand model, then it has an acyclic Herbrand model, and there are at most triple exponentially many acyclic Herbrand models of C.
Proof.Since there are at most exponentially many shortcuts, any path in the acyclic dependency tree is at most exponentially long.Hence all terms in an acyclic Herbrand model are at most exponentially long, too.There are at most double exponentially many such terms.An interpretation of a predicate is a subset of these terms.There are at most triple exponentially many possible interpretations of a predicate, and there are at most polynomially many predicates.
Hence there are at most triple exponentially many acyclic Herbrand models.

Conclusions
We have developed a method to decide the existence of a finite Herbrand model of a set of propagation rules in exponential time.Moreover, we have demonstrated that finite acyclic Herbrand models may be of double exponential size if one actually wants to construct them.In future work, it would be interesting to extend these results to other classes of formulas, e.g. using multiple constants and variables.We also want to study the applications of our algorithm for the analysis of termination in logic programming and acyclicity for existential rules.
then add the flat clause A(x) → P (x) to C and replace P (a) with in all clauses of C. • If P / ∈ P a , then add the flat clause A(x) ∧ P (x) → ⊥ to C, and replace P (a) with ⊥ in all clauses of C.

1 c 2 ,a,P f 1 − 2 c 3 ,a,Q f 2 −
} and construct an expansion sequence, by choosing c 1 , a and P 1 : H 0 c 1 ,a,P 1 − −−− → H 1 where H 1 = {A(a), P 1 (a)}.Now we choose c 2 for expansion with the same term a: H −−− → H 2 .Similarly, we do expansion with c 3 : H −−− → H 3 .At this moment clauses 4, 5 and 7 are satisfied.Since Q f (a) is in H 3 clause 6 is also satisfied.This leave us with increasing clauses c 8 and c 10 .

Definition 9 .
The set possibilities(c) for a flat clause c is h(c), i.e. the set of all predicates in the head of c.For a finite set C = {c 1 , . . ., c k } of clauses, we define possibilities(C) as {P 1 , . . ., P k } | ∀i ∈ {1, . . ., k} : P i ∈ possibilities(c i ) .

Example 11 .
Consider Example 8 and assume that we have not yet computed any shortcuts.We consider the computation of possibilities(C, S, {A}) with S = {(∅, ∅)}.

Definition 22 . 1 and Y +f 2 ⊆
Let (X 1 , Y 1 ) be a shortcut.Hence for each f ∈ F, such that Y −f 1 is not empty, there is a shortcut (X 2 , Y 2 ) such that X 2 = Y −f Y 1 .
Lemma 3. The set C has a finite Herbrand model iff there is a set P a for which the normalization process produces a set C that has a finite Herbrand model.Proof.(⇒): Let H be a finite Herbrand model for C. We show how to construct a set P a and a finite Herbrand model H for C , by following the normalization steps.
Definition 7. Let X ⊆ Y ⊆ P. The pair (X , Y) is called a shortcut (for C) if there is a ground term t and an expansion sequence H 0 . ..H m that satisfies the following conditions.S1 H 0 = {P (t) | P ∈ X }, i.e.H 0 contains only the term t in the predicates from X .The height of this expansion sequence is max{|wt| − |t| | P (wt) ∈ H m }.The height of the shortcut (X , Y) is the smallest height of an expansion sequence satisfying S1-S4 for (X , Y) and some ground term t.
S2 For all P (t ) ∈ H m , we have t = wt with w ∈ F * , i.e. every term in H m has suffix t.S3 Y = {P | P (t) ∈ H m }, i.e.H m contains the term t in exactly the predicates from Y. S4 For every (t , c) ∈ act(H m ), we have t = t and c is decreasing.