text:
# Tight Logic Programs

## 1 Introduction

This note is about the relationship between two theories of negation as failure—one based on program completion \[Clark (1978)\], the other based on stable models, or answer sets \[Gelfond and Lifschitz (1988)\]. François Fages (1994) showed that if a logic program satisfies a certain syntactic condition, which is now called “tightness,”111The term used by Fages is “positive-order-consistent.” then its stable models can be characterized as the models of its completion. Lifschitz (1996) observed that Fages’ theorem can be extended to programs with infinitely many rules and to programs with classical negation \[Gelfond and Lifschitz (1991)\] if the concept of completion in the statement of the theorem is replaced by its semantic counterpart—the concept of a supported model \[Apt et al. (1988)\]. Fages’ theorem was further generalized in \[Babovich et al. (2000)\].

In this paper we show how to extend Fages’ theorem to programs with nested expressions in the bodies of rules. A generalization of the completion semantics to such programs was proposed in \[Lloyd and Topor (1984)\], and a similar generalization of the answer set semantics is given in \[Lifschitz et al. (1999)\]. Here is an example. Program

$$\begin{array}{c}p\text{not}\text{not}p\hfill \\ pp,q\hfill \end{array}$$
(1)
contains nested occurrences of negation as failure in the body of the first rule.222The double negation in the first rule of (1) is redundant from the point of view of the completion semantics, but it does affect the program’s answer sets. On the other hand, the second rule is redundant from the point of view of the answer set semantics. But, generally, dropping a rule like this can change a program’s completion in an essential way. It belongs to the syntactic class for which our theorem guarantees the equivalence of the answer set semantics to the completion semantics. This program has two answer sets $`\mathrm{}`$, $`\{p\}`$; they are identical to the models of the completion

$$\begin{array}{c}p\neg \neg p(pq)\hfill \\ q\hfill \end{array}$$
(2)
of this program.

A preliminary report on the tightness of programs with nested expressions is published in \[Erdem and Lifschitz (2001a)\].

The second question studied here is the tightness of logic programs containing the definition of the transitive closure of a predicate:

$$\begin{array}{c}\text{tc}(x,y)p(x,y)\hfill \\ \text{tc}(x,y)p(x,v),\text{tc}(v,y).\hfill \end{array}$$

Such rules are found in many useful programs. Unfortunately, the definition of tightness may be difficult to verify directly for a program containing these rules. We give here a sufficient condition that can make this easier. A preliminary report on this part of the work was presented at the 2001 AAAI Spring Symposium on Answer Set Programming \[Erdem and Lifschitz (2001b)\].

The concept of a tight program and generalizations of Fages’ theorem may be interesting for two reasons.

First, the completion semantics and the stable model semantics are among the most widely used definitions of the meaning of negation as failure, and it is useful to know under what conditions they are equivalent to each other.

Second, the class of tight programs is important from the perspective of answer set programming. Whenever the two semantics are equivalent, answer sets for the program can be computed by solving the satisfiability problem for its completion. This can be done using a satisfiability solver such as sato333http://www.cs.uiowa.edu/~hzhang/sato.html . or mchaff444http://www.ee.princeton.edu/~mchaff/ . \[Babovich et al. (2000)\]. The idea of computing answer sets for a program using a satisfiability solver led to the creation of the system cmodels555http://www.cs.utexas.edu/users/tag/cmodels.html . which, in some cases, finds answer sets faster than “general-purpose” answer set solvers such as smodels666http://www.tcs.hut.fi/Software/smodels/ . and dlv777http://www.dbai.tuwien.ac.at/proj/dlv/ .. Our generalization of Fages’ theorem allows us to apply this idea to programs containing weight constraint rules \[Simons et al. (2002)\], because such programs can be viewed as a special case of programs with nested expressions \[Ferraris and Lifschitz (2003)\]. For instance, rule $`\{p\}`$ can be treated as shorthand for

$$p\text{not}\text{not}p.$$

cmodels uses this fact to handle programs with weight constraints, and our generalization of Fages’ theorem allows cmodels to decide whether the answer sets for such a program are identical to the models of its completion.

We begin by reviewing the definitions of answer sets, closure, supportedness and completion for programs with nested expressions (Sections 2, 3). After discussing the concept of tightness for such programs in Sections 4 and 5, we state our generalization of Fages’ theorem (Section 6). As an example, we show how this generalized form applies to a formalization of the $`n`$-queens problem (Section 7). Then we study the tightness of programs containing the definition of the transitive closure of a relation (Section 8). A logic programming description of the blocks world is used as an example in Section 9. Proofs of theorems are given in Section 10.

## 2 Programs and Answer Sets

This section is a review of the answer set semantics for nondisjunctive programs with nested expressions.

The words atom and literal are understood here as in propositional logic; we call the sign $`\neg `$ in a negative literal $`\neg A`$ classical negation, to distinguish it from the symbol for negation as failure (not). Elementary formulas are literals and the 0-place connectives $``$ and $``$. Formulas are built from elementary formulas using the unary connective not and the binary connectives , (conjunction) and ; (disjunction). A (nondisjunctive) rule is an expression of the form

$$\text{Head}\text{Body}$$
(3)
where Head is a literal or $``$, and Body is a formula.888In \[Lifschitz et al. (1999)\], the syntax of rules is more general: the head may be an arbitrary formula, in particular a disjunction. If $`\text{Body}=`$, we will drop both the body and the arrow separating it from the head; rules with the body $``$ are called facts. If $`\text{Head}=`$, we will drop the head; rules with the head $``$ are called constraints.

A (nondisjunctive logic) program is a set of rules.

We define when a consistent set $`X`$ of literals satisfies a formula $`F`$ (symbolically, $`XF`$) recursively, as follows:

* for elementary $`F`$, $`XF`$ if $`FX`$ or $`F=`$,
* $`X\text{not}F`$ if $`X\vDash ̸F`$,
* $`X(F,G)`$ if $`XF`$ and $`XG`$,
* $`X(F;G)`$ if $`XF`$ or $`XG`$.

A consistent set $`X`$ of literals is closed under a program $`\mathrm{\Pi }`$ if, for every rule (3) in $`\mathrm{\Pi }`$, $`\text{Head}X`$ whenever $`X\text{Body}`$.

Let $`\mathrm{\Pi }`$ be a program without negation as failure. We say that $`X`$ is an answer set for $`\mathrm{\Pi }`$ if $`X`$ is minimal among the consistent sets of literals closed under $`\mathrm{\Pi }`$. It is easy to see that there can be at most one such set. For instance, the answer set for the program

$$\begin{array}{c}p\hfill \\ pp,q\hfill \end{array}$$
(4)
is $`\{p\}`$.

The reduct $`\mathrm{\Pi }^X`$ of a program $`\mathrm{\Pi }`$ relative to a set $`X`$ of literals is obtained from $`\mathrm{\Pi }`$ by replacing every maximal occurrence of a formula of the form $`\text{not}F`$ in $`\mathrm{\Pi }`$ (that is, every occurrence of $`\text{not}F`$ that is not in the scope of another not) with $``$ if $`XF`$, and with $``$ otherwise.999This definition is equivalent to the recursive definition of the reduct given in \[Lifschitz et al. (1999)\]. A consistent set $`X`$ of literals is an answer set for $`\mathrm{\Pi }`$ if it is the answer set for the reduct $`\mathrm{\Pi }^X`$. For instance, $`\{p\}`$ is an answer set for program (1) since it is the answer set for the reduct (4) of (1) relative to $`\{p\}`$.

