1. Introduction
Answer Set Programming (ASP) is about mapping a logic program onto its so-called stable models. Over the decades, stable models have been characterized in various ways [
1], somehow underpinning their appropriateness as semantics for logic programs. However, over the same period, the syntax of logic programs has continuously been enriched, equipping ASP with a highly attractive modeling language. This development also brought about much more intricate semantics, as nicely reflected by the long distance traveled from the mathematical apparatus used in the original definition [
2] to the one for capturing the input language of the ASP system
clingo [
3].
With the growing range of ASP applications in academia and industry [
4], we also witness the emergence of more and more hybrid ASP systems [
5,
6], similar to the rise of SMT solving from plain SAT solving [
7]. From a general perspective, the resulting paradigm of ASP
modulo theories (AMT) can be seen as a refinement of ASP, in which an external theory certifies some of a program’s stable models. A common approach, stemming from lazy theory solving [
7], is to view a theory as an oracle that determines the truth of a designated set of (theory) atoms in the program. Meanwhile, this idea has been adapted to the setting of ASP in various ways, most prominently in Constraint ASP [
5], extending ASP with linear equations over integers in various ways [
8,
9,
10,
11,
12,
13,
14]. Beyond this, ASP systems such as
clingo or
dlvhex [
15] leave the choice of the specific theory largely open. For instance,
clingo merely requires fixing the interaction between theories and their theory atoms. As attractive as this generality may be from an implementation point of view, it complicates the development of generic semantics that are meaningful to existing systems. Not to mention that in ASP, the integration of theories takes place in a non-monotonic context.
As a matter of fact, most formal accounts of existing hybrid systems are implementation driven and lack a clear elaboration of the underlying semantic principles. We address this by separating the semantic foundations of hybrid languages from the corresponding systems’ design decisions. As a result, we present a framework in which we can characterize such decisions semantically. More precisely, we provide an extension of logic programs to incorporate very general abstract theories for which no predefined syntax is assumed. We extend the semantics of stable models for these programs, dealing with two types of theory atoms called defined and external. We further classify some types of abstract theories, which we call structured, where we may distinguish variables inside atoms, and the semantics can be defined in terms of denotations (via functions assigning values to those variables). Finally, we explain how several existing hybrid ASP systems, such as clingcon, clingo[dl], and clingo[lp], can be accommodated as instances of this general framework.
2. Background
We start considering an alphabet consisting of two disjoint sets, namely, a set
of
propositional (
regular)
atoms and a set
of
theory atoms, whose truth is governed by some external theory. Several theory atoms may represent the same theory entity. We use letters
,
, and
b for atoms in
,
and
, respectively. In
clingo, these theory atoms are expressions preceded by ‘&’, but their internal syntax is not predetermined: it can be defined by the user to build new extensions. As an example, the system
clingcon extends the input language of
clingo with linear equations, represented as theory atoms of the form
where for each
i such that
, each
is an integer variable and each
is an integer constant, whereas ≺ is a comparison symbol, such as
<=,
=,
!=,
<,
>,
>=. As we said above, we may have two different theory atoms, such as
and
, actually representing the same condition (as a linear equation).
A
literal is any atom
or its default negation
. A
-logic program over
is a set of rules of the form
where
for
and
with
denoting the falsum constant. We let notations
,
, and
stand for the
head, the
positive, and the
negative body atoms of a rule
r of the form of (
2). The set of
body atoms of
r is just
. Finally, the sets of
body and
head atoms of a program
P are respectively defined as
and
, as expected. An example of a system using
-logic programs is the aforementioned
clingcon, whose theory atoms correspond to linear integer equations. We refer to logic programs augmented by such theory atoms as
clingcon-programs.
Next, we describe the semantics of
-logic programs in
clingo [
16], used for several extensions such as the addition of difference constraints in
clingo[
dl], of linear equations over integers in
clingcon, and over reals in
clingo[
lp]. In all these systems, we can see the role of the corresponding external theory as a kind of “
certification authority” that sanctions regular stable models whose theory atoms are in accord with their underlying constraints. To this end, we envisage a two-step process: (1) generate regular stable models and (2) select the ones passing the theory certification. In step (1), we ignore the distinction between atoms in
and
and plainly apply the stable model semantics [
2]. More precisely, a set
of atoms is a
model of a
-logic program
P over
, if, for every rule
such that
and
, we have
. In the case of an integrity constraint with
, note that
⊥ does not belong to
. The stable models of
P are defined via the
reduct of
P relative to a set
X of atoms, viz.
Then, as usual, a set,
X, of atoms is a
stable model of
P if
X is the least model of
. In step (2), an external theory
is used to eliminate any stable model
X whose theory atoms
are not
in accord with
. Suppose step (1) yields a stable model of a
clingcon-program containing both atoms
and
. This stable model would not pass theory certification since no values for integer variables
x and
y can satisfy both corresponding linear equations, viz.
and
(note that the latter is equivalent to
).
In fact, the treatment of each theory atom
(as obtained in the stable model) leaves room for different semantic options [
16]. The first option is about the justification for the truth of
in step (1). A theory atom
is called
defined if its truth must be derived through the program’s rules. Otherwise,
is said to be
external, and we are always free to add it to the program without further justification. A second semantic option has to do with how we treat
for a stable model
X in step (2). We say that
is
strict when
implies that the theory check requires the “opposite” constraint of
to be satisfied. Otherwise, we say that
is
non-strict, and the fact
has no relevant effect during theory certification. Of course, in both cases,
implies that the constraint of
is satisfied. As an example, suppose that
is the strict atom
, and we get
in some stable model
X. Then, step (2) imposes the same constraint as if we had obtained atom
in
X.
Janhunen et al. [
14] argue that combinations (non-strict, defined) and (strict, external) are the only sensible ones for linear equation theories. With our focus on these theories, we follow this proposition, and partition the set
of theory atoms into two disjoint sets,
and
, standing for
external and
founded atoms, respectively. Intuitively, each external atom in
is interpreted as (strict, external), so its truth requires no justification, whereas if we decide to make it false, then its corresponding opposite constraint must be considered in step (2). On the other hand, founded atoms in
are those interpreted in a (non-strict, defined) manner, so they must be derived by the
-logic program, and when they remain eventually false, they do not impose any additional constraint on the final solution. Additionally, we require that founded atoms do not occur in the rule bodies, that is,
, for any program
P. We do allow external atoms to occur in the head, but, as we see later, they can always be equivalently shifted to the body. For the sake of brevity, we assume that an atom that only occurs in rule heads (but not in bodies) is founded unless explicitly stated otherwise. Let us emphasize that any atom that occurs in some body is mandatorily external, as discussed above. The signature of a program,
P, as described above, is denoted as
, leaving
implicit.
With this restriction to two interpretations of theory atoms, we can formulate
clingo’s semantics for
-logic programs as follows [
16]: Informally speaking, a
-solution
S is a subset
of theory atoms whose associated constraints are “sanctioned” by abstract theory
; this is made precise in
Section 3. A set
of atoms is a
-stable model of a
-logic program
P over
, if there is some
-solution
S such that
X is a stable model of the logic program
That is, external atoms in
S are added as facts to the program, whereas for any theory atom
occurring as a rule head but not in
S, we add the constraint
. For illustration, consider the
clingcon-program
:
This program contains two theory atoms: and . We refer to them by and , respectively. Theory atom is external since it occurs in the body of a rule, whereas we decide that is founded.
As explained above, the absence of any external atom,
, in our candidate set,
, imposes its complementary constraint to be satisfied. This is the so-called “strict” behavior. For this reason, we assume that, for any external atom, there always exists another external atom that is associated with that complementary constraint, even if this complementary atom does not occur in the program. We formalize this intuition in
Section 3 below. In our example, since
is external, we require a second, implicit external atom
, which we name
, for short, and which stands for the complement of
. As a result, our example deals with two external atoms
that are complementary to each other and one defined atom
. Another consequence of the strict behavior is that any candidate
-solution
S must contain either
or
, because the absence of one of them implies forcing the other, whereas the two of them cannot be selected at the same time because they are inconsistent altogether.
To obtain the stable models of
, we must decide first which candidate set
S of theory atoms are actually
-solutions. Although the definition of
-stable models starts by considering each
-solution
S and builds an associated program (
3) afterward, in practice, we can just start from any possible candidate set of theory atoms
S to form program (
3) and just check if they form a
-solution once we obtain the stable models
X for that program. In our example, we are free to either add the external atom
or its complement
as a fact. If we decide to leave
, we must add the constraint
. This amounts to two possibilities:
and
. If
is the theory of linear equations, it is not difficult to see that
is a
-solution because the associated constraints
and
are satisfiable: as a justification take, for instance, the variable assignment
. When we use a variable assignment in this way, we say that it constitutes a
witness of satisfiability for the set of constraints. In the case of
, we must simply satisfy the constraint
and we can use, for instance, the witness
with
n being any integer (note that the value of
z is irrelevant for satisfying this constraint).
3. Transformation-Based Semantics Revisited
Now, we provide a characterization of the theory reasoning framework of clingo that allows for formal elaborations of -logic programs. To this end, we introduce the concept of an abstract theory , which is our key instrument for establishing more fine-grained formal foundations. With it, we revisit the transformation-based approach and give a formal account of -solutions.
3.1. Abstract Theories
An abstract theory is a triple where is the set of theory atoms we can handle in the theory, is the set of -satisfiable sets of theory atoms, and is a function mapping theory atoms to their complement such that for any . We define for any set . Note that the set acts as an oracle whose rationality is beyond our reach: to see if some set S of theory atoms is satisfiable, we may only check .
Despite the limited structure of such theories, some simple properties can be formulated: a set of theory atoms is
inconsistent, if both and for some atom , (consistent otherwise)
-complete for some subset , if for all , either or , and
closed, if implies .
The definition of completeness is relative to some subset of theory atoms, but when , we simply say that S is complete. An abstract theory is consistent or complete if all its -satisfiable sets are consistent or complete, respectively.
Note that any non-empty closed set is inconsistent but can be -satisfiable (e.g., for paraconsistent theories). We mostly use closed sets to describe subtypes of theory atoms rather than satisfiable solutions.
As an example, consider an abstract theory of linear equations that can be used to capture clingconprograms, where
Note that the set of theory atoms in is closed.
Similarly, to cover
clingo[
dl]-programs, we introduce abstract theory
capturing
difference constraints over integers, which is a subset of the already seen abstract theory
where theory atoms have the fixed form
but are rewritten instead as:
where
x and
y are integer variables and
.
Even though this definition of abstract theories is limited to a minimum set of requirements (no particular syntax, a set used for satisfiability testing and a complement function), we can already define an abstract form of entailment as follows.
Definition 1 (Abstract Entailment)
. Letbe an abstract theory. We say that a setof theory atoms entails a theory atom, written, when.
In other words,
when adding the complement of
s to
S becomes inconsistent. When
is a singleton, we normally remove the set braces and just write
instead of
. For example, it is easy to see that
because the pair of atoms
and
(the complement of
) are in no satisfiable set in
under the usual meaning of linear equations.
3.2. Stable Models of Logic Programs with Abstract Theories
With a firm definition of what constitutes a theory
, we can now make precise the definition of a
-solution and
-stable model of a
-logic program given in (
3). For clarity, we refine those definitions by further specifying the subset of external theory atoms in
. Moreover, given any set
S of theory atoms, we define its
(complemented) completion with respect to external atoms
, denoted by
, as the following superset of
S:
In other words, we add the complement atom
for every external atom
that does not occur explicitly in
S. Note that
S is
-complete iff
. As an example, consider an abstract theory from
with the theory atoms
given above with
Suppose we only have one external atom
and assume that the complements
and
are defined as expected. Then, set
is
-incomplete because neither
nor
. The completion of
S corresponds to
so we eventually add
. On the other hand, set
is
-complete because we do have information about the external atom
, and so,
does not provide any additional information.
Definition 2 (
-solution)
. Given an abstract theory and a set of external theory atoms, we define as a-solution, if , that is, the completion of S is -satisfiable.
The next result shows that
-complete solutions suffice when considering the existence of a solution (The proofs for all propositions can be found in
Appendix B):
Proposition 1. Let be an abstract theory and be a set of external atoms. For any-solution, wehave:
- 1.
is -complete and is also a-solution.
- 2.
If S is -complete, then S is -satisfiable.
Moreover, we can identify a quite general family of consistent abstract theories for which all their solutions are always -complete. Consider atoms and its complement from the above example. Assume that we have some set that contains none of the two. If the two atoms are considered external, that is, , then must include their complements, which are the two atoms themselves again, since . However, then, becomes inconsistent, and so it cannot be a -solution for any consistent abstract theory. As a result, if the theory is consistent and is closed, that is, it contains all the complements of its elements, then all solutions must be -complete:
Proposition 2. Let be a consistent abstract theory with a closed set of external atoms . Then, all -solutions are -complete.
In analogy to
Section 2, a set
of atoms is a
-
stable model of a
-logic program
P, if there is some
-solution
S such that
X is a stable model of the program in (
3). As an example, take again the
clingcon-program consisting of rules (
4) and (
5) with abstract theory
, the already seen theory atoms
, and the closed subset of external atoms
. This program has two
-stable models:
To verify
, take the
-solution
and the resulting program transformation
We see that
is a stable model of the logic program and, as such, also a
-stable model. Similarly, with
-solution
, we get program
Again, we have
as a stable model, confirming it as a
-stable model. Notice that, in this case, the
-solution
corresponding to
is not unique. For instance, we could also have the
-solution
, which results in program (
11).
This program also has as a stable model. As a third alternative, we could have the -solution . This leads to the same program as -solution and, therefore, it is also a valid witness for stable model . This example illustrates that, for founded theory atoms not derived by any rule, the represented linear equation, its complement, or none of the two can be in the -solution used as a witness for a particular -stable model.
As mentioned in
Section 2, we may freely shift any external theory atom in the head to the body (after negating it). This is formalized in the following proposition, whose proof can be found in
Appendix B.
Proposition 3. Let P be a -logic program and be an abstract theory. Let be a set of external atoms, and let be one of those external atoms. Then, programs and have the same -stable models for any list B of literals.
4. Structured Theories and Answer Sets
The notion of
-
stable model introduced in
Section 3 precisely characterizes the semantics of
clingo 5 [
16]. The strength of this semantic is two-fold. First, it provides an effective way to develop algorithms that connect answer set solvers with abstract theories. Second, it is very general as it puts very few requirements on the abstract theories it can be applied to. This applies to constraint answer set solvers based on
clingo, such as the mentioned
clingo[
dl],
clingcon and
clingo[
lp].
The price to pay for this generality is that some important features of these constraint answer set solvers cannot be captured by these two concepts alone. In many practical applications of hybrid systems, we are interested in the assignment to some variables rather than the theory atoms that are satisfied. For instance, we discussed above that a program consisting of rules (
4) and (
5) has two stable models,
and
. However, if we use this program as an input to
clingcon, typing the command:
we obtain the output
Answer: 1
a
Assignment:
x=4 y=0 z=2
Answer: 2
a
Assignment:
x=3 y=1 z=1
...
Both answers shown above correspond to stable model , but only the regular atom is printed. In addition, each answer is accompanied by an assignment of values to the variables. This assignment represents a witness for the satisfiability of the pair of constraints corresponding to theory atoms and in the stable model. In fact, there are infinitely many different witnesses for stable model , and clingcon enumerates it one by one, if asked for more solutions.
In this section, we define an answer set as each of the individual answers, such as the ones shown above (that is, regular atoms and variable assignments), generated from the stable models of the program. To make the idea of a witness more precise, we first need to formalize the use of variables in theory atoms, something that has not been required so far. To this aim, we next introduce a quite general class of abstract theories called compositional.
4.1. Structured and Compositional Theories
We have seen that the set of satisfiable sentences
of an abstract theory
is treated as an oracle or a blackbox: knowing its inner structure or behavior (if it has so) is not required at all for defining
-stable models. There may be cases where deciding whether some set
S of theory atoms is satisfiable (
) depends on the whole set together and cannot be decided in a compositional way, that is, in terms of some constructive condition about the satisfiability of the elements
. For instance, most abstract theories based on non-monotonic formalisms are non-compositional. Example A1 in
Appendix A illustrates the case in which we use
Equilibrium Logic [
17] as the external theory: since equilibrium models are a kind of minimal models of some theories, their existence depends on the whole set of formulas in that theory. However, in most cases, the set
is defined in a compositional way, the following conditions imposed on the structure and elements used inside the theory atoms, as happens with linear equations containing integer variables and arithmetic operations. Trying to keep as much generality as possible, we introduce the use of variables inside theory atoms but rather than describing the semantics of operations among them, we just require the existence of some denotational semantics. Such theory-specific structures allow us to establish properties of abstract theories and ultimately characterize their integration into ASP.
Definition 3 (Structure)
. Given an abstract theory , we define a structure as a tuple where
- 1.
is a set of variables,
- 2.
is a set of domain elements,
- 3.
is a function giving the set of variables contained in a theory atom such that for all theory atoms ,
- 4.
is the set of all valuations over and , and
- 5.
is a function mapping theory atoms to sets of valuations such that for all theory atoms and every pair of valuations agreeing on the value of all variables occurring in .
Whenever an abstract theory is associated with such a structure, we call it structured (rather than abstract).
In what follows, we represent a valuation v as a set of pairs where and for all . Since the valuation stands for a function, we do not allow and for two different values . On the other hand, we are sometimes interested in partial valuations that, when represented as sets of pairs happen to be incomplete. That is, there may be variables for which no pair is included in v (and so the variable is undefined). Given any valuation v, we define its domain as , that is, the set of variables that are defined in v. Total valuations satisfy .
Given a set S of theory atoms, we define its denotation as . We say that a theory structured by is compositional if . Therefore, a set S is -satisfiable iff its denotation is not empty. As an example, let us associate the theory of linear equations with the structure , where
is an infinite set of integer variables,
,
, and
With , a set S of theory atoms capturing linear equations is -satisfiable whenever is non-empty. Once is structured in this way, we can establish the following properties.
Proposition 4. Theory structured by is compositional and consistent.
If a theory is compositional, we can define an associated entailment relation as follows.
Definition 4 (Compositional entailment)
. Let be a compositional theory structured by . We say that a set of theory atoms (compositionally) entails a theory atom , written , when .
Again, for a singleton , we omit braces and simply write .
Back to the example we used to illustrate abstract entailment
, we can easily see now that
since any integer valuation
v such that
must satisfy
as well. Unlike
, this compositional entailment
is always monotonic; that is,
implies
. This is because, when
, we obtain
too. As we explained before, in general, most non-monotonic formalisms are non-compositional in the sense that their satisfiability condition
usually depends on the whole set
S of theory atoms and cannot be described in terms of the individual satisfiability of each atom
. Compositional theories are interesting from an implementation point of view, since they allow for handling partial assignments that can be extended monotonically. The following result proves that, for a given consistent, compositional abstract theory
, compositional entailment implies abstract entailment.
Proposition 5. For any compositional and consistent theory , implies .
In general, however, the opposite may not hold; that is, abstract entailment is weaker than compositional entailment. Example A3 in
Appendix A illustrates a consistent, compositional theory where we may have
but not
.
Some compositional theories have a complement
whose denotation is precisely the set complement of
, that is,
. In this case, we say that the complement is
absolute. This is, in fact, the case of linear constraints
complement: For instance,
. Examples of non-absolute complements may arise when the abstract theory is, for instance, a multi-valued logic (See Examples A2 and A4 with Kleene’s three-valued logic and Fuzzy Logic based on ukasiewizc’s operators in
Appendix A, respectively) where we may have valuations that are not models of a formula nor its complement (assuming we use negation for that role). Having an absolute complement directly implies that the theory is consistent. This is because the denotations
and
are disjoint, and so any set including
is
-unsatisfiable.
Proposition 6. For any compositional theory with an absolute complement , any and , we have that iff .
4.2. Answer Sets of Logic Programs with Compositional Theories
We can formalize the idea of an answer set as a pair containing a set of regular atoms plus an (possibly partial) assignment of values to the theory variables. The definition presented here is not tailored to any particular system but only requires that the structured theory is consistent, compositional, and has an absolute complement. These are three properties that the theories of the three mentioned systems share, and that may very well cover future hybrid systems based on clingo 5.
To formally establish the concept of answer sets, let us introduce some notations. Given any valuation
and a subset of variables
, the function
stands for the restriction of
v to
. Accordingly, for any set of valuations
we define their restriction to
as
. Given a structured theory
, if
is a set of atoms, we define
that is,
collects all pairs
where
Y is fixed to the regular atoms in
X, and
varies among all valuations in
from the theory atoms in
X but restricted to the variables occurring in those theory atoms. Note that
v is only defined for a subset of variables
. We can also understand
v as a partial valuation
, where
, leaving all variables in
undefined. In fact, the values of these variables are irrelevant due to Condition 5 in Definition 3 for a structured theory.
Definition 5 (Answer Set)
. If X is a -stable model of some program P and belongs to , then we say that is a -answer set of P.
For instance, in our running example, the first answer set printed by
clingcon corresponds to the
-
answer set where
is a set of regular atoms and
is the valuation
. Recall that the theory atoms in
are
and
, and note that
satisfies both. Similarly, the second answer set printed by
clingcon corresponds to the
-
answer set where
is the valuation
. As stated in (
7), the other stable model of the program was
. The answer sets for this stable model have the form
where
v is assignments for the subset of variables
occurring in
, so that
, such as, for instance,
or
, to put a pair of examples. Note that the value of
z in these cases is irrelevant.
Let us examine an example program that is accepted by
clingo[
dl] and its answer sets.
The only theory atom in this example is founded, and the answer sets of clingo[dl] are the following:
Answer: 1
Answer: 2
dl(x,0) dl(y,2) a
Here, the first answer corresponds to the
-stable model
∅ and the
-answer set
, and the second answer corresponds to the
-stable model
and the
-answer set
. Note that the first answer set has an empty valuation since no theory atoms are true, and, therefore, no values for
or
are actually required (any arbitrary assignment forms a
-solution). Further, there are obviously infinitely many answer sets in
, but
clingo[
dl] selects a particular one for output, which we further discuss in
Section 5.
As may be expected, given a consistent, compositional theory , for every -stable model, we always obtain at least one -answer set.
Proposition 7. Let be a compositional theory and let be a closed set of external atoms. If X is a -stable model of some program P, then .
As we show above, is, in general, not a singleton, so the correspondence between the -stable model and -answer sets is one-to-many. However, if we focus on consistent, compositional theories that have an absolute complement, then we can reconstruct the -stable model from any of its corresponding -answer sets. In fact, we can establish a one-to-one correspondence between the -stable model of a program and a kind of equivalence class of its -answer sets. Each of the equivalence classes may contain many -answer sets, but any of them has enough information to reconstruct the corresponding -stable model. We say that an answer set satisfies an atom , written , when:
Note that the second condition restricts the denotation to . This is because v can be partial and if so, we just require that there exists some complete valuation in that agrees with the values assigned by v to its defined variables . For any negative literal , we say that simply when . If B is a rule body, we write to stand for for every literal L in B.
Formally, for a program
P and an
-
answer set , we define
We also write if and say that and belong to the same equivalence class with respect to P.
Proposition 8. Let be a consistent compositional theory with an absolute complement and let be a closed set of external atoms. Then, there is a one-to-one correspondence between the -stable models of some program P and the equivalence classes with respect to P of its -answer sets. Furthermore, if is a -answer set, then is a -stable model of P and belongs to .
Despite this one-to-one correspondence, there is a crucial difference between
-stable models and
-answer sets: it is possible for two different programs to have the same
-answer sets but different
-stable models. This is a result of the use of the program to build the corresponding
-stable model in function
. For instance, program
has a unique answer set
with
and
. This is also the unique answer set of the program obtained by extending the above program with rule
However, we can easily see that (
14) and (
15) have the unique stable model
, whereas (
14)–(
16) has the unique stable model
. This shows that stable models are more sensible to changes in the program than answer sets. This difference becomes crucial, for instance, if we want to consider strong equivalence between programs.
5. Answer Set Solving Modulo Linear Equations
Now that we have provided a characterization of AMT with compositional theories, we finally show how our formalism can be used to capture the semantics of several clingo extensions with linear equations. At first, we use the structured theory of linear equations to describe the semantics of clingcon. Then, we introduce structured theories and to analogously capture clingo[dl] and clingo[lp]. This allows us to compare the systems and their features.
5.1. clingcon
In clingcon, all theory atoms are external, that is , and may indistinctly occur in the head or in the body. As we already mentioned, one interesting feature of clingcon is that it does not only show the -stable models but also allows for enumerating all -answer sets for those stable models.
To illustrate differences between -stable models and -answer sets, consider Listing 1, which contains a program calculating the overall taxes in the language of clingcon. To interpret this program in our notation, we consider “.” to be the separation between the rules of the program, “:-” is the implication ←, “not” is the negation ¬, and the choice rule eligible is an abbreviation for the rule eligibleeligible. The program contains one propositional variable, eligible, signifying whether one is eligible for a tax deduction, and three integer variables tax, deduction, and overall that are used in theory atoms and represent taxes before deduction, possible tax deduction, and the overall taxes to pay, respectively. Lines 1 and 2 describe the domain of the integer variables tax and deduction via theory atoms that state that tax is greater or equal to zero and smaller or equal to two, and deduction is greater or equal to zero and at most, the value of tax. Line 3 allows propositional atoms eligible to be freely chosen. Overall, Lines 1 to 3 describe the solution space with six overall combinations of values for the integer variables that are doubled by the possible truth values of eligible to a total of twelve combinations. In practice, these values would, of course, be subject to more complex computations. Lines 5 and 6 then calculate the value of the integer variable overall. The former, by subtracting the value of deduction from tax if eligible, is true, and the latter sets overall equal to tax if eligible is false.
Listing 1: clingcon-program calculating taxes |
|
In the following, the set is comprised of the theory atoms occurring in Listing 1 and their complement. The clingcon-program has four -stable models:
{&sum{tax}>=0, &sum{tax}<=2,
&sum{deduction}>=0, &sum{deduction}<=tax,
&sum{tax;-deduction}=overall, &sum{tax}!=overall, eligible}
{&sum{tax}>=0, &sum{tax}<=2,
&sum{deduction}>=0, &sum{deduction}<=tax,
&sum{tax;-deduction}=overall, &sum{tax}=overall, eligible}
{&sum{tax}>=0, &sum{tax}<=2,
&sum{deduction}>=0, &sum{deduction}<=tax,
&sum{tax}=overall, &sum{tax;-deduction}!=overall}
and
{&sum{tax}>=0, &sum{tax}<=2,
&sum{deduction}>=0, &sum{deduction}<=tax,
&sum{tax}=overall, &sum{tax;-deduction}=overall\}
We have four stable models since variable
deduction can be zero, so whether we are eligible or not, we may have
tax=tax−
deduction=overall. These four
-stable models yield the following twelve answer sets:
In contrast to -stable models, -answer sets provide the precise value associated to each variable. This is usually the information that the user is interested in.
Answer sets also provide a better object of study regarding program transformations. For instance, we may replace Line 5 in Listing 1 with the following two rules:
Intuitively, this replacement leads to an equivalent program. Indeed, this is the case when we look at -answer sets (both programs have the same -answer sets), but it is not the case when we look at -stable models. The program obtained after this replacement has the following four -stable models:
{...,&sum{tax;-deduction}<=overall, eligible
&sum{tax;-deduction}>=overall, &sum{tax}!=overall}
{...,&sum{tax;-deduction}<=overall, eligible
&sum{tax;-deduction}>=overall, &sum{tax}=overall}
{...,&sum{tax;-deduction}<overall,
&sum{tax;-deduction}<=overall, &sum{tax}=overall}
and
{...,&sum{tax;-deduction}>=overall,
&sum{tax;-deduction}<=overall, &sum{tax}=overall}
Note that the -answer sets are independent of what theory atoms are syntactically used. The twelve answer sets are exactly the same in both programs. On the other hand, -stable models are different, depending on the particular theory atoms used. For instance, the first -stable model of both programs captures the same information, but they are slightly different: the one corresponding to the second program is obtained from the first -stable model by replacing theory atom &sum{tax;-deduction}=overall} by atoms &sum{tax;-deduction}<=overall} and &sum{tax;-deduction}>=overall}. That is, the syntactic changes in the program are carried to the -stable mode but not to the -answer sets.
It is also worth mentioning that, since all theory atoms in clingcon are external, we can always apply Proposition 3 to constrain atoms in the head and shift them to the body. As an example, we can safely replace Line 5 in Listing 1 with the following constraint and retain the same stable models:
As we discuss below, this is not true for the remaining systems that combine external and founded atoms.
5.2. clingo[dl]
Let us now return to the
clingo[
dl] system that uses the theory
in which theory atoms have the form
, as introduced in (
6). As with
, the abstract theory
also has a complete complement operation. However, while in linear constraints, the complementary atom would be obtained by just switching the ordering relation from ‘
’ to ‘>’, in the case of
, the resulting construct
is not exactly in the format of a difference constraint, where we must always use the ‘
’ relation. Fortunately, as we deal with integer numbers, we can reformulate the complement simply as
. For example, the complement of
would be
.
In
clingo[
dl], the set of external atoms
consists of all body atoms: atoms that do not occur in rule bodies are founded. One difference with respect to
clingcon is that, in this case, we do have a one-to-one correspondence between the
-solutions and the
-stable models of a
clingo[
dl]-logic program
P. Another important difference is that, for a given stable model,
clingo[
dl] does not enumerate all possible
-answer sets but only provides one of them. This answer set corresponds to the case where all integer variables are assigned a non-negative integer with the minimal possible value. That is,
clingo[
dl]-answer sets are a selection among the
-answer sets of the program. Formally, to characterize this minimal answer set, we start defining a partial order
between two
-answer sets
and
as follows:
As usual, we write when and .
Definition 6 (
clingo[
dl]-answer set)
. A-answer setis called aclingo[dl]-answer setof P ifis-minimal among the-answer sets of P that do not assign a negative value to any variable.
Note that if a set of difference constraints has a solution, then it also has a solution that assigns non-negative integer values to all variables. As a simple example consider a
clingo[
dl]-program that just consists of the fact
This program is imposing the condition
and has infinitely many answer sets: we can choose any integer value for
x and then fix
y as any value greater than or equal to
. However, since
clingo[
dl]-answer sets do not admit negative numbers, we must further pick
, leaving the possible answer sets shown in
Figure 1, where each pair of numbers
represents the valuation
,
. The arrows show the
relations among them. In this case, there exists a unique
clingo[
dl]-answer set corresponding to the valuation
.
5.3. clingo[lp]
A third AMT system covered by our formalization is
clingo[
lp]. In this case, the abstract theory
is about linear equations over reals. It is identical to
but structured by
where
is an infinite set of real variables and the domain
is the set of real numbers
. Previous versions of
clingo[
lp] treated either all theory atoms as external,
, or founded,
. Since it imposes no restriction on the occurrence of linear equation atoms; the counter-intuitive behavior identified in [
14] may emerge. The current version behaves like
clingo[
dl] and treats body atoms as external and head atoms as founded. Another commonality with
clingo[
dl] is a selection among the
-answer sets that are printed. In the case of
clingo[
lp], the selection is configurable by the user via a directive with a linear term:
where
and
. Then, the partial order
between two
-answer sets
and
is defined as:
Similarly, we write when and .
Definition 7 (
clingo[
lp]-answer set)
. A-answer set is called aclingo[lp]-answer set ofP ifis-minimal among the-answer sets of P.
If no minimize directive is provided, the linear term with is assumed by default. That is, the answer set with the smallest sum of variables is selected. For instance, given the program , clingo[lp] only outputs the answer set where .