<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Answer Set Application Programming: a Case Study on Tetris</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>PETER SCH ULLER</string-name>
          <email>P@next</email>
          <email>peter.schuller@marmara.edu.tr</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Computer Engineering, Faculty of Engineering, Marmara University</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Institute of Information Systems</institution>
          ,
          <addr-line>TU Wien</addr-line>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2015</year>
      </pub-date>
      <history>
        <date date-type="accepted">
          <day>5</day>
          <month>6</month>
          <year>2015</year>
        </date>
      </history>
      <abstract>
        <p>Answer-Set Programming (ASP) is a successful branch of the logic programming paradigm with many applications in modelling and solving of NP-hard problems. Combinatorial problems are the main application domain of ASP and it seems unsuitable for serving as a programming language for interactive applications. However, we conjecture that there is no theoretical obstacle for using ASP to that end. As witnessed by functional programming, it can be useful to use a declarative paradigm for creating applications. In this work we explore possibilities, bene ts, and drawbacks, of programming an interactive application in ASP. We nd that this is hard mainly for the following reasons: managing change over time, interaction with the user, generating output that is ordered (i.e., not a set), handling persistence of certain data, and ensuring e ciency. ASP and related elds provide powerful techniques for representing actions and change, executing programs with respect to external environments, and processing external events. Even if the full power of these techniques is not required to build an interactive application, combining them is necessary, and putting together these concepts in a practical framework is challenging. We realize such an integration in a framework we call Answer Set Application Programming framework which is based on the HEX language and features syntactic shortcuts to make application programming more intuitive. We describe design decisions and discuss alternative possibilities. Our sample application is a playable version of Tetris which demonstrates that ASP can be used as a general-purpose programming-language.</p>
      </abstract>
      <kwd-group>
        <kwd>Answer-Set Programming</kwd>
        <kwd>Programming Techniques</kwd>
        <kwd>Knowledge Representation</kwd>
        <kwd>Software Engineering</kwd>
        <kwd>Nonmonotonic Reasoning</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Introduction</title>
      <p>Answer-Set Programming (ASP) is a successful approach for modelling and
solving NP-hard problems. We propose a framework for general-purpose
applicationprogramming based on ASP and realize Tetris as a case study.</p>
      <p>Using ASP instead of imperative languages like Java would likely be met with
skepticism. We think this is mainly due to the following reasons: rstly, ASP is
lacking features such as input/output facilities and programming libraries; secondly,
Prolog aimed for the same but it set a negative example since it forced programmers
to think in terms of the evaluation underlying Prolog (e.g., using red cuts). The
resulting application programs cannot be understood in a declarative way since
their (temporal) behavior is based on the Prolog search/evaluation algorithm.</p>
      <p>We therefore consider it paramount to maintain declarativity when aiming to
broaden the scope of ASP. In this work we realize a small application, the game
Tetris, to investigate from a practicioner's perspective how far ASP can serve as a
basis for application programming. We identi ed several critical points: the
interaction of real time, logical time (steps) and state of a program, external e ects that
in uence ASP reasoning, and causing change in the outside world.</p>
      <p>We present a theoretical framework to achieve the above and we report on an
implementation of this framework. The feasibility of our approach is demonstrated
by ASPeTris, an interactive and playable implementation of Tetris which features
editing the player name, playing the game, interrupting and continuing a game
later, and a persistent high score list. Figure 1 shows two screenshots of ASPeTris.</p>
      <p>
        Our Answer-Set Application-Programming framework (ASAP) allows
declarative reasoning between two logical time points: the closest time point in the past
(called prev) and the closest time point in the future (called next). ASAP enables
interaction with the real world through external atoms and actions, similar as in
acthex
        <xref ref-type="bibr" rid="ref2">(Basol et al. 2010)</xref>
        . Program states that change over time are represented
by uents similar as in ASP planning
        <xref ref-type="bibr" rid="ref19">(Gelfond and Lifschitz 1993)</xref>
        . Logical time
next1
prev2
next2
Actions
      </p>
      <p>Idle</p>
      <sec id="sec-1-1">
        <title>Event</title>
        <p>ASP
&gt; &gt;
uents change
Actions</p>
      </sec>
      <sec id="sec-1-2">
        <title>Logical time</title>
        <p>initial = prev1
uents</p>
      </sec>
      <sec id="sec-1-3">
        <title>Event</title>
      </sec>
      <sec id="sec-1-4">
        <title>Real time ASP</title>
        <p>
          &gt; &gt;
uents change
and real time are coupled via events. An event, such as keyboard activity or a
timer, triggers evaluation of ASP semantics to determine the e ect of the event.
An ASAP program de nes the reaction of the application to an event in terms of
new uent values and actions to be executed as a consequence of the event, such
as drawing the user interface or starting a timer. Actions have an execution order
and ASAP provides speci c syntax for comfortably de ning that order. After
executing actions, the framework waits for arrival of the next event which triggers
evaluation of ASP semantics anew. Fluent inertia is realized using the encoding of
          <xref ref-type="bibr" rid="ref22">Lee et al. (2012)</xref>
          which yields a declarative management of changing program state
over time. ASP evaluation requires time itself, therefore we cannot guarantee that
events are handled immediately. However ASAP guarantees that events are handled
in exactly the order they occurred and as soon as possible after all previous events
have been evaluated, similar as in the Event Calculus
          <xref ref-type="bibr" rid="ref21">(Kowalski and Sergot 1986)</xref>
          .
        </p>
        <p>The conceptual view of time in ASAP is shown in Figure 2. Real time and logical
