Logic Programs with Compiled Preferences

03/08/2000 ∙ by James P. Delgrande, et al. ∙ Universität Potsdam TU Wien 0

We describe an approach for compiling preferences into logic programs under the answer set semantics. An ordered logic program is an extended logic program in which rules are named by unique terms, and in which preferences among rules are given by a set of dedicated atoms. An ordered logic program is transformed into a second, regular, extended logic program wherein the preferences are respected, in that the answer sets obtained in the transformed theory correspond with the preferred answer sets of the original theory. Our approach allows both the specification of static orderings (as found in most previous work), in which preferences are external to a logic program, as well as orderings on sets of rules. In large part then, we are interested in describing a general methodology for uniformly incorporating preference information in a logic program. Since the result of our translation is an extended logic program, we can make use of existing implementations, such as dlv and smodels. To this end, we have developed a compiler, available on the web, as a front-end for these programming systems.



There are no comments yet.


page 1

page 2

page 3

page 4

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

In commonsense reasoning one frequently prefers one outcome over another, or the application of one rule over another, or the drawing of one default conclusion over another. For example, in buying a car one may have various desiderata in mind (inexpensive, safe, fast, etc.) where these preferences come in varying degrees of importance. In legal reasoning, laws may apply by default but the laws themselves may conflict. So municipal laws will have a lower priority than state laws, and newer laws will take priority over old. Further, if these preferences conflict, there will need to be higher-order preferences to decide the conflict.

In this paper we explore the problem of preference orderings within the framework of extended logic programs under the answer set semantics [Gelfond & Lifschitz1991]. The general methodology was first proposed in [Delgrande & Schaub1997], in addressing preferences in default logic. Previous work in dealing with preferences has for the most part treated preference information at the meta-level (see next to the last section for a discussion of previous approaches). In contrast, we remain within the framework of extended logic programs: We begin with an ordered logic program, which is an extended logic program in which rules are named by unique terms and in which preferences among rules are given by a new set of atoms of the form , where and are names. Thus, preferences among rules are encoded at the object-level. An ordered logic program is transformed into a second, regular, extended logic program wherein the preferences are respected, in the sense that the answer sets obtained in the transformed theory correspond to the preferred answer sets of the original theory. The approach is sufficiently general to allow the specification of preferences among preferences, preferences holding in a particular context, and preferences holding by default.

Our approach can be seen as a general methodology for uniformly incorporating preference information within a logic program. This transformational approach has several advantages. First, it is flexible. So one can encode how a preference order interacts with other information, or how different types of preference orders (such as specificity, authority, recency, etc.) are to be integrated. Second, it is easier to compare differing approaches handling such orderings, since they can be represented uniformly in the same general setting. Thus, for instance, if someone doesn’t like the notion of preference developed here, they may encode their own within this framework. Lastly, it is straightforward implementing our approach: In the present case, we have developed a translator for ordered logic programs that serves as a front-end for the logic programming systems dlv [Eiter et al.1997] and smodels [Niemelä & Simons1997].

The next section gives background terminology and notation. Afterwards, our central approach is described, followed by an exploration of its formal properties. We then continue with an overview of further features and extensions, and provide a pointer to the implementation. Finally, a comparison with related work is given, and we conclude with a short discussion.

2 Definitions and Notation

We deal with extended logic programs, which allow for expressing both classical negation111 Note that classical is a bit of a misnomer since the operator does not support, for example, contraposition. as well as negation as failure [Lifschitz1996]. We use “” for classical negation and “” for negation as failure. Classical negation is also referred to as strong negation, whilst negation as failure is termed weak negation.

Our formal treatment is based on propositional languages. As usual, a literal, , is an expression of the form or , where is an atom. We assume a possibly infinite set of such atoms. The set of all literals is denoted by . A literal preceded by the negation as failure sign is said to be a weakly negated literal. A rule,

, is an ordered pair of the form


where , and each is a literal. The literal is called the head of , and the set is the body of . If , then is a basic rule; if , then is a fact. An (extended) logic program, or simply a program, is a finite set of rules. A program is basic if all rules in it are basic. We use to denote the head of rule , and to denote the body of . Furthermore, let and . The elements of are referred to as the prerequisites of . We say that a rule is defeated by a set of literals iff . As well, each literal in is said to defeat .

A set of literals is consistent iff it does not contain a complementary pair , of literals. We say that is logically closed iff it is either consistent or equals . Furthermore, is closed under a basic program iff for any , whenever . The smallest set of literals which is both logically closed and closed under a basic program is denoted by .

Let be a basic program and a set of literals. The operator is defined as follows:

if is consistent, and otherwise. Iterated applications of are written as (), where and for . It is well-known that , for any basic program .

Let be a rule. Then denotes the basic program obtained from by deleting all weakly negated literals in the body of , i.e., . The reduct, , of a program relative to a set of literals is defined by

In other words, is obtained from by (i) deleting any which is defeated by and (ii) deleting each weakly negated literal occurring in the bodies of the remaining rules. We say that a set of literals is an answer set of a program iff . Clearly, for each answer set of a program , it holds that . The answer set semantics for extended logic programs has been defined in [Gelfond & Lifschitz1991] as a generalization of the stable model semantics [Gelfond & Lifschitz1988] for general logic programs (i.e., programs not containing classical negation, ). The reduct is often called the Gelfond-Lifschitz reduction.

The set of all generating rules of an answer set from is defined as follows:

That is, each prerequisite of is in and is not defeated by . Finally, a sequence of rules is grounded iff, for all , is inconsistent, or else .

3 Logic Programs with Preferences


Figure 1: Translated rules .


A logic program over a propositional language is said to be ordered iff contains the following pairwise disjoint categories:

  • a set of terms serving as names for rules;

  • a set of regular (propositional) atoms of a program; and

  • a set of preference atoms , where are names.

For each ordered program , we assume furthermore a bijective222In practice, function is only required to be injective in order to allow for rules not participating in the resultant preference relation. function assigning to each rule a name . To simplify our notation, we usually write instead of (and we sometimes abbreviate by ). Also, the relation is written as , leaving the naming function implicit. The elements of express preference relations among rules. Intuitively, asserts that has “higher” priority than . Thus, is viewed as having precedence over , i.e.,  should, in some sense, always be considered “before” .

Most importantly, we impose no restrictions on the occurrences of preference atoms. This allows for expressing preferences in a very flexible, dynamic way. For instance, we may specify

where and may themselves be (or rely on) preference atoms.

A special case is given by programs containing preference atoms only among their facts. We say that a logic program over is statically ordered if it is of the form , where is an ordered logic program over and The static case can be regarded as being induced from an external order “”, where the relation between two rules holds iff the fact is included in the ordered program. We make this explicit by denoting a statically ordered program as a pair , representing the program . This static concept of preference corresponds in fact to most previous approaches to preference handling in logic programming and nonmonotonic reasoning, where the preference information is specified as a fixed relation at the meta-level (see, e.g., [Baader & Hollunder1993, Brewka1994, Zhang & Foo1997, Brewka & Eiter1999]).

Our approach provides a mapping that transforms an ordered logic program into a regular logic program , such that the preferred answer sets of are given by the (regular) answer sets of . Intuitively, the translated program is constructed in such a way that the ensuing answer sets respect the inherent preference information induced by the given program (see Theorems 3 and 4 below). This is achieved by adding sufficient control elements to the rules of which guarantee that successive rule applications are in accord with the intended order.

Given the relation , we want to ensure that is considered before , in the sense that, for a given answer set , rule is known to be applied or defeated ahead of with respect to the grounded enumeration of generating rules of . We do this by first translating rules so that the order of rule application can be explicitly controlled. For this purpose, we need to be able to detect when a rule has been applied or when a rule is defeated; as well we need to be able to control the application of a rule based on other antecedent conditions. For a rule , there are two cases for it not to be applied: it may be that some literal in does not appear in the answer set, or it may be that the negation of a literal in is in the answer set. For detecting this case, we introduce, for each rule in the given program , a new, special-purpose atom . Similarly, we introduce a special-purpose atom to detect the case where a rule has been applied. For controlling application of rule we introduce the atom . Informally, we conclude that it is to apply a rule just if it is with respect to every -greater rule; for such a -greater rule , this will be the case just when is known to be blocked or applied.

More formally, given an ordered program over , let be the language obtained from by adding, for each , new pairwise distinct propositional atoms , , , and . Then, our translation maps an ordered program over into a regular program over in the following way.

Definition 1

Let be an ordered logic program over . For each , let be the collection of rules depicted in Figure 1, where , , and . Then, the logic program over is given by .

The first four rules of Figure 1 express applicability and blocking conditions of the original rules: For each rule , we obtain two rules, and , along with rules of the form , , where is the number of literals in the body. The second group of rules encodes the strategy for handling preferences. The first of these rules, , “quantifies” over the rules in . This is necessary when dealing with dynamic preferences since preferences may vary depending on the corresponding answer set. The three rules , , and specify the pairwise dependency of rules in view of the given preference ordering: For any pair of rules , with , we derive whenever fails to hold, or whenever either or is true. This allows us to derive , indicating that may potentially be applied whenever we have for all with that has been applied or cannot be applied. It is important to note that this is only one of many strategies for dealing with preferences: different strategies are obtainable by changing the specification of . Finally, we note that our implementation represents the second group of rules in terms of four rule schemas (using variables), where the first one depends on the number of names (as opposed to the number of rules; cf. Definition 1).

