<<

The Thirty-Fourth AAAI Conference on Artificial Intelligence (AAAI-20)

ElGolog: A High-Level Programming Language with Memory of the Execution

Giuseppe De Giacomo Yves Lesperance´ Eugenia Ternovska Sapienza Universita` di Roma York University Simon Fraser University Roma, Italy Toronto, Canada Burnaby, BC Canada [email protected] [email protected] [email protected]

Abstract may not support these fluents. All it is likely to say is that immediately after delivering an item to a location, the item programming languages only support tests that refer - will be this location. To be able to the above pro- clusively to the current state. This applies even to high-level programming languages based on the situation calculus such gram, the programmer would first need to extend the action as Golog. The result is that additional variables/fluents/data theory/world model with these additional task-specific flu- structures must be introduced to track conditions that the pro- ents. Such an extension might be needed for every new task. gram uses in tests to decisions. In this paper, draw- generally, most programming languages only sup- ing inspiration from McCarthy’s Elephant 2000, we pro- port queries about the current state of the system. This is pose an extended version of Golog, called ElGolog, that sup- the so-called Markov property: the executability of an action ports rich tests about the execution history, where tests are and its effects are entirely determined by the current state or expressed in a first-order variant of two-way linear dynamic situation. This assumption is commonly made in formalisms logic that uses ElGolog programs with converse. We show for reasoning about action, such as the situation calculus that in spite of rich tests, ElGolog shares key features with Golog, including a sematics based on macroexpansion into (McCarthy and Hayes 1969; Reiter 2001). It is also made situation calculus formulas, upon regression can still in the high-level programming languages Golog (Levesque be applied. We also show that like Golog, our extended lan- et al. 1997) and ConGolog (De Giacomo, Lesperance,´ and guage can easily be implemented in Prolog. Levesque 2000) based on it (as well as in any standard pro- gramming language such as C, Java, etc.), where tests may only query the current situation/state. If one wants to query Introduction some historical information, one has to introduce some data Suppose that we want to give the following instructions to a structures or fluents to remember what happened in the past. robot assistant: In contrast, in natural language instructions, one simply You have already delivered coffee to some offices. Now, refers to past states and events. go back and deliver milk as well. It should be that referring to the past to specify a task is useful in many applications, for instance, in robotics. We If we want to write a high-level program to represent these might want to order the robot to “go back to all rooms where instructions, we might write the following: you saw discarded pop cans and bring them to the recycling bin”. Note that bringing milk to people to whom one has while ∃o.(DeliveredCoffee(o) ∧¬DeliveredMilk(o)) already delivered coffee is not necessarily just a “fix” to the do πo.[(DeliveredCoffee(o) ∧¬DeliveredMilk(o))?; earlier behavior, as the milk may only have been ordered goto(o); deliverMilk(o)] later, or it might not have been possible to deliver both at the same (perhaps the milk is stored in a fridge far from the i.e., while there is an office where coffee has been delivered coffee machine). but not milk, (nondeterministically) pick such an office and In this paper, we show that we can conveniently extend a go there and deliver milk. This program is written in Golog programming language to support queries about the past. In (Levesque et al. 1997), but there is nothing essential about particular, we define ElGolog, which extends Golog with this; any language where one can iterate over items that sat- the possibility of using (converse) programs in tests, as isfy a condition would do. sometimes allowed in Dynamic Logic (Harel, Kozen, and Notice that the program relies on fluents (essentially, Tiuryn 2000). However we interpret such tests on the current boolean functions that change value over time) such as DeliveredCoffee( ) ( ) history, or log, which is provided by the current situation. So o and DeliveredMilk o that memorize in a sense we are equipping Golog with a of two-way historical information. The model of the world that captures version of Linear Dynamic Logic operators (De Giacomo the dynamics of the domain (i.e., the action theory in Golog) and Vardi 2013). Copyright c 2020, Association for the Advancement of Artificial With this addition, we can write programs that capture Intelligence (www.aaai.org). All rights reserved. more directly the natural language instructions. For exam-

2806 ple, we would write: state axioms encode the causal laws of the world being mod- eled; they take the place of the so-called effect axioms and ∃ (deliverCoffee( ); ∗)− while o. o any provide a solution to the frame problem. (¬any∗; deliverMilk(o)True) [(deliverCoffee( ); ∗)− A key feature of BATs is the existence of a sound and do πo. o any complete regression mechanism for answering queries about (¬any∗; deliverMilk(o)True)?; ( ); ( )] situations resulting from performing a sequence of actions goto o deliverMilk o (Pirri and Reiter 1999; Reiter 2001). In a nutshell, the re- R∗ The in this example means that there is an office location gression operator reduces a formula φ about a partic- R∗[ ] o such that there is a state in the past where deliverCoffee ular future situation to an equivalent formula φ about has occurred for that o, and, in the future of that state, there is the initial situation S0, essentially by substituting fluent re- no deliverMilk for o. Here, any means any atomic action, lations with the right-hand side formula of their successor state axioms. A formula φ is regressable if and only if (i) which can be defined as (πx.A1(x)) | ... | (πx.Ak(x)), 1 ([ ] ) assuming that A1,...,A are all the action types/functions. all situation terms in it are of the form do a1,...,an ,S0 , k ( ) John McCarthy made a similar point to motivate his pro- (ii) in every atom of the form Poss a, σ , the action func- ( ) posal for a programming language Elephant 2000, which, tion is specified, i.e., a is of the form A t1,...,tn , (iii) it among other features, “does not forget” (McCarthy 1992; does not quantify over situations, and (iv) it does not contain  2007). ElGolog is named after this. We go over other related or equality over situation terms. Thus in essence, a for- work in the discussion section. mula is regressable if it does not contain situation variables. Another key result about BATs is the relative satisfiability theorem (Pirri and Reiter 1999; Reiter 2001): D is satisfi- Preliminaries D ∪D able if and only if S0 una is satisfiable (the latter being Situation Calculus. The situation calculus is a well known a purely first-order theory). This implies that we can check predicate logic language for representing and reasoning if a regressable formula φ is entailed by D, by checking if about dynamically changing worlds (McCarthy and Hayes R∗[ ] D ∪D its regression φ is entailed by S0 una only. 1969; Reiter 2001). All changes to the world are the re- sult of actions, which are terms in the language. A pos- sible world history is represented by a term called a situ- Golog. To represent and reason about complex actions or ation. The constant S0 is used to denote the initial situa- processes obtained by suitably executing atomic actions, tion where no actions have yet been performed. Sequences various so-called high-level programming languages have of actions are built using the function symbol do, such that been defined such as Golog (Levesque et al. 1997; Reiter do(a, s) denotes the successor situation resulting from per- 2001), which includes the usual procedural programming forming action a in situation s. Predicates and functions constructs and constructs for nondeterministic choices.2 whose value varies from situation to situation are called flu- The syntax of Golog programs is as follows: ents, and are denoted by symbols taking a situation term  ∗ as their last argument (e.g., Holding(x, s)). s  s means δ ::= a | (δ1; δ2) | (δ1|δ2) | πz.δ | δ | ϕ?   that s is a predecessor situation to s , and s  s stands for ϕ ::= P (x) |¬ϕ | ϕ1 ∧ ϕ2 |∃x.ϕ   s  s ∨ s = s . The abbreviation do([a1,...,an],s) stands In the above, a is an action term, possibly with parameters, for do(an,do(an−1,...do(a1,s) ...)). Within the language, one can formulate action theories and ϕ is situation-suppressed formula, i.e., a formula with that describe how the world changes as a result of the avail- all situation arguments in fluents suppressed. Atomic pro- ? able actions. A basic action theory (BAT) D (Pirri and Reiter gram a executes the action a, while a test ϕ confirms that 1999; Reiter 2001) is the union of the following disjoint sets: ϕ holds. The sequence of program δ1 followed by program ; | the foundational, domain independent, axioms of the situa- δ2 is denoted by δ1 δ2. Program δ1 δ2 allows for the nonde- tion calculus (Σ), which include a second order axiom char- terministic branch between programs δ1 and δ2, while πx.δ acterizing the situation domain; precondition axioms stat- executes program δ for some nondeterministic choice of a D binding for object variable x (observe that such a choice is, ing when actions can be legally performed ( poss); suc- ∗ cessor state axioms describing how fluents change between in general, unbounded). δ performs δ zero or more times. Conditionals and while loops can be defined as in Dynamic situations (Dssa); unique name axioms for actions (Duna); and axioms describing the initial configuration of the world Logic (Harel, Kozen, and Tiuryn 2000). Note the presence of D ( ) nondeterministic constructs, which allow a loose specifica- ( S0 ). A special predicate Poss a, s is used to state that action a is executable in situation s; precondition axioms tion of behavior by leaving “gaps” that ought to be resolved by the executor (one can write anything from a generic - in Dposs characterize this predicate. Executable(s) means that every action performed in reaching situation s is exe- ning program to a fully deterministic plan/program). cutable in the situation in which it occurs. In turn, successor The semantics of Golog programs is specified by defin- ing an abbreviation Do(δ, s, s), which means that program 1Note that tests are used in Golog not just to branch (in condi- tionals and loops), but also to constrain the nondeterministic choice 2Extensions of Golog include ConGolog (De Giacomo, of arguments of actions/programs within the “pick” construct. The Lesperance,´ and Levesque 2000), which supports concurrency, and rich tests in ElGolog can be used to select program arguments IndiGolog (Sardina˜ et al. 2004), which provides means for inter- based on complex historical conditions. leaving sensing, planning, and execution.

2807  δ, when executed starting in situation s, has s as a legal ter- st. Note that the current situation sn acts as a log and δϕ minating situation. It is defined inductively as follows: queries the log. . (a, s, s) = s = do(a, s) ∧ Poss(a, s) We also define Do . (δ ; δ ,s,s) = ∃s. (δ ,s,s) ∧ (δ ,s,s) . Do 1 2 . Do 1 Do 2 [δ]ϕ = ¬δ¬ϕ (δ |δ ,s,s) = (δ ,s,s) ∨ (δ ,s,s) Do 1 2 . Do 1 Do 2 (πx.δ, s, s) = ∃x. (δ, s, s) meaning that for all situations reached by executing δ, ϕ Do . Do Do(δ∗,s,s) = ∀P. holds. [∀s1.P (s1,s1)] ∧ For all the Golog constructs, Do is defined exactly as be- [∀s1,s2,s3.Do(δ, s1,s2) ∧ P (s2,s3) ⊃ P (s1,s3)] fore, except for tests, where we now have a slightly different ⊃ P (s, s) definition:  .  Do(ϕ?,s,s ) = s = s ∧ ϕ[s]  .  Do(ϕ?,s,s) = s = s ∧ ϕ[s, s] In the above definition, we use ϕ[s] to denote the formula ϕ[s ,s ] obtained from ϕ by restoring the situation argument s into A rich test t n is evaluated over a pair of situations, s all fluents in ϕ. More formally: where n is the current situation (“now”), i.e., the situation at s . the end of the log, and t is the situation in the past (“then”), P (x)[s] = P (x, s) where the condition ϕ is being evaluated. In the definition of .  (¬ϕ)[s] = ¬(ϕ[s]) Do(ϕ?,s,s) for tests above, both sn and st get initialized to .   (ϕ1 ∧ ϕ2)[s] = ϕ1[s] ∧ ϕ2[s] the current situation s, but as we will see the δ ϕ operator .  (∃x.ϕ)[s] = ∃x.ϕ[s] may bind st to a different past situation to evaluate ϕ . ( ) The semantics of rich tests in general is defined follows: Thus, for any Golog program δ, Do δ, s, s expands into . P (x)[s ,s ] = P (x, s ) a situation calculus formula that characterizes the pairs of t n . t   (¬ϕ)[s ,s ] = ¬(ϕ[s ,s ]) situations s, s over which a complete execution of δ oc- t n . t n (ϕ1 ∧ ϕ2)[s ,s ] = ϕ1[s ,s ] ∧ ϕ2[s ,s ] curs. Note also that for any Golog program δ without non- t n. t n t n ( ) (∃x.ϕ)[s ,s ] = ∃x.ϕ[s ,s ] deterministic iteration, Do δ, s, s expands to a first-order t n . t n regressable formula. Thus one can find executions of such (δϕ)[st,sn] = ∃s.Dolog(δ, st,s,sn) ∧ ϕ[s, sn] a program though first-order theorem proving. (Levesque et δϕ al. 1997; Reiter 2001) presents an interpreter for Golog im- All cases other than just recursively obtain the truth plemented in Prolog for the case where the initial situation value of the formula in terms of that of their subformulas s δϕ[s ,s ] description satisfies the Prolog closed world assumption, in t (as in Golog). t n holds if and only if there which is shown to be sound/correct with respect to the se- exists a situation s, such that there is an execution of δ from st to s within the log, such that ϕ[s, sn] holds. It uses the mantics under some assumptions. But note that there is no  new abbreviation Dolog(δ, s, s ,sn) that holds if and only if guarantee of termination in general (e.g., one might have a  program of the form “while (true) do ....”). Regarding the there is an execution of δ from s to s that is entirely within π nondeterministic choice of argument construct, if the do- the log sn. Note that the program δ may contain the converse operator, and Dolog needs to handle it. main is finite and the regressed queries evaluated by the in- (  ) terpreter succeed or finitely fail, backtracking will exhaust Dolog δ, s, s ,sn is defined inductively as follows: . all possible bindings of a π variable; but backtracking on Dolog(a, s, s ,sn) = s = do(a, s) ∧ Poss(a, s) infinitely many instances of a π variable is another case of ∧ s  sn . non-termination. The interpreter searches for a way to re- Dolog(δ1; δ2,s,s ,sn) = ∃s .Dolog(δ1,s,s ,sn) ∧ (δ ,s,s,s ) solve the nondeterministic choices in the program that leads Dolog 2 n . Dolog(δ1|δ2,s,s ,sn) = Dolog(δ1,s,s ,sn) ∨ to a complete execution. In doing this, it actually interleaves Dolog(δ2,s,s ,sn) expanding the Do definition, regression, and reasoning about . Dolog(πx.δ, s, s ,sn) = ∃x.Dolog(δ, s, s ,sn) the initial situation, to try to detect failures early. ∗ . Dolog(δ ,s,s ,sn) = ∀P. [∀s1.s1  sn ⊃ P (s1,s1,sn)] ∧ The ElGolog Language [∀s1,s2,s3.Dolog(δ, s1,s2,sn) ∧ P (s2,s3,sn) ⊃ P (s1,s3,sn)] ⊃ P (s, s,s ) The syntax of ElGolog is same as that of Golog except for . n (ϕ?,s,s,s ) = s = s ∧ ϕ[s, s ] ∧ s  s tests: Dolog n n n . − ∗ Do (a−,s,s,s ) = Do (a, s,s,s ) δ ::= a | δ | (δ1; δ2) | (δ1|δ2) | πz.δ | δ | ϕ? log n . log n ((δ ; δ )−,s,s,s ) = ((δ )−;(δ )−,s,s,s ) ::= ( ) |¬ | ∧ |∃ |  Dolog 1 2 n Dolog 2 1 n ϕ P x ϕ ϕ1 ϕ2 x.ϕ δ ϕ − . − − Dolog((δ1|δ2) ,s,s ,sn) = Dolog((δ1) |(δ2) ,s,s ,sn) − − . − where the converse program construct δ , which is bor- Dolog((πx.δ) ,s,s ,sn) = Dolog(πx.(δ) ,s,s ,sn) ∗ − . − ∗ rowed from Dynamic Logic (Harel, Kozen, and Tiuryn Dolog((δ ) ,s,s ,sn) = Dolog(((δ) ) ,s,s ,sn)   − . 2000), can only be used in tests, i.e., in the δ ϕ construct. Dolog((ϕ?) ,s,s ,sn) = Dolog(ϕ?,s,s ,sn) − − . As we will see, tests are interpreted over the past history Dolog((δ ) ,s,s ,sn) = Dolog(δ, s, s ,sn) up to the current situation, and δ−ϕ holds in the current situation sn if there exists a situation in the past, say st, such Golog program constructs are handled as in Do, but we ad- that there is an execution of δ from st to sn (i.e., a “back- ditionally ensure that the execution remains within the log − ward” execution of δ from sn to st) and where ϕ held in sn (see the parts in bold). For converse programs δ ,we

2808 have various cases according to the form of δ. For the prim- The test formula then expands to: itive action case, a converse execution of a, i.e., an execu- ( ; )− [ ] tion of a−, occurs between s and s if a “forward” execution a b P s, s   ≡∃  (( ; )−  ) ∧ [  ] of a occurs between s and s (i.e., if s is do(a, s ) and a s .Dolog a b ,s,s ,s P s ,s  ≡∃s.Do ((a; b)−,s,s,s) ∧ P (s) was executable in s ) within the log sn,. For the case of the log − (δ1; δ2)  sequence, , the converse is distributed into the se- i.e., the test holds in [s, s] if there is some situation s where quence and the order of the subprograms is reversed. In the −  − − ∗ − P holds and there is an execution of (a; b) from s to s (δ1 | δ2) (πx.δ) (δ ) cases of , and the converse op- within the log s. erator is simply pushed inwards. In the case of a test, the Then if we Do we have that: converse operator can be dropped. Finally, double converse log −  cancels out. Dolog((a; b) ,s,s ,s) − −  We say that an ElGolog program δ (or test formula ϕ)is ≡ Dolog((b ; a ),s,s ,s)  −  −   in converse normal form (NFC) if every occurrence of the ≡∃s .Dolog(b ,s,s ,s) ∧ Dolog(a ,s ,s ,s)     converse construct it contains applies to a primitive action ≡∃s .Dolog(a, s ,s ,s) ∧ Dolog(b, s ,s,s) only. ≡∃s.s = do(a, s) ∧ Poss(a, s) ∧ s s ∧ We can define a transformation nfc(δ) which for any s = do(b, s) ∧ Poss(b, s) ∧ s s    ElGolog program δ returns an equivalent program δ that ≡ s = do(b, do(a, s )) ∧ Poss(a, s ) ∧ Poss(b, do(a, s )) is in converse normal form. (( ; )− ? )  = nfc(δ) is defined inductively as follows: Thus Do a b P ,s,s holds if and only if s s and there is some situation s in the past of s such that .   nfc(a) = a s = do(b, do(a, s )), P (s ) holds, and a followed by b is .  nfc(ϕ?) = nfc(ϕ)? executable in s . . nfc(P (x)) = P (x) A concrete instance of the above program is the following: . nfc(¬ϕ) = ¬nfc(ϕ) −  . Do((goto(O2); deliverCoffee(O2)) At(O1)?,s,s) nfc(ϕ1 ∧ ϕ2) = nfc(ϕ1) ∧ nfc(ϕ2) . nfc(∃x.ϕ) = ∃x.nfc(ϕ) . i.e., the robot was at office O1 before it went to office O2 nfc(δϕ) = nfc(δ)nfc(ϕ) . and then delivered coffee there to end up in situation s. nfc(δ1; δ2) = nfc(δ1); nfc(δ2) . It is easy to show that the programs involving nested tests nfc(δ1|δ2) = nfc(δ1)|nfc(δ2) . nfc(πx.δ) = πx.nfc(δ) below are equivalent to the one in the previous example: . nfc(δ∗) = nfc(δ)∗ Example 3. − . − nfc(a ) = a (( ; )− ? ) − . − − Do a b P ,s,s nfc((δ1; δ2) ) = nfc(δ2 ); nfc(δ1 ) ≡ ( −( − )? ) − . − − Do b a P ,s,s nfc((δ1|δ2) ) = nfc(δ )|nfc(δ ) − −  . 1 2 ≡ Do((b ;(a P ?))True?,s,s) nfc((πx.δ)−) = πx.nfc(δ−) . nfc((δ∗)−) = nfc(δ−)∗ The example in the introduction section shows how one . nfc((ϕ?)−) = nfc(ϕ?) can use rich tests in ElGolog to specify complex history de- . nfc((δ−)−) = nfc(δ) pendent tasks. Another useful application of rich tests is to ensure that the “pick” construct choses a different entity at Essentially, nfc(δ) applies the definition of Dolog to non- each iteration of a loop: atomic converse programs to push the converse construct Example 4. The following program makes a robot deliver down to the atomic action level. coffee to some office zero or more times such that no office It is easy to show that: is visited twice (and infinite loops are avoided):   Lemma 1. Do (nfc(δ),s,s,s )=Do (δ, s, s ,s ) ∗ − log n log n (πo.¬(deliverCoffee(o); any ) True?; Observe that for any ElGolog program δ in converse nor- goto(o); deliverCoffee(o))∗  mal form, Dolog(δ, s, s ,sn) is defined purely in terms of We can also ensure that every office gets a coffee delivery Dolog for subprograms of δ. Also the cases of the defini- by adding a test at the end: tion of Dolog for non-atomic converse program are no longer necessary. (πo.¬(deliverCoffee(o); any∗)−True?; goto(o); deliverCoffee(o))∗; Examples ∀o.Office(o) ⊃(deliverCoffee(o); any∗)−True? Let’s look at some examples to understand the ElGolog se- mantics better. Properties δ− ( ; )− ? First, we show that an execution of a converse program Example 2. Consider the test program a b P . Then is effectively a backwards execution δ: we have that : Theorem 5. For any ElGolog program δ, we have that −  .  − −   Do((a; b) P ?,s,s) = s = s ∧(a; b) P [s, s] D|= Dolog(δ ,s,s,sn) ≡ Dolog(δ, s ,s,sn).

2809  ∗ Proof. By induction on the structure of δ. Base cases: In term S within the log Sn, then there is an execution of δ  case δ is an atomic action a, the thesis follows by the defini- from S to S within the log Sn that performs at most |Sn| tion of DoLog. In case δ is a test φ?, we have that iterations of δ:3 −  δ D|= Dolog(δ ,s,s,sn) Lemma 7. For any ElGolog program and any ground sit- −  uation terms, S, S, and S , we have that: ≡ Dolog((ϕ?) ,s,s,sn) n  ≡ Dolog((ϕ?),s,s,sn) D|= ( ∗  ) ⊃ ( ≤|Sn|  )  DoLog δ ,S,S ,Sn DoLog δ ,S,S ,Sn ≡ s = s ∧ ϕ[s, s] ∧ s  sn  D ≡ Dolog((ϕ?),s,s,sn) Proof. Take an arbitrary model M of and assume that  ∗  ≡ ( ) M |= DoLog(δ ,S,S ,Sn). Then there exists situations Dolog δ, s ,s,sn  s1,...,sk with s1 = S and sk = S such that M |= Otherwise, assume as induction hypothesis that the thesis DoLog(δ, s ,s +1,S ) for 1 ≤ i

2810 Inductive step: contains iteration and the situation parameters s and s are Assume that the thesis holds for all subtests and subpro- not ground, then Do(δ, s, s) expands to a second-order for- grams in ϕ and δ (induction hypothesis, IH for short). mula in both the Golog and the ElGolog case. Hence, in = ¬  =  ∧  = ∃  For the cases ϕ ϕ , ϕ ϕ ϕ , and ϕ x.ϕ , the spite of its ability to query the execution history, ElGolog thesis follows immediately by the IH and the definition of can be handled with the same technical machinery as stan- regressable formula. For ϕ = δϕ, we have that dard Golog.  .  ( δ ϕ )[St,Sn] = ∃s.Dolog(δ, St,s,Sn) ∧ ϕ [s, Sn]     Prolog Implementation ≡ :  Dolog(δ, S, S ,Sn) ∧ ϕ [S ,Sn] S S Sn 4 since by Lemma 6 s must be a prefix of ground situation Sn. We have developed an implementation of ElGolog in SWI-Prolog, which is based on the implementation of The thesis then follows immediately by the IH and the defi- Golog in (Levesque et al. 1997; Reiter 2001). Our imple- nition of regressable formula.  mentation assumes that the basic action theory is repre- For the cases δ = δ1|δ2 and δ = πx.δ , the thesis follows immediately by the IH and the definition of regressable for- sented in a particular way in Prolog and that the initial situ- mula. ation description satisfies the Prolog closed world assump- For δ = δ1; δ2, we have that tion. We use the same implementation syntax for programs . (and action theories) as (Reiter 2001), to which we add Dolog((δ1; δ2),S,S ,Sn) = diamond(Delta,Phi) for δϕ and conv(Delta) ∃s.Dolog(δ1,S,s,Sn) ∧ Do(δ2,s,S ,Sn) − for δ , where Delta and Phi are δ and ϕ expressed in ≡   Do (δ1,S,S ,S ) ∧ Do (δ2,S ,S ,S ) S .S Sn log n log n the implementation syntax. since by Lemma 6 s must be a prefix of ground situation Sn. The main predicate of the ElGolog interpreter is The thesis then follows immediately by the IH and the defi- do(Delta,S1,S2), which implements Do(δ, s1,s2). nition of regressable formula. ∗ The definition contains clauses such as: For δ = δ1 , by Lemma 7, we have that do(E,S,do(E,S)) :- ∗  ≤|Sn|  primitive_action(E), poss(E,S). Dolog(δ1 ,S,S ,Sn) ≡ Dolog(δ1 ,S,S ,Sn). do(?(P),S,S) :- holds(P,S,S). Then we can use the same arguments as in the nondetermin- do(E1 : E2,S,S1) :- % handles sequence istic branch and sequence cases to show that the thesis holds. do(E1,S,S2), do(E2,S2,S1). do(E1 # E2,S,S1) :- % handles nondet branch do(E1,S,S1) ; do(E2,S,S1). We can also draw some results about Golog from this. do(star(E),S,S1) :- First, we have that: S1=S;do(E : star(E),S,S1). Lemma 9. For any Golog program δ, The predicate holds(Phi,St,Sn) implements the [ ]   evaluation of a test formula ϕ st,sn . The definition con- D|= Do(δ, s, s ) ⊃ s  s tains clauses such as: This can be proven by induction on situations and on the holds(P & Q,St,Sn) :- structure of Golog programs. holds(P,St,Sn), holds(Q,St,Sn). We can also show that for Golog programs, Dolog is equivalent to Do: As in the original Golog implementation, atomic fluent for- mulas are handled by restoring the situation argument and Theorem 10. For any Golog program δ, invoking the result in Prolog, which first regresses it and    D|= Dolog(δ, s, s ,s) ≡ Do(δ, s, s ) then evaluates it in the initial situation. Existentially quanti- fied variables are handled by substituting in a fresh Prolog The proof is by induction on the structure of δ, using the fact D|= ( ) ⊃   variable, and using Prolog evaluation. Negation is handled that for any Golog program δ, Do δ, s, s s s . by applying Lloyd-Topor transformations and using Prolog From this, it follows that the result in Theorem 8 also ap- negation-as-failure. See (Reiter 2001) for more details. plies to programs: Golog The following clause implements the evaluation of the Corollary 11. For any Golog program δ, and ground situa- temporal operator: tion terms S and S, there exist a first-order regressable sit- uation calculus formula ψ such that D|= Do(δ, S, S) ≡ ψ. holds(diamond(E,P),St,Sn) :- doLog(E,St,S1,Sn), holds(P,S1,Sn). In summary, when the situation parameter is ground, ElGolog rich tests can be handled with the same techniques It uses the predicate doLog(Delta,S1,S2,Sn), which as standard tests without temporal operators. More gener- implements Dolog(δ, s1,s2,sn). This predicate first pushes ally, observe that for both Golog and ElGolog programs δ, the converse construct inwards, all the way down to atomic if the situation parameters s and s are ground, Do(δ, s, s) actions. Then there are various clauses that handle other is equivalent to a first-order situation calculus formula. Also, forms of programs, such as: for both Golog and ElGolog programs δ,ifδ contains no  iteration, Do(δ, s, s ) is also equivalent to a first-order situ- 4The ElGolog interpreter together with some examples is avail- ation calculus formula. Of course, in the general case, if δ able at https://www.eecs.yorku.ca/∼lesperan/code/ElGolog.

2811 doLog(E,S,do(E,S),Sn) :- primitive_action(E), do(goto(giuseppeOf), s0)))) leq(do(E,S),Sn), poss(E,S). ... doLog(conv(E),S,S1,Sn) :- primitive_action(E), doLog(E,S1,S,Sn). doLog(?(P),S,S,Sn) :- Discussion leq(S,Sn), holds(P,S,S). The need to handle domain dynamics which depends on doLog(E1 : E2,S,S1,Sn) :- past histories has long been recognized as an important issue doLog(E1,S,S2,Sn), doLog(E2,S2,S1,Sn). in reasoning about action (Giunchiglia and Lifschitz 1995; These are mostly as in do(Delta,S1,S2), except that Mendez, Lobo, and Baral 1996; Gelfond and Lifschitz we check that the execution remains in the log Sn. This uses 1998). In particular, Gabaldon (Gabaldon 2011) extends Re- the auxiliary predicate leq(S1,S2), which implements iter’s basic action theories (Reiter 2001), which are Marko- s1  s2: vian, to non-Markovian basic action theories, thus allowing leq(S,S). preconditions and effects of actions to be determined by the leq(S,do(A,S1)) :- leq(S,S1). whole history, not just the current situation. He also extends regression to handle formulas that quantify over situations Example 12. The basic action theory for a simple version of that are bounded by a ground situation term, thus supporting the coffee delivery domain can be implemented as follows: regression over non-Markovian basic action theories. (Ga- room(giuseppeOf). room(yvesOf). baldon 2011) does in fact advocate for future work on a ver- room(eugeniaOf). sion of Golog would support test conditions that refer to the past, as we have provided in ElGolog. primitive_action(goto(R)) :- room(R). primitive_action(deliverCoffee(R)):- room(R). There is also related work in the “action languages” ap- primitive_action(). proach (Gelfond and Lifschitz 1998). For instance, Gonzalez et al. (Gonzalez, Baral, and Gelfond 2005) introduced Alan, poss(goto(R),S) :- room(R), \+ at(R,S). an A-like language for modeling non-Markovian domains. poss(deliverCoffee(R),S) :- at(R,S). One of their motivations is the practical problem of mod- poss(wait,S). eling multimedia presentations that involve temporal condi- at(R,do(A,S)) :- A = goto(R) ; tions constraining how a presentation evolves. (Giunchiglia at(R,S), \+ A = goto(R1). and Lifschitz 1995) also handled non-Markovian domain specifications. More recently, non-Markovian planning do- at(coffeeRoom,s0). mains expressed in Linear Dynamic Logic have been studied We can define a nondeterministic coffee delivery procedure in (Brafman and De Giacomo 2019). that never delivers to the same office twice as follows: Our contribution in this paper is orthogonal to work on handling non-Markovian action theories, since our focus is proc(cdp, on allowing the agent’s program to make non-Markovian star(pi(r, ( ?(room(r) & tests consisting of historical queries on its log. For simplic- -diamond(conv((deliverCoffee(r) : ity, we have assumed world dynamics to be specified by clas- star(any)), sical basic action theories (Reiter 2001), but our work could true)) be easily extended to deal with non-Markovian ones. : goto(r) : deliverCoffee(r))))). To sumarize, in this paper, we have presented ElGolog, a high-level programming language extending Golog that When we execute this procedure, we obtain various execu- supports rich tests about the execution history, where tests tions that deliver coffee to zero or more offices, never going are expressed in a first-order variant of two-way linear dy- to the same office twice: namic logic that uses ElGolog programs with converse. This ?- do(cdp,s0,S). allows procedures that involve complex history-dependent S=s0; conditions to be expressed naturally, without having to in- S = do(deliverCoffee(giuseppeOf), troduce new task-specific fluents or data structures into the do(goto(giuseppeOf), s0)) ; action theory/domain model. We have shown that in spite S = do(deliverCoffee(yvesOf), of its rich tests, ElGolog can be provided with a semantics do(goto(yvesOf), based on macroexpansion into situation calculus formulas do(deliverCoffee(giuseppeOf), (Levesque et al. 1997; Reiter 2001), upon which regression do(goto(giuseppeOf), s0)))) ; can be applied, just like Golog. We also described an imple- S = do(deliverCoffee(eugeniaOf), mentation of ElGolog in Prolog. do(goto(eugeniaOf), The ability to refer to the past, as advocated by McCarthy do(deliverCoffee(yvesOf), (McCarthy 1992; 2007). is important to keep the model of do(goto(yvesOf), the world (the fluents and atomic actions) and the model of do(deliverCoffee(giuseppeOf), the task (the Golog/ElGolog program) separate. Indeed on do(goto(giuseppeOf), s0)))))) ; the same world model, we may run several programs per- S = do(deliverCoffee(eugeniaOf), forming different tasks. If we cannot refer to the history, do(goto(eugeniaOf), then we need to summarize the relevant part of the history in do(deliverCoffee(giuseppeOf), newly introduced fluents in an extended world model. But

2812 these fluents depend on the task, so for every new task we LTLf /LDLf goals in non-Markovian fully observable non- would need to add new task-specific fluents. This clutters deterministic domains. In IJCAI, 1602–1608. the world model with extra information that does not per- Dastani, M. 2008. 2APL: a practical agent programming tain to the world itself, but to the (essentially unboundedly language. Autonomous Agents and Multi-Agent Systems many) tasks that we may perform on it. 16(3):214–248. Note that in the related work on non-Markovian action De Giacomo, G., and Vardi, M. Y. 2013. Linear temporal theories by Gabaldon, Gonzalez et al., etc., avoiding the in- logic and linear dynamic logic on finite traces. In IJCAI. troduction of auxiliary fluents is one of the main motiva- tions. This argument applies to any kind of system where De Giacomo, G.; Lesperance,´ Y.; and Levesque, H. J. 2000. we distinguish between a world model (including dynam- ConGolog, a concurrent programming language based on ics) that remains valid over time and a variety of control the situation calculus. Artificial Intelligence 121(1–2):109– tasks that are performed on it at different times. Even in C 169. or Java it may be advantageous to refer to the log when pro- Gabaldon, A. 2011. Non-Markovian control in the situation gramming such tasks. However, in these languages, we do calculus. Artificial Intelligence 175(1):25–48. not have a convenient data structure for the log. Instead in Gelfond, M., and Lifschitz, V. 1998. Action languages. the situation calculus, we do have one, the current situation, Electron. Trans. Artif. Intell. 2:193–210. which is in fact the history from the starting state to the cur- Giunchiglia, E., and Lifschitz, V. 1995. Dependent fluents. rent one. In Golog, this log is used only when doing regres- In IJCAI, 1964–1969. Morgan Kaufmann. sion, but in ELGolog instead we use it as well for querying the past, and as we have shown, we can still apply regres- Gonzalez, G.; Baral, C.; and Gelfond, M. 2005. Alan: An sion as we do in the standard Golog. Obviously, from time action language for modelling non-Markovian domains. Stu- to time we will “progress” the action theory to the current dia Logica 79(1):115–134. situation (Reiter 2001), and this corresponds to erasing the Harel, D.; Kozen, D.; and Tiuryn, J. 2000. Dynamic Logic. log and having a fresh start in the state corresponding to the MIT Press. current situation. This means that we lose access to the his- Levesque, H. J.; Reiter, R.; Lesperance,´ Y.; Lin, F.; and tory. The question of how to handle progression in ElGolog Scherl, R. B. 1997. Golog: A logic programming language is an interesting topic for future research. for dynamic domains. The Journal of Logic Programing Our approach should be applicable to other agent pro- 31(1-3):59–83. gramming languages. For instance, one could try to extend McCarthy, J., and Hayes, P. J. 1969. Some Philosophi- Thielscher’s FLUX language (Thielscher 2005) along these cal Problems From the Standpoint of Artificial Intelligence. lines. Our ideas could also be applied to BDI agent pro- Machine Intelligence 4:463–502. gramming languages (e.g., Jason (Bordini, Hubner,¨ and Wooldridge 2007), 2APL (Dastani 2008), etc.), although McCarthy, J. 1992. Elephant 2000: A programming lan- this would be more challenging as these typically only re- guage based on speech acts. Available at http://www- member the current belief state. Note that it would also in- formal.stanford.edu/jmc/elephant.pdf. teresting to investigate techniques to remember only the part McCarthy, J. 2007. Elephant 2000: a programming language of the past history that is required to evaluate the historical based on speech acts. In OOPSLA, 723–724. tests that appear in a given program. Mendez, G.; Lobo, J.; and Baral, J. L. C. 1996. Temporal In future work, we would like to extend our results to a logic and reasoning about actions. In Commonsense. version of ElGolog based on non-Markovian action theo- Pirri, F., and Reiter, R. 1999. Some contributions to the ries. It would also be interesting to generalize the approach metatheory of the situation calculus. J. ACM 46(3):325–361. to handle concurrent programs as in ConGolog. Finally, it would be worthwhile to investigate the usability of ElGolog Reiter, R. 2001. Knowledge in Action. Logical Foundations in practical domains such as cognitive robotics. for Specifying and Implementing Dynamical Systems. The MIT Press. Acknowledgments Sardina,˜ S.; De Giacomo, G.; Lesperance,´ Y.; and Levesque, H. J. 2004. On the semantics of deliberation in Indigolog This work is supported in part by the European Research - from theory to implementation. Ann. Math. Artif. Intell. Council under the European Union’s Horizon 2020 pro- 41(2-4):259–299. gramme through the ERC Advanced Grant WhiteMec (No. Thielscher, M. 2005. FLUX: A logic programming method 834228), and the National Science and Engineering Re- for reasoning agents. TPLP 5(4-5):533–565. search Council of Canada.

References Bordini, R. H.; Hubner,¨ J. F.; and Wooldridge, M. 2007. Pro- gramming Multi-Agent Systems in AgentSpeak using Jason. Wiley. Brafman, R. I., and De Giacomo, G. 2019. Planning for

2813