time are synchronized via the order of events. Reasoning is based on the previous
logical time point, and actions are executed after computing the next logical time
point. (Events that occur in the meantime are enqueued and processed later.)</p>
        <p>This paper contributes a framework for ASP application programming which
features the following concrete solutions: (i) inertial uents for declarative
reasoning about program state; (ii) event- and action-based interaction with the outside
world; (iii) a syntax to specify the execution order of actions; (iv) out-of-the box
persistence for selected uents; (v) a working prototype implementation of the
framework in hex and a playable version of Tetris.1 We found that Tetris is a
demanding application scenario which points to necessary improvements of ASP
syntax, software engineering tools, and solvers. At the same time our realization
of Tetris shows that the declarative nature of ASP can be exploited as a strength
in application programming. We believe that this work can be bene cial both for
application programming and for ASP.</p>
        <p>We give preliminaries in Section 2, discuss uents and time in Section 3, events in
Section 4, actions in Section 5, persistence and the overall framework in Section 6.
We discuss related work in Section 7 and conclude with Section 8.
1 Source code is available at https://bitbucket.org/peterschueller/asap-aspetris .</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>2 Preliminaries</title>
      <p>
        Answer Set Programming (ASP). We assume familiarity with ASP
        <xref ref-type="bibr" rid="ref13 ref16 ref18 ref24">(Gelfond
and Lifschitz 1988; Lifschitz 2008; Gebser et al. 2012)</xref>
        and give only brief preminaries
of logic programs with (uninterpreted) function symbols and aggregates and a brief
overview of hex. A logic program consists of rules of the form
1 _
_ k
1; : : : ; n; not n+1; : : : ; not
m
where i and i are head and body atoms, respectively. Atoms can contain
constants, variables, and function terms, and a program must allow for a nite
instantiation. Details of these restrictions and syntax/semantics of ASP are described
in the ASP-Core-2 standard
        <xref ref-type="bibr" rid="ref4">(Calimeri et al. 2012)</xref>
        of which we will mainly use
aggregates. An aggregate literal can occur in the body of a rule; it accumulates
truth values from a set of atoms, e.g., 2 = #count { X : p(X) } is true in an
answer set candidate I i the extension of p in I contains exactly 2 elements. hex
        <xref ref-type="bibr" rid="ref10 ref9">(Eiter et al. 2006; Eiter et al. 2015)</xref>
        extends ASP with external atoms of the form
&amp;atom[p1; : : : ; pn](q1; : : : ; qm) where atom is the name of the external atom, and
pi and qj are lists of input and output terms. We denote by AS(P; ff; f 0g) the
set of answer sets of a program P which is de ned using its Herbrand universe,
ground instantiation, the FLP-reduct
        <xref ref-type="bibr" rid="ref11">(Faber et al. 2011)</xref>
        which intuitively reduces
a program using assumptions in an answer set candidate, and oracle functions f , f 0
of form f&amp;atom (I; p1; : : : ; pn; q1; : : : ; qm) 2 f0; 1g to represent semantics of external
atoms. For example &amp;setminus [a; b](X) could have its oracle function de ned as
f&amp;setminus (I; a; b; X) = 1 for all X such that a(X) 2 I and b(X) 2= I.
Tetris. Tetris is played in a grid that is initially empty. A piece is a set of four stones
arranged such that they are connected by adjacency. Pieces are created randomly
and appear on the top center of the grid. They fall down with a certain speed that
increases with the score. The user can rotate pieces by 90 degree, or move them left
or right by one stone. If a piece hits the bottom or another stone then it becomes
xed and the next random piece starts to fall. If a grid row becomes lled, these
stones are removed, stones above move down by one row and the score increases.
The game ends when the new random piece hits stones before falling down.
      </p>
    </sec>
    <sec id="sec-3">
      <title>3 Application State and Time: Fluents</title>
      <p>
        Applications that interact with users are usually driven by the input from the user.
If the user clicks the menu button, the menu should appear, if the user clicks on exit,
the program stops, if the user gives no input, then the application should remain
in its current state (or the state evolves in a pre-de ned manner). Altogether, the
behaviour of an application is driven not only by a sequence of inputs but also
by the passage of time. Hence managing the change of state over time is one of
the most important concepts that distinguishes classical usage of ASP for solving
combinatorial problems from its usage for programming applications. Fortunately,
ASP has been applied to perform reasoning with time, in particular (i) in planning
(e.g.,
        <xref ref-type="bibr" rid="ref19">(Gelfond and Lifschitz 1993)</xref>
        ), where we reason about a hypothetical sequence
of possible future worlds; and (ii) in stream reasoning (e.g.,
        <xref ref-type="bibr" rid="ref13 ref16">(Gebser et al. 2012)</xref>
        ),
where we reason about a possibly in nite sequence of data.
      </p>
      <p>In an interactive application, reasoning is done on-line while the application is
running and while future input is not yet known, which is similar to stream
reasoning. At the same time, applications mostly have one deterministic future, and
running an application means to determine what changes from the present to the
future. This is similar to executing an action in planning and it also requires to
solve the frame problem, i.e., the problem of what does not change.</p>
      <p>
        We next combine notions of planning and stream reasoning to obtain a
declarative treatment of time and change in ASP applications. We use inertial uents
        <xref ref-type="bibr" rid="ref25">(McCarthy and Hayes 1969)</xref>
        for modelling the state of the application, and we