We have the following characterisation of preferred answer sets.

Definition 2

Let be an ordered logic program over language and a set of literals. We say that is a preferred answer set of iff for some answer set of .

In what follows, answer sets of standard (i.e., unordered) logic programs are also referred to as regular answer sets.

As an illustration of our approach, consider the following program :

where denotes the name of rule . This program has two regular answer sets, one containing and the other containing ; both contain and . However, only the first is a preferred answer set. To see this, observe that for any , we have for each . We thus get for such and that by (reduced) rules , and so via rule . Analogously, we get . Now consider the following rules from :

Given and , rule leaves us with the choice between or . First, assume . We get from . Hence, we get , , and finally , which results in via . Omitting further details, this yields an answer set containing while excluding . Second, assume . This eliminates when turning into . Also, is defeated since is derivable. is inapplicable, since is only derivable (from via ) in the presence of . But is not derivable since neither nor is derivable. Since this circular situation is unresolvable, there is no preferred answer set containing .

4 Properties of the Approach

Our first result ensures that the dynamically generated preference information enjoys the usual properties of strict orderings. To this end, we define the following relation: for each set of literals and every , the relation holds iff .

Theorem 1

Let be an ordered logic program and a consistent answer set of . Then is a strict partial order. Moreover, if has only static preferences, then , for any answer set of .

The following results shed light on the functioning induced by translation ; they elaborate upon the logic programming operator  :

Theorem 2

Let be a consistent answer set of for an ordered program , and let . Then, for any :

  1. ;

  2. iff ;

  3. if is not defeated by , , and , then ;

  4. and implies ;

  5. if is defeated by and , then for some ;

  6. implies and for all .

The next result shows that the translated rules are considered in accord to the partial order induced by the given preference relation:

Theorem 3

Let be an ordered logic program, a consistent answer set of , and a grounded enumeration of the set of generating rules of from . Then, for all :

for all equaling or , and some equaling or , with , , and .

For static preferences, our translation amounts to selecting the answer sets of the underlying unordered program that comply with the ordering, .

Definition 3

Let be a statically ordered program. An answer set of is called -preserving if is either inconsistent, or else there exists a grounded enumeration of such that, for every , we have that:

  1. if , then ;  and

  2. if and then or is defeated by the set .

The next result furnishes semantical underpinnings for statically ordered programs; it provides a correspondence between preferred answer sets and regular answer sets of the original program:

Theorem 4

Let be a statically ordered logic program and a set of literals. Then, is a preferred answer set of iff is a -preserving answer set of .

This gives rise to the following corollary:

Corollary 1

Let and be as in Theorem 4. If is a preferred answer set of , then is an answer set of .

Note that the last two results have no counterparts in the general (dynamic) case, due to the lack of a regular answer set of the original program. The preference information is only fully available in the answer sets of the translated program (hence the restriction of the notion of -preservation to the static case).

Also, if no preference information is present, our approach is equivalent to standard answer set semantics. Moreover, the notions of statically ordered and (dynamically) ordered programs coincide in this case.

Theorem 5

Let be a logic program over and a set of literals. If contains no preference information, i.e. if , then the following statements are equivalent:

  1. is a preferred answer set of statically ordered logic program ;

  2. is a preferred answer set of ordered logic program ;

  3. is a regular answer set of logic program .

Recently, Brewka and Eiter [Brewka & Eiter1999] suggested two principles, simply termed Principle I and Principle II, which, they argue, any defeasible rule system handling preferences should satisfy. The next result shows that our approach obeys these principles. However, since the original formulation of Principle I and II is rather generic—motivated by the aim to cover as many different approaches as possible—we must instantiate them in terms of our formalism. It turns out that Principle I is only suitable for statically ordered programs, whilst Principle II admits two guises, one for statically ordered programs, and another one for (dynamically) ordered programs.

Principles I and II, formulated for our approach, are as follows:

Principle I.

Let be a statically ordered logic program, and let and be two (regular) answer sets of generated by and , respectively, where . If , then is not a preferred answer set of .

Principle II-S (Static Case).

Let be a preferred answer set of statically ordered logic program , let be a rule wherein , and let be a strict partial order which agrees with on rules from . Then, is an answer set of , where

