# Translating LPOD and CR-Prolog2 into Standard Answer Set Programs

Logic Programs with Ordered Disjunction (LPOD) is an extension of standard answer set programs to handle preference using the construct of ordered disjunction, and CR-Prolog2 is an extension of standard answer set programs with consistency restoring rules and LPOD-like ordered disjunction. We present reductions of each of these languages into the standard ASP language, which gives us an alternative way to understand the extensions in terms of the standard ASP language.

## Authors

• 19 publications
• 2 publications
• ### Possibilistic Answer Set Programming Revisited

03/15/2012 ∙ by Kim Bauters, et al. ∙ 0

• ### A System for Explainable Answer Set Programming

We present xclingo, a tool for generating explanations from ASP programs...
09/22/2020 ∙ by Pedro Cabalar, et al. ∙ 0

• ### A Logical Charaterisation of Ordered Disjunction

In this paper we consider a logical treatment for the ordered disjunctio...
11/22/2010 ∙ by Pedro Cabalar, et al. ∙ 0

• ### A Paraconsistent ASP-like Language with Tractable Model Generation

12/20/2019 ∙ by Andrzej Szałas, et al. ∙ 0

• ### An integrated Graphical User Interface for Debugging Answer Set Programs

Answer Set Programming (ASP) is an expressive knowledge representation a...
11/15/2016 ∙ by Philip Gasteiger, et al. ∙ 0

• ### Discovering and Proving Invariants in Answer Set Programming and Planning

Answer set programming (ASP) and planning are two widely used paradigms ...
05/08/2019 ∙ by Patrick Lühne, et al. ∙ 0

• ### Iterative Learning of Answer Set Programs from Context Dependent Examples

In recent years, several frameworks and systems have been proposed that ...
08/05/2016 ∙ by Mark Law, 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

In answer set programming, each answer set encodes a solution to the problem that is being modeled. There is often a need to express that one solution is preferable to another, so several extensions of answer set programs were made to express a qualitative preference over answer sets. In Logic Programs with Ordered Disjunction (LPOD) [Brewka (2002)], this is done by introducing the construct of ordered disjunction in the head of a rule: intuitively means, when Body is true, if possible then , but if is not possible, then at least . Proposition 2 from [Brewka (2002)] states that there is no reduction of LPOD to disjunctive logic programs [Gelfond and Lifschitz (1991)] based on the fact that the answer sets of disjunctive logic programs are subset-minimal whereas LPOD answer sets are not necessarily so. However, this justification is limited to translations that preserve the underlying signature, and it remained an open question if it is possible to turn LPOD into the language of standard ASP such as ASP-Core 2 [Calimeri et al. (2012)] by using auxiliary atoms. In this paper, we provide a positive answer to this question.

We present a reduction of LPOD to standard answer set programs by compiling away ordered disjunctions. The translation gives us an alternative way to understand the semantics of LPOD in terms of the standard ASP language, and more generally, a method to express preference relations among answer sets. Instead of iterating the generator and the tester programs as in [Brewka et al. (2002)], our reduction is one-pass: the preferred answer sets can be computed by calling an answer set solver one time.

It turns out that the translation idea is not restricted to LPOD but also applies to [Balduccini and Mellarkod (2004)], which not only has a construct similar to ordered disjunction in LPOD but also inherits the construct of consistency-restoring rules—rules that can be added to make inconsistent programs to be consistent—from CR-Prolog [Balduccini and Gelfond (2003)]. With some modifications to the LPOD translation, we show that programs can also be turned into standard answer set programs by compiling away both ordered disjunctions and consistency-restoring rules.

The paper is organized as follows. Section 2 reviews LPOD and presents a translation that turns LPOD into standard answer set programs. Section 3 reviews and presents a translation that turns into standard answer set programs. The complete proofs are in the appendix.

## 2 LPOD to ASP with Weak Constraints

### 2.1 Review: LPOD

We review the definition of LPOD by brewka02logic. As in that paper, for simplicity, we assume the underlying signature is propositional.

Syntax:   A (propositional) LPOD is , where its regular part consists of usual ASP rules , and its ordered disjunction part consists of LPOD rules of the form

 C1×⋯×Cn←Body\/ (1)