limit the number of situations of interest to just two: the closest point in the past,
and the closest point in the future. We call these two time points previous situation
and next situation. In the (real) time that passes between the previous and next
situation, we evaluate ASP semantics to determine what happens next. Events that
happened during evaluation are enqueued for later processing (see next section).
      </p>
      <p>To work with uents we de ne uent atoms that are of the form
#initially fluent=v
in the head of a rule, with fluent and v as above.</p>
      <sec id="sec-3-1">
        <title>Example 1</title>
        <p>The Tetris game area is de ned using a rule with an #initially head:
#initially area(X,Y)=empty :- xcoo(X), ycoo(Y).
where xcoo and ycoo represent x and y coordinates of the game area.</p>
        <p>The stones in a falling piece are represented in an atom fallingStone(X,Y,S)
with coordinates X and Y and stone of type S. If a piece cannot fall further, fixPiece
becomes true and the game area is changed to contain the stones of the falling piece:
area(X,Y)=S@next :- fixPiece, fallingStone(X,Y,S).</p>
        <p>All uents are inertial: if the value is not changed by any rule, it stays at
the value from the previous situation. This is realized by a rewriting to ordinary
ASP atoms and an inertia encoding inspired by existing ASP planning systems.
A uent fluent=v@prev is transformed into an atom val(fluent,v,1), similarly
fluent=v@next becomes val(fluent,v,0). The reserved predicate val is used
throughout the program to represent the values of uents, 1 denotes the
previous situation and 0 the next. We decided to use 0 and 1 in this way to allow a
straightforward extension for programs that need to look further into the past with
increasing integers, e.g., 2 would be the situation before 1.</p>
        <p>
          An initialization atom of form #initially fluent=v can only occur in the head
(1)
(2)
of a rule and is rewritten to ifluentinit(fluent,v). Initialization and inertia of
uents is handled by the following rules, inspired by
          <xref ref-type="bibr" rid="ref22">(Lee 2012)</xref>
          .
        </p>
        <p>sit(0). sit(1). prevsit(0).
ifluent(F) :- ifluentinit(F,_).
val(F,V,S+1) :- &amp;event[first], ifluentinit(F,V), prevsit(S). (5)
val(F,V,S+1) :- not &amp;event[first], &amp;prevval[F](V,S),</p>
        <p>prevsit(S), sit(S+1), ifluent(F).
val(F,V,0) :- not nval(F,V,0), val(F,V,1).
nval(F,V,0) :- not val(F,V,0), val(F,V,1).
:- 2 &lt;= #count { V : val(F,V,S) }, ifluent(F), sit(S).
:- 0 = #count { V : val(F,V,S) }, ifluent(F), sit(S).
(3)
(4)
(6)
(7)
(8)
(9)
(10)
Facts (3) de ne situations of interest: we can access the previous situation's uent
values with time point S=1 and in every evaluation of the program we consider two
situations: prev=1 and next=0 (see also Fig. 2). Rule (4) represents which uents
exist, (5) manages initialization where &amp;event[first] is true in the rst evaluation
of semantics (see Algorithm 1). External atom &amp;prevval[F](V,S) provides access
to the value of uent F in the answer set of the previous evaluation of the program.
If an evaluation yields a uent value at time point S, in the next evaluation this
uent value is provided as &amp;prevval[F](V,S) and shifted to time point S+1 using
(6). Inertia is realized using (7) and (8): a value in the past possibly remains like
that in the future, moreover (9) and (10) ensure that each uents has a single unique
value per situation. This encoding has the advantage that it does not require to
de ne a uent domain, which is particularly important for uents with a practically
in nite domain such as player names and highscores. The encoding relies on the
&amp;prevval[.](.,.) external atom to `remember' the history of uent values, i.e,
the values f=v@prev. Note that determining the next state f=v'@next with the
help of inertia is realized purely in ASP (without any outside machinery).</p>
        <p>Note that the above rules can handle an arbitrary amount of previous situations
by adding situations to the extension of sit and prevsit predicates in (3). In
ASPeTris we did not encounter a need for more than one previous situation.</p>
        <p>
          A natural question is whether all atoms in an ASP application should be uents.
Similar to the notion of the volatile part of a program in incremental answer set
programming
          <xref ref-type="bibr" rid="ref15">(Gebser et al. 2008)</xref>
          we decided to allow non- uent atoms that can
be used in reasoning but are not preserved among situations.
        </p>
        <p>
          In an interactive application we must forget past information, since every point
in time adds new atoms, meaning that eventually atoms with information about the
past occupy all available memory. This is mainly a practical issue which we solve by
using a xed window of size k = 2. Several more involved aspects of such reasoning
have been analyzed in stream-based reasoning
          <xref ref-type="bibr" rid="ref13 ref16 ref3">(Gebser et al. 2012; Beck et al. 2015)</xref>
          and these could be useful for applications, e.g., for deducing a maximum required
window size for certain atoms, or giving each predicate its own xed windows size.
        </p>
        <p>Regarding the future values of uents, one can model just the next point in time,
or several future steps. The latter may allow easier modelling but it is not strictly
necessary, since anything deduced for k steps in the future may be deduced at k 1
steps in the future by looking back k 1 steps into the past. We here consider a
minimal setting with a single future time point.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4 External Input: Events</title>
      <p>The ASP semantics of the application program are evaluated repeatedly. But how
often should the ASP program be evaluated? In principle, one could evaluate
immediately after evaluation of the previous time step nished. This realizes a busy-loop
which is easy to implement but wastes resources. We therefore decided to evaluate
the program only if some event occurred, e.g., a key press or an expired timer.</p>
      <p>Conceptually, the only thing happening between the previous and the next
situation is the evaluation of an ASP program to determine the future. This takes time
in practice, therefore a thread collects all events that happen during this time in
an event queue which preserves the order of events.</p>
      <p>Events are exposed to the application program through external atoms, so their
occurrence and the properties of an event can be obtained through hex as truth
values. For example, &amp;event["keyboard","special"]("Esc") becomes true if the
`Esc' key is pressed on the keyboard. Multiple events may be treated by the same
rules, for example &amp;event["keyboard","normal"](Key) becomes true if any
character or number key is pressed and the key is instantiated in the variable Key.</p>
      <sec id="sec-4-1">
        <title>Example 2</title>
        <p>Displaying the name of the player in uent player and editing that name is achieved