We say that a formula (or a program) is normal if it does not contain classical negation. We will sometimes identify a normal formula $`F`$ with the propositional formula obtained from $`F`$ by replacing every comma with $``$, every semicolon with $``$, and every occurrence of not with $`\neg `$. It is easy to see that, for any normal formula $`F`$ and any set $`X`$ of atoms, $`XF`$ iff $`X`$ satisfies $`F`$ in the sense of propositional logic.

## 3 Supported Sets and Completion

This section is a review of supported sets and completion for the class of logic programs introduced above.

We say that a set $`X`$ of literals is supported by a program $`\mathrm{\Pi }`$ if for every literal $`LX`$ there exists a rule (3) in $`\mathrm{\Pi }`$ such that $`\text{Head}=L`$ and $`X\text{Body}`$.101010In \[Baral and Gelfond (1994)\] and \[Inoue and Sakama (1998)\] the definition of supportedness from \[Apt et al. (1988)\] is generalized in a different direction—it is extended to disjunctive programs. For instance, each of the sets $`\{p\}`$, $`\{\neg q\}`$ is supported by the program

$$\begin{array}{c}p\text{not}\neg q\hfill \\ \neg q\text{not}p\hfill \end{array}$$
(5)
but their union is not. The set $`\{p\}`$ is supported by program (1); $`\{q\}`$ is not.

We are interested in the relationship between the concept of an answer set on the one hand, and the conjunction of the closure and supportedness conditions on the other. According to the following proposition, every answer set is both closed under the program and supported by it.

###### Proposition 1

For any program $`\mathrm{\Pi }`$ and any consistent set $`X`$ of literals, if $`X`$ is an answer set for $`\mathrm{\Pi }`$ then $`X`$ is closed under and supported by $`\mathrm{\Pi }`$.

For instance, the answer sets for program (5) are $`\{p\}`$ and $`\{\neg q\}`$; each of them is closed under and supported by (5). The answer sets for program (1) are $`\mathrm{}`$ and $`\{p\}`$; each of them is closed under and supported by (1).

The converse, in general, is not true. The easiest counterexample is the program consisting of one rule $`pp`$. The set $`\{p\}`$ is closed under this program and supported by it, although it is not an answer set. Tightness, defined in Section 4 below, is a syntactic condition that eliminates programs like this.

Let $`\mathrm{\Pi }`$ be a finite normal program. The “completion” of $`\mathrm{\Pi }`$ is the set of propositional formulas defined as follows. If $`A`$ is an atom or the symbol $``$, by $`\text{Comp}(\mathrm{\Pi },A)`$ we denote the propositional formula

$$A\text{Body}_1\mathrm{}\text{Body}_k$$
(6)
where the disjunction extends over all rules

$$A\text{Body}_i$$
(7)
in $`\mathrm{\Pi }`$ with the head $`A`$. The completion of $`\mathrm{\Pi }`$ is the set of formulas $`\text{Comp}(\mathrm{\Pi },A)`$ for all $`A`$.111111This is essentially the definition from \[Lloyd and Topor (1984)\] restricted to the propositional case. It is restricted to finite programs to avoid the need to use an infinite disjunction in (6).

For instance, the bodies of rules (1), written as propositional formulas, are $`\neg \neg p`$ and $`pq`$; for this program $`\mathrm{\Pi }`$, formulas (2) are $`\text{Comp}(\mathrm{\Pi },p)`$ and $`\text{Comp}(\mathrm{\Pi },q)`$. In addition to these two formulas, the completion of this program includes also $`\text{Comp}(\mathrm{\Pi },)`$, which is the tautology $``$.

In application to finite normal programs, the conjunction of closure and supportedness exactly corresponds to the program’s completion:

###### Proposition 2

For any finite normal program $`\mathrm{\Pi }`$, a set of atoms satisfies the completion of $`\mathrm{\Pi }`$ iff it is closed under and supported by $`\mathrm{\Pi }`$.

From Propositions 1 and 2, we conclude:

###### Corollary 1

For any finite normal program $`\mathrm{\Pi }`$ and any set $`X`$ of atoms, if $`X`$ is an answer set for $`\mathrm{\Pi }`$ then $`X`$ satisfies the completion of $`\mathrm{\Pi }`$.

## 4 Tight Programs

To define the concept of a tight program, we need a few auxiliary definitions.

Recall that an occurrence of a formula $`F`$ in a formula $`G`$ is singular if the symbol before this occurrence is $`\neg `$; otherwise, the occurrence is regular \[Lifschitz et al. (1999)\]. It is clear that the occurrence of $`F`$ can be singular only if $`F`$ is an atom. For any formula $`G`$, by $`\text{lit}(G)`$ we denote the set of all literals having regular occurrences in $`G`$. For instance, $`\text{lit}(p;\text{not}\neg r)=\{p,\neg r\}`$. For any formula $`G`$, by $`\text{poslit}(G)`$ we denote the set of all literals having a regular occurrence in $`G`$ that is not in the scope of negation as failure. For instance, $`\text{poslit}(p,\text{not}q,(\text{not}\text{not}r;\neg s))=\{p,\neg s\}`$.

For any program $`\mathrm{\Pi }`$ and any set $`X`$ of literals, we say about literals $`L,L^{}X`$ that $`L`$ is a parent of $`L^{}`$ relative to $`\mathrm{\Pi }`$ and $`X`$ if there is a rule (3) in $`\mathrm{\Pi }`$ such that

* $`X\text{Body}`$,
* $`L\text{poslit}(\text{Body})`$, and
* $`L^{}=\text{Head}`$.

For instance, the parents of $`p`$ relative to the program

$$\begin{array}{c}p\text{not}q\hfill \\ q\text{not}p\hfill \\ pp,r\hfill \end{array}$$
(8)
and the set $`\{p,q,r\}`$ are $`p`$ and $`r`$; on the other hand, $`p`$ has no parents relative to (8) and the set $`\{p,q\}`$.

Now we are ready to give the main definition of this paper:

A program $`\mathrm{\Pi }`$ is tight on a set $`X`$ of literals if there is no infinite sequence $`L_1,L_2,\mathrm{}`$ of elements of $`X`$ such that for every $`i`$, $`L_{i+1}`$ is a parent of $`L_i`$ relative to $`\mathrm{\Pi }`$ and $`X`$.

In other words, $`\mathrm{\Pi }`$ is tight on a set $`X`$ iff the parent relation relative to $`\mathrm{\Pi }`$ and $`X`$ is well-founded.121212A binary relation $`R`$ is well-founded if there is no infinite sequence $`x_1,x_2,\mathrm{}`$ of elements of its domain such that, for all $`i`$, $`x_{i+1}Rx_i`$.

If $`X`$ is finite then the tightness condition can be reformulated as follows: there is no finite sequence $`L_1,\mathrm{},L_n`$ of elements of $`X`$ ($`n>1`$) such that for every $`i`$ ($`1i<n`$), $`L_{i+1}`$ is a parent of $`L_i`$ relative to $`\mathrm{\Pi }`$ and $`X`$, and $`L_n=L_1`$.

