# Fages' Theorem and Answer Set Programming

We generalize a theorem by Francois Fages that describes the relationship between the completion semantics and the answer set semantics for logic programs with negation as failure. The study of this relationship is important in connection with the emergence of answer set programming. Whenever the two semantics are equivalent, answer sets can be computed by a satisfiability solver, and the use of answer set solvers such as smodels and dlv is unnecessary. A logic programming representation of the blocks world due to Ilkka Niemelae is discussed as an example.

## Authors

• 1 publication
• 21 publications
• 10 publications
• ### SMT-based Constraint Answer Set Solver EZSMT+

05/08/2019 ∙ by Da Shen, et al. ∙ 0

In recent work we defined resource-based answer set semantics, which is ...
08/04/2016 ∙ by Stefania Costantini, et al. ∙ 0

• ### Probability Aggregates in Probability Answer Set Programming

Probability answer set programming is a declarative programming that has...

• ### Quantitative and Stream Extensions of Answer Set Programming

Answer Set Programming has separately been extended with constraints, to...
09/17/2021 ∙ by Rafael Kiesel, et al. ∙ 0

• ### diff-SAT – A Software for Sampling and Probabilistic Reasoning for SAT and Answer Set Programming

This paper describes diff-SAT, an Answer Set and SAT solver which combin...
01/03/2021 ∙ by Matthias Nickles, et al. ∙ 0

• ### Disjunctive Answer Set Solvers via Templates

10/06/2015 ∙ by Remi Brochenin, et al. ∙ 0

• ### Automated Aggregator – Rewriting with the Counting Aggregate

09/22/2020 ∙ by Michael Dingess, et al. ∙ 0

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

This note is about the relationship between the completion semantics [Clark1978] and the answer set (“stable model”) semantics [Gelfond & Lifschitz1991] for logic programs with negation as failure. The study of this relationship is important in connection with the emergence of answer set programming [Marek & Truszczyński1999, Niemelä1999, Lifschitz1999]. Whenever the two semantics are equivalent, answer sets can be computed by a satisfiability solver, and the use of “answer set solvers” such as smodels and dlv is unnecessary.

Consider a finite propositional (or grounded) program without classical negation, and a set of atoms. If is an answer set for then , viewed as a truth assignment, satisfies the completion of . The converse, generally, is not true. For instance, the completion of

 p←p (1)

is . This formula has two models , ; the first is an answer set for (1), but the second is not. François Fages [fag94] defined a syntactic condition on logic programs that implies the equivalence between the two semantics—“positive-order-consistency,” also called “tightness” [Lifschitz1996]. What he requires is the existence of a function from atoms to nonnegative integers (or, more generally, ordinals) such that, for every rule

 A0←A1,…,Am,\it not\/ Am+1,…,\it not% \/ An

in ,

 λ(A1),…,λ(Am)<λ(A0).

It is clear, for instance, that program (1) is not tight. Fages proved that, for a tight program, every model of its completion is an answer set. Thus, for tight programs, the completion semantics and the answer set semantics are equivalent.

Our generalization of Fages’ theorem allows us to draw similar conclusions for some programs that are not tight. Here is one such program:

 p←\it not\/ q,q←\it not\/ p,p←p,r. (2)

It is not tight. Nevertheless, each of the two models , of its completion

 p≡¬q∨(p∧r),q≡¬p,r≡⊥

is an answer set for (2).

The idea of this generalization is to make function partial. Instead of tight programs, we will consider programs that are “tight on a set of literals.”

First we relate answer sets to a model-theoretic counterpart of completion introduced in [Apt, Blair, & Walker1988], called supportedness. This allows us to make the theorem applicable to programs with both negation as failure and classical negation, and to programs with infinitely many rules.333The familiar definition of completion (see Appendix) is applicable to finite programs only, unless we allow infinite disjunctions in completion formulas. Then a corollary about completion is derived, and applied to a logic programming representation of the blocks world due to Ilkka Niemelä. We show how the satisfiability solver sato [Zhang1997] can be used to find answer sets for that representation, and compare the performance of smodels and sato on several benchmarks.