by the following short set of ASP rules,
#initially player="New Player".
player=New@next :- &amp;event["keyboard","normal"](Key),
player=Old@prev, &amp;concat[Old,Key](New).
(11)
(12)
(13)
(14)
where (11) declares the uent, (12) displays it, (13) appends a pressed key to the
uent's value, and (14) removes the last character if Backspace is pressed. The
required string operations are realized in external atoms &amp;concat and &amp;chop.</p>
        <p>An important design issue regarding events is the question whether one iteration
should handle a single or multiple events. Handling multiple events at once requires
to process them in a particular order or as if they happened simultaneously. The
former strategy means to represent multiple steps in one evaluation, which would
make application programs more complex. Moreover, we already handle multiple
time steps using repeated evaluation, hence this strategy would introduce
redundancy in the framework. The latter possibility creates additional complexity as
several events potentially compete for what should happen in the program, e.g., to
move the Tetris piece to the right and to the left simultaneously.</p>
        <p>While realizing ASPeTris we observed that handling only a single event at a time
greatly simpli es the application program and helps to avoid bugs. Moreover, in
case an event depends on complex conditions, one may be tempted to check these
conditions in the framework and outside of ASP. However, this makes the
interface between ASP and the outside world more complex and duplicates reasoning
facilities. We decided that the ASAP framework should provide only basic events,
whereas complex conditions are supposed to be represented in ASP.</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>5 Executing Actions</title>
      <p>The syntax of actions in our framework is inspired by acthex: an action is an atom
preceeded by @ and contains as the last argument a number which is called the
action's priority. For example, @exit(27,0) states that the program execution
shall end with return code 27 and that the action has priority 0, i.e., it shall be
executed as one of the rst actions. Multiple actions in an answer-set are executed
in ascending order of their last argument (ties are broken arbitrarily).</p>
      <p>Action ordering is especially important for drawing user interfaces: it makes a
big di erence whether a blue rectangle is drawn and then some red text, or if the
red text is drawn rst and then some blue rectangle (erasing the text).</p>
      <p>
        We observe from imperative languages that establishing the order in which
statements are executed is no problem at all: the execution order is given straight by the
order of statements in the input program. This implicit ordering based on the
sequence of statements in the code is missing in ASP, because of the guiding principle
of declarativity: to treat programs and many aspects of semantics as (unordered)
sets instead of lists. Because the order of actions is relevant in an application, having
the possibility of ordering actions comfortably makes programs more maintainable
and readable. In functional programming, Monads
        <xref ref-type="bibr" rid="ref28">(Wadler 1995)</xref>
        were introduced
to achieve an ordering of events within a declarative formalism. To the best of our
knowledge, such a mechanism does not exist in ASP.
      </p>
      <p>In the ASAP framework we therefore propose a minor syntactic addition, namely
code blocks enclosed by [ and ] brackets. Actions in these blocks are automatically
ordered in the same order as they appear in the source program, without the need to
explicitly specify their priorities. We consider this syntactic sugar for specifying an
order, although one might say this weakens declarativity. For example, the program
[
]
draws a main menu consisting of the headline \ASPeTris Game Menu", followed
by a newline, followed by the menu item \New Game".</p>
      <p>In practice we realize this implicit action priority using a rewriter which