For instance, program (1) is tight on $`\{p\}`$: $`p`$ does not have parents relative to (1) and $`\{p\}`$, so that the parent relation relative to (1) and $`\{p\}`$ is well-founded. But that program is not tight on $`\{p,q\}`$. Indeed, $`p`$ and $`q`$ are the parents of $`p`$ relative to (1) and $`\{p,q\}`$, so that in the sequence $`p,p,\mathrm{}`$ every element is followed by its parent.

The proposition below gives an equivalent characterization of tightness:

###### Proposition 3

A program $`\mathrm{\Pi }`$ is tight on a set $`X`$ of literals iff there exists a function $`\lambda `$ from $`X`$ to ordinals satisfying the following condition:

* for every rule (3) in $`\mathrm{\Pi }`$ such that $`\text{Head}X`$ and $`X\text{Body}`$, and for every $`L`$ in $`X\text{poslit}(\text{Body})`$, $`\lambda (L)<\lambda (\text{Head}).`$

For instance, to show that program (1) is tight on $`\{p\}`$, we can take $`\lambda (p)=0`$. To show that program

$$\begin{array}{c}pq;\text{not}r\hfill \end{array}$$
(9)
is tight on $`\{p,q,r\}`$, take $`\lambda (p)=1`$, $`\lambda (q)=\lambda (r)=0`$.

If $`X`$ is finite then the values of $`\lambda `$ in the statement of Proposition 3 can be assumed to be finite.

Proposition 3 is a special case of the following general fact:

*
* A binary relation $`R`$ is well-founded iff there exists a function $`\lambda `$ from the domain of $`R`$ to ordinals such that, for all $`x`$ and $`y`$, $`xRy`$ implies $`\lambda (x)<\lambda (y)`$.

To compare the definition of tightness above with the definition given earlier in \[Babovich et al. (2000)\], assume that the rules of $`\mathrm{\Pi }`$ have the form

$$\text{Head}L_1,\mathrm{},L_m,\text{not}L_{m+1},\mathrm{},\text{not}L_n$$
(10)
where each $`L_i`$ is a literal. In this case, condition (\*) says: for every rule (10) in $`\mathrm{\Pi }`$, if

$$\text{Head}X,$$
(11)
$$L_1,\mathrm{},L_mX$$
(12)
and

$$L_{m+1},\mathrm{},L_nX$$
(13)
then, for all $`LX\{L_1,\mathrm{},L_m\}`$, $`\lambda (L)<\lambda (\text{Head})`$. In view of (12), the intersection $`X\{L_1,\mathrm{},L_m\}`$ here can be replaced by $`\{L_1,\mathrm{},L_m\}`$. The only difference between this form of condition (\*) and the corresponding condition in \[Babovich et al. (2000)\] is the presence of restriction (13). The additional generality gained by including (13) can be illustrated by the program

$$\begin{array}{c}p\hfill \\ q\hfill \\ pp,\text{not}q\hfill \end{array}$$

—it is tight on $`\{p,q\}`$ in the sense of this paper, but not in the sense of \[Babovich et al. (2000)\].

## 5 Absolutely Tight Programs

The following modification of the tightness condition is often useful. A program $`\mathrm{\Pi }`$ is absolutely tight if there is no infinite sequence $`L_1,L_2,\mathrm{}`$ of literals such that for every $`i`$ there is a rule (3) in $`\mathrm{\Pi }`$ for which $`L_{i+1}\text{poslit}(\text{Body})`$ and $`L_i=\text{Head}`$. It is clear that an absolutely tight program is tight on any set of literals.

To prove that a program $`\mathrm{\Pi }`$ is absolutely tight, it is sufficient to find a function $`\lambda `$ from literals to ordinals such that for every rule (3) in $`\mathrm{\Pi }`$ with $`\text{Head}`$ and for every literal $`L\text{poslit}(\text{Body})`$, $`\lambda (L)<\lambda (\text{Body})`$.

For a program containing finitely many atoms, absolute tightness can be characterized as follows. The positive dependency graph of a program $`\mathrm{\Pi }`$ is the directed graph $`G`$ such that

* the vertices of $`G`$ are the literals that have regular occurrences in $`\mathrm{\Pi }`$, and
* $`G`$ has an edge from $`L`$ to $`L^{}`$ if there is a rule (3) in $`\mathrm{\Pi }`$ for which $`L\text{poslit}(\text{Body})`$ and $`L^{}=\text{Head}`$.

A program containing finitely many atoms is absolutely tight iff its positive dependency graph has no cycles.

In application to programs whose rules have the form (10) and contain neither $``$ nor classical negation, the definition of absolute tightness above turns into (the propositional case of) Fages’ original definition of tightness \[Fages (1994)\].

## 6 Generalization of Fages’ Theorem

###### Theorem 1

For any program $`\mathrm{\Pi }`$ and any consistent set $`X`$ of literals such that $`\mathrm{\Pi }`$ is tight on $`X`$, $`X`$ is an answer set for $`\mathrm{\Pi }`$ iff $`X`$ is closed under and supported by $`\mathrm{\Pi }`$.

For instance, program (5) is tight on the sets $`\{p\}`$ and $`\{\neg q\}`$ that are closed under and supported by (5). By Proposition 1 and the theorem above, it follows that $`\{p\}`$ and $`\{\neg q\}`$ are the answer sets for (5).

By Proposition 2, we conclude:

###### Corollary 2

For any finite normal program $`\mathrm{\Pi }`$ and any set $`X`$ of atoms such that $`\mathrm{\Pi }`$ is tight on $`X`$, $`X`$ is an answer set for $`\mathrm{\Pi }`$ iff $`X`$ satisfies the completion of $`\mathrm{\Pi }`$.

For instance, program (1) is tight on the models $`\mathrm{}`$, $`\{p\}`$ of its completion (2). In accordance with Proposition 1 and Corollary 2, these two models are the answer sets for (1).

By $`\text{pos}(\mathrm{\Pi })`$ we denote the set of literals $`L`$ such that $`\mathrm{\Pi }`$ contains a rule (3) with $`\text{Head}`$ and $`L\text{poslit}(\text{Body})`$. For instance, if $`\mathrm{\Pi }`$ is (1) then $`\text{pos}(\mathrm{\Pi })=\{p,q\}`$. If a set $`X`$ of literals is disjoint from $`\text{pos}(\mathrm{\Pi })`$ then no literal in $`X`$ has a parent relative to $`\mathrm{\Pi }`$ and $`X`$, and consequently $`\mathrm{\Pi }`$ is tight on $`X`$. We conclude:

###### Corollary 3

For any program $`\mathrm{\Pi }`$ and any consistent set $`X`$ of literals disjoint from $`\text{pos}(\mathrm{\Pi })`$, $`X`$ is an answer set for $`\mathrm{\Pi }`$ iff $`X`$ is closed under and supported by $`\mathrm{\Pi }`$.

By Proposition 2, it follows then:

###### Corollary 4