## 2 Generalized Fages’ Theorem

We define a rule to be an expression of the form

 \it Head\/←L1,…,Lm,\it not\/ Lm+1,…,\it not\/ Ln (3)

where each is a literal (propositional atom possibly preceded by classical negation ), and Head is a literal or the symbol . A rule (3) is called a fact if , and a constraint if . A program is a set of rules. The familiar definitions of answer sets, closed sets and supported sets for a program, as well as the definition of the completion of a program, are reproduced in the appendix.

Instead of “level mappings” used by Fages, we consider here partial level mappings—partial functions from literals to ordinals. A program is tight on a set of literals if there exists a partial level mapping with the domain such that, for every rule (3) in , if then

(For the constraints in this condition holds trivially, because the head of a constraint is not a literal and thus cannot belong to .)

###### Theorem

For any program and any consistent set of literals such that is tight on , is an answer set for  iff  is closed under and supported by .

The proof below is almost unchanged from the proof of Fages’ theorem given in [Lifschitz & Turner1999, Section 7.4].

###### Lemma

For any program without negation as failure and any consistent set of literals such that is tight on , if  is closed under and supported by , then  is an answer set for .

Proof: We need to show that  is minimal among the sets closed under . Assume that it is not. Let be a proper subset of  that is closed under , and let be a partial level mapping establishing that is tight on . Take a literal  such that is minimal. Since is supported by , there is a rule

 L←L1,…,Lm

in such that . By the choice of ,

 λ(L1),…,λ(Lm)<λ(L).

By the choice of , we can conclude that

 L1,…,Lm∈Y.

Consequently  is not closed under , contrary to the choice of .

Proof of the Theorem: Left-to-right, the proof is straightforward. Right-to-left: assume that is closed under and supported by . Then  is closed under and supported by . Since is tight on , so is . Hence, by the lemma,  is an answer set for , and consequently an answer set for .

In the special case when is a finite program without classical negation, a set of atoms satisfies the completion of iff it is closed under and supported by . We conclude:

###### Corollary 1

For any finite program without classical negation and any set of atoms such that is tight on , is an answer set for  iff  satisfies the completion of .

For instance, program (2) is tight on the model of its completion: take . By Corollary 1, it follows that is an answer set for (2). In a similar way, the theorem shows that is an answer set also.

By we denote the set of all literals that occur without negation as failure at least once in the body of a rule of .

###### Corollary 2

For any program and any consistent set of literals disjoint from , is an answer set for  iff is closed under and supported by .

###### Corollary 3

For any finite program without classical negation and any set of atoms disjoint from , is an answer set for  iff satisfies the completion of .

To derive Corollary 2 from the theorem, and Corollary 3 from Corollary 1, take for every .

Consider, for instance, the program

 p←\it not\/ q,q←\it not\/ p,r←r,p←r. (4)

The completion of (4) is

 p≡¬q∨r,q≡¬p,r≡r.

The models of these formulas are , and . The only literal occurring in the bodies of the rules of (4) without negation as failure is . In accordance with Corollary 3, the models of the completion that do not contain —sets and —are answer sets for (4).

## 3 Planning in the Blocks World

As a more interesting example, consider a logic programming encoding of the blocks world due to Ilkka Niemelä. The main part of the encoding consists of the following schematic rules:

goal :- time(T), goal(T).
:- not goal.

goal(T2) :- nextstate(T2,T1), goal(T1).

moveop(X,Y,T):-
time(T), block(X), object(Y), X != Y,
on_something(X,T), available(Y,T),
not covered(X,T), not covered(Y,T),
not blocked_move(X,Y,T).

on(X,Y,T2) :-
block(X), object(Y), nextstate(T2,T1),
moveop(X,Y,T1).

on_something(X,T) :-
block(X), object(Z), time(T), on(X,Z,T).

available(table,T) :- time(T).