transforms this into an ordinary hex program by removing the `@' symbol and adding to</p>
      <p>ASP</p>
      <sec id="sec-5-1">
        <title>Application</title>
      </sec>
      <sec id="sec-5-2">
        <title>Program</title>
      </sec>
      <sec id="sec-5-3">
        <title>Fluent</title>
      </sec>
      <sec id="sec-5-4">
        <title>Engine</title>
      </sec>
      <sec id="sec-5-5">
        <title>External</title>
      </sec>
      <sec id="sec-5-6">
        <title>Atoms</title>
      </sec>
      <sec id="sec-5-7">
        <title>Answer</title>
        <p>Set</p>
        <p>actions
uent values
previous uent values
events</p>
      </sec>
      <sec id="sec-5-8">
        <title>Action</title>
      </sec>
      <sec id="sec-5-9">
        <title>Execution</title>
      </sec>
      <sec id="sec-5-10">
        <title>Fluent</title>
      </sec>
      <sec id="sec-5-11">
        <title>Manager</title>
      </sec>
      <sec id="sec-5-12">
        <title>Persistence</title>
      </sec>
      <sec id="sec-5-13">
        <title>Event</title>
      </sec>
      <sec id="sec-5-14">
        <title>Queue</title>
      </sec>
      <sec id="sec-5-15">
        <title>Drawing</title>
      </sec>
      <sec id="sec-5-16">
        <title>Timers</title>
      </sec>
      <sec id="sec-5-17">
        <title>Python</title>
      </sec>
      <sec id="sec-5-18">
        <title>Engine</title>
      </sec>
      <sec id="sec-5-19">
        <title>User Actions</title>
      </sec>
      <sec id="sec-5-20">
        <title>OS Events Timers</title>
        <p>g
n
i
tra em
epO tsyS
each atom a priority argument. Actions that are not inside square brackets receive
priority 0, and if multiple square brackets occur, then the actions inside are ordered,
but no order is enforced across both brackets, e.g., [ @aa. @bb. ] [ @cc. @dd. ]
is rewritten to aa(0). bb(1). cc(0). dd(1). This guarantees that aa is executed
before bb as well as that cc is executed before dd, but enforces no further ordering.
Timers and Soft Events. In Tetris, pieces are falling from the top to the bottom
without any user interaction, so a timer is required to trigger evaluation of a new
situation. Timers are started using the action @startTimer(name,delay) where
name indicates an identi er for the timer and delay is an integer in milliseconds.
Timers produce events of the form &amp;event[timer](name) which trigger evaluation
of a new situation and can be handled like other events.</p>
        <p>In ASPeTris, when the falling piece stops and is xed in the game area we also
need to handle the elimination of full rows. This intuitively happens sequentially. To
perform both, xing the piece and eliminating full rows in one time step, requires
an extra copy of the gaming area, however. As an alternative, we introduce soft
events which create a new time step and cause immediate reevaluation of the ASP
program (bypassing all queued events). In our case this allows some separation of
concerns and makes the program easier to write and read (at the potential cost of
losing some declarativity).</p>
      </sec>
    </sec>
    <sec id="sec-6">
      <title>6 The Application Execution Framework</title>
      <p>An overview of the components of the ASAP framework is given in Figure 3, where
arrows indicate information ow. The ASPeTris game is implemented purely as
an ASP application program (top left component); the ASAP framework itself is
mainly implemented as a Python program (center components) that controls the
ASP evaluation and communicates with the operating system (right).</p>
      <p>In addition to the above features, the ASAP framework also provides facilities
for persistence, since this is an important topic for applications. Information is
persistent if it remains known to the application across runs.</p>
      <p>As we use uents in our framework, we chose to realize a selective persistence
for uents. A declaration of the form `#persistent name.' in the program causes
the code that takes care of &amp;prevval[.](.,.) to store those uents that match
10
11
12</p>
      <p>Algorithm 1: Core ASAP Algorithm.</p>
      <p>input: Answer Set Application Program P (after rewriting, including uent engine)
1 A fval(F lu,V al,0) j (F lu; V al) in persistent storage on disk g // can be ;
2 f&amp;event f(first) 7! 1g // initial event
repeat
4 f&amp;prevval f(F lu; V al; 0) 7! 1 j val(F lu,V al,0) 2 Ag
5 S AS(P; ff&amp;prevval ; f&amp;event g) // evaluate ASP application program
if S 6= fA0 g then return "Error: zero or more than one answer set found."
if @exit 2 A0 then return "Application nished."
Execute actions in A0 ordered by their last argument.</p>
      <p>Store to disk: f(F lu; V al) j val(F lu,V al,0) 2 A0 and F lu is #persistent g
Ev next event in queue // waits for next event if queue is empty
f&amp;event f(Ev) 7! 1g</p>
      <p>A A0