For any finite normal program $`\mathrm{\Pi }`$ and any set $`X`$ of atoms disjoint from $`\text{pos}(\mathrm{\Pi })`$, $`X`$ is an answer set for $`\mathrm{\Pi }`$ iff $`X`$ satisfies the completion of $`\mathrm{\Pi }`$.

Since an absolutely tight program is tight on every set of literals, we conclude from Theorem 1 and Corollary 2:

###### Corollary 5

For any absolutely tight program $`\mathrm{\Pi }`$ and any consistent set $`X`$ of literals, $`X`$ is an answer set for $`\mathrm{\Pi }`$ iff $`X`$ is closed under and supported by $`\mathrm{\Pi }`$.

###### Corollary 6

For any finite normal absolutely tight program $`\mathrm{\Pi }`$ and any set $`X`$ of atoms, $`X`$ is an answer set for $`\mathrm{\Pi }`$ iff $`X`$ satisfies the completion of $`\mathrm{\Pi }`$.

## 7 Example: The N-Queens Problem

In the $`n`$-queens problem, the goal is to find a configuration of $`n`$ queens on an $`n\times n`$ chessboard such that no queen can be taken by any other queen. In other words, (a) no two queens may be on the same column, (b) no two queens may be on the same row, and (c) no two queens may be on the same diagonal.

A solution to the $`n`$-queens problem can be described by a set of atoms of the form $`\text{queen}(R,C)`$ ($`1R,Cn`$) satisfying conditions (a)–(c); including $`\text{queen}(R,C)`$ in the set indicates that there is a queen in position $`(R,C)`$.

The $`n`$-queens problem can be described by a program whose answer sets are solutions, as follows. The selections satisfying condition (a) correspond to the answer sets for the program consisting of the rules

$$\text{queen}(R,C)\text{not}\text{not}\text{queen}(R,C)$$
(14)
for all $`R,C`$ in $`\{1,\mathrm{},n\}`$,

$$\text{not}\text{queen}(1,C),\mathrm{},\text{not}\text{queen}(n,C)$$
(15)
for all $`C`$ in $`\{1,\mathrm{},n\}`$, and

$$\text{queen}(R,C),\text{queen}(R1,C)$$
(16)
for all $`R,R1,C`$ in $`\{1,\mathrm{},n\}`$ such that $`R<R1`$. Conditions (b) and (c) are represented by the constraints

$$\text{queen}(R,C),\text{queen}(R,C1)$$
(17)
for all $`R,C,C1`$ in $`\{1,\mathrm{},n\}`$ such that $`C<C1`$ and

$$\text{queen}(R,C),\text{queen}(R1,C1)$$
(18)
for all $`R,R1,C,C1`$ in $`\{1,\mathrm{},n\}`$ such that $`C<C1`$ and $`|RR1|=|CC1|`$.

The answer sets for program (14)–(18) are in a 1–1 correspondence with the possible arrangements of $`n`$ queens. According to \[Ferraris and Lifschitz (2003)\], rules (14)–(16) can be rewritten as weight constraints

$$1\{\text{queen}(1,C),\mathrm{},\text{queen}(n,C)\}1$$
(19)
for all $`C`$ in $`\{1,\mathrm{},n\}`$ Then the program can be presented to smodels as shown in Figure 1.

Program (14)–(18) is a finite normal absolutely tight program. By Corollary 6, its answer sets are identical to the models of its completion. (Note the use of nested negations in rule (14); this is the reason why the new generalization of Fages’ theorem is needed here.) This fact can be used to find solutions to the n-queens problem using cmodels, that is to say, by running a satisfiability solver on the program’s completion. cmodels transforms the input shown in Figure 1 into (14)–(18), computes the completion, clausifies it, and calls mchaff to find a model. For $`n=20`$ cmodels finds a solution in 2 seconds (for comparison, smodels, given the same input file, finds one in 55 seconds).131313 We have used lparse 1.0.11, smodels 2.27, cmodels 1.03, and mchaff spelt3. All CPU times here are for a SunBlade 1000, with two 600MHz UltraSPARC-III processors and 5GB RAM. For $`n=25`$, cmodels finds a solution in 3 seconds, whereas smodels requires more than 2 hours.

This example confirms the conjecture underlying the design of cmodels: using satisfiability solvers to compute answer sets for tight programs may be computationally advantageous. Systematic experimental evaluation of this form of answer set programming is a topic for future research.

## 8 Transitive Closure

In logic programming, the transitive closure tc of a binary predicate $`p`$ is usually defined by the rules

$$\begin{array}{c}\text{tc}(x,y)p(x,y)\hfill \\ \text{tc}(x,y)p(x,v),\text{tc}(v,y).\hfill \end{array}$$

If we combine this definition Def with any set $`\mathrm{\Pi }`$ of facts defining $`p`$, and consider the minimal model of the resulting program, the extent of tc in this model will be the transitive closure of the extent of $`p`$. In this sense, Def is a correct characterization of the concept of transitive closure. We know, on the other hand, that the sets of atoms closed under and supported by $`\mathrm{\Pi }\text{Def}`$ may be different from the minimal model. In these “spurious” sets of atoms, tc is weaker than the transitive closure of $`p`$. The absence of such “spurious” sets can be assured by requiring that facts in $`\mathrm{\Pi }`$ define relation $`p`$ to be acyclic.

In this section we study the more general situation when $`\mathrm{\Pi }`$ is a logic program, not necessarily a set of facts. This program may define several predicates besides $`p`$. Even tc is allowed to occur in $`\mathrm{\Pi }`$, except that all occurrences of this predicate are supposed to be in the bodies of rules, so that all rules defining tc in $`\mathrm{\Pi }\text{Def}`$ will belong to Def. The rules of $`\mathrm{\Pi }`$ may include negation as failure, and, accordingly, we talk about answer sets instead of the minimal model. Program $`\mathrm{\Pi }\text{Def}`$ may have many answer sets. According to Proposition 4 below, the extent of tc in each of these sets is the transitive closure of the extent of $`p`$ in the same set.

Recall that programs in the sense of Section 2 are propositional objects; there are no variables in them. Expressions containing variables, such as Def, can be treated as schematic: we select a non-empty set $`C`$ of symbols (“object constants”) and view an expression with variables as shorthand for the set of all its ground instances obtained by substituting these symbols for variables. It is convenient, however, to be a little more general. We assume $`p`$ and tc to be functions from $`C\times C`$ to the set of atoms such that all atoms $`p(x,y)`$ and $`\text{tc}(x,y)`$ are pairwise distinct.

###### Proposition 4

Let $`\mathrm{\Pi }`$ be a program that does not contain atoms of the form $`\text{tc}(x,y)`$ in the heads of rules. If $`X`$ is an answer set for $`\mathrm{\Pi }\text{Def}`$ then

$$\{x,y:\text{tc}(x,y)X\}$$
(20)
is the transitive closure of

$$\{x,y:p(x,y)X\}.$$
(21)
If atoms of the form $`\text{tc}(x,y)`$ do not occur in $`\mathrm{\Pi }`$ at all then the answer sets for $`\mathrm{\Pi }\text{Def}`$ are actually in a 1-1 correspondence with the answer sets for $`\mathrm{\Pi }`$.141414This observation is due to Hudson Turner (personal communication, October 3, 2000). The answer set for $`\mathrm{\Pi }\text{Def}`$ corresponding to an answer set $`X`$ for $`\mathrm{\Pi }`$ is obtained from $`X`$ by adding a set of atoms of the form $`\text{tc}(x,y)`$.