available(X,T) :-
block(X), time(T), on_something(X,T).

covered(X,T) :-
block(Z), block(X), time(T), on(Z,X,T).

on(X,Y,T2) :-
nextstate(T2,T1), block(X), object(Y),
on(X,Y,T1), not moving(X,T1).

moving(X,T) :- time(T), block(X), object(Y),
moveop(X,Y,T).

blocked_move(X,Y,T):-
block(X), object(Y), time(T), goal(T).

blocked_move(X,Y,T) :-
time(T), block(X), object(Y),
not moveop(X,Y,T).

blocked_move(X,Y,T) :-
block(X), object(Y), object(Z), time(T),
moveop(X,Z,T), Y != Z.

blocked_move(X,Y,T) :-
block(X), object(Y), time(T), moving(Y,T).

blocked_move(X,Y,T) :-
block(X), block(Y), block(Z), time(T),
moveop(Z,Y,T), X != Z.

:- block(X), time(T), moveop(X,table,T),
on(X,table,T).

:- nextstate(T2,T1), block(X), object(Y),
moveop(X,Y,T1), moveop(X,table,T2).

nextstate(Y,X) :- time(X), time(Y),
Y = X + 1.

object(table).
object(X) :- block(X).



To solve a planning problem, we combine these rules with

1. a set of facts defining time/1 as an initial segment of nonnegative integers, for instance

  time(0).   time(1).   time(2).

2. a set of facts defining block/1, such as

  block(a).  block(b).  block(c).

3. a set of facts encoding the initial state, such as

  on(a,b,0).  on(b,table,0).

4. a rule that encodes the goal, such as

  goal(T) :- time(T), on(a,b,T), on(b,c,T).


The union is given as input to the “intelligent grounding” program lparse, and the result of grounding is passed on to smodels [Niemelä1999, Section 7]. The answer sets for the program correspond to valid plans.

Concurrently executed actions are allowed in this formalization as long as their effects are not in conflict, so that they can be arbitrarily interleaved.

The schematic rules above contain the variables T, T1, T2, X, Y, Z that range over the object constants occurring in the program, that is, over the nonnegative integers that occur in the definition of time/1, the names of blocks a, b, that occur in the definition of block/1, and the object constant table.

The expressions in the bodies of the schematic rules that contain = and != restrict the constants that are substituted for the variables in the process of grounding. For instance, we understand the schematic rule

nextstate(Y,X) :- time(X), time(Y),
Y = X + 1.


as an abbreviation for the set of all ground instances of

nextstate(Y,X) :- time(X), time(Y).


in which X and Y are instantiated by a pair of consecutive integers. The schematic rule

blocked_move(X,Y,T) :-
block(X), object(Y), object(Z), time(T),
moveop(X,Z,T), Y != Z.


stands for the set of all ground instances of

blocked_move(X,Y,T) :-
block(X), object(Y), object(Z), time(T),
moveop(X,Z,T).


in which Y and Z are instantiated by different object constants.

According to this understanding of variables and “built-in predicates,” Niemelä’s schematic program, including rules (i)–(iv), is an abbreviation for a finite program BW in the sense defined above.

In the proposition below we assume that schematic rule (iv) has the form

   goal(T) :- time(T), ...


where the dots stand for a list of schematic atoms with the predicate symbol on and the last argument T.

###### Proposition

Program BW is tight on each of the models of its completion.

###### Lemma

For any atom of the form nextstate(Y,X) that belongs to a model of the completion of program BW, .

Proof: The completion of BW contains the formula

 nextstate(Y,X)≡false

for all Y, X such that .

Proof of the Proposition. Let be an answer set for BW. By we denote the largest argument of time/1 in its definition (i). Consider the partial level mapping with domain defined as follows:

 λ(time(T))=0,λ(block(X))=0,λ(object(X))=1,λ(nextstate(Y,X))=1,λ(covered(X,T))=4⋅T+3,λ(on_something(X,T))=4⋅T+3,λ(available(X,T))=4⋅T+4,λ(moveop(X,Y,T))=4⋅T+5,λ(on(X,Y,T))=4⋅T+2,λ(moving(X,T))=4⋅T+6,λ(goal(T))=4⋅T+3,λ(blocked_move(X,Y,T))=4⋅T+7,λ(goal)=4⋅Tmax+4.