in which are atoms, is at least , and Body is a conjunction of atoms possibly preceded by not.111In [Brewka (2002)], a usual ASP rule is viewed as a special case of a rule with ordered disjunction when but in this paper, we distinguish them. This simplifies the presentation of the translation and also allows us to consider LPOD that are more general than the original definition by allowing modern ASP constructs such as aggregates. Rule (1) intuitively says “when Body is true, if possible then ; if is not possible then ; …; if all of are not possible then .”

Semantics:   For an LPOD rule (1), its -th option () is defined as

 Ci←Body\/,not\/ C1,…,not\/ Ci−1.

A split program of an LPOD is obtained from by replacing each rule in by one of its options. A set of atoms is a candidate answer set of if it is an answer set of a split program of .

###### Example 1

(From [Brewka (2002)]) The following LPOD ,

 a×b←not\/ cb×c←not\/ d,

has four split programs:

 a←not\/ ca←not\/ cb←not\/ dc←not\/ d,not\/ bb←not\/ c,not\/ ab←not\/ c,% not\/ ab←not\/ dc←not\/ d,not\/ b. (2)

Each of them has the following answer sets respectively, which are the candidate answer sets of .

 {a,b}{c}{b}{b},{c}.

A candidate answer set of is said to satisfy rule (1)

• to degree if does not satisfy Body, and

• to degree () if satisfies Body and .

When contains LPOD rules, the satisfaction degree list of a candidate answer set of is where is the degree to which satisfies rule in . For a candidate answer set , let denote the set of rules in satisfied by to degree . For candidate answer sets and of , brewka05preferences introduces the following four preference criteria.

1. Cardinality-Preferred: is cardinality-preferred to () if there is a positive integer such that , and for all .

2. Inclusion-Preferred: is inclusion-preferred to () if there is a positive integer such that , and for all .

3. Pareto-Preferred: is Pareto-preferred to () if there is a rule that is satisfied to a lower degree in than in , and there is no rule that is satisfied to a lower degree in than in .

4. Penalty-Sum-Preferred: is penalty-sum-preferred to () if the sum of the satisfaction degrees of all rules is smaller in than in .

A candidate answer set of is a k-preferred () answer set if there is no candidate answer set of such that .

Example 1 (Continued)
Recall that has three candidate answer sets: , , and . Their satisfaction degree lists are (1,1), (2,1), and (1,2), respectively. One can check that is the only preferred answer set according to any of the four preference criteria.

###### Example 2

To illustrate the difference among the four preference criteria, consider the following LPOD about picking a hotel near the Grand Canyon. is a 2 star hotel but is close to the Grand Canyon, is a 3 star hotel and the distance is medium, and is a 4 star hotel but is too far.

 close×med×far×tooFarstar4×star3×star21{hotel(X):X=1..3}1⊥←hotel(1), not\/ close⊥←hotel(1), not\/ star2
 ⊥←hotel(2), not\/ med⊥←hotel(2), not\/ star3⊥←hotel(3), not\/ tooFar⊥←hotel(3), not\/ star4

has split programs but only the following three programs are consistent (The regular part of is not listed).

 closemed←not\/ closestar2←not\/ star4,not\/ star3star3←% not\/ star4tooFar←not\/ close,not\/ med,not\/ farstar4

The candidate answer sets of and their satisfaction degree lists are

 S1={hotel(1),close,star2,…},(1,3)S2={hotel(2),med,star3,…},(2,2)S3={hotel(3),tooFar,star4,…},(4,1)

By definition, the cardinality-preferred answer set is , the inclusion-preferred answer sets are and , the Pareto-preferred answer sets are , and , while the penalty-sum-preferred answer sets are and .

### 2.2 An Alternative Way to Generate Candidate Answer Sets: Assumption Programs

Before we describe the translation of LPOD into standard answer set programs, we consider an alternative way to generate candidate answer sets together with their “assumption degrees,” which serves as a basis of our translation.

Let be an LPOD with LPOD rules. For an LPOD rule ()

 C1i×⋯×Cnii←Body\/i , (3)