forever
name to disk. The name matches if it matches the complete uent name, or if the
uent name is a function term and the name matches the outermost function (for
example `#persistent area.' makes all area(X,Y) uents persistent).</p>
      <p>To restore a serialized state, the ASAP framework initializes &amp;prevval[.](.,.)
with the stored uent values. In the rst situation uents are then initialized using
these previous values and if none is available, the #initial value of the uent is
taken. The following rules achieve this when we use them instead of (5).
prevFluent(F) :- &amp;event[first], ifluent(F), &amp;prevval[F](V,0).
val(F,V,1) :- &amp;event[first], prevFluent(F), &amp;prevval[F](V,0).
val(F,V,1) :- &amp;event[first], not prevFluent(F),
ifluentinit(F,V), ifluent(F).
(15)</p>
      <p>In ASPeTris we found it useful to make only selected uents persistent. For
example the highscore list and the player name are persistently stored, however,
the currently active menu item is not persistent (otherwise starting the game would
always select `exit' from the previous run).</p>
      <p>This notion of persistence makes it signi cantly easier to return to previous states
of the application compared with imperative programming. In ASPeTris, simply by
adding persistence of the game eld and the score and falling stones, we realized
a `Continue Game' functionality. Note that we do not require explicit reading or
writing of persistence, although using actions to that end might improve e ciency.
Evaluation Algorithm. The core behaviour of the ASAP framework is given by
Algorithm 1. Line 1 loads persistent uent values from disk. Line 2 prepares the
initial event which causes loading persistence or falling back to initialization values
in the rst iteration of the loop using encoding (15).</p>
      <p>
        In the loop, line 4 con gures &amp;prevval[.](.,.) to provide uent values in A to
the next evaluation of P . Line 5 evaluates the program with respect to the prepared
oracle functions for external atoms. We ensure that there is a single answer set (this
check could be replaced by mechanisms for selecting a preferred single answer set
as described in
        <xref ref-type="bibr" rid="ref12">(Fink et al. 2013)</xref>
        ). After executing actions from answer set A0 and
storing persistent uent values to disk, line 10 obtains the next event from the
queue. If no event is in the queue, this step waits for an event to become available.
Line 11 prepares the oracle function of &amp;event[.](.) for the next iteration and
line 12 stores the answer set as the basis for the next iteration where it will be
communicated to the hex program via line 4. The algorithm loops inde nitely
until the ASP application program yields an @exit action or an error occurs. Note
that other external atoms (such as &amp;concat) can be used but we do not show them
as they are not speci c to the ASAP framework.
      </p>
    </sec>
    <sec id="sec-7">
      <title>7 Related Work</title>
      <p>This work is related to several important papers in the areas of planning and
interacting with an (in nitely) changing world. Therefore we will only give a brief
discussion of some important related work.</p>
      <p>
        Our framework manages program state as uents and situations as already
described by
        <xref ref-type="bibr" rid="ref25">McCarthy and Hayes (1969)</xref>
        . Planning with ASP was analyzed in several
projects, for example
        <xref ref-type="bibr" rid="ref19 ref22 ref23 ref8">(Gelfond and Lifschitz 1993; Eiter et al. 2004; Lifschitz 2002;
Lee 2012)</xref>
        (we realize uent inertia based on the last of these papers). Our
framework preserves the order of events but not their absolute time, which is similar to
one of the guiding principles of the Event Calculus
        <xref ref-type="bibr" rid="ref21">(Kowalski and Sergot 1986)</xref>
        .
      </p>
      <p>
        The acthex formalism
        <xref ref-type="bibr" rid="ref12 ref2">(Basol et al. 2010; Fink et al. 2013)</xref>
        extends hex with
actions and an environment. Actions are extracted from answer sets similar as in our
framework, however acthex immediately repeats semantic evaluation after
executing actions, until no more actions are generated. Actions in our framework can have
implicit execution order using the [ ] notation, while in acthex an explicit
assignment of priorities is required. The acthex formalism is designed for programs that
act in the world, driven by their own actions. Di erent from that, our framework is
driven by outside events and can remain idle between subsequent semantic
evaluations. Another di erence is that our framework includes mechanisms for managing
inertia and persistence (which requires additional work in acthex).
      </p>
      <p>
        The oClingo framework and reactive ASP
        <xref ref-type="bibr" rid="ref14">(Gebser et al. 2011)</xref>
        deal with ASP
in the context of reacting to external events. To that end an incremental solving
approach was de ned which has a performance advantage over repeated complete
re-evaluation (as done in our framework). Partial incremental evaluation comes
at the price of a modularity condition
        <xref ref-type="bibr" rid="ref26">(Oikarinen and Janhunen 2006)</xref>
        that makes
programming cumbersome. As a result, Online Agent Logic Programming
        <xref ref-type="bibr" rid="ref6">(Cerexhe
et al. 2014)</xref>
        was de ned to satisfy modularity automatically at the cost of restricting
use of negation. In ASPeTris we consider e ciency to be future work and
concentrate on ease of use. Clingo-4
        <xref ref-type="bibr" rid="ref17 ref6">(Gebser et al. 2014)</xref>
        allows to control grounding and
solving using Python. We decided to allow Python and nondeclarative code only
within the boundaries of our framework, i.e., to realize actions and external atoms.
We believe this helps to maintain declarativity and provides su cient exibility
for creating applications. Realizing ASAP in Clingo-4 is possible, but requires to
change the program at each time point (e.g., realizing (11)-(14) for editing the
player name in Clingo-4 is challenging). hex as a foundation has the advantage
that the same program is used for all time points, only oracle functions of external
atoms change (see Alg. 1).
      </p>
      <p>
        Stream reasoning
        <xref ref-type="bibr" rid="ref13 ref16 ref3">(Gebser et al. 2012; Beck et al. 2015)</xref>
        focuses on processing
continuous data streams with ASP; the main issue is to limit the amount of data
being processed. The ASAP framework discards all historical information beyond
the previous state, while stream reasoning uses more sophisticated techniques.
      </p>
      <p>
        Dedalus
        <xref ref-type="bibr" rid="ref1">(Alvaro et al. 2011)</xref>
        is a Datalog framework for modeling distributed,
asynchronous systems, where each atom obtains an additional time argument. Rules
can de ne truth within a timepoint or one timepoint into the future.
      </p>
      <p>
        Di erent from ASPeTris, most ASP research related to games focuses on
combinatorial problems of generating new game instances
        <xref ref-type="bibr" rid="ref27">(Smith and Mateas 2011)</xref>
        or
solving existing instances
        <xref ref-type="bibr" rid="ref5 ref7">(Denecker et al. 2009; Calimeri et al. 2014)</xref>
        .
      </p>
    </sec>
    <sec id="sec-8">
      <title>8 Conclusion and Future Work</title>
      <p>In this paper we showed that ASP can be used for application programming, an
area with many potential applications. We took inspirations from several existing
areas of ASP and related areas and developed the ASAP framework which captures
application programming and time-dependent interaction in a declarative way.</p>
      <p>To demonstrate the feasibility of our approach, we implemented ASAP using
the Python extension of the dlvhex solver, and within ASAP we realized ASPeTris,
an implementation of the well-known game of Tetris. ASPeTris is a fully playable
game: interactive input from the user is processed, the game is drawn, a list of
highscores is persistenly stored, and the player name can be edited interactively.
Our key contribution is a framework for interactive and declarative problem solving.</p>
      <p>We furthermore proposed syntactic shortcuts that ease application programming:
ordering actions implicitly by using their order of appearance in the input program,
and an engine for uents to reason between logical points in time.</p>
      <p>
        The work shown here is only a case study from which we have learned that the
following important issues need to be addressed in the future: (i) the full ASP code is
instantiated and evaluated over and over, which makes ASPeTris slow (2 frames per
second) and could be avoided if the solver would automatically disregard large sets
of irrelevant rules for evaluation; (ii) a declarative concept of modularity should
be integrated into the syntax to ease programming and simultaneously facilitate
automatic optimizations in the solver; (iii) a declarative method for error handling
to catch and treat exceptional cases within ASP itself would be useful; (iv) enabling
usage of nondeterminism within ASAP programs is an open issue; nally (v) a
notion of library functions to avoid `reinventing the wheel' over and over again
(e.g.,
        <xref ref-type="bibr" rid="ref20">(Ianni et al. 2004)</xref>
        ) and also to integrate existing functionalities written in
imperative programming languages, possibly through the use of external atoms.
      </p>
    </sec>
    <sec id="sec-9">
      <title>Acknowledgements</title>
      <p>We thank the anonymous reviewers and Yuliya Lierler for their feedback.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          <string-name>
            <surname>Alvaro</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Marczak</surname>
            ,
            <given-names>W. R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Conway</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Hellerstein</surname>
            ,
            <given-names>J. M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Maier</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Sears</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          <year>2011</year>
          .
          <article-title>Dedalus: Datalog in Time and Space</article-title>
          .
          <source>In Datalog 2010 Workshop</source>
          . Vol.
          <volume>6702</volume>
          LNCS.
          <volume>262</volume>
          {
          <fpage>281</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          <string-name>
            <surname>Basol</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Fink</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Erdem</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Ianni</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          <year>2010</year>
          .
          <article-title>HEX Programs with Action Atoms</article-title>
          .
          <source>In International Conference on Logic Programming (ICLP)</source>
          ,
          <source>Technical Communications</source>
          .
          <volume>24</volume>
          {
          <fpage>33</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          <string-name>
            <surname>Beck</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Dao-Tran</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Eiter</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Fink</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <year>2015</year>
          .
          <article-title>LARS: A Logic-based Framework for Analyzing Reasoning over Streams</article-title>
          .
          <source>In AAAI Conference on Arti cial Intelligence.</source>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          <string-name>
            <surname>Calimeri</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Faber</surname>
            ,
            <given-names>W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ianni</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kaminski</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Krennwallner</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Leone</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ricca</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Schaub</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          <year>2012</year>
          .
          <article-title>ASP-Core-2 Input language format</article-title>
          .
          <source>Tech. rep.</source>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          <string-name>
            <surname>Calimeri</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ianni</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Ricca</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          <year>2014</year>
          .
          <article-title>The third open answer set programming competition</article-title>
          .
          <source>Theory and Practice of Logic Programming</source>
          <volume>14</volume>
          ,
          <issue>1</issue>
          , 117{
          <fpage>135</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          <string-name>
            <surname>Cerexhe</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Thielscher</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <year>2014</year>
          .
          <article-title>Online Agent Logic Programming with oClingo</article-title>
          .
          <source>In Paci c Rim International Conference on Arti cial Intelligence (PRICAI)</source>
          .
          <volume>945</volume>
          {
          <fpage>957</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          <string-name>
            <surname>Denecker</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Vennekens</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Bond</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Truszczynski</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <year>2009</year>
          .
          <article-title>The second answer set programming competition</article-title>
          .
          <source>In Logic Programming and Nonmonotonic Reasoning (LPNMR)</source>
          . Vol.
          <volume>5753</volume>
          LNAI.
          <volume>637</volume>
          {
          <fpage>654</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          <string-name>
            <surname>Eiter</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Faber</surname>
            ,
            <given-names>W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Leone</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pfeifer</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Polleres</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          <year>2004</year>
          .
          <article-title>A Logic Programming Approach to Knowledge-State Planning: Semantics and Complexity</article-title>
          .
          <source>ACM Transactions on Computational Logic 5</source>
          ,
          <issue>2</issue>
          , 206{
          <fpage>263</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          <string-name>
            <surname>Eiter</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Fink</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ianni</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Krennwallner</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Redl</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          , and Schuller, P.
          <year>2015</year>
          .
          <article-title>A Model Building Framework for Answer Set Programming with External Computations. Theory and Practice of Logic Programming</article-title>
          . To appear, arXiv:
          <fpage>1507</fpage>
          .
          <fpage>01451</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          <string-name>
            <surname>Eiter</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ianni</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schindlauer</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Tompits</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          <year>2006</year>
          .
          <article-title>E ective Integration of Declarative Rules with External Evaluations for Semantic-Web Reasoning</article-title>
          .
          <source>In European Semantic Web Conference (ESWC)</source>
          .
          <volume>273</volume>
          {
          <fpage>287</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          <string-name>
            <surname>Faber</surname>
            ,
            <given-names>W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pfeifer</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Leone</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          <year>2011</year>
          .
          <article-title>Semantics and complexity of recursive aggregates in answer set programming</article-title>
          .
          <source>Arti cial Intelligence</source>
          <volume>175</volume>
          ,
          <issue>1</issue>
          , 278{
          <fpage>298</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          <string-name>
            <surname>Fink</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Germano</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ianni</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Redl</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          , and Schuller, P.
          <year>2013</year>
          .
          <article-title>ActHEX: Implementing HEX Programs with Action Atoms</article-title>
          .
          <source>In Logic Programming and Nonmonotonic Reasoning (LPNMR)</source>
          .
          <volume>317</volume>
          {
          <fpage>322</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Grote</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kaminski</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Obermeier</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sabuncu</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Schaub</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          <year>2012</year>
          .
          <article-title>Stream Reasoning with Answer Set Programming: Preliminary Report</article-title>
          .
          <source>Principles of Knowledge Representation and Reasoning (KR)</source>
          ,
          <volume>613</volume>
          {
          <fpage>617</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Grote</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kaminski</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Schaub</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          <year>2011</year>
          .
          <article-title>Reactive Answer Set Programming</article-title>
          .
          <source>In Logic Programming and Nonmonotonic Reasoning</source>
          .
          <volume>54</volume>
          {
          <fpage>66</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kaminski</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          , Kaufmann,
          <string-name>
            <given-names>B.</given-names>
            ,
            <surname>Ostrowski</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            ,
            <surname>Schaub</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            , and
            <surname>Thiele</surname>
          </string-name>
          ,
          <string-name>
            <surname>S.</surname>
          </string-name>
          <year>2008</year>
          .
          <article-title>Engineering an incremental ASP solver</article-title>
          .
          <source>In International Conference on Logic Programming</source>
          . Vol.
          <volume>5366</volume>
          LNCS.
          <volume>190</volume>
          {
          <fpage>205</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kaminski</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          , Kaufmann,
          <string-name>
            <given-names>B.</given-names>
            , and
            <surname>Schaub</surname>
          </string-name>
          ,
          <string-name>
            <surname>T.</surname>
          </string-name>
          <year>2012</year>
          .
          <article-title>Answer Set Solving in Practice</article-title>
          . Morgan Claypool.
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          <string-name>
            <surname>Gebser</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kaminski</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          , Kaufmann,
          <string-name>
            <given-names>B.</given-names>
            , and
            <surname>Schaub</surname>
          </string-name>
          ,
          <string-name>
            <surname>T.</surname>
          </string-name>
          <year>2014</year>
          . Clingo = ASP + Control:
          <source>Preliminary Report. Tech. rep.</source>
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          <string-name>
            <surname>Gelfond</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          <year>1988</year>
          .
          <article-title>The Stable Model Semantics for Logic Programming</article-title>
          .
          <source>In International Conference and Symposium on Logic Programming (ICLP/SLP)</source>
          .
          <volume>1070</volume>
          {
          <fpage>1080</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          <string-name>
            <surname>Gelfond</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          <year>1993</year>
          .
          <article-title>Representing action and change by logic programs</article-title>
          .
          <source>The Journal of Logic Programming</source>
          <volume>17</volume>
          ,
          <issue>301</issue>
          {
          <fpage>321</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          <string-name>
            <surname>Ianni</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ielpa</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pietramala</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Santoro</surname>
            ,
            <given-names>M. C.</given-names>
          </string-name>
          , and
          <string-name>
            <surname>Calimeri</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          <year>2004</year>
          .
          <article-title>Enhancing Answer Set Programming with Templates</article-title>
          .
          <source>In Workshop on Nonmonotonic Reasoning (NMR)</source>
          .
          <volume>233</volume>
          {
          <fpage>239</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          <string-name>
            <surname>Kowalski</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Sergot</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <year>1986</year>
          .
          <article-title>A logic-based calculus of events</article-title>
          .
          <source>New generation computing 4</source>
          ,
          <year>June 1975</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          <string-name>
            <surname>Lee</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          <year>2012</year>
          .
          <article-title>Reformulating Action Language C+ in Answer Set Programming</article-title>
          .
          <source>In Correct Reasoning. Number 7265 of LNCS</source>
          .
          <volume>405</volume>
          {
          <fpage>421</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref23">
        <mixed-citation>
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          <year>2002</year>
          .
          <article-title>Answer set programming and plan generation</article-title>
          .
          <source>Arti cial Intelligence</source>
          <volume>138</volume>
          ,
          <fpage>1</fpage>
          -
          <lpage>2</lpage>
          ,
          <issue>39</issue>
          {
          <fpage>54</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref24">
        <mixed-citation>
          <string-name>
            <surname>Lifschitz</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          <year>2008</year>
          .
          <article-title>What Is Answer Set Programming</article-title>
          ?
          <source>In AAAI Conference on Arti cial Intelligence</source>
          .
          <volume>1594</volume>
          {
          <fpage>1597</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref25">
        <mixed-citation>
          <string-name>
            <surname>McCarthy</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Hayes</surname>
            ,
            <given-names>P. J.</given-names>
          </string-name>
          <year>1969</year>
          .
          <article-title>Some philosophical problems from the standpoint of arti cial intelligence</article-title>
          .
          <source>Machine Intelligence</source>
          <volume>4</volume>
          ,
          <issue>463</issue>
          {
          <fpage>502</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref26">
        <mixed-citation>
          <string-name>
            <surname>Oikarinen</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Janhunen</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          <year>2006</year>
          .
          <article-title>Modular Equivalence for Normal Logic Programs</article-title>
          .
          <source>European Conference on Arti cial Intelligence (ECAI)</source>
          ,
          <volume>412</volume>
          {
          <fpage>416</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref27">
        <mixed-citation>
          <string-name>
            <surname>Smith</surname>
            ,
            <given-names>A. M.</given-names>
          </string-name>
          and
          <string-name>
            <surname>Mateas</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <year>2011</year>
          .
          <article-title>Answer Set Programming for Procedural Content Generation: A Design Space Approach</article-title>
          .
          <source>IEEE Transactions on Computational Intelligence and AI in Games 3</source>
          ,
          <issue>3</issue>
          , 187{
          <fpage>200</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref28">
        <mixed-citation>
          <string-name>
            <surname>Wadler</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          <year>1995</year>
          .
          <article-title>Monads for functional programming</article-title>
          .
          <source>In Advanced Functional Programming</source>
          .
          <volume>24</volume>
          {
          <fpage>52</fpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>