This level mapping satisfies the inequality from the definition of a tight program for every rule of BW; the lemma above allows us to verify this assertion for the rules containing nextstate in the body.

According to Corollary 1, we can conclude that the answer sets for program BW can be equivalently characterized as the models of the completion of BW.

## 4 Answer Set Programming with CCALC and SATO

The equivalence of the completion semantics to the answer set semantics for program BW shows that it is not necessary to use an answer set solver, such as smodels, to compute answer sets for BW; a satisfiability solver can be used instead. Planning by giving the completion of BW as input to a satisfiability solver is a form of answer set programming and, at the same time, a special case of satisfiability planning [Kautz & Selman1992].

The Causal Calculator, or , is a system that is capable, among other things, of grounding and completing a schematic logic program, clausifying the completion, and calling a satisfiability solver (for instance, sato) to find a model. We have conducted a series of experiments aimed at comparing the run times of sato, when its input is generated from BW by ccalc, with the run times of smodels, when its input is generated from BW by lparse.

Because the built-in arithmetic of ccalc is somewhat different from that of lparse, we had to modify BW slightly. Our ccalc input file uses variables of sorts object, block and time instead of the unary predicates with these names. The rules of BW that contain those predicates in their bodies are modified accordingly. For instance, rule

on_something(X,T) :-
block(X), object(Z), time(T), on(X,Z,T).


turns into

on_something(B1,T) :- on(B1,O2,T).


The macro expansion facility of ccalc expands

   nextstate(T2,T1)


into the expression

   T2 is T1 + 1


that contains Prolog’s built-in is.

