0% found this document useful (0 votes)
3 views15 pages

Abstract Gringo

This paper aims to define the syntax and semantics of the input language of the ASP grounder gringo in a more comprehensive way than previous work. It covers additional constructs like integer intervals, pooling, different types of aggregates, and arithmetic expressions. The definition serves to formally specify the current version of gringo and address limitations of prior semantic characterizations that excluded these features.

Uploaded by

payam habiby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views15 pages

Abstract Gringo

This paper aims to define the syntax and semantics of the input language of the ASP grounder gringo in a more comprehensive way than previous work. It covers additional constructs like integer intervals, pooling, different types of aggregates, and arithmetic expressions. The definition serves to formally specify the current version of gringo and address limitations of prior semantic characterizations that excluded these features.

Uploaded by

payam habiby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

TLP 15 (4–5): 449–463, 2015.


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])

submitted 29 April 2015; revised 3 July 2015; accepted 15 July 2015

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.

Table 1. An ASP solution to the n-queens problem.

% place queens on the chess board


{ q(1..n,1..n) }.

% exactly 1 queen per row/column


:- X = 1..n, not #count{ Y : q(X,Y) } = 1.
:- Y = 1..n, not #count{ X : q(X,Y) } = 1.

% pre-calculate the diagonals


d1(X,Y,X-Y+n) :- X = 1..n, Y = 1..n.
d2(X,Y,X+Y-1) :- X = 1..n, Y = 1..n.

% at most one queen per diagonal


:- D = 1..n*2-1, 2 { q(X,Y) : d1(X,Y,D) }.
:- D = 1..n*2-1, 2 { q(X,Y) : d2(X,Y,D) }.

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

Pooling is often used to abbreviate a set of facts. For instance, instead of

p(a,5). p(b,10). p(c,12).

we can write p(a,5;b,10;c,12). In this paper, we talk about “pools”—groups of


terms such as a,5;b,10;c,12.
Yet another limitation of the proposal from Harrison et al. (2014) is related to
the difference between “dlv-style” aggregates, such as

not #count{ Y : q(X,Y) } = 1 (1)

in the second rule of the program shown in Table 1, and “lparse-style” aggregates,
such as

2 { q(X,Y) : d2(X,Y,D) } (2)

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

2 <= #count{ q(X,Y) : q(X,Y), d2(X,Y,D) }.

(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)

inf sup (4)


= = < > 6 > (5)
⊥ not ∧ ∨ ← (6)
, ; : ( ) { }  (7)
and that they are pairwise disjoint. All these symbols together form the alphabet of
AG, and AG rules will be defined as strings over this alphabet.
When a symbol is represented in ASCII, its type is determined by its first two
characters. For instance, a numeral starts with a digit or - followed by a digit. A

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:

• all numerals, symbolic constants, and variables are terms;


• if f is a symbolic constant and t is a tuple5 of terms then f(t) is a term;
• if t1 and t2 are terms and  is one of the symbols (3) then (t1  t2 ) is a term;
• if t is a tuple of terms then t is a term.

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;

4 When an AG term representing a tuple of length 1, such as a , is represented in ASCII, a comma is


appended to the tuple: (a,) .
5 In this paper, when we refer to a tuple of syntactic objects, we mean that the tuple may be empty and
that its members are separated by commas.
6 This understanding of bα is different from that given by Harrison et al. (2014, Section 3.3). There, b
α is
understood as a function that maps tuples of precomputed terms to elements of Z ∪ {∞, −∞}.

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.

2.2 Atoms, literals, and choice expressions


A pool is an expression of the form t1 ; . . . ; tn where n > 1 and each ti is a tuple of
terms.7 In particular, every tuple of terms is a pool.
An atom is a string of one of the forms p(P ), p̃(P ) where p is a symbolic constant
and P is a pool. In an atom of the form p() or p̃() the parentheses can be dropped,
so that all symbolic constants and all negated constants can be viewed as atoms.
For any atom A, the strings

A not A not not A (8)

are symbolic literals.8 An arithmetic literal is a string of the form t1 ≺ t2 where t1 , t2


are terms and ≺ is one of the symbols (5).
A conditional literal is a string of the form H : L where H is a symbolic or
arithmetic literal or the symbol ⊥ and L is a tuple of symbolic or arithmetic literals.
If L is empty then we will drop the colon, so that every symbolic or arithmetic literal
can be viewed as a conditional literal.9
An aggregate atom is a string of one of the forms

