Answer Set Programming Made Easy

11/11/2021
by   Jorge Fandinno, et al.
0

We take up an idea from the folklore of Answer Set Programming, namely that choices, integrity constraints along with a restricted rule format is sufficient for Answer Set Programming. We elaborate upon the foundations of this idea in the context of the logic of Here-and-There and show how it can be derived from the logical principle of extension by definition. We then provide an austere form of logic programs that may serve as a normalform for logic programs similar to conjunctive normalform in classical logic. Finally, we take the key ideas and propose a modeling methodology for ASP beginners and illustrate how it can be used.

READ FULL TEXT VIEW PDF

Authors

page 1

page 2

page 3

page 4

03/15/2012

Possibilistic Answer Set Programming Revisited

Possibilistic answer set programming (PASP) extends answer set programmi...
08/10/2020

ASP(AC): Answer Set Programming with Algebraic Constraints

Weighted Logic is a powerful tool for the specification of calculations ...
09/17/2021

Quantitative and Stream Extensions of Answer Set Programming

Answer Set Programming has separately been extended with constraints, to...
06/20/2017

An Online Development Environment for Answer Set Programming

Recent progress in logic programming (e.g., the development of the Answe...
09/04/2021

Automata for dynamic answer set solving: Preliminary report

We explore different ways of implementing temporal constraints expressed...
09/30/2018

An Application of ASP Theories of Intentions to Understanding Restaurant Scenarios: Insights and Narrative Corpus

This paper presents a practical application of Answer Set Programming to...
07/24/2011

The PITA System: Tabling and Answer Subsumption for Reasoning under Uncertainty

Many real world domains require the representation of a measure of uncer...
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

Many people like Answer Set Programming (ASP [18]) because its declarative approach frees them from expressing any procedural information. In ASP, neither the order of rules nor the order of conditions in rule antecedents or consequents matter and thus leave the meaning of the overall program unaffected. Although this freedom is usually highly appreciated by ASP experts, sometimes laypersons seem to get lost without any structural guidance when modeling in ASP.

We address this issue in this (preliminary) paper and develop a methodology for ASP modeling that targets laypersons, such as biologists, economists, engineers, and alike. As a starting point, we explore an idea put forward by Ilkka Niemelä in [23], although already present in [9, 15] as well as the neighboring area of Abductive Logic Programming [8, 7]. To illustrate it, consider the logic program encoding a Hamiltonian circuit problem in Listing 1.

1node(1..4).           start(1).
2edge(1,2). edge(2,3). edge(2,4). edge(3,1).
3edge(3,4). edge(4,1). edge(4,3).
4
5{ hc(V,U) } :- edge(V,U).
6reached(V) :- hc(S,V), start(S).
7reached(V) :- reached(U), hc(U,V).
8:- node(V), not reached(V).
9:- hc(V,U), hc(V,W), U!=W.
10:- hc(U,V), hc(W,V), U!=W.
Listing 1: A logic program for a Hamiltonian circuit problem

Following good practice in ASP, the problem is separated into the specification of the problem instance in lines 1-3 and the problem class in lines 5-10. This strict separation, together with the use of facts for problem instances, allows us to produce uniform111A problem encoding is uniform, if it can be used to solve all its problem instances. and elaboration tolerant222A formalism is elaboration tolerant if it is convenient to modify a set of facts expressed in the formalism to take into account new phenomena or changed circumstances [22]. specifications. Building upon the facts of the problem instance, the actual encoding follows the guess-define-check methodology of ASP. A solution candidate is guessed in Line 5, analyzed by auxiliary definitions in Line 6 and 7, and finally checked through integrity constraints in lines 8-10.

A closer look reveals even more structure in this example. From a global perspective, we observe that the program is partitioned into facts, choices, rules, and integrity constraints, and in this order. From a local perspective, we note moreover that the predicates in all rule antecedents are defined beforehand. This structure is not arbitrary and simply follows the common practice that concept formation is done linearly by building concepts on top of each other. Moreover, it conveys an intuition on how a solution is formed. Importantly, such an arrangement of rules is purely methodological and has no impact on the meaning (nor the performance333Shuffling rules in logic programs has an effect on performance since it affects tie-breaking during search; this is however unrelated to the ordering at hand.) of the overall program. From a logical perspective, it is interesting to observe that the encoding refrains from using negation explicitly, except for the integrity constraints. Rather this is hidden in Line 5, where the choice on hc(V,U) amounts to the disjunction hc(V,U)hc(V,U), an instance of the law of the excluded middle. Alternatively, hc(V,U) can also be regarded as an abducible that may or may not be added to a program, as common in Abductive Logic Programming.

Presumably motivated by similar observations, Ilkka Niemelä already argued in [23] in favor of an ASP base language based on choices, integrity constraints, and stratified negation.444This concept eliminates the (problematic) case of recursion through negation. We also have been using such an approach when initiating students to ASP as well as teaching laypersons. Our experience has so far been quite positive and we believe that a simple and more structured approach helps to get acquainted with posing constraints in a declarative setting.

We elaborate upon this idea in complementary ways. First of all, we lift it to a logical level to investigate its foundations and identify its scope. Second, we want to draw on this to determine a syntactically restricted subclass of logic programs that still warrants the full expressiveness of traditional ASP. Such a subclass can be regarded as a normalform for logic programs in ASP. This is also interesting from a research perspective since it allows scientists to initially develop their theories in a restricted setting without regarding all corner-cases emerging in a full-featured setting. And last but not least, inspired by this, we want to put forward a simple and more structured modeling methodology for ASP that aims at beginners and laypersons.

2 Background

We start by defining the monotonic logic of Here-and-There (HT). Let be a set of atoms. A formula over  is an expression built with the grammar:

for any atom . We also use the abbreviations: , , and . Given formulas and , we write to denote the uniform substitution of all occurrences of formula in by . This generalizes to the replacement of multiple formulas in the obvious way. As usual, a theory over  is a set of formulas over . We sometimes understand finite theories as the conjunction of their formulas.

An interpretation over  is a pair of atoms (standing for “here” and “there”, respectively) satisfying . An interpretation is total whenever . An interpretation satisfies a formula , written , if the following conditions hold:

A formula is valid, written , if it is satisfied by all interpretations. An interpretation is a model of a theory , written , if for all .

Classical entailment is obtained via the restriction to total models. Hence, we define the classical satisfaction of a formula by an interpretation , written , as .

A total interpretation is an equilibrium model of a theory if is a model of and there is no other model of with . In that case, we also say that is a stable model of . We denote the set of all stable models of  by and use for their projection onto some vocabulary .

Given two theories and and a set of atoms, we say that and are -strongly equivalent [2], written , if for any theory over such that . For formulas  and , we write  if .

A rule is a (reversed) implication of the form

(1)

where each is a literal, that is, either an atom or a negated atom, for . If , we refer to the rule as a fact and write it as by dropping the trailing implication symbol. A rule is said to be normal whenever and is an atom. A negation-free normal rule is called definite. An integrity constraint is a rule with and equivalent to . Finally, the law of the excluded middle is often represented as and called a choice. Accordingly, a rule with a choice on the left-hand side is called a choice rule. A logic program is a set of rules. It is called normal, if it consists only of normal rules and integrity constraints, and definite if all its rules are definite.

3 Logical Foundations

We begin by investigating the logical underpinnings of the simple format of logic programs discussed in the introductory section. To this end, we resort to the base logics of ASP, namely, the logic of Here-and-There (HT), along with its non-monotonic extension, Equilibrium Logic. Although the discussion of the exemplary logic program has revealed several characteristic properties, not all of them can be captured in a logical setting, such as order related features. What remains is the division of the encoding into facts, rules, choices, and integrity constraints. In logical terms, the first two amount to negation-free formulas, choices are instances of the law of the excluded middle, and finally integrity constraints correspond to double-negated formulas in HT. While the first two types of formulas are arguably simpler because of their restricted syntax, the latter’s simplicity has a semantic nature and is due to the fact that in HT double negated formulas can be treated as in classical logic.

In what follows, we show that any formula can be divided into a conjunction of corresponding subformulas. This conjunction is strongly equivalent to the original formula and the translation can thus also be applied to substitute subformulas. Interestingly, the resulting conjunction amounts to a conservative extension of the original formula and the underlying translation can be traced back to the logical principle of extension by definition, as we show below.

To this end, we associate with each formula over  a new propositional atom . We then consider defining axioms of the form . We can now show that replacing any subformula by while adding a corresponding defining axiom amounts to a conservative extension of .

Proposition 1

Let and be formulas over  and .

Then, .

Moreover, we get a one-to-one correspondence between the stable models of both formulas.

Proposition 2

Let and be formulas over  and .

  1. If is a stable model of , then is a stable model of .

  2. If is a stable model of , then is a stable model of .

Clearly, the above results generalize from replacing and defining a single subformula to several such subformulas.

With this, we can now turn our attention to negated subformulas: Given a formula , let stand for the set of all maximal negated subformulas occurring in . This leads us to the following variant of Proposition 1.

Corollary 1

Let be a formula over  and .

Then, .

Given that we exclusively substitute negated subformulas, we can actually treat the defining axiom as in classical logic. This is because in HT, we have that iff (classically) . The classical treatment of the defining axiom is then accomplished by replacing by and . This results in the following decomposition recipe for formulas.

Definition 1

Let be a formula over  and .

Then, we define

Example 1

Let be . Then,

With the translation from Definition 1, we obtain an analogous conservative extension result as above.

Theorem 3.1

Let be a formula over .

Then, we have .

In analogy to Proposition 2, we get a one-to-one correspondence between the stable models of both formulas.

Theorem 3.2

Let be a formula over .

  1. If is a stable model of , then is a stable model of .

  2. If is a stable model of , then is a stable model of .

For instance, is a stable model of the formula from Example 1. From Theorem 3.1, is a stable model of . Conversely, from the stable model of , we get the stable model of by dropping the new atoms.

4 Austere Answer Set Programming

In this section, we restrict the application of our formula translation to logic programs. Although we focus on normal programs, a similar development with other classes of logic programs, like disjunctive ones, can be done accordingly.

For simplicity, we write instead of for and let stand for . Note that, for a rule as in (1), the set consists of negative literals only. The next two definitions specialize our translation of formulas to logic programs.

Definition 2

Let be a rule over  as in (1) with .

Then, we define

Definition 3

Let be a logic program over . Then, .

This translation substitutes negated literals in rule bodies with fresh atoms and adds a choice rule along with a pair of integrity constraints providing an equivalence between the eliminated negated body literals and the substituted atoms.

By applying the above results in the setting of logic programs, we get that a logic program and its translation have the same stable models when restricted to the original vocabulary.

Corollary 2

Let be a logic program over .

Then, we have

In other words, every stable model of a logic program can be extended to a stable model of its translation and vice versa.

Corollary 3

Let be a logic program over .

  1. If is a stable model of , then is a stable model of .

  2. is a stable model of , then is a stable model of .

For illustration, consider the following example.

Example 2

Consider the normal logic program :

Then, is:

The stable models of are and and the ones of are and , respectively.

The example underlines that our translation maps normal rules to definite ones along with choices and pairs of integrity constraints. In other words, it can be seen as a means for expressing normal logic programs in the form of programs with facts, definite rules, choice rules and integrity constraints over an extended vocabulary. We call this class of programs austere logic programs, and further elaborate upon them in the following.

4.1 Austere Logic Programs

We define austere logic programs according to the decomposition put forward in the introduction.

Definition 4 (Austere logic program)

An austere logic program is a quadruple consisting of a set of facts, a set of choices,555That is, choice rules without body literals. a set of definite rules, and a set of integrity constraints.

A set of atoms is a stable model of an austere logic program, if it is a stable model of the union of all four components.

In view of the above results, austere logic programs can be regarded as a normalform for normal logic programs.

Corollary 4

Every normal logic program can be expressed as an austere logic program and vice versa.

The converse follows from the fact that choice rules are expressible by a pair of normal rules [24].

In fact, the (instantiation of) Listing 1 constitutes an austere logic program. To see this observe that

  • lines 1-3 provide facts, , capturing the problem instance, here giving the specification of a graph;

  • Line 5 provides choices, , whose instantiation is derived from facts in the previous lines. Grounding expands this rule to several plain choice rules with empty bodies;

  • lines 5-6 list definite rules, , defining (auxiliary) predicates used in the integrity constraints;

  • finally, integrity constraints, , are given in lines 7-9, stating conditions that solutions must satisfy.

This example nicely illustrates a distinguishing feature of austere logic programs, namely, the compartmentalization of the program parts underlying ASP’s guess-define-check encoding methodology (along with its strict separation of instance and encoding): The problem instance is described by means of

  • the facts in

and the problem encoding confines

  • non-deterministic choices to ,

  • the deterministic extension of the taken decisions to , and

  • the test of the obtained extension to .

This separation also confines the sources of multiple or non-existing stable models to well-defined locations, namely, and , respectively (rather than spreading them over several circular rules; see below). As well, the rather restricted syntax of each compartment gives rise to a very simple operational semantics of austere logic programs, as we see in the next section.

4.2 Operational Semantics

In our experience, a major factor behind the popularity of the approach sketched in the introductory section lies in the possibility to intuitively form stable models along the order of the rules in a program. In fact, the simple nature of austere logic programs provides a straightforward scheme for computing stable models by means of the well-known immediate consequence operator, whose iteration mimics this proceeding. Moreover, the simplicity of the computation provides the first evidence of the value of austere logic programs as a normalform.

The operational semantics of austere logic programs follows ASP’s guess-define-check methodology. In fact, the only non-determinism in austere logic programs is comprised of choice rules. Hence, once choices are made, we may adapt well-known deterministic bottom-up computation techniques for computing stable models. However, the results of this construction provide merely candidate solutions that still need to satisfy all integrity constraints. If this succeeds, they constitute stable models of the austere program.

Let us make this precise for an austere logic program in what follows. To make choices and inject them into the bottom-up computation, we translate the entire set of choices, , into a set of facts:

A subset of , the original facts , along with the definite program are then passed to a corresponding consequence operator that determines a unique stable model candidate. More precisely, the operator of a definite program is defined for an interpretation as follows [21]:

With this, the candidate solutions of an austere program can be defined.

Definition 5

Let be an austere logic program over .

We define a set of atoms as a candidate stable model of , if is the least fixpoint of for some .

The existence of the least fixpoint is warranted by the monotonicity of  [21]. Similar to traditional ASP, several candidate models are obtained via the different choices of .

While the choice of constitutes the guess part and the definite rules in the define part of the approach, the check part is accomplished by the integrity constraints in .

Proposition 3

Let be an austere logic program over  and .

Then, is a stable model of iff is a candidate stable model of such that .

We illustrate the computation of stable models of austere logic programs in the following example.

Example 3

Consider the austere logic program

We get the candidate stable models and from the first three rules depending on whether we choose to be true or not, that is, whether we add the fact or not. Then, on testing them against the integrity constraint expressed by the fourth rule, we see that is indeed a stable model, since it satisfies the integrity constraint, while is not a stable model since checking the integrity constraint fails.

A major intention of austere logic programs is to confine the actual guess and check of an encoding to dedicated components, namely, the choices in and constraints in . The definite rules in help us to analyze and/or extend the solution candidate induced by the facts and the actual choices in . The emerging candidate is then evaluated by the integrity constraints in . This stresses once more the idea that the extension of a guessed solution candidate should be deterministic; it elaborates the guess but refrains from introducing any ambiguities. This is guaranteed by the definite rules used in austere programs.

Observation 1

For any austere logic program and , the logic program has a unique stable model.

This principle is also in accord with [23], where stratified logic programs are used instead of definite ones (see below).

5 Easy Answer Set Programming

Austere logic programs provide a greatly simplified format that reflects ASP’s guess-define-check methodology [18] for writing encodings. Their simple structure allows for translating the methodology into an intuitive process that consists of making non-deterministic choices, followed by a deterministic bottom-up computation, and a final consistency check.

In what follows, we want to turn the underlying principles into a modeling methodology for ASP that aims at laypersons. To this end, we leave the propositional setting and aim at full-featured input languages of ASP systems like clingo [13] and dlv [17]. Accordingly, we shift our attention to predicate symbols rather than propositions and let the terms ‘logic program’, ‘rule’, etc. refer to these languages without providing a technical account (cf. [11, 6]). Moreover, we allow for normal rules instead of definite ones as well as aggregate literals in bodies in order to accommodate the richness of existing ASP modeling languages.

The admission of normal rules comes at the expense of losing control over the origin of multiple or non-existing stable models as well as over a deterministic development of guessed solutions. In fact, the idea of Easy Answer Set Programming (ezASP) is to pursue the principles underlying austere logic programs without enforcing them through a severely restricted syntax. However, rather than having the user fully absorb the loss in control, we shift our focus to a well-founded development of ASP encodings, according to which predicates are defined on top of previously defined predicates (or facts). This parallels the structure and the resulting operational semantics of austere logic programs.

To this end, we start by capturing dependencies among predicates [3].

Definition 6

Let be a logic program.

  • A predicate symbol depends upon a predicate symbol , if there is a rule in with on its left-hand side and on its right-hand side.

    If depends on and depends on , then depends on , too.

  • The definition of a predicate symbol is the subset of consisting of all rules with on their left-hand side.

We denote the definition of a predicate symbol in by and view integrity constraints as rules defining .

Our next definition makes precise what we mean by a well-founded development of a logic program. 666The term stratification differs from the one used in the literature [3].

Definition 7

Let be a logic program.

We define a partition of as a stratification of , if

  1. for all predicate symbols and some and

  2. if depends on , , and for some , then

    1. unless depends on , and

    2. otherwise

Any normal logic program has such a stratification. One way to see this is that mutually recursive programs can be trivially stratified via a single partition. For instance, this applies to both programs and in which and mutually depend upon each other. Accordingly, similar recursive structures in larger programs are confined to single partitions, as required by (2b) above.

With it, we are ready to give shape to the concept of an easy logic program.

Definition 8 (Easy logic program)

An easy logic program is a logic program having stratification such that is a set of facts, is a set of choice rules, is a set of normal rules for , and is a set of integrity constraints.

As in traditional ASP, we often divide a logic program into facts representing a problem instance and the actual encoding of the problem class. For easy programs, this amounts to separating from .

Clearly, an austere logic program is also an easy one.

Thus, the program in Listing 1 is also an easy logic program having the stratification

where each number stands for the rules in the respective line.

Predicates node/1, edge/2, and start/1 are only used to form facts or occur in rule bodies. Hence, they do not depend on any other predicates and can be put together in a single component, . This makes sense since they usually constitute the problem instance. Putting them first reflects that the predicates in the actual encoding usually refer to them. The choices in provide a solution candidate that is checked by means of the rules in the following components. In our case, the guessed extension of predicate hc/2 in Line 5 is simply a subset of all edges provided by predicate edge/2. Tests for being a path or even a cycle are postponed to the define-check part: The rules in , that is, , define the auxiliary predicate reached/1, and aim at analyzing and/or extending our guessed solution candidate by telling us which nodes are reachable via the instances of hc/2 from the start node. The actual checks are then conducted by the integrity constraints, , in the final partition . At this point, the solution candidate along with all auxiliary atoms are derived and ready to be checked. Line 8 tests whether each node is reached in the solution at hand, while lines 9 and 10 make sure that a valid cycle never enters or leaves any node twice.

Finally, it is instructive to verify that strata and cannot be reversed or merged. We observe that

  • hc/2 depends on edge/2 only,

while

  • reached/1 depends on hc/2, edge/2, start/1, and itself,

and no other dependencies. The rules defining hc/2 and reached/1 must belong to the same partition, respectively, as required by (2a) above. Thus, and for some . Because reached/1 depends on hc/2 and not vice versa, we get . This dependency rules out an inverse arrangement, and the fact that it is not symmetric excludes a joint membership of both definitions in the same partition, as stipulated by (2b) above.

5.1 Modeling Methodology

The backbone of easy ASP’s modeling methodology is the structure imposed on its programs in Definition 8. This allows us to encode problems by building concepts on top of each other. Also, its structure allows for staying in full tune with ASP’s guess-define-check methodology [18] by offering well-defined spots for all three parts.

Easy logic programs tolerate normal rules in order to encompass full-featured ASP modeling languages. Consequently, the interplay of the guess, define, and check parts of an easy logic program defies any control. To tame this opening, we propose to carry over Observation 1 to easy logic programs: For any easy logic program and , the logic program should have a unique stable model. Even better if this can be obtained in a deterministic way.

This leads us to the following advice on easy ASP modeling:

  1. Compartmentalize a logic program into facts, , choice rules, , normal rules, , and integrity constraints ,

    such that the overall logic program has stratification .

  2. Aim at defining one predicate per stratum and avoid cycles within each for .

  3. Ensure that has a unique stable model for any .

While the first two conditions have a syntactic nature and can thus be checked automatically, the last one refers to semantics and, to the best of our knowledge, has only sufficient but no known necessary syntactic counterparts. One is to restrict to definite rules as in austere programs, the other is to use stratified negation, as proposed in [23] and detailed in the next section.

Our favorite is to stipulate that has a total well-founded model [25] for any but unfortunately, we are unaware of any syntactic class of logic programs warranting this condition.

5.2 Stratified Negation

The purpose of stratified negation is to eliminate the (problematic) case of recursion through negation. What makes this type of recursion problematic is that it may eliminate stable models and that the actual source may be spread over several rules. To give some concise examples, consider the programs and

admitting no stable models. Following the dependencies in both examples, we count one and three dependencies, respectively, all of which pass through negated body literals. More generally, cyclic dependencies traversing an odd number of negated body literals (not necessarily consecutively) are known sources of incoherence. Conversely, an even number of such occurrences on a cycle is not harmful but spawns alternatives, usually manifested in multiple stable models. To see this, consider the program

producing two stable models. Neither type of rule interaction is admitted in austere logic programs. Rather the idea is to confine the sources of multiple and eliminated stable models to dedicated components, namely, choices and integrity constraints. The same idea was put forward by Niemelä in [23] yet by admitting a more general setting than definite rules by advocating the concept of stratified negation.

To eliminate the discussed cyclic constellations, stratified negation imposes an additional constraint on the stratification of a logic program: Given the prerequisites of Definition 7, we define:

  1. If a predicate symbol occurs in a negative body literal of a rule in , then for some .

In other words, while the definitions of predicates appearing positively in rule bodies may appear in a lower or equal partition, the ones of negatively occurring predicates are restricted to lower components. Although this condition tolerates positive recursion as in , it rules out negative recursion as in the above programs. Since using programs with stratified negation rather than definite programs generalizes austere logic programs, their combination with choices and integrity constraints is also as expressive as full ASP [23].

An example of stratified negation can be found in Listing 3. The negative literal in Line 5 refers to a predicate defined — beforehand — in Line 8.

An attractive feature of normal logic programs with stratified negation is that they yield a unique stable model, just as with austere programs (cf. Observation 1). Hence, they provide an interesting generalization of definite rules maintaining the property of deterministically extending guessed solution candidates.

5.3 Complex Constraints

As mentioned, we aim at accommodating complex language constructs as aggregates in order to leverage the full expressiveness of ASP’s modeling languages. For instance, we may replace lines 9 and 10 in Listing 1 by

9:- { hc(U,V) } >= 2, node(U).
10:- { hc(U,V) } >= 2, node(V).

without violating its stratification.

More generally, a rule with an aggregate ‘’ in the consequent can be represented with choice rules along with an integrity constraint, as shown in [24]. That is, we can replace any rule of form

by777In practice, a set of such choice rules can be represented by a single one of form .

This allows us to integrate aggregate literals into easy logic programs without sacrificing expressiveness.

In fact, many encodings build upon restricted choices that are easily eliminated by such a transformation. A very simple example is graph coloring. Assume a problem instance is given in terms of facts node/1, edge/2, and color/1. A corresponding encoding is given by the following two rules:

1{ assign(X,C) : color(C)} = 1 :- node(X).
2:- edge(X,Y), assign(X,C), assign(Y,C).

Note that the aggregate in the consequent of Line 1 is a shortcut for a #count aggregate.

To eliminate the restricted choice from the consequent in Line 1, we may apply the above transformation to obtain the following easy encoding:

1{ assign(X,C) } :- node(X), color(C).
2:- not { assign(X,C) : color(C)} = 1, node(X).
3:- edge(X,Y), assign(X,C), assign(Y,C).

Given some set of facts, , this encoding amounts to the easy logic programs

The decomposition into a choice and it restriction may appear unnecessary to the experienced ASP modeler. However, we feel that such a separation adds clarity and is preferable to language constructs combining several aspects, at least for ASP beginners. Also, it may be worth noting that this decomposition is done anyway by an ASP system and hence brings about no performance loss.

Two further examples of easy logic programs are given in Listing 2 and 3, solving the Queens and the Tower-of-Hanoi puzzles both with parameter n. 888This parameter is either added from the command line via option --const or a default added via directive #const (see [12] for details).

1{ queen(1..n,1..n) }.
2
3d1(I,J,I-J+n) :- I = 1..n, J = 1..n.
4d2(I,J,I+J-1) :- I = 1..n, J = 1..n.
5
6:- { queen(I,1..n) } != 1, I = 1..n.
7:- { queen(1..n,J) } != 1, J = 1..n.
8
9:- { queen(I,J) : d1(I,J,D) } > 1, D=1..n*2-1.
10:- { queen(I,J) : d2(I,J,D) } > 1, D=1..n*2-1.
Listing 2: An easy logic program for the -Queens puzzle
1peg(a;b;c).
2disk(1..4).
3init_on(1..4,a).
4goal_on(1..4,c).
5
6{ move(D,P,T) : disk(D), peg(P) } :- T = 1..n.
7
8move(D,T)          :- move(D,_,T).
9
10on(D,P,0)          :- init_on(D,P).
11on(D,P,T)          :- move(D,P,T).
12on(D,P,T+1)        :- on(D,P,T), not move(D,T+1), T < n.
13
14blocked(D-1,P,T+1) :- on(D,P,T), T < n.
15blocked(D-1,P,T)   :- blocked(D,P,T), disk(D).
16
17:- { move(D,P,T) : disk(D), peg(P) } != 1, T = 1..n.
18
19:- move(D,P,T), blocked(D-1,P,T).
20:- move(D,T), on(D,P,T-1), blocked(D,P,T).
21:- not 1 { on(D,P,T) } 1, disk(D), T = 1..n.
22
23:- goal_on(D,P), not on(D,P,n).
Listing 3: An easy logic program for a Towers-of-Hanoi puzzle (for plans of length )

While the easy logic program for the -Queens puzzle has the format

the one for the Tower-of-Hanoi puzzle can be partitioned into

5.4 Limitations

The methodology of ezASP has its limits. For instance, sometimes it is convenient to make choices depending on previous choices. Examples of this are the combination of routing and scheduling, as in train scheduling [1], or the formalization of frame axioms in (multi-valued) planning advocated in [16]. Another type of encodings escaping our methodology occurs in meta programming, in which usually a single predicate, like holds, is used and atoms are represented as its arguments. Thus, for applying the ezASP methodology, one had to refine the concept of stratification to access the term level in order to capture the underlying structure of the program. And finally, formalizations of planning and reasoning about actions involve the formalization of effect and inertia laws that are usually self-referential on the predicate level (sometimes resolved on the term level, through situation terms or time stamps). A typical example of circular inertia laws is the following:

 holds(F,T) :-  holds(F,T-1), not -holds(F,T).
-holds(F,T) :- -holds(F,T-1), not  holds(F,T).

Here, ‘-’ denotes classical negation, and F and T stand for (reified) atoms and time points. On the other hand, the sophistication of the given examples illustrates that they are usually not addressed by beginners but rather experts in ASP for which the strict adherence to ezASP is less necessary.

6 Related Work

Apart from advocating the idea illustrated in the introduction, Ilkka Niemelä also showed in [23] that negative body literals can be replaced by a new atom for which a choice needs to be made whether to include it in the model or not; and such that a model cannot contain both the new atom and the atom of the replaced literal but one of them needs to be included. This technique amounts exactly to the transformation in Definition 2 and traces back to Abductive logic programming [8, 7]. Indeed, it was already shown in [15] that for DATALOG queries the expressive power of stable model semantics can be achieved via stratified negation and choices.

We elaborated upon this idea in several ways. First, we have shown that the full expressiveness of normal logic programs can even be achieved with definite rules rather than normal ones with stratified negation. Second, we have provided a strong equivalence result that allows for applying the transformation in Definition 2 to selected rules only. Third, we have generalized the idea by means of the logic of Here-and-There, which made it applicable to other fragments of logic programs. And finally, this investigation has revealed that the roots of the idea lie in the logical principle of extension by definition.

Over the last decades many more related ideas were presented in the literature. For instance, in [9], normal logic programs are translated into positive disjunctive programs by introducing new atoms for negative literals. Also, strong negation is usually compiled away via the introduction of new atoms along with integrity constraints excluding that both the original atom and the atom representing its strong negation hold [14]. The principle of extension by definition was also used in [10] to prove properties about programs with nested expressions. Finally, the paradigm of IDP [5] is closely related to ezASP in the sense that , and are expressed in IDP in first-order logic while the ’s form inductive definitions.

7 Conclusion

We have revisited an old idea from the literature on logic programming under stable model semantics and elaborated upon it in several ways. We started by tracing it back to the principle of extension by definition. The resulting formalization in the setting of the logic of Here-and-there provides us with a logical framework that can be instantiated in various ways. Along these lines, we have shown that normal logic programs can be reduced to choices, definite rules, and integrity constraints, while keeping the same expressiveness as the original program. A major advantage of this austere format is that it confines non-determinism and incoherence to well-defined spots in the program. The resulting class of austere logic programs could play a similar role in ASP as formulas in conjunctive normal form in classical logic.

Drawing on the properties observed on austere logic program, we put forward the modeling methodology of ezASP. The idea is to compensate for the lacking guarantees provided by the restricted format of austere programs by following a sequential structure when expressing a problem in terms of a logic program. This makes use of the well-known concept of stratification to refine ASP’s traditional guess-define-check methodology. Although the ordering of rules may seem to disagree with the holy grail of full declarativeness, we evidence its great value in introducing beginners to ASP. Also, many encodings by experienced ASP users follow the very same pattern.

Moreover, the ezASP paradigm aligns very well with that of achievements [19] that aims not only at easily understandable but moreover provably correct programs. To this end, formal properties are asserted in between a listing of rules to express what has been achieved up to that point. Extending ezASP with achievements and automatically guiding the program development with ASP verifiers, like anthem [20], appears to us as a highly interesting avenue of future research. In this context, it will also be interesting to consider the components of an easy logic program as modules with an attached input-output specification, so that the meaning of the overall program emerges from the composition of all components. This would allow for successive refinements of programs’ components, while maintaining their specification.

References

  • [1] Abels, D., Jordi, J., Ostrowski, M., Schaub, T., Toletti, A., Wanko, P.: Train scheduling with hybrid ASP. In: Balduccini et al. [4], pp. 3–17
  • [2]

    Aguado, F., Cabalar, P., Fandinno, J., Pearce, D., Pérez, G., Vidal, C.: Forgetting auxiliary atoms in forks. Artificial Intelligence

    275, 575–601 (2019)
  • [3] Apt, K., Blair, H., Walker, A.: Towards a theory of declarative knowledge. In: Minker, J. (ed.) Foundations of Deductive Databases and Logic Programming, chap. 2, pp. 89–148. Morgan Kaufmann Publishers (1987)
  • [4] Balduccini, M., Lierler, Y., Woltran, S. (eds.): Proceedings of the Fifteenth International Conference on Logic Programming and Nonmonotonic Reasoning (LPNMR’19), Lecture Notes in Artificial Intelligence, vol. 11481. Springer-Verlag (2019)
  • [5]

    Bruynooghe, M., Blockeel, H., Bogaerts, B., De Cat, B., De Pooter, S., Jansen, J., Labarre, A., Ramon, J., Denecker, M., Verwer, S.: Predicate logic as a modeling language: Modeling and solving some machine learning and data mining problems with IDP3. Theory and Practice of Logic Programming

    15(6), 783–817 (2015)
  • [6] Calimeri, F., Faber, W., Gebser, M., Ianni, G., Kaminski, R., Krennwallner, T., Leone, N., Maratea, M., Ricca, F., Schaub, T.: ASP-Core-2 input language format. Theory and Practice of Logic Programming 20(2), 294–309 (2019)
  • [7] Denecker, M., Kakas, A.: Abduction in logic programming. In: Kakas, A., Sadri, F. (eds.) Computational logic: Logic programming and beyond, pp. 402–436. Springer-Verlag (2002)
  • [8] Eshghi, K., Kowalski, R.: Abduction compared with negation by failure. In: Levi, G., Martelli, M. (eds.) Proceedings of the Sixth International Conference on Logic Programming (ICLP’89). pp. 234–255. MIT Press (1989)
  • [9] Fernández, J., Lobo, J., Minker, J., Subrahmanian, V.: Disjunctive LP + integrity constraints= stable model semantics. Annals of Mathematics and Artificial Intelligence 8(3-4), 449–474 (1993)
  • [10] Ferraris, P., Lifschitz, V.: Weight constraints as nested expressions. Theory and Practice of Logic Programming 5(1-2), 45–74 (2005)
  • [11] Gebser, M., Harrison, A., Kaminski, R., Lifschitz, V., Schaub, T.: Abstract Gringo. Theory and Practice of Logic Programming 15(4-5), 449–463 (2015), http://arxiv.org/abs/1507.06576
  • [12] Gebser, M., Kaminski, R., Kaufmann, B., Lindauer, M., Ostrowski, M., Romero, J., Schaub, T., Thiele, S.: Potassco User Guide. University of Potsdam, 2 edn. (2015), http://potassco.org
  • [13] Gebser, M., Kaminski, R., Kaufmann, B., Schaub, T.: Multi-shot ASP solving with clingo. Theory and Practice of Logic Programming 19(1), 27–82 (2019), http://arxiv.org/abs/1705.09811
  • [14] Gelfond, M., Lifschitz, V.: Logic programs with classical negation. In: Warren, D., Szeredi, P. (eds.) Proceedings of the Seventh International Conference on Logic Programming (ICLP’90). pp. 579–597. MIT Press (1990)
  • [15] Greco, S., Saccà, D., Zaniolo, C.: Extending stratified datalog to capture complexity classes ranging from P to QH. Acta Informatica 37(10), 699–725 (2001)
  • [16] Lee, J., Lifschitz, V., Yang, F.: Action language BC: Preliminary report. In: Rossi, F. (ed.) Proceedings of the Twenty-third International Joint Conference on Artificial Intelligence (IJCAI’13). pp. 983–989. IJCAI/AAAI Press (2013)
  • [17] Leone, N., Pfeifer, G., Faber, W., Eiter, T., Gottlob, G., Perri, S., Scarcello, F.: The DLV system for knowledge representation and reasoning. ACM Transactions on Computational Logic 7(3), 499–562 (2006), http://www.arxiv.org/ps/cs.AI/0211004
  • [18] Lifschitz, V.: Answer set programming and plan generation. Artificial Intelligence 138(1-2), 39–54 (2002)
  • [19] Lifschitz, V.: Achievements in answer set programming. Theory and Practice of Logic Programming 17(5-6), 961–973 (2017)
  • [20] Lifschitz, V., Lühne, P., Schaub, T.: Verifying strong equivalence of programs in the input language of GRINGO. In: Balduccini et al. [4], pp. 270–283
  • [21] Lloyd, J.: Foundations of Logic Programming. Symbolic Computation, Springer-Verlag (1987)
  • [22] McCarthy, J.: Elaboration tolerance (1998), http://www-formal.stanford.edu/jmc/elaboration.html
  • [23] Niemelä, I.: Answer set programming without unstratified negation. In: Garcia de la Banda, M., Pontelli, E. (eds.) Proceedings of the Twenty-fourth International Conference on Logic Programming (ICLP’08). Lecture Notes in Computer Science, vol. 5366, pp. 88–92. Springer-Verlag (2008)
  • [24] Simons, P., Niemelä, I., Soininen, T.: Extending and implementing the stable model semantics. Artificial Intelligence 138(1-2), 181–234 (2002)
  • [25] Van Gelder, A., Ross, K., Schlipf, J.: The well-founded semantics for general logic programs. Journal of the ACM 38(3), 620–650 (1991)