Principle II-D (Dynamic Case).

Let be a preferred answer set of a (dynamically) ordered logic program , and let be a rule such that . Then, is an answer set of .

Theorem 6

Statically ordered logic programs obey Principles I and II-S. Furthermore, ordered logic programs enjoy Principle II-D.

Observe that, since transformation is clearly polynomial in the size of ordered logic programs, and because of Theorem 5, the complexity of our approach is inherited from the complexity of standard answer set semantics in a straightforward way. We just note the following result:

Theorem 7

Given an ordered program , checking whether has a preferred answer set is NP-complete.

5 Further Issues and Refinements

In this section, we sketch the range of applicability and point out distinguishing features of our approach. We briefly mention two points concerning expressiveness, and then sketch how we can deal with preferences over sets of rules. Lastly, we refer to the implementation of our approach.

First, we draw the reader’s attention to the expressive power offered by dynamic preferences in connection with variables in the input language, such as


where are names of rules containing the variables and , respectively. Although such a rule represents only its set of ground instances, it is actually a much more concise specification. Also, since most other approaches employ static preferences of the form such approaches would necessarily have to express (2) as an enumeration of static ground preferences rather than a single rule.

Second, we note that transformation is also applicable to disjunctive logic programs (where rule heads are disjunctions of literals). To see this, observe that the transformed rules unfold the conditions expressed in the body of the rules, while the rules’ head remain untouched, as manifested by rule .

Third, we have extended the approach to allow for preferences between sets of rules. Although we do not include a full discussion here, we remark that this extension has also been implemented (see below). In order to refer to sets of rules, the language is adjoined by a set of terms serving as names for sets of rules, and, in addition, the set may now include atoms of the form with . Accordingly, set-ordered programs contain preference information between names of sets. Informally, set of rules is applicable iff all its members are applicable. Consequently, if is preferred over , then is considered after all rules in are found to be applicable, or some rule in is found to be inapplicable. As before, set-ordered programs are translated into standard logic programs, where suitable control elements , , and , ranging over names of sets, take care of the intended ordering information.

As an example, consider where in buying a car one ranks the price () over safety features () over power (), but safety features together with power is ranked over price. Taking for , we can write this (informally) as:

The terms , , , and are names of sets of rules. If we were given only that not all desiderata can be satisfied (i.e. ) then we could apply the rules in the set (named) and conclude that and can be met. Furthermore, sets of rules are described extensionally by means of atoms . Thus, the set is captured by and . Accordingly, we have , , and . Given rules and the previous facts about , the specification of our example is completed by the preferences for .

Lastly, the approach has been implemented in Prolog and serves as a front-end to the logic programming systems dlv and smodels. The current prototype is available at


This URL contains also diverse examples taken from the literature. Both the dynamic approach to (single) preferences and the set-based approach have been implemented. We note also that the implementation differs from the approach described here in two respects: first, the translation applies to named rules only, i.e., it leaves unnamed rules unaffected; and second, it provides a module which admits the specification of rules containing variables, whereby rules of this form are processed by applying an additional grounding step. A more detailed account regarding the implemented front-end can be found in [Delgrande, Schaub, & Tompits2000].

6 Comparison with Related Work

Dealing with preferences on rules seems to necessitate a two-level approach. This in fact is a characteristic of many approaches found in the literature. The majority of these approaches treat preference at the meta-level by defining alternative semantics. [Brewka1996] proposes a modification of well-founded semantics in which dynamic preferences may be given for rules employing . [Zhang & Foo1997] and [Brewka & Eiter1999] propose different prioritized versions of answer set semantics. In [Zhang & Foo1997] static preferences are addressed first, by defining the reduct of a logic program , which is a subset of that is most preferred. For the following example, their approach gives two answer sets (one with and one with ) which seems to be counter-intuitive; ours in contrast has a single answer set containing .

Moreover, the dynamic case is addressed by specifying a transformation of a dynamic program to a set of static programs.

Brewka and Eiter [Brewka & Eiter1999] address static preferences on rules in extended logic programs. They begin with a strict partial order on a set of rules, but define preference with respect to total orders that conform to the original partial order. Preferred answer sets are then selected from among the collection of answer sets of the (unprioritised) program. In contrast, we deal only with the original partial order, which is translated into the object theory. As well, only preferred extensions are produced in our approach; there is no need for meta-level filtering of extensions.