α{t1 : L1 ; . . . ; tn : Ln } ≺ s (9)
s ≺ α{t1 : L1 ; . . . ; tn : Ln } (10)
s1 ≺1 α{t1 : L1 ; . . . ; tn : Ln } ≺2 s2 (11)

(n > 0), where

• α 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.

2.3 Rules and programs


A rule is a string of the form
H1 ∨ · · · ∨ Hk ← B1 ∧ · · · ∧ Bm (12)
or of the form
C ← B1 ∧ · · · ∧ Bm (13)
(k, m > 0), where each Hi is a symbolic or arithmetic literal, C is a choice 10

expression, and each Bj is a literal. The expression B1 ∧ · · · ∧ Bm is the body of the


rule; H1 ∨ · · · ∨ Hk is the head of (12); C is the head of (13). If the body of a rule is
empty and the head is not then the arrow can be dropped.
For instance, here are the first five rules of the program from Table 1 written in
the syntax of AG:
R1 : { q(1 .. n, 1 .. n) },
R2 : ← X = 1 .. n ∧ not count{Y : q(X, Y )} = 1,
R3 : ← Y = 1 .. n ∧ not count{X : q(X, Y )} = 1,
R4 : d1 (X, Y , X − Y + n) ← X = 1 .. n ∧ Y = 1 .. n,
R5 : d2 (X, Y , X + Y − 1) ← X = 1 .. n ∧ Y = 1 .. n.
The other two rules use abbreviations introduced in the next section.
A program is a finite set of rules.

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)

10 In the input language of gringo, Hi may be any conditional literal.

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.

and, for each Li in (14) such that Li is an atom, the rule


{Li } ← B1 ∧ · · · ∧ Bm ∧ Ci (18)
where Ci is the conjunction of the members of Li .
In both (17) and (18), the conjunction sign shown after Bm should be dropped if
m = 0; in (18) it should also be dropped if Ci is empty. The parts s1 ≺1 and ≺2 s2 in
(14) are optional; if one of them is missing then it is dropped from (17) as well; if
both are missing then rule (17) is dropped from the set altogether. If m = 0 in (16)
then the arrow can be dropped.
The term representations of literals (15) are the tuples
0, p(t) 1, p(t) 2, p(t)
of terms. (Each of them is indeed a tuple of terms, because p(t) can be viewed as a
term.)
Also viewed as an abbreviation is any expression of the form
s1 {L1 : L1 ; . . . ; Ln : Ln } s2 (19)
(n > 0), where s1 , s2 are terms, each Li is a symbolic literal of one of the forms (15)
that does not contain .. , and each Li is a tuple of symbolic or arithmetic literals.11
Such an expression is understood differently depending on whether it occurs in the
head or the body of a rule. In the head of a rule, (19) is understood as shorthand
for an expression of the form (14):
s1 6 count{t1 : L1 : L1 ; . . . ; tn : Ln : Ln } 6 s2 (20)
where ti is the term representation of Li . If either or both of the terms s1 , s2
are missing, the abbreviation is understood in a similar way. (Note that choice
expressions that do not contain .. are expressions of the form (19) where both s1
and s2 are missing, n = 1, L1 is of the form p(t), and L1 is empty. In this case, we
do not view (19) as an abbreviation.)
In the body of a rule (19) is understood as shorthand for the aggregate atom
s1 6 count{t1 : L1 , L1 ; . . . ; tn : Ln , Ln } 6 s2
where ti is the term representation of Li .12 If either of the terms s1 , s2 in (19) is
missing, the abbreviation is understood in a similar way.
These abbreviations can be used, for instance, to represent the last two rules of
the program from Table 1 in the syntax of AG:
← D = 1 .. n ∗ 2 − 1 ∧ 2 {q(X, Y ) : d1(X, Y , D)},
← D = 1 .. n ∗ 2 − 1 ∧ 2 {q(X, Y ) : d2(X, Y , D)}.
Written out in full, these expressions become
R6 : ← D = 1 .. n ∗ 2 − 1 ∧ 2 6 count{0, q(X, Y ) : q(X, Y ), d1(X, Y , D)},
R7 : ← D = 1 .. n ∗ 2 − 1 ∧ 2 6 count{0, q(X, Y ) : q(X, Y ), d2(X, Y , D)}.