its -th assumption (), denoted by , is defined as the set of ASP rules

 bodyi ←  Body\/i (4) ⊥ ←  x=0, bodyi (5) ⊥ ←  x>0, not\/ bodyi (6) Cji ←  bodyi, x=j (for 1≤j≤ni) (7) ⊥ ←  bodyi, x≠j,not\/ C1i,…,not\/ Cj−1i, Cji (for 1≤j≤ni) (8)

where is a new, distinct atom for each LPOD rule . Rules (4)—(6) ensure that the body of (3) is false iff . Rule (7) represents that is true under the -th assumption, and rule (8) ensures that all atoms are false. The last two rules together tells us that the first atom in that is true is . The reason we call rules (4)—(8) the -th assumption is because they encode a certain assumption imposed on rule (3) in deriving each candidate answer set: assumes is false, whereas assumes is true and the -th atom in the head is to be derived.

An assumption program of an LPOD is obtained from by replacing each rule in by one of its assumptions. If each LPOD rule is replaced by its -th assumption, we call the assumption degree list of the assumption program.

The following proposition asserts that the candidate answer sets can be obtained from assumption programs instead of split programs.

###### Proposition 1

For any LPOD of and any set of atoms of , is a candidate answer set of iff satisfies the body of rule in is an answer set of some assumption program of .

Example 1 (Continued)   The assumptions for rule denoted by , and the assumptions for rule denoted by are as follows, where and range over .

 O1(X1):body1←% not\/ cO2(X2):body2←not\/ d⊥←X1=0,body1⊥←X2=0,body2⊥←X1>0,not\/ body1⊥←X2>0,not\/ body2a←body1,X1=1b←body2,X2=1b←body1,X1=2c←body2,X2=2⊥←body1,X1≠1,a⊥←body2,X2≠1,b⊥←body1,X1≠2,not\/ a,b⊥←body2,X2≠2,not\/ b,c

has 9 assumption programs,

 O1(0)∪O2(0) O1(0)∪O2(1)\framebox$O1(0)∪O2(2)$,{c}O1(1)∪O2(0)\framebox$O1(1)∪O2(1)$,{a,b} O1(1)∪O2(2)O1(2)∪O2(0)\framebox$O1(2)∪O2(1)$,{b} O1(2)∪O2(2),

among which the three assumption programs in the boxes are consistent. Their answer sets are shown together.

An advantage of considering assumption programs over split programs is that the satisfaction degrees—a basis of comparing the candidate answer sets—can be obtained from the assumption degrees with a minor modification (Section 2.3.1). This is in part because each candidate answer set is obtained from only one assumption program whereas the same candidate answer set can be obtained from multiple split programs (e.g., in Example 1).

### 2.3 Turning LPOD into Standard Answer Set Programs

We define a translation that turns an LPOD into a standard answer set program.

Let be an LPOD of signature where contains propositional rules with ordered disjunction:

 1: C11×⋯×Cn11 ←  Body\/1 … (9) m: C1m×⋯×Cnmm ←  Body\/m

where are rule indices, and for .

The first-order signature of contains -ary predicate constant for each propositional constant of . Besides, contains the following predicate constants not in : (“assumption program”), , (), (“preferred”), and (“preferred answer set”). Furthermore, contains the following predicate constants according to each preference criterion:

• for cardinality-preferred: , ,

• for inclusion-preferred: , ,

• for Pareto-preferred:

• for penalty-sum-preferred: .

#### 2.3.1 Generate Candidate Answer Sets

The first part of the translation is to generate all candidate answer sets of based on the notion of assumption programs. We use the assumption degree list as a “name space” for each candidate answer set, so that we can compare them in a single answer set program.

1.  We use atom to denote the assumption program whose assumption degree list is . We consider all consistent assumption programs by generating a maximal set of atoms: is included in an optimal answer set 222For programs containing weak constraints, an optimal answer set is defined by the penalty that comes from the weak constraints that are violated. [Calimeri et al. (2012)] iff the assumption program denoted by is consistent.

 {ap(X1,…,Xm): X1=0..n1, … ,Xm=0..nm}. (10) :∼ap(X1,…,Xm).  [−1,X1,…,Xm] (11)

