Abstract Gringo
Abstract Gringo
C Cambridge University Press 2015 449
doi:10.1017/S1471068415000150
Abstract gringo
MARTIN GEBSER
Aalto University, HIIT, Finland
University of Potsdam, Germany
(e-mail: [email protected])
AMELIA HARRISON†
Univeristy of Texas at Austin, USA
(e-mail: [email protected])
ROLAND KAMINSKI
University of Potsdam, Germany
(e-mail: [email protected])
VLADIMIR LIFSCHITZ†
Univeristy of Texas at Austin, USA
(e-mail: [email protected])
TORSTEN SCHAUB‡
University of Potsdam, Germany
INRIA Rennes, France
(e-mail: [email protected])
Abstract
This paper defines the syntax and semantics of the input language of the ASP grounder
gringo. The definition covers several constructs that were not discussed in earlier work on
the semantics of that language, including intervals, pools, division of integers, aggregates with
non-numeric values, and lparse-style aggregate expressions. The definition is abstract in the
sense that it disregards some details related to representing programs by strings of ASCII
characters. It serves as a specification for gringo from Version 4.5 on.
1 Introduction
Version 4.0 of the ASP grounder gringo was released in March of 2013.1 Harrison
et al. (2014) defined the semantics of a subset of its input language in terms of stable
models of infinitary propositional formulas (Truszczynski 2012).
Supported by AoF (grant 251170) and DFG (grants SCHA 550/8 and 550/9).
† Partially supported by the National Science Foundation under Grant IIS-1422455.
‡ Affiliated with Simon Fraser University, Canada, and IIIS Griffith University, Australia.
1 http://potassco.sourceforge.net/
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
450 M. Gebser et al.
That subset does not include, however, several constructs that are frequently used
in ASP programs. One such construct is integer intervals. Take, for instance, the
ASP solution to the n-queens problem shown in Table 1. (It is similar to one of the
solutions in the language of Version 3 presented by Gebser et al. (2011).) Intervals
are used in each rule of this program. To include intervals, we have to modify
the semantics from Harrison et al. (2014) in two ways. First, we have to say that
an arithmetic term denotes, generally, a finite set of integers, not a single integer.
(And it is not necessarily a set of consecutive integers, because the language of
gringo allows us to write (1..3)*2, for instance. This expression denotes the set
{2, 4, 6}.) Second, in the presence of intervals we cannot treat a choice rule {A} as
shorthand for the disjunctive rule A ; not A as proposed by Ferraris and Lifschitz
2
(2005). Indeed, the first rule of the program in Table 1 has 2n stable models; the
rule
q(1..n,1..n) ; not q(1..n,1..n)
has only 2 stable models.
Another feature of gringo not covered by Harrison et al. (2014), which is
somewhat similar to integer intervals, is pooling. Pooling is used, for instance,
in the head of the rule
p(X;Y) :- q(X,Y).
(Note that a semicolon, not a comma, separates X from Y in the head.) This rule has
the same meaning as the pair of rules
p(X) :- q(X,Y).
p(Y) :- q(X,Y).
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
Abstract gringo 451
in the second rule of the program shown in Table 1, and “lparse-style” aggregates,
such as
in the last rule of the program. Both expressions have to do with counting.
Syntactically, the difference is that in expression (1) both the name of the aggregate
(#count) and the binary relation applied to the result of counting and a constant
(=) are shown explicitly; in (2), the fact that the constant 2 occurs on the left, in the
lower bound position, tells us that the relation 6 is applied to that number and to
the result of counting. More importantly, there is a difference between the kinds of
objects that we count. In case of expression (1) we count, for a given value of X, the
values of the variable Y such that q(X,Y) belongs to the stable model. In case of (2)
we count, for a given value of D, the atoms q(X,Y) that belong to the stable model
and satisfy an additional condition: d2(X,Y,D) belongs to the model as well. Thus
the atom in front of the colon in (2) plays two roles: it tells us what to count, and
it gives a condition on the stable model that needs to be checked.
The language studied by Harrison et al. (2014) does not include lparse-style
aggregates. The easiest way to add such aggregates is to treat them as abbreviations.
For instance, (2) can be viewed as shorthand for the dlv-style expression
(In this paper we adopt a more elaborate translation that allows us to accommodate
negated atoms in front of the colon.) In this expression, the first occurrence of
q(X,Y) is syntactically a term, and the second is an atom. Thus treating (2) as an
abbreviation depends on the possibility of using the same symbol as a function and
as a predicate. This is customary in Prolog, but not in first-order logic, and this was
not allowed by Harrison et al. (2014).
Our goal is to define the syntax and semantics of the language AG (short for
Abstract Gringo)—a large subset of the input language of gringo that includes the
features mentioned previously and a few other constructs not described by Harrison
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
452 M. Gebser et al.
et al. (2014). This is similar to the work that has led to the definition of the ASP
Core language (Calimeri et al. 2012).2,3
The semantics of AG defined in this paper serves a specification for gringo from
Version 4.5 on. It can be used to prove the correctness of programs written in its
input language. As an example, in the electronic appendix we prove the correctness
of the program shown in Table 1.
AG is abstract in the sense that its definition disregards some details related to
representing programs by strings of ASCII characters. For example, semicolons are
used in the input language of gringo in at least three ways: to denote disjunction
in the head of a rule, conjunction in the body, and pooling within an atom. In AG,
three different symbols play these different roles. The richer alphabet of AG makes
it easier to define the semantics of the language and to reason about ASP programs.
2 Syntax of AG
2.1 Symbols and terms
We assume that five sets of symbols are selected: numerals, symbolic constants,
negated constants, variables, and aggregate names. We assume that a 1–1 corre-
spondence between the set of symbolic constants and the set of negated constants is
chosen. For every symbolic constant p, the corresponding negated constant will be
called its strong negation and denoted by p̃. Further, we assume that these sets do
not contain the symbols
+ − × / .. (3)
2 Syntactically, AG is essentially an extension of ASP Core. But it does not include extra-logical
constructs, such as weak constraints and queries. The semantics of aggregates in AG is based on the
approach of Ferraris (2005) and thus is not equivalent to the semantics of aggregates in ASP Core
when aggregates are used recursively in the presence of negation. Among the language constructs that
are not in ASP Core, in AG we find pooling, intervals, and conditional literals. (These constructs
originally appeared in the input language of lparse, but in AG they are more general; for instance,
interval bounds may contain variables, and restrictions to “domain predicates” have disappeared.)
Unlike ASP Core, AG supports aggregates in rule heads; see Section 3.
3 The definition of ASP Core does not refer to infinitary objects, such as infinitary propositional formulas
used in this paper. But it appears that infinitary objects of some kind will be required to correct the
oversight in (Calimeri et al. 2012, Section 2.2)—the set inst({e1 ; . . . ; en }), included in the body of a rule
in the process of instantiation, can be infinite.
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
Abstract gringo 453
symbolic constant starts with a lower-case letter. A negated constant starts with -
followed by a lower-case letter. A variable starts with an upper-case letter, and an
aggregate name starts with #. (The strings #false, #inf, and #sup, which represent
⊥, inf , and sup, also start with #.) The symbols and (which are used to indicate the
boundaries of a tuple within a term) correspond to the ASCII characters ( and ).4
Each of the symbols (3)–(7) except for ∧ and ∨ has a unique ASCII representation;
the symbols ∧ and ∨ can be represented by semicolons and in some cases also by
commas.
We assume that a 1–1 correspondence between the set of numerals and the set Z
of integers is chosen. For every integer n, the corresponding numeral will be denoted
by n.
Terms are defined recursively, as follows:
In a term of the form f() the parentheses can be dropped, so that every symbolic
constant can be viewed as a term. In a term of the form (t1 t2 ) we will drop the
parentheses when it should not lead to confusion. A term of the form (0 − t) can be
abbreviated as −t.
A term, or a tuple of terms, is precomputed if it contains neither variables nor
symbols (3). We assume a total order on precomputed terms such that inf is its least
element, sup is its greatest element, and, for any integers m and n, m 6 n iff m 6 n.
We assume that for each aggregate name α a function b α is chosen that maps every
set of tuples of precomputed terms to a precomputed term.6 The AG counterparts
of the aggregates implemented in Version 4.5 of gringo are defined below using
the following terminology. If the first member of a tuple t of precomputed terms is
a numeral n then we say that the integer n is the weight of t; if t is empty or its
first member is not an integer then the weight of t is 0. For any set T of tuples of
precomputed terms,
1
• count(T ) is the numeral corresponding to the cardinality of T if T is finite,
and sup otherwise;
b
• sum(T ) is the numeral corresponding to the sum of the weights of all tuples
in T if T contains finitely many tuples with non-zero weights, and 0 otherwise;
1
• sum+(T ) is the numeral corresponding to the sum of the weights of all tuples
in T whose weights are positive if T contains finitely many such tuples, and
sup otherwise;
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
454 M. Gebser et al.
b
• min(T ) is sup if T is empty, the least element of the set consisting of the first
elements of the tuples in T if T is a finite non-empty set, and inf if T is
infinite;
b
• max (T ) is inf if T is empty, the greatest element of the set consisting of the
first elements of the tuples in T if T is a finite non-empty set, and sup if T is
infinite.
α{t1 : L1 ; . . . ; tn : Ln } ≺ s (9)
s ≺ α{t1 : L1 ; . . . ; tn : Ln } (10)
s1 ≺1 α{t1 : L1 ; . . . ; tn : Ln } ≺2 s2 (11)
• α is an aggregate name,
• each ti is a tuple of terms,
• each Li is a tuple of symbolic or arithmetic literals (if Li is empty and ti is
nonempty then the preceding colon may be dropped),
• each of ≺, ≺1 , ≺2 is one of the symbols (5),
• each of s, s1 , s2 is a term.
7 This form of pooling is less general than what is allowed in the input language of gringo. For instance,
f(a; b) is neither a term nor a pool.
8 Semantically, the status of “double negations” in AG is the same as in logic programs with nested
expressions (Lifschitz et al. 1999), where conjunction, disjunction, and negation can be nested arbitrarily.
Dropping a double negation may change the meaning of a rule. For instance, the one-rule program
p ← not not p has two stable models ∅, {p} (see Section 4.1); the latter will disappear if we drop
not not.
9 In the input language of gringo, dropping the colon when L is empty is required.
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
Abstract gringo 455
For any aggregate atom A, the strings (8) are aggregate literals.
A literal is a conditional literal or an aggregate literal.
A choice expression is a string of the form {A} where A is an atom.
3 Abbreviations
Let C be an expression of the form
s1 ≺1 α{t1 : L1 : L1 ; . . . ; tn : Ln : Ln } ≺2 s2 (14)
(n > 0), where each Li is a symbolic literal of one of the forms
p(t) not p(t) not not p(t) (15)
(p is a symbolic or negated constant and t is a tuple of terms) and α, ti , Li , ≺1 , ≺2 ,
s1 , and s2 are as in the definition of an aggregate atom. Then a string of the form
C ← B1 ∧ · · · ∧ Bm (16)
(m > 0), where each Bj is a literal, is shorthand for the set of rules consisting of the
rule
← B1 ∧ · · · ∧ Bm ∧ not s1 ≺1 α{t1 : L1 , L1 ; . . . ; tn : Ln , Ln } ≺2 s2 (17)
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
456 M. Gebser et al.
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
Abstract gringo 457
4 Semantics of AG
We will define the semantics of AG using a syntactic transformation τ. The function τ
converts rules into infinitary formulas formed from atoms of the form p(t) or p̃(t),
where p is a symbolic constant, and t is a tuple of precomputed terms. Then the
stable models of a program will be defined in terms of stable model semantics of
infinitary formulas in the sense of Truszczynski (2012), which is reviewed below.
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
458 M. Gebser et al.
• if t is t1 , . . . , tn then [t] is the set of terms r1 , . . . , rn for all r1 ∈ [t1 ], . . . ,
rn ∈ [tn ].
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
Abstract gringo 459
• τ∧ (t1 ≺ t2 ) is if the relation ≺ holds between the terms r1 and r2 for all
r1 ∈ [t1 ] and r2 ∈ [t2 ], and ⊥ otherwise;
• τ∨ (t1 ≺ t2 ) is if the relation ≺ holds between the terms r1 and r2 for some
r1 , r2 such that r1 ∈ [t1 ] and r2 ∈ [t2 ], and ⊥ otherwise.
13 This definition differs slightly from that given by Harrison et al. (2014, Section 3.3). There, substitutions
that yield symbolic constants in the scope of arithmetical operators do not form instances. In a similar
way, we treat variables in conditional literals and aggregate literals (Sections 4.6 and 4.7) differently
than how they are treated by Harrison et al. (2014).
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
460 M. Gebser et al.
For example, X is global in the rule R2 from Section 2.3, so that the instances of
R2 are rules of the form
← r = 1 .. n ∧ not count{Y : q(r, Y )} = 1
for all precomputed terms r. The variables X and Y are global in R4 ; instances of
R4 are
d1 (r, s, r − s + n) ← r = 1 .. n ∧ s = 1 .. n
for all precomputed terms r and s.
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
Abstract gringo 461
5 Simplifying τΠ
When we investigate the stable models of an AG program, it is often useful
to simplify the formulas obtained by applying transformation τ to its rules. By
simplifying an infinitary propositional formula we mean turning it into a strongly
equivalent formula that has simpler syntactic structure. The definition of strong
equivalence, introduced by Lifschitz et al. (2001), is extended to infinitary formulas
by Harrison et al. (2015). Corollary 1 from that paper shows that the stable models
of an infinitary formula are not affected by simplifying its parts.
Proofs of the theorems stated in this section are outlined in the electronic appendix.
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
462 M. Gebser et al.
Theorem 3
For any closed aggregate atom E of the form
count{t1 : L1 ; . . . ; tn : Ln } 6 m
where m is an integer and each ti is interval-free, τE is strongly equivalent to
¬ τ∨ ((Li )xr i ). (24)
Δ⊆A (i,r)∈Δ
|[Δ]|=m+1
Without the assumption that each ti is interval-free the assertions of the theorems
would be incorrect. For instance, if E is count{1..2 : p} > 1 then τE is → p, and
(23) is ⊥.
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150
Abstract gringo 463
In the special (but common) case when E has the form count{x : L} > m, where
x is a tuple of variables and each variable occurring in L occurs also in x, the
condition |[Δ]| = m in (23) can be replaced by |Δ| = m. Indeed, in this case Δ and
[Δ] have the same cardinality because [Δ] is the set of tuples r of terms such that
(1, r) ∈ Δ. Similarly, the condition |[Δ]| = m+1 in (24) can be replaced by |Δ| = m+1
if E has the form count{x : L} 6 m.
6 Conclusion
We proposed a definition of stable models for programs in the language AG and
stated a few theorems that facilitate reasoning about them. This definition can be
viewed as a specification for the answer set system clingo (see Footnote 1) and
other systems with the same input language. If such a system terminates given the
ASCII representation of an AG program Π as input, and produces neither error
messages nor warnings, then its output is expected to represent the stable models
of Π.
Acknowledgements
We are grateful to the anonymous referees for useful comments.
References
Calimeri, F., Faber, W., Gebser, M., Ianni, G., Kaminski, R., Krennwallner, T., Leone,
N., Ricca, F. and Schaub, T. 2012. ASP-Core-2: Input language format. Available at
https://www.mat.unical.it/aspcomp2013/files/ASP-CORE-2.0.pdf.
Ferraris, P. 2005. Answer sets for propositional theories. In Proceedings of International
Conference on Logic Programming and Nonmonotonic Reasoning (LPNMR). 119–131.
Ferraris, P. and Lifschitz, V. 2005. Weight constraints as nested expressions. Theory and
Practice of Logic Programming 5, 1–2, 45–74.
Gebser, M., Kaminski, R., Kaufmann, B. and Schaub, T. 2011. Challenges in answer
set solving. In Logic programming, knowledge representation, and nonmonotonic reasoning.
Springer, 74–90.
Harrison, A., Lifschitz, V., Pearce, D. and Valverde, A. 2015. Infinitary equilibrium logic
and strong equivalence. In Proceedings of International Conference on Logic Programming
and Nonmonotonic Reasoning (LPNMR). http://www.cs.utexas.edu/users/vl/
papers/iel lpnmr.pdf; to appear.
Harrison, A., Lifschitz, V. and Yang, F. 2014. The semantics of Gringo and
infinitary propositional formulas. In Proceedings of International Conference on Principles
of Knowledge Representation and Reasoning (KR).
Lifschitz, V., Pearce, D. and Valverde, A. 2001. Strongly equivalent logic programs. ACM
Transactions on Computational Logic 2, 526–541.
Lifschitz, V., Tang, L. R. and Turner, H. 1999. Nested expressions in logic programs. Annals
of Mathematics and Artificial Intelligence 25, 369–389.
Truszczynski, M. 2012. Connecting first-order ASP and the logic FO(ID) through reducts.
In Correct Reasoning: Essays on Logic-Based AI in Honor of Vladimir Lifschitz, E. Erdem,
J. Lee, Y. Lierler, and D. Pearce, Eds. Springer, 543–559.
Downloaded from https://www.cambridge.org/core. SuUB Bremen, on 23 Oct 2020 at 07:45:18, subject to the Cambridge Core terms of use, available at
https://www.cambridge.org/core/terms. https://doi.org/10.1017/S1471068415000150