11 To be precise, if Li is empty then the colon after Li is dropped.


12 If Li is empty then the comma after Li in this expression should be dropped.

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.

4.1 Review: infinitary propositional formulas


Let σ be a propositional signature, that is, a set of propositional atoms. The sets
F0 , F1 , . . . are defined as follows:
• F0 = σ,
• Fi+1 is obtained from Fi by adding expressions H∧ and H∨ for all subsets
H of Fi , and expressions F → G for all F, G ∈ Fi .

The elements of ∞ i=0 Fi are called (infinitary) formulas over σ.
In an infinitary formula, the symbols  and ⊥ are understood as abbreviations
for ∅∧ and ∅∨ respectively; ¬F stands for F → ⊥, and F ↔ G stands for
(F → G) ∧ (G → F).
Subsets of a signature σ will also be called its interpretations. The satisfaction
relation between an interpretation and a formula is defined recursively as follows:
• For every atom p from σ, I |= p if p ∈ I.
• I |= H∧ if for every formula F in H, I |= F.
• I |= H∨ if there is a formula F in H such that I |= F.
• I |= F → G if I |= F or I |= G.
We say that an interpretation satisfies a set H of formulas, or is a model of H, if
it satisfies every formula in H. Two sets of formulas are equivalent if they have the
same models.
The reduct F I of a formula F w.r.t. an interpretation I is defined as follows:
• For p ∈ σ, pI = ⊥ if I |= p; otherwise pI = p.
• (H∧ )I = {GI | G ∈ H}∧ .
• (H∨ )I = {GI | G ∈ H}∨ .
• (G → H)I = ⊥ if I |= G → H; otherwise (G → H)I = GI → H I .
An interpretation I is a stable model of a set H of formulas if it is minimal w.r.t. set
inclusion among the interpretations satisfying the reducts of all formulas from H.
For instance, if I = ∅ then
(¬¬p → p)I = (¬¬p)I → pI = ⊥ → ⊥;
if I = {p} then
(¬¬p → p)I = (¬¬p)I → pI = ¬(¬p)I → p = ¬⊥ → p.
In both cases, I is a minimal model of the reduct. Consequently, both ∅ and {p} are
stable models of {¬¬p → p}.

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.

4.2 Semantics of terms and pools


A term is ground if it does not contain variables. The definition of “ground”
for pools, symbolic literals, and arithmetic literals is the same. Semantically, every
ground term t represents a finite set of precomputed terms [t], which is defined
recursively:

• if t is a numeral or a symbolic constant then [t] is {t};


• if t is f(t1 , . . . , tn ) then [t] is the set of terms f(r1 , . . . , rn ) for all r1 ∈ [t1 ], . . . ,
rn ∈ [tn ];
• if t is (t1 + t2 ) then [t] is the set of numerals n1 + n2 for all integers n1 , n2 such
that n1 ∈ [t1 ] and n2 ∈ [t2 ]; similarly when t is (t1 − t2 ) or (t1 × t2 );
• if t is (t1 /t2 ) then [t] is the set of numerals n1 /n2  for all integers n1 , n2 such
that n1 ∈ [t1 ], n2 ∈ [t2 ], and n2 = 0;
• if t is (t1 .. t2 ) then [t] is the set of numerals m for all integers m such that, for
some integers n1 , n2 ,
n1 ∈ [t1 ], n2 ∈ [t2 ], n1 6 m 6 n2 ;

• if t is t1 , . . . , tn then [t] is the set of terms r1 , . . . , rn for all r1 ∈ [t1 ], . . . ,
rn ∈ [tn ].

This definition is extended to an arbitrary ground pool P ; [P ] is a finite set of


precomputed tuples:

• if P is a tuple t1 , . . . , tn of terms (n = 1) then [P ] is the set of tuples r1 , . . . , rn


for all r1 ∈ [t1 ], . . . , rn ∈ [tn ];
• if P is a pool t1 ; . . . ; tn (n > 1) then [P ] is [t1 ] ∪ · · · ∪ [tn ].

For instance, [1..n, 1..n] is the set {i, j : 1 6 i, j 6 n}.