Under what conditions can we assert that the consistent sets of literals closed under and supported by a program containing Def are not “spurious”? As we know from Theorem 1, such a condition is provided by the tightness of the program. The verification of the tightness of programs containing Def is facilitated by the theorem below, which tells us that in some cases the tightness of a program is preserved after adding Def to it.

For any program $`\mathrm{\Pi }`$ and any set $`X`$ of literals, we say about literals $`L,L^{}X`$ that $`L^{}`$ is an ancestor of $`L`$ relative to $`\mathrm{\Pi }`$ and $`X`$ if there exists a finite sequence of literals $`L_1,\mathrm{},L_nX`$ $`(n>1)`$ such that $`L=L_1`$, $`L^{}=L_n`$ and for every $`i`$ ($`1i<n`$), $`L_{i+1}`$ is a parent of $`L_i`$ relative to $`\mathrm{\Pi }`$ and $`X`$. In other words, the ancestor relation is the transitive closure of the parent relation.

###### Theorem 2

Let $`\mathrm{\Pi }`$ be a program that does not contain atoms of the form $`\text{tc}(x,y)`$ in the heads of rules. For any set $`X`$ of literals, if

1. $`\mathrm{\Pi }`$ is tight on $`X`$,
2. $`\{x,y:p(y,x)X\}`$ is well-founded, and
3. no atom of the form $`\text{tc}(x,y)`$ is an ancestor of an atom of the form $`p(x,y)`$ relative to $`\mathrm{\Pi }`$ and $`X`$,

then $`\mathrm{\Pi }\text{Def}`$ is tight on $`X`$.

By Theorem 1 and Proposition 4, we conclude:

###### Corollary 7

Let $`\mathrm{\Pi }`$ be a program that does not contain atoms of the form $`\text{tc}(x,y)`$ in the heads of rules, and let $`X`$ be a set of literals satisfying conditions (i)–(iii) from Theorem 2. If, in addition,

1. $`X`$ is a consistent set closed under and supported by $`\mathrm{\Pi }\text{Def}`$

then $`X`$ is an answer set for $`\mathrm{\Pi }\text{Def}`$, and

$$\{x,y:\text{tc}(x,y)X\}$$

is the transitive closure of

$$\{x,y:p(x,y)X\}.$$

Proposition 2 shows that if $`X`$ is a set of atoms and $`\mathrm{\Pi }`$ is a finite program without classical negation then condition (iv) can be reformulated as follows:

1. $`X`$ is a model of the completion of $`\mathrm{\Pi }\text{Def}`$.

Condition (ii) in the statement of Theorem 2 is similar to the acyclicity property mentioned at the beginning of this section. In fact, if the underlying set $`C`$ of constants is finite then (ii) is obviously equivalent to the following condition: there is no finite sequence $`x_1,\mathrm{},x_nC`$ $`(n>1)`$ such that

$$p(x_1,x_2),\mathrm{},p(x_{n1},x_n)X$$
(22)
and $`x_n=x_1`$. For an infinite $`C`$, well-foundedness implies acyclicity, but not the other way around.

Here is a useful syntactic sufficient condition for (ii):

###### Proposition 5

If $`\mathrm{\Pi }`$ contains constraint

$$\text{tc}(x,x)$$
(23)
and $`C`$ is finite then, for every set $`X`$ of literals closed under $`\mathrm{\Pi }\text{Def}`$, set $`\{x,y:p(y,x)X\}`$ is well-founded.

Without condition (ii), the assertion of the theorem would be incorrect. Program $`\mathrm{\Pi }`$ that consists of one fact $`p(1,1)`$, with $`C=\{1,2\}`$ and

$$X=\{p(1,1),\text{tc}(1,1),\text{tc}(1,2)\},$$

provides a counterexample.

Condition (iii) is essential as well. Indeed, take $`\mathrm{\Pi }`$ to be

$$\begin{array}{c}p(x,y)\text{tc}(x,y).\hfill \end{array}$$

With $`C=\{1,2\}`$, set $`X=\{p(2,1),\text{tc}(2,1)\}`$ is closed under and supported by $`\mathrm{\Pi }\text{Def}`$, but is is not an answer set for $`\mathrm{\Pi }\text{Def}`$: the only answer set for this program is empty.

## 9 Example: The Blocks World

As an example of the use of Theorem 2, consider a “history program” for the blocks world—a program whose answer sets represent possible “histories”of the blocks world over a fixed time interval. A history of the blocks world is characterized by the truth values of atoms of two kinds: $`\text{on}(b,l,t)`$ (“block $`b`$ is on location $`l`$ at time $`t`$”) and $`\text{move}(b,l,t)`$ (“block $`b`$ is moved to location $`l`$ between times $`t`$ and $`t+1`$”). Here

* $`b`$ ranges over a finite set of “block constants,”
* $`l`$ ranges over the set of location constants that consists of the block constants and the constant table,
* $`t`$ ranges over the symbols representing an initial segment of integers $`0,\mathrm{},T`$,

except that in $`\text{move}(b,l,t)`$ we require $`t<T`$. One other kind of atoms used in the program is $`\text{above}(b,l,t)`$: “block $`b`$ is above location $`l`$ at time $`t`$”. These atoms are used to express constraint (32) that requires every block to be “supported by the table” and thus eliminates stacks of blocks flying in space.

The program consists of the following rules:151515This program is similar to the history program for the blocks world from \[Lifschitz (1999)\]. Instead of rules (24), the program in that paper contains a pair of disjunctive rules; according to Theorem 1 from \[Erdem and Lifschitz (1999)\], this difference does not affect the program’s answer sets. The intuitive meaning of rules (25)–(28) is discussed in \[Lifschitz (1999)\], Section 6. Rule (29) prohibits concurrent actions. Rules (30) and (31) were suggested to us by Norman McCain and Hudson Turner on June 11, 1999; similar rules are discussed in \[Lifschitz (1999)\], Section 8.

$$\begin{array}{c}\text{on}(b,l,0)\text{not}\neg \text{on}(b,l,0)\hfill \\ \neg \text{on}(b,l,0)\text{not}\text{on}(b,l,0)\hfill \\ \text{move}(b,l,t)\text{not}\neg \text{move}(b,l,t)\hfill \\ \neg \text{move}(b,l,t)\text{not}\text{move}(b,l,t)\hfill \end{array}$$
(24)
$$\begin{array}{c}\text{on}(b,l,t+1)\text{move}(b,l,t)\hfill \\ \text{on}(b,l,t+1)\text{on}(b,l,t),\text{not}\neg \text{on}(b,l,t+1)\hfill \end{array}$$
(25)
$$\neg \text{on}(b,l,t)\text{on}(b,l^{},t)(ll^{})$$
(26)
$$\text{on}(b,b^{\prime \prime },t),\text{on}(b^{},b^{\prime \prime },t)(bb^{})$$
(27)
$$\text{move}(b,l,t),\text{on}(b^{},b,t)$$
(28)
$$\text{move}(b,l,t),\text{move}(b^{},l^{},t)(bb^{}\text{ or }ll^{})$$
(29)
$$\begin{array}{c}\text{above}(b,l,t)\text{on}(b,l,t)\hfill \\ \text{above}(b,l,t)\text{on}(b,b^{},t),\text{above}(b^{},l,t)\hfill \end{array}$$
(30)
$$\text{above}(b,b,t)$$
(31)
$$\text{not}\text{above}(b,table,t)$$
(32)
To illustrate the use of Theorem 2, in Section 10 we use it to prove the following proposition:

###### Proposition 6

Program (24)–(32) is tight on every set of literals that is closed under it.

This proposition, in combination with Proposition 1 and Theorem 1, tells us that the answer sets for (24)–(32) can be characterized as the sets that are closed under this program and supported by it. These answer sets can be computed by eliminating classical negation in favor of new atoms and generating models of the completion of the resulting program.

The idea of the proof is to check first that program (24)–(29), (31), (32) is tight, and then use Theorem 2 to conclude that tightness is preserved when we add the definition (30) of above. There are two complications, however, that need to be taken into account.

First, on and above are ternary predicates, not binary. To relate them to the concept of transitive closure, we can say that any binary “slice” of above obtained by fixing its last argument is the transitive closure of the corresponding “slice” of on. Accordingly, Theorem 2 will need to be applied $`T+1`$ times, once for each slice.

Second, the first two arguments of on do not come from the same set $`C`$ of object constants, as required in the framework of Theorem 2: the set of block constants is a proper part of the set of location constants. In the proof, we will introduce a program similar to (24)–(32) in which, syntactically, table is allowed as the first argument of both on and above.

## 10 Proofs

###### Lemma 1

Given a formula $`F`$ without negation as failure and two sets $`Z,Z^{}`$ of literals such that $`Z^{}Z`$, if $`Z^{}F`$ then $`ZF`$.

*
* Immediate by structural induction.

The following lemma is the special case of Proposition 1 in which $`\mathrm{\Pi }`$ is assumed to be a program without negation as failure.

###### Lemma 2

For any program $`\mathrm{\Pi }`$ without negation as failure and any consistent set $`X`$ of literals, if $`X`$ is an answer set for $`\mathrm{\Pi }`$ then $`X`$ is closed under and supported by $`\mathrm{\Pi }`$.

*
* Let $`\mathrm{\Pi }`$ be a program without negation as failure and $`X`$ be an answer set for $`\mathrm{\Pi }`$. By the definition of an answer set for programs without negation as failure, $`X`$ is closed under $`\mathrm{\Pi }`$. To prove supportedness, take any literal $`L`$ in $`X`$. Since $`X`$ is minimal among the sets closed under $`\mathrm{\Pi }`$, $`X\{L\}`$ is not closed under $`\mathrm{\Pi }`$. This means that $`\mathrm{\Pi }`$ contains a rule (3) such that $`X\{L\}\text{Body}`$ but $`\text{Head}X\{L\}`$. By Lemma 1, $`X\text{Body}`$. Since $`X`$ is closed under $`\mathrm{\Pi }`$, it follows that $`\text{Head}X`$, so that $`\text{Head}=L`$.

The definition of the reduct $`F^X`$ of a formula $`F`$ is similar to the definition of the reduct of a program given in Section 2.

###### Lemma 3

For any formula $`F`$, any program $`\mathrm{\Pi }`$, and any consistent set $`X`$ of literals,

* $`XF`$ iff $`XF^X`$;
* $`X`$ is closed under $`\mathrm{\Pi }`$ iff $`X`$ is closed under $`\mathrm{\Pi }^X`$;
* $`X`$ is supported by $`\mathrm{\Pi }`$ iff $`X`$ is supported by $`\mathrm{\Pi }^X`$.

*
* Part (i) is immediate by structural induction; parts (ii) and (iii) follow from (i).

*
* Consider a program $`\mathrm{\Pi }`$ and an answer set $`X`$ for $`\mathrm{\Pi }`$. By the definition of an answer set, $`X`$ is an answer set for $`\mathrm{\Pi }^X`$. Then, by Lemma 2, $`X`$ is closed under and supported by $`\mathrm{\Pi }^X`$. By Lemma 3(ii,iii), it follows that $`X`$ is closed under and supported by $`\mathrm{\Pi }`$.

*
* Let $`\mathrm{\Pi }`$ be a finite normal program. Recall that the completion of $`\mathrm{\Pi }`$ consists of the equivalences (6) where $`A`$ is an atom or the symbol $``$. It is clear that a set $`X`$ of atoms satisfies the completion of $`\mathrm{\Pi }`$ iff, for each $`A`$,

+ for every rule (7) in $`\mathrm{\Pi }`$ with the head $`A`$, if $`X\text{Body}_i`$ then $`AX`$, and
    + if $`AX`$ then $`X\text{Body}_i`$ for some rule (7) in $`\mathrm{\Pi }`$ with the head $`A`$.

Condition (a) expresses that $`X`$ is closed under $`\mathrm{\Pi }`$, and condition (b) expresses that $`X`$ is supported by $`\mathrm{\Pi }`$.

*
* The “if” part follows from the well-foundedness of $`<`$ on sets of ordinals. To prove the “only if” part, consider the following transfinite sequence of subsets of the domain of $`R`$:

$$\begin{array}{c}S_0=\mathrm{},\hfill \\ S_{\alpha +1}=\{x:y(yRxyS_\alpha )\},\hfill \\ S_\alpha =_{\beta <\alpha }S_\beta \text{if }\alpha \text{ is a limit ordinal.}\hfill \end{array}$$

For any $`x_\alpha S_\alpha `$, define $`\lambda (x)`$ to be the smallest $`\alpha `$ such that $`xS_\alpha `$. From the well-foundedness of $`R`$ we can conclude that $`_\alpha S_\alpha `$ is the whole domain of $`R`$.

###### Lemma 4

For any formula $`F`$ and any set $`X`$ of literals, $`XF`$ iff $`X\text{lit}(F)F`$.

*
* Immediate by structural induction.

The following lemma is the special case of one half of Theorem 1 in which $`\mathrm{\Pi }`$ is assumed to be a program without negation as failure.

###### Lemma 5

Let $`\mathrm{\Pi }`$ be a program without negation as failure. For any consistent set $`X`$ of literals such that $`\mathrm{\Pi }`$ is tight on $`X`$, if $`X`$ is closed under and supported by $`\mathrm{\Pi }`$ then $`X`$ is an answer set for $`\mathrm{\Pi }`$.

*
* Let $`\mathrm{\Pi }`$ be a program without negation as failure and $`X`$ be a consistent set of literals such that $`\mathrm{\Pi }`$ is tight on $`X`$. Suppose that $`X`$ is closed under and supported by $`\mathrm{\Pi }`$. By the definition of an answer set for programs without negation as failure, we need to show that no proper subset of $`X`$ is closed under $`\mathrm{\Pi }`$. Let $`Y`$ be a proper subset of $`X`$. Note first that there exists a literal $`L`$ in $`XY`$ that does not have a parent in $`XY`$ relative to $`\mathrm{\Pi }`$ and $`X`$. Indeed, assume that there is no such literal, so that every literal in $`XY`$ has a parent relative to $`\mathrm{\Pi }`$ and $`X`$ in this set; then there exists an infinite sequence $`L_1,L_2,\mathrm{}`$ of elements of $`XY`$ such that $`L_{i+1}`$ is a parent of $`L_i`$, which contradicts the assumption that $`\mathrm{\Pi }`$ is tight on $`X`$.