A two-level approach is also found in [Gelfond & Son1997], where a methodology for directly encoding preferences in logic programs is proposed. The “second-order flavour” of this approach stems from the reification of rules and preferences. For example, a rule is expressed by the formula where is the name of the rule. The Prolog-like list notation and raises the possibility of an infinite Herbrand universe; this is problematic for systems like smodels and dlv that rely on finite Herbrand universes.

7 Conclusion

We have described an approach for compiling preferences into logic programs under the answer set semantics. An ordered logic program, in which preferences appear in the program rules, is transformed into a second, extended logic program wherein the preferences are respected, in that the answer sets obtained in the transformed theory correspond with the preferred answer sets of the original theory. In a certain sense, our transformation can be regarded as an axiomatisation of (our interpretation of) preference. Arguably then, we describe a general methodology for uniformly incorporating preference information in a logic program. In this approach, we avoid the two-level structure of previous work. While the previous “meta-level” approaches must commit themselves to a semantics and a fixed strategy, our approach (as well as that of [Gelfond & Son1997]) is very flexible with respect to changing strategies, and is open for adaptation to different semantics and different concepts of preference handling.

The approach is easily restricted to reflect a static ordering in which preferences are external to a logic program. We also indicated how the approach can be extended to deal with preferences among sets of rules. Finally, this paper demonstrates that our approach is easily implementable; indeed, we have developed a compiler, as a front-end for dlv and smodels.


  • [Baader & Hollunder1993] Baader, F., and Hollunder, B. 1993. How to prefer more specific defaults in terminological default logic. In

    Proceedings of the International Joint Conference on Artificial Intelligence

    , 669–674.
  • [Brewka & Eiter1999] Brewka, G., and Eiter, T. 1999. Preferred answer sets for extended logic programs. Artificial Intelligence 109(1-2):297–356.
  • [Brewka1994] Brewka, G. 1994. Adding priorities and specificity to default logic. In Pereira, L., and Pearce, D., eds., European Workshop on Logics in Artificial Intelligence (JELIA’94), Lecture Notes in Artificial Intelligence, 247–260. Springer Verlag.
  • [Brewka1996] Brewka, G. 1996. Well-founded semantics for extended logic programs with dynamic preferences. Journal of Artificial Intelligence Research 4:19–36.
  • [Delgrande & Schaub1997] Delgrande, J., and Schaub, T. 1997. Compiling reasoning with and about preferences into default logic. In Pollack, M., ed., Proceedings of the International Joint Conference on Artificial Intelligence, 168–174. Morgan Kaufmann Publishers.
  • [Delgrande, Schaub, & Tompits2000] Delgrande, J.; Schaub, T.; and Tompits, H. 2000. A compiler for ordered logic programs. In Proceedings of the Eight International Workshop on Nonmonotonic Reasoning.
  • [Eiter et al.1997] Eiter, T.; Leone, N.; Mateis, C.; Pfeifer, G.; and Scarcello, F. 1997. A deductive system for nonmonotonic reasoning. In Dix, J.; Furbach, U.; and Nerode, A., eds., Proceedings of the Fourth International Conference on Logic Programming and Non-Monotonic Reasoning, volume 1265 of Lecture Notes in Artificial Intelligence, 363–374. Springer Verlag.
  • [Gelfond & Lifschitz1988] Gelfond, M., and Lifschitz, V. 1988. The stable model semantics for logic programming. In Proceedings of the International Conference on Logic Programming, 1070–1080. MIT Press.
  • [Gelfond & Lifschitz1991] Gelfond, M., and Lifschitz, V. 1991. Classical negation in logic programs and deductive databases. New Generation Computing 9:365–385.
  • [Gelfond & Son1997] Gelfond, M., and Son, T. 1997. Reasoning with prioritized defaults. In Dix, J.; Pereira, L.; and Przymusinski, T., eds., Third International Workshop on Logic Programming and Knowledge Representation, volume 1471 of Lecture Notes in Computer Science, 164–223. Springer Verlag.
  • [Lifschitz1996] Lifschitz, V. 1996. Foundations of logic programming. In Brewka, G., ed., Principles of Knowledge Representation. CSLI Publications. 69–127.
  • [Niemelä & Simons1997] Niemelä, I., and Simons, P. 1997. Smodels: An implementation of the stable model and well-founded semantics for normal logic programs. In Dix, J.; Furbach, U.; and Nerode, A., eds., Proceedings of the Fourth International Conference on Logic Programming and Nonmonotonic Reasoning, 420–429. Springer.
  • [Zhang & Foo1997] Zhang, Y., and Foo, N. 1997. Answer sets for prioritized logic programs. In Maluszynski, J., ed., Proceedings of the International Symposium on Logic Programming (ILPS-97), 69–84. MIT Press.