Rule (10) generates an arbitrary subset of atoms, each of which records an assumption degree list. Rule (11) is a weak constraint that maximizes the number of atoms by adding the penalty for each true instance of . Together with the rules below, these rules ensure that we consider all assumption programs that are consistent and that no candidate answer sets are missed in computing preference relationship in the second part of the translation.

2.  We extend each atom to include the assumption degrees , and append atom in the bodies of rules.

• For each rule in , contains

where and are obtained from Head and Body by replacing each atom in them with . Each schematic variable ranges over .

• For each rule

 C1i×⋯×Cnii←Body\/i

in , where , contains

 bodyi(X1,…,Xm)← ap(X1,…,Xm),Body\/i(X1,…,Xm) (13) ⊥← ap(X1,…,Xm), Xi=0, bodyi(X1,…,Xm) (14) ⊥← ap(X1,…,Xm), Xi>0, not\/ bodyi(X1,…,Xm). (15)

And for , contains

 Cji(X1,…,Xm)←  bodyi(X1,…,Xm),Xi=j. (16)
 ⊥←  bodyi(X1,…,Xm),Xi≠j,              not\/ C1i(X1,…,Xm),…,not\/ Cj−1i(X1,…,Xm),Cji(X1,…,Xm). (17)

3.  The satisfaction degree list can be obtained from the assumption degree list encoded in by changing to if it was . For this, contains

 1{degree\/(ap(X1,…,Xm),D1,…,Dm): D1=1..n1,…,Dm=1..nm}1 ←ap(X1,…,Xm). (18)

and for , contains

 ⊥ ← degree\/(ap(X1,…,Xm),D1,…,Dm), Xi=0, Di≠1. (19) ⊥ ← degree\/(ap(X1,…,Xm),D1,…,Dm), Xi>0, Di≠Xi. (20)

Since all answer sets of the same assumption program are associated with the same satisfaction degree list, we say an assumption program satisfies LPOD rule to degree if its answer sets satisfy the rule to degree . Rule (18) reads “for any assumption program , it has exactly one assignment of satisfaction degrees .” Rules (19) and (20) say that the assumption program satisfies LPOD rule to degree 1 if (in which case is false) and to degree if (in which case is true).

Let us denote the set of rules (10)—(20) by . Observe that the atoms in the original signature are in the form of in the answer sets of . We define a way to retrieve the candidate answer set of by removing as follows. Let be an optimal answer set of , and let

 shrink(S,x1,…,xm) be {a(v)∣a(v,x1,…,xm)∈S and a(v)∈σ}.

If , we define the set as a candidate answer set on of .333We also apply this notation to the full translation and below.

The following proposition asserts the soundness of the translation .

###### Proposition 2

The candidate answer sets of an LPOD of signature are exactly the candidate answer sets on of .

Example 1 Continued: The following is the encoding of in the input language of clingo.

%%%% 1 %%%%
{ap(X1,X2): X1=0..2, X2=0..2}.             :~ ap(X1,X2). [-1, X1, X2]
%%%% 2 %%%%
% a*b <- not c.
body_1(X1,X2) :- ap(X1,X2), not c(X1,X2).
:- ap(X1,X2), X1=0, body_1(X1,X2).         :- ap(X1,X2), X1>0, not body_1(X1,X2).
a(X1,X2) :- body_1(X1,X2), X1=1.           b(X1,X2) :- body_1(X1,X2), X1=2.
:- body_1(X1,X2), X1!=1, a(X1,X2).
:- body_1(X1,X2), X1!=2, not a(X1,X2), b(X1,X2).
% b*c <- not d.
body_2(X1,X2) :- ap(X1,X2), not d(X1,X2).
:- ap(X1,X2), X2=0, body_2(X1,X2).         :- ap(X1,X2), X2>0, not body_2(X1,X2).
b(X1,X2) :- body_2(X1,X2), X2=1.           c(X1,X2) :- body_2(X1,X2), X2=2.
:- body_2(X1,X2), X2!=1, b(X1,X2).
:- body_2(X1,X2), X2!=2, not b(X1,X2), c(X1,X2).
%%%% 3 %%%%
1{degree(ap(X1,X2), D1, D2): D1=1..2, D2=1..2}1 :- ap(X1,X2).
:- degree(ap(X1,X2), D1, D2), X1=0, D1!=1.
:- degree(ap(X1,X2), D1, D2), X1>0, D1!=X1.
:- degree(ap(X1,X2), D1, D2), X2=0, D2!=1.
:- degree(ap(X1,X2), D1, D2), X2>0, D2!=X2.