Take such a literal $`L`$. Since $`X`$ is supported by $`\mathrm{\Pi }`$, there is a rule

$$L\text{Body}$$

in $`\mathrm{\Pi }`$ such that

$$X\text{Body}.$$
(33)
By the definition of the parent relation, the elements of $`X\text{poslit}(\text{Body})`$ are parents of $`L`$ relative to $`\mathrm{\Pi }`$ and $`X`$. By the choice of $`L`$, no parent of $`L`$ relative to $`\mathrm{\Pi }`$ and $`X`$ belongs to $`XY`$, so that $`X\text{poslit}(\text{Body})`$ is disjoint from $`XY`$. Consequently, $`X\text{poslit}(\text{Body})Y`$. Since $`\mathrm{\Pi }`$ does not contain negation as failure, $`\text{lit}(\text{Body})=\text{poslit}(\text{Body})`$, so that

$$X\text{lit}(\text{Body})Y.$$
(34)
By Lemma 4, we can conclude from (33) that

$$X\text{lit}(\text{Body})\text{Body}.$$

In view of (34), it follows by Lemma 1 that $`Y\text{Body}`$. Since $`LY`$, it follows that $`Y`$ is not closed under $`\mathrm{\Pi }`$.

###### Lemma 6

For any program $`\mathrm{\Pi }`$ and any consistent set $`X`$ of literals, if $`\mathrm{\Pi }`$ is tight on $`X`$ then so is $`\mathrm{\Pi }^X`$.

*
* Let $`\mathrm{\Pi }`$ be a program and $`X`$ be a consistent set of literals. Suppose that $`\mathrm{\Pi }^X`$ is not tight on $`X`$; we want to show that $`\mathrm{\Pi }`$ is not tight on $`X`$. It is clear from the definition of reduct of a program that every rule of $`\mathrm{\Pi }^X`$ has the form

$$\text{Head}\text{Body}^X$$
(35)
for some rule (3) in $`\mathrm{\Pi }`$. Then there is an infinite sequence $`L_1,L_2,\mathrm{}`$ in $`X`$ such that, for every $`i`$, there is a rule (35) in $`\mathrm{\Pi }^X`$ with $`L_i=\text{Head}`$, $`L_{i+1}\text{poslit}(\text{Body}^X)X`$ and $`X\text{Body}^X`$.

By Lemma 3(i), $`X\text{Body}^X`$ iff $`X\text{Body}`$. From the definition of the reduct, $`\text{poslit}(\text{Body}^X)\text{poslit}(\text{Body})`$. Therefore, there is an infinite sequence $`L_1,L_2,\mathrm{}`$ in $`X`$ such that, for every $`i`$, there is a rule (3) in $`\mathrm{\Pi }`$ with $`L_i=\text{Head}`$, $`L_{i+1}\text{poslit}(\text{Body})X`$ and $`X\text{Body}`$. This contradicts the assumption that $`\mathrm{\Pi }`$ is tight on $`X`$.

*
* Consider a program $`\mathrm{\Pi }`$ and a consistent set $`X`$ of literals such that $`\mathrm{\Pi }`$ is tight on $`X`$. Assume that $`X`$ is closed under and supported by $`\mathrm{\Pi }`$. Then, by Lemma 3(ii,iii), $`X`$ is closed under and supported by $`\mathrm{\Pi }^X`$. By Lemma 6, $`\mathrm{\Pi }^X`$ is tight on $`X`$. Hence, by Lemma 5, $`X`$ is an answer set for $`\mathrm{\Pi }^X`$, and consequently an answer set for $`\mathrm{\Pi }`$. In the other direction, the assertion of the theorem follows from Proposition 1.

*
* We will first prove the special case when $`\mathrm{\Pi }`$ doesn’t contain negation as failure. Let $`X`$ be an answer set for $`\mathrm{\Pi }\text{Def}`$; denote set (21) by $`R`$, and its transitive closure by $`R^{\mathrm{}}`$. We need to prove that for all $`x`$ and $`y`$, $`\text{tc}(x,y)X`$ iff $`x,yR^{\mathrm{}}`$.

Left-to right. Since there is no negation as failure in $`\mathrm{\Pi }`$, $`X`$ can be characterized as the union $`_iX_i`$ of the sequence of sets of literals defined as follows: $`X_0=\mathrm{}`$; $`X_{i+1}`$ is the set of all literals $`L`$ such that $`\mathrm{\Pi }\text{Def}`$ contains a rule $`L\text{Body}`$ with Body satisfied by $`X_i`$. We will show by induction on $`i`$ that $`\text{tc}(x,y)X_i`$ implies $`x,yR^{\mathrm{}}`$. If $`i=0`$, the assertion is trivial because $`X_0`$ is empty. Assume that for all $`x`$ and $`y`$, $`\text{tc}(x,y)X_i`$ implies $`x,yR^{\mathrm{}}`$, and take an atom $`\text{tc}(x,y)`$ from $`X_{i+1}`$. Take a rule $`\text{tc}(x,y)\text{Body}`$ in $`\mathrm{\Pi }\text{Def}`$ such that $`X_i\text{Body}`$. Since $`\mathrm{\Pi }`$ doesn’t contain atoms of the form $`\text{tc}(x,y)`$ in the heads of rules, this rule belongs to Def. Case 1: $`\text{Body}=p(x,y)`$. Then $`p(x,y)X_iX`$, so that $`x,yRR^{\mathrm{}}`$. Case 2: $`\text{Body}=p(x,v),\text{tc}(v,y)`$. Then $`p(x,v)X_iX`$, so that $`x,vRR^{\mathrm{}}`$; also, $`\text{tc}(v,y)X_i`$, so that, by the induction hypothesis, $`v,yR^{\mathrm{}}`$. By the transitivity of $`R^{\mathrm{}}`$, it follows that $`x,yR^{\mathrm{}}`$.

Right-to-left. Since $`R^{\mathrm{}}=_{j>0}R^j`$, it is sufficient to prove that for all $`j>0`$, $`x,yR^j`$ implies $`\text{tc}(x,y)X`$. The proof is by induction on $`j`$. When $`j=1`$, $`x,yR`$, so that $`p(x,y)X`$; since $`X`$ is closed under Def, it follows that $`\text{tc}(x,y)X`$. Assume that for all $`x`$ and $`y`$, $`x,yR^j`$ implies $`\text{tc}(x,y)X`$, and take a pair $`x,y`$ from $`R^{j+1}`$. Take $`v`$ such that $`x,vR`$ and $`v,yR^j`$. Then $`p(x,v)X`$ and, by the induction hypothesis, $`\text{tc}(v,y)X`$. Since $`X`$ is closed under Def, it follows that $`\text{tc}(x,y)X`$.