It is clear that if a ground term t contains neither symbolic constants nor the
symbols  and then every element of [t] is a numeral. If a tuple t of ground
terms is precomputed then [t] is {t}. The set [t] can be empty. For example,
[1..0] = [1/0] = [1 + a] = ∅.
About a tuple of terms that does not contain .. we say that it is interval-free. It is
clear that if a tuple t of ground terms is interval-free then the cardinality of the set
[t] is at most 1.

4.3 Semantics of arithmetic and symbolic literals


For any ground (symbolic or arithmetic) literal L we will define two translations, τ∧ L
and τ∨ L. The specific translation function applied to an occurrence of a symbolic
or arithmetic literal in a rule depends on the context, as we will see in the following
sections.
We will first consider symbolic literals. For any ground atom A,

• if A is p(P ) then τ∧ A is the conjunction of atoms p(t) over all tuples t in [P ],


and τ∨ A is the disjunction of these atoms;

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

• if A is p̃(P ) then τ∧ A is the conjunction of atoms p̃(t) over all tuples t in [P ],


and τ∨ A is the disjunction of these atoms;
• τ∧ (not A) is ¬τ∨ A, and τ∨ (not A) is ¬τ∧ A;
• τ∧ (not not A) is ¬¬τ∧ A, and τ∨ (not not A) is ¬¬τ∨ A.

The definitions of τ∧ and τ∨ for arithmetic literals are as follows:

• τ∧ (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.

For instance, τ∨ p(2..4) is p(2) ∨ p(3) ∨ p(4), and τ∨ (2 = 2..4) is .


For any tuple L of ground literals, τ∨ L stands for the conjunction of the formulas
τ∨ L for all members L of L. The expressions τ∧ ⊥ and τ∨ ⊥ both stand for ⊥.
It is clear that if A has the form p(t) or p̃(t), where t is a tuple of precomputed
terms, then each of the formulas τ∧ A and τ∨ A is A.

4.4 Semantics of choice expressions


The result of applying τ to a choice expression {p(P )} is the conjunction of the
formulas p(t) ∨ ¬p(t) over all tuples t in [P ]. Similarly, the result of applying τ to
a choice expression {p̃(P )} is the conjunction of the formulas p̃(t) ∨ ¬p̃(t) over all
tuples t in [P ].
For instance, the result of applying τ to rule R1 (see Section 2.3) is
  
q(i, j) ∨ ¬q(i, j) . (21)
16i,j6n

4.5 Global variables


About a variable we say that it is global

• in a conditional literal H : L, if it occurs in H but does not occur in L;


• in an aggregate literal A, not A, or not notA, where A is of one of the
forms (9)–(11), if it occurs in s, s1 , or s2 ;
• in a rule (12), if it is global in at least one of the expressions Hi , Bj ;
• in a rule (13), if it occurs in C or is global in at least one of the expressions Bj .

An instance of a rule R is any rule that can be obtained from R by substituting


precomputed terms for all global variables.13 A literal or a rule is closed if it has no
global variables. It is clear that any instance of a rule is closed.

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.

4.6 Semantics of conditional literals


If t is a term, x is a tuple of distinct variables, and r is a tuple of terms of the same
length as x, then the term obtained from t by substituting r for x will be denoted by
txr . Similar notation will be used for the result of substituting r for x in expressions
of other kinds, such as literals and tuples of literals.
The result of applying τ to a closed conditional literal H : L is the conjunction of
the formulas
τ∨ (Lxr ) → τ∨ (Hrx )
where x is the list of variables occurring in H : L, over all tuples r of precomputed
terms of the same length as x.
For instance, the result of applying τ to the arithmetic literal r = 1..n, where r is
a precomputed term, is τ∨ () → τ∨ (r = 1..n), where  is the tuple of length 0. The
antecedent of this implication is . The consequent is  if r is one of the numerals
1, . . . , n and ⊥ otherwise.

4.7 Semantics of aggregate literals


In this section, the semantics of ground aggregates proposed by Ferraris (2005,
Section 4.1) is adapted to closed aggregate literals. Let E be a closed aggregate atom
of one of the forms (9)–(11), and let xi be the list of variables occurring in ti : Li
(1 6 i 6 n). By Ai we denote the set of tuples r of precomputed terms of the same
length as xi . By A we denote the set {(i, r) : i ∈ {1, . . . , n}, r ∈ Ai }.
Let Δ be a subset of A. Then by [Δ] we denote the union of the sets [(ti )xr i ] for all
pairs (i, r) ∈ Δ. We say that Δ justifies E if
• E is of the form (9) and the relation ≺ holds between bα[Δ] and t for at least
one precomputed term t ∈ [s], or
• E is of the form (10) and the relation ≺ holds between t and b
α[Δ] for at least
one precomputed term t ∈ [s], or
• E is of the form (11), the relation ≺1 holds between t1 and bα[Δ] for at least
one precomputed term t1 ∈ [s1 ], and the relation ≺2 holds between bα[Δ] and
t2 for at least one precomputed term t2 ∈ [s2 ].
We define τE as the conjunction of the implications
 
τ∨ ((Li )xr i ) → τ∨ ((Li )xr i ) (22)
(i,r)∈Δ (i,r)∈A\Δ

over all sets Δ that do not justify E.

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

For instance, if E is count{p(X) : p(X)} > 0 then τE is the implication expressing


that p(r) holds for at least one precomputed term r:

 → p(r).
r

If L is an aggregate literal of the form not E where E is an aggregate atom then


τL is ¬τE; if L is of the form not not E then τL is ¬¬τE.

4.8 Semantics of rules and programs


For any rule R of form (12), τR stands for the set of the formulas
τB1 ∧ · · · ∧ τBm → τ∧ H1 ∨ · · · ∨ τ∧ Hk
for all instances (12) of R. For a rule of form (13), τR stands for the set of the
formulas
τB1 ∧ · · · ∧ τBm → τC
for all instances (13) of R. For any program Π, τΠ stands for the union of the sets
τR for all rules R of Π.
A stable model of a program Π is any stable model of τΠ (in the sense of
Section 4.1) that does not contain any pair of atoms of the form p(t), p̃(t).

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.

5.1 Monotone and anti-monotone aggregate atoms


When a rule contains aggregate atoms, we can sometimes simplify the implica-
tions (22) in the corresponding infinitary formula using the theorems on monotone
and anti-monotone aggregates from Harrison et al. (2014, Section 6.1). The mono-
tonicity or non-monotonicity of an aggregate atom (9) can sometimes be established
simply by looking at its aggregate name α and its relation symbol ≺. If α is one
of the symbols count, sum+, max , then (9) is monotone when ≺ is < or 6, and
anti-monotone when ≺ is > or >. It is the other way around if α is min.
Our semantics of aggregates is somewhat different from that adopted by Harrison
et al. (2014, Section 3.5), as explained in Footnote 6 (and also in view of the
difference in the treatment of variables discussed in Footnote 13). Nevertheless, the
statements and proofs of the two theorems mentioned above remain essentially the
same in the framework of AG. The theorems show that the antecedent in (22) can

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.

be dropped if E is monotone, and that the consequent can be replaced by ⊥ if E is


anti-monotone. These simplifications produce strongly equivalent formulas.

5.2 Eliminating equality from aggregate atoms


If ≺ in an aggregate atom (9) is = then the following proposition can be useful, in
combination with the facts reviewed in Section 5.1:
Theorem 1
Let E be a closed aggregate atom of the form
α{t1 : L1 ; . . . ; tn : Ln } = s,
where s is an interval-free term. If E6 is
α{t1 : L1 ; . . . ; tn : Ln } 6 s
and E> is
α{t1 : L1 ; . . . ; tn : Ln } > s,
then τE is strongly equivalent to τE6 ∧ τE> .
Without the assumption that s is interval-free the assertion of Theorem 1 would
be incorrect: if E is count{a : p} = (0..1) × 2 then τE is p → ⊥, but each of the
formulas τE6 , τE> is the empty conjunction .

5.3 Properties of counting


For any set S, by |S| we denote the cardinality of S if S is finite, and ∞ otherwise.
Theorem 2
For any closed aggregate atom E of the form
count{t1 : L1 ; . . . ; tn : Ln } > m
where m is an integer and each ti is interval-free, τE is strongly equivalent to
 
τ∨ ((Li )xr i ). (23)
Δ⊆A (i,r)∈Δ
|[Δ]|=m

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

You might also like