The optimal answer set of is

 {ap(1,1),a(1,1),b(1,1),…,ap(2,1),b(2,1),…,ap(0,2),c(0,2),…} (21)

( and atoms are not listed). Since satisfies , , and , the candidate answer sets on of are

 shrink(S,1,1)={a,b},shrink(S,2,1)={b},shrink(S,0,2)={c}

which are exactly the candidate answer sets of .

#### 2.3.2 Find Preferred Answer Sets

The second part of the translation is to compare the candidate answer sets to find the preferred answer sets. For each preference criterion, contains the following rules respectively. Below is .

1. Cardinality-Preferred: For this criterion, contains the following rules.

 card(P,X,N) ← degree\/(P,D1,…,Dm),X=1..maxdegree, N={D1=X;…;Dm=X}. (22) equ2degree(P1,P2,X) ← card(P1,X,N),card(P2,X,N),P1≠P2. (23) prf2degree(P1,P2,X) ← card(P1,X,N1),card(P2,X,N2),N1>N2. (24) prf\/(P1,P2) ← X=0..maxdegree−1,prf2degree(P1,P2,X+1), X{equ2degree(P1,P2,Y):Y=1..X}. (25) pAS(X1,…,Xm) ← ap(X1,…,Xm),{prf\/(P,ap(X1,…,Xm))}0. (26)

, , and denote assumption programs in the form of . is true if satisfies rules in to degree . is true if and have the same number of rules that are satisfied to degree . is true if satisfies more rules to degree than does. is true if is cardinality-preferred to : satisfies more rules to degree than does whereas they satisfy the same number of rules up to degree . Rule (26) reads as: given an assumption program represented by , if we cannot find an assumption program that is more preferable, then the answer sets of are all preferred answer sets of . Note that in rule (26) is a local variable that ranges over all atoms.

2. Inclusion-Preferred: For this criterion, contains the following rules.

 even(0;2). (27) equ2degree(P1,P2,X) ← P1≠P2,X=1..maxdegree, degree\/(P1,D11,…,D1m),degree\/(P2,D21,…,D2m), C1={D11=X;D21=X},…,Cm={D1m=X;D2m=X}, even(C1),…,even(Cm). (28) prf2degree(P1,P2,X) ← P1≠P2,X=1..maxdegree, not\/ equ2degree(P1,P2,X), degree\/(P1,D11,…,D1m),degree\/(P2,D21,…,D2m), {D11≠X;D21=X}1,…,{D1m≠X;D2m=X}1. (29) prf\/(P1,P2) ← X=0..maxdegree−1,prf2degree(P1,P2,X+1), X{equ2degree(P1,P2,Y):Y=1..X}. (30) pAS(X1,…,Xm) ← ap(X1,…,Xm),{prf\/(P,ap(X1,…,Xm))}0. (31)

where counts the number of true atoms in this set, so it equals to 0 (or 2) when none (or both) of and are true; means that the number of true atoms in this set must be smaller or equal to 1, which means that and cannot be true at the same time – in other words, implies .

3. Pareto-Preferred: For this criterion, contains the following rules.

 equ(P1,P2) ← degree\/(P1,D1,…,Dm),degree\/(P2,D1,…,Dm). (32) prf\/(P1,P2) ← degree\/(P1,D11,…,D1m),degree\/(P2,D21,…,D2m), not\/ equ(P1,P2),D11≤D21,…,D1m≤D2m. (33) pAS(X1,…,Xm) ← ap(X1,…,Xm),{prf\/(P,ap(X1,…,Xm))}0. (34)

where means that is equivalent to at all degrees.

4. Penalty-Sum-Preferred: For this criterion, contains the following rules.

 sum(P,N) ← degree\/(P,D1,…,Dm),N=D1+⋯+Dm. (35) prf\/(P1,P2) ← sum(P1,N1),sum(P2,N2),N1

where means that the sum of ’s satisfaction degrees of all rules is .

If , we define the set to be a preferred answer set on of