We have proved the assertion of Proposition 4 for programs without negation as failure. Now let $`\mathrm{\Pi }`$ be any program that does not contain atoms of the form $`\text{tc}(x,y)`$ in heads of rules, and let $`X`$ be an answer set for $`\mathrm{\Pi }\text{Def}`$. Clearly, the reduct $`\mathrm{\Pi }^X`$ is a program without negation as failure that does not contain atoms of the form $`\text{tc}(x,y)`$ in the heads of rules, and $`X`$ is an answer set for $`\mathrm{\Pi }^X\text{Def}`$. By the special case of the theorem proved above, applied to $`\mathrm{\Pi }^X`$, (20) is the transitive closure of (21).

*
* Assume (i)–(iii), and assume that $`\mathrm{\Pi }\text{Def}`$ is not tight on $`X`$. Then there exists an infinite sequence $`L_1,L_2,\mathrm{}`$ of elements of $`X`$ such that for every $`i`$, $`L_{i+1}`$ is a parent of $`L_i`$ relative to $`\mathrm{\Pi }\text{Def}`$ and $`X`$. Consider two cases.

Case 1: Sequence $`L_1,L_2,\mathrm{}`$ contains only a finite number of terms of the form $`\text{tc}(x,y)`$. Let $`L_n`$ be the last of them. Then for every $`i>n`$, $`L_{i+1}`$ is a parent of $`L_i`$ relative to $`\mathrm{\Pi }`$ and $`X`$. Sequence $`L_{n+1},L_{n+2},\mathrm{}`$ shows that $`\mathrm{\Pi }`$ is not tight on $`X`$, contrary to (i).

Case 2: Sequence $`L_1,L_2,\mathrm{}`$ contains infinitely many terms of the form $`\text{tc}(x,y)`$. By (iii), it follows that this sequence has no terms of the form $`p(x,y)`$. The examination of rules Def shows that every $`\text{tc}(x,y)`$ in this sequence is immediately followed by a term of the form $`\text{tc}(v,y)`$ such that $`p(x,v)X`$. Consequently, sequence $`L_1,L_2,\mathrm{}`$ consists of some initial segment followed by an infinite sequence of literals of the form

$$\text{tc}(v_0,y),\text{tc}(v_1,y),\mathrm{}$$

such that, for every $`i`$, $`p(v_i,v_{i+1})X`$. This is impossible by (ii).

*
* Let $`\mathrm{\Pi }`$ be a program containing constraint (23), with finite $`C`$, and let $`X`$ be a set of literals closed under $`\mathrm{\Pi }\text{Def}`$. Assume that $`\{x,y:p(y,x)X\}`$ is not well-founded. Take $`x_1,\mathrm{},x_nC`$ that satisfy (22) and $`x_n=x_1`$. Since $`X`$ is closed under Def, $`tc(x_1,x_1)X`$. But this is impossible because $`X`$ is closed under (23).

*
* Let $`\mathrm{\Pi }`$ be the program that differs from (24)–(32) in that

+ its underlying set of atoms includes, additionally, expressions of the forms $`\text{on}(\text{table},l,t)`$ and $`\text{above}(\text{table},l,t)`$, and
    + rules (30) and (31) are replaced by

    $$\begin{array}{c}\text{above}(l,l^{},t)\text{on}(l,l^{},t)\hfill \\ \text{above}(l,l^{},t)\text{on}(l,l^{\prime \prime },t),\text{above}(l^{\prime \prime },l^{},t)\hfill \end{array}$$
    (36)
    and

    $$\text{above}(l,l,t).$$
    (37)

Let $`X`$ be a set of literals that does not contain any of the newly introduced atoms or their negations and is closed under the original program (24)–(32). We will prove that $`\mathrm{\Pi }`$ is tight on $`X`$. It will follow then that the original program is tight on $`X`$ as well, because that program is a subset of $`\mathrm{\Pi }`$.

For every $`k=0,\mathrm{},T+1`$, let $`\mathrm{\Pi }_k`$ be the subset of the rules of $`\mathrm{\Pi }`$ in which rules (36) are restricted to $`t<k`$. Since $`\mathrm{\Pi }_{T+1}=\mathrm{\Pi }`$, it is sufficient to prove that, for all $`k`$, $`\mathrm{\Pi }_k`$ is tight on $`X`$. The proof is by induction on $`k`$. Basis: $`k=0`$. The rules of $`\mathrm{\Pi }_0`$ are (24)–(29), (32) and (37). To see that this program is tight, define

$$\begin{array}{c}\lambda (\text{on}(l,l^{},t))=t+1,\hfill \\ \lambda (\neg \text{on}(l,l^{},t))=t+2,\hfill \\ \lambda (\text{move}(b,l,t))=\lambda (\neg \text{move}(b,l,t))=0,\hfill \\ \lambda (\text{above}(l,l^{},t))=\lambda (\neg \text{above}(l,l^{},t))=0.\hfill \end{array}$$

Induction step: Assume that $`\mathrm{\Pi }_k`$ is tight on $`X`$. Let $`C`$ be the set of location constants, and let functions $`p`$ and tc be defined by

$$\begin{array}{c}p(l,l^{})=\text{on}(l,l^{},k),\hfill \\ tc(l,l^{})=\text{above}(l,l^{},k).\hfill \end{array}$$

Then $`\mathrm{\Pi }_{k+1}=\mathrm{\Pi }_k\text{Def}`$. Let us check that all conditions of Theorem 2 are satisfied. Condition (i) holds by the induction hypothesis. Since $`X`$ is closed under the original program (24)–(32) and does not contain any of the newly introduced literals, it is closed under $`\mathrm{\Pi }_{k+1}`$ as well; in view of the fact that $`\mathrm{\Pi }_{k+1}`$ contains constraint (37), condition (ii) follows by Proposition 5. By inspection, (iii) holds also. By Theorem 2, it follows that $`\mathrm{\Pi }_{k+1}`$ is tight on $`X`$.

## 11 Conclusion

For absolutely tight logic programs, the answer set semantics is equivalent to the completion semantics. Answer sets for a finite normal absolutely tight program can be found by running a satisfiability solver on the program’s completion. Defining tightness relative to a set of literals extends the applicability of this method to some programs that are not absolutely tight. This method of computing answer sets is applicable to rules with nested expressions and with weight constraints.

Although this method is not directly applicable to disjunctive programs, disjunction in the head of a rule can be sometimes eliminated in favor of nested expressions in its body \[Lifschitz et al. (1999)\]\[Lifschitz (2002)\]. For instance, the disjunctive rule

$$p;\text{not}qr$$

in any program can be replaced by

$$pr,\text{not}\text{not}q$$

without changing the program’s answer sets.

## Acknowledgments

We are grateful to Yuliya Babovich, Selim Erdoğan, Paolo Ferraris, Joohyung Lee, Victor Marek, Norman McCain and Emilio Remolina for comments and discussions related to the subject of this paper. Special thanks to Hudson Turner for many useful suggestions, including the use of poslit in the definition of tightness instead of the more complicated condition from \[Erdem and Lifschitz (2001a)\], and the possibility of restriction (13) from Section 4.

This work was partially supported by National Science Foundation under grant IIS-9732744 and by the Texas Higher Education Coordinating Board under grant 003658-0322-2001. The first author was also supported by a NATO Science Fellowship.