Figure 1 shows the run times of smodels (Version 2.24 and sato (Version 3.1.2) in seconds, measured using the Unix time command, on the benchmarks from [Niemelä1999, Section 9, Table 3]. For each problem, one of the two entries corresponds to the largest number of steps for which the problem is not solvable, and the other to the smallest number of steps for which a solution exists. The experiments were performed on an UltraSPARC with 124 MB main memory and a 167 MHz CPU.

The numbers in Figure 1 are “search times”—the grounding and completion times are not included. The computation involved in grounding and completion does not depend on the initial state or the goal of the planning problem and, in this sense, can be viewed as “preprocessing.” lparse performs grounding more efficiently than ccalc, partly because the former is written in C and the latter in Prolog. The last benchmark in Figure 1 was grounded by lparse (Version 0.99.41) in 16 seconds; ccalc (Version 1.23) spent 50 seconds in grounding and about the same amount of time forming the completion. But the size of the grounded program is approximately the same in both cases: lparse generated 191621 rules containing 13422 atoms, and ccalc generated 200661 rules containing 13410 atoms.

## 5 Discussion

Fages’ theorem, and its generalization proved in this note, allow us to compute answer sets for some programs by completing them and then calling a satisfiability solver. We showed that this method can be applied, for instance, to the representation of the blocks world proposed in [Niemelä1999]. This example shows that satisfiability solvers may serve as useful computational tools in answer set programming.

There are cases, on the other hand, when the completion method is not applicable. Consider computing Hamiltonian cycles in a directed graph [Marek & Truszczyński1999]. We combine the rules

in(U,V) :- edge(U,V), not out(U,V).
out(U,V) :- edge(U,V), not in(U,V).

:- in(U,V), in(U,W), V != W.
:- in(U,W), in(V,W), U != V.

reachable(V) :- in(v0,V).
reachable(V) :- reachable(U), in(U,V).

:- vertex(U), not reachable(U).


with a set of facts defining the vertices and edges of the graph; v0 is assumed to be one of the vertices. The answer sets for the resulting program correspond to the Hamiltonian cycles. Generally, the completion of the program has models different from its answer sets. Take, for instance, the graph consisting of two disjoint loops:

   vertex(v0).  vertex(v1).
edge(v0,v0).  edge(v1,v1).


This graph has no Hamiltonian cycles, and, accordingly, the corresponding program has no answer sets. But the set

   vertex(v0), vertex(v1), edge(v0,v0),
edge(v1,v1), in(v0,v0), in(v1,v1),
reachable(v0), reachable(v1)


is a model of the program’s completion.

## Acknowledgements

We are grateful to Victor Marek, Emilio Remolina, Mirek Truszczyński and Hudson Turner, and to the anonymous referees, for comments and criticisms. This work was partially supported by National Science Foundation under grant IIS-9732744.

## References

• [Apt, Blair, & Walker1988] Apt, K.; Blair, H.; and Walker, A. 1988. Towards a theory of declarative knowledge. In Minker, J., ed., Foundations of Deductive Databases and Logic Programming. San Mateo, CA: Morgan Kaufmann. 89–148.
• [Clark1978] Clark, K. 1978. Negation as failure. In Gallaire, H., and Minker, J., eds., Logic and Data Bases. New York: Plenum Press. 293–322.
• [Fages1994] Fages, F. 1994. Consistency of Clark’s completion and existence of stable models. Journal of Methods of Logic in Computer Science 1:51–60.
• [Gelfond & Lifschitz1991] Gelfond, M., and Lifschitz, V. 1991. Classical negation in logic programs and disjunctive databases. New Generation Computing 9:365–385.
• [Kautz & Selman1992] Kautz, H., and Selman, B. 1992. Planning as satisfiability. In Proc. ECAI-92, 359–363.
• [Lifschitz & Turner1999] Lifschitz, V., and Turner, H. 1999. Representing transition systems by logic programs. In

Logic Programming and Non-monotonic Reasoning: Proc. Fifth Int’l Conf. (Lecture Notes in Artificial Intelligence 1730)

, 92–106.
• [Lifschitz1996] Lifschitz, V. 1996. Foundations of logic programming. In Brewka, G., ed., Principles of Knowledge Representation. CSLI Publications. 69–128.
• [Lifschitz1999] Lifschitz, V. 1999. Answer set planning. In Proc. ICLP-99, 23–37.
• [Marek & Truszczyński1999] Marek, V., and Truszczyński, M. 1999. Stable models and an alternative logic programming paradigm. In The Logic Programming Paradigm: a 25-Year Perspective. Springer Verlag. 375–398.
• [Niemelä1999] Niemelä, I. 1999. Logic programs with stable model semantics as a constraint programming paradigm. Annals of Mathematics and Artificial Intelligence 25:241–273.
• [Zhang1997] Zhang, H. 1997. An efficient propositional prover. In Proc. CADE-97.

## Appendix: Definitions

The notion of an answer set is defined first for programs whose rules do not contain negation as failure. Let be such a program, and let be a consistent set of literals. We say that is closed under if, for every rule

in , whenever . (For a constraint, this condition means that the body is not contained in .) We say that is an answer set for if is minimal among the sets closed under w.r.t. set inclusion. It is clear that a program without negation as failure can have at most one answer set.

To extend this definition to arbitrary programs, take any program , and let be a consistent set of literals. The reduct of relative to is the set of rules

for all rules (3) in such that . Thus is a program without negation as failure. We say that is an answer set for  if  is an answer set for .

A set of literals is closed under if, for every rule (3) in , whenever and . We say that  is supported by  if, for every , there is a rule (3) in  such that , and .

Let be a finite program without classical negation. If is an atom or the symbol , by we denote the formula

 H≡⋁(A1∧⋯∧Am∧¬Am+1∧⋯∧¬An)

where the disjunction extends over all rules

 H←A1,…,Am,\it not\/ Am+1,…,\it not\/ An

in with the head . The completion of is set of formulas for all .