Institute for Software Technology

Situation Calculus

Gerald Steinbauer Institute for Software Technology

Gerald Steinbauer Situation Calculus - Introduction 1 Institute for Software Technology

Organizational Issues

• Dates – 05.10.2017 8:45-11:00 (HS i12) lecture and first assignment – 12.10.2017 8:45-11:00 (HS i12) lecture and programming assignment – 11.10.2017 18:00-18:45 (HS i11) practice – 18.10.2017 18:00-18:45 (HS i11) practice and solution for first assignment – 16.10.2017 12:00 (office IST) submission first assignment – 09.11.2016 23:59 (group SVN) submission programming assignment

Gerald Steinbauer Situation Calculus - Introduction 2 Institute for Software Technology

Agenda

• Organizational Issues • Motivation • Introduction – Brief Recap of First Order (if needed) • Situation Calculus (today) – Introduction – Formal Definition – Usage • Programming with Situation Calculus (next week) – Implementation – Domain Modeling

Gerald Steinbauer Situation Calculus - Introduction 3 Institute for Software Technology

Literature “Knowledge in Action” “: A by Raymond Reiter Modern Approach” MIT Press by Stuart Russel amd Peter Norvig Prentice Hall

Gerald Steinbauer Situation Calculus - Introduction 4 Institute for Software Technology

Motivation

What is Situation Calculus good for?

Gerald Steinbauer Situation Calculus - Introduction 5 Institute for Software Technology

There is nothing permanent except change. Heraclitus of Ephesus, 535–c. 475 BC

Gerald Steinbauer Situation Calculus - Introduction 6 Institute for Software Technology

Perception-Decision-Execution

Gerald Steinbauer Situation Calculus - Introduction 7 Institute for Software Technology

Dealing with Multiple Worlds

Gerald Steinbauer Situation Calculus - Introduction 8 Institute for Software Technology

Belief Management

Gerald Steinbauer Situation Calculus - Introduction 9 Institute for Software Technology

Brief Recap First Order Logic

Gerald Steinbauer Situation Calculus - Introduction 10 Institute for Software Technology

The Situation Calculus

• is a methodology to reason about actions and change • it allows deductive reasoning on • how to behave • what are the consequences • proposed by John McCarthy (1963) • further developed by Raymond Reiter and others • originally used for database transactions (1995) • uses second-order logic (Reiter 2001) • modeling of dynamic systems (e.g., robots, plants, …) • basis for several (action) programming languages (e.g. Golog, Yagi)

Gerald Steinbauer Situation Calculus - Introduction 11 Institute for Software Technology

Properties of the Situation Calculus

• Advantages • allows for reasoning about actions and change • uses the foundations of logic • allows for testing and proving of properties • is a solution to some fundamental problems of AI (e.g. ) • Drawbacks • based on second-order logic • domain modeling is complex and error prune • real implementations are somehow fuzzy • computational expensive (in particular if you do it wrong)

Gerald Steinbauer Situation Calculus - Introduction 12 Institute for Software Technology

Building Blocks

Domain Dependent Fluents Objects

Situations Actions

The green building blocks are different sorts in the second order logic. The blue building block is used to retrieve properties about the world.

Gerald Steinbauer Situation Calculus - Introduction 13 Institute for Software Technology

States

• abstraction of the world (temporal, situation) • Electrical Engineering or Computer Science • several applications of states • Deterministic Finite Automaton • protocols, parser • model checking, testing

submission signup pass A  Q,, ,q0, F  q0 q1 q2 q30

no submission

not pass

Gerald Steinbauer Situation Calculus - Introduction 14 Institute for Software Technology

Situations

• inductively defined as term

• a constant symbol S0 denotes the initial situation (nothing happened so far) • a binary function symbol do:actionssitationssituations • situations can be interpreted as sequences of actions • do(a,s) performs action a in situation s • do(a,s) adds action a to sequence represented by s

• binary predicate symbol :situationsituation ss’ denotes that s is a proper subsequence of s’

Gerald Steinbauer Situation Calculus - Introduction 15 Institute for Software Technology

Sates versus Situations

• situations are different to states • they contain a history of what happened so far

• snapshots of properties of the world are retrieved by fluents, i.e. which predicates hold in a situation

• two situations are different if their sequence is different • the “state” of fluents may be the same

Gerald Steinbauer Situation Calculus - Introduction 16 Institute for Software Technology

Situation Tree

an do(an,S0)

a3 a2

an a1

S0 a3

a2 do(an,do(a1,S0))

a1 an

a3 a do(a1,S0) 2 a1

Gerald Steinbauer Situation Calculus - Introduction 17 Institute for Software Technology

Example – Dress Up

Gerald Steinbauer Situation Calculus - Introduction 18 Institute for Software Technology

Actions • actions are the only entities which change something (i.e., situations or truth values of fluents) • actions are represented as function symbols (can be used as terms) • actions have a unique name, if the names are different the actions perform different things • actions can have parameters of arity n, e.g. moveto(object, room) or sleep() • an action a is executed in a situation s by the function s’=do(a,s) leading to a new situation s’ • an action has a precondition – in which situation an action is possible to be executed

Gerald Steinbauer Situation Calculus - Introduction 19 Institute for Software Technology

Action Precondition Axioms

• take care if an action a is executable • we introduce a binary predicate symbol Poss:actionsituation • is a sentence in the form

Poss(A(x1,…,xn),s)A(x1,…,xn,s)

• A is a formula with free variables x1,…,xn and s • e.g. • axioms have to be defined for all actions

Gerald Steinbauer Situation Calculus - Introduction 20 Institute for Software Technology

Fluents

• used to catch the dynamic world • fluents are related to states • represent relations that change from situation to situation • we call them relational fluents

Gerald Steinbauer Situation Calculus - Introduction 21 Institute for Software Technology

Relational Fluents

• represents a relation (or properties) of objects in a situation s • it is represented by a predicate symbol with arity n+1

in the form F(x1,…,xn,s) • F:(objectsactions)nsituation→{T,F} • it represents the truth value of a relation or property in a certain situation • examples: at(x,y,s) or broken(x,s)

Gerald Steinbauer Situation Calculus - Introduction 22 Institute for Software Technology

Frame Problem

• a important (fundamental) problem of AI • formulated by John McCarhty and Patrick Hayes • related to the abstract modeling of dynamic domains • how to efficiently specify what is changed by an action and what remains the same • sloppy justification: logic has no memory • we need frame axioms • example: the color of an object does not change if it is lifted, color(x,c,s)→color(x,c,do(lift(x),s))

Gerald Steinbauer Situation Calculus - Introduction 23 Institute for Software Technology

Successor State Axioms (1)

• are a solution to the Frame Problem • naively we have to specify all effect axioms (because of the frame problem) + a. φF (x1,…,xn, y1,…,ym,s)→F(x1,…,xn,do(A(y1,…,ym),s)) - b. φF (x1,…,xn, y1,…,ym,s)→¬F(x1,…,xn,do(A(y1,…,ym),s)) + - • φF and φF formulas with free variables x1,…,xn; y1,…,ym and s • example: fragile(x,s)→broken(x,do(drop(x),s)) • we use the Causal Completeness Assumption • a and b specify all casual laws related to A and F • we are looking for a more compact representation relating situations

Gerald Steinbauer Situation Calculus - Introduction 24 Institute for Software Technology

Successor State Axioms (2)

• we start with a reasonable assumption - • F(x1,…,xn,s)˄¬F(x1,…,xn,do(A(y1,…,ym),s))→φF (x1,…,xn,y1,…,ym,s) - • F(x1,…,xn,s)˄¬φF (x1,…,xn,y1,…,ym,s)→F(x1,…,xn,do(A(y1,…,ym),s)) [PFA]

+ • ¬F(x1,…,xn,s)˄F(x1,…,xn,do(A(y1,…,ym),s))→φF (x1,…,xn,y1,…,ym,s) + • ¬F(x1,…,xn,s)˄¬φF (x1,…,xn,y1,…,ym,s)→¬F(x1,…,xn,do(A(y1,…,ym),s)) [NFA]

• lead to 2 x #actions x #fluents frame axioms

• fragile(x,s)→broken(x,do(drop(x),s)) [PEA] • ¬broken(x,s)˄¬fragile(x,s)→¬broken(x,do(drop(x),s)) [NFA]

Gerald Steinbauer Situation Calculus - Introduction 25 Institute for Software Technology

Successor State Axioms (3)

• the general solution • positive and negative normal form effect axioms + •  → F(t1,…,tn,do(α,s)) + • (y1,…,ym)[a=α˄x=t ˄ ] → F(x1,…,xn,do(a,s)) + •  → F(x1,…,xn,do(a,s)) +(1) +(k) • ( ˅…˅ ) → F(x1,…,xn,do(a,s)) + •  (x1,…,xn,a,s) → F(x1,…,xn,do(a,s)) [PNF] - •  (x1,…,xn,a,s) → ¬F(x1,…,xn,do(a,s)) [NNF] • unique name axiom for actions

• A(x)B(y) and A(x1,…,xn)=A(y1,…,yn) → x1=y1˄…˄ xn=yn • if T entails ¬(x,a,s). +(x,a,s)˄  -(x,a,s) F(x,do(a,s)) +(x,a,s)˅F(x,s)˄¬ -(x,a,s) [SSA-RF]

Gerald Steinbauer Situation Calculus - Introduction 26 Institute for Software Technology

Successor State Axioms (4)

• now we need only #actions + #fluents axioms

Gerald Steinbauer Situation Calculus - Introduction 27 Institute for Software Technology

Summary Successor State Axioms

• provides a solution to the Frame Problem • yields simple compact axioms • does not solve the qualification and ramification problem • length of successor state axioms ~ #actions change a fluent • assumption: only a few actions change a fluent

Gerald Steinbauer Situation Calculus - Introduction 28 Institute for Software Technology

Initial Situation

• S0 is a special constant of sort situation • it represents the initial situation

• DS0 is the initial database • it comprises sentences describing the initial theory of

the world, i.e. fluents that hold in S0

• S0 is the only situation mentioned

• DS0 must not mention Poss, do or  • it may comprise non-situation terms

• examples: location(robot,office1,S0 ), mountain(MtEverest)

Gerald Steinbauer Situation Calculus - Introduction 29 Institute for Software Technology

Foundational Axioms for Situations

• ensure some properties of situations • situations are understood as sequence of actions

• abbreviation: do(an,(…do(a1,S0)) = do([a1,an],S0) • s’ s denotes that s’ is a subsequence of s

1. do(a1,s1)=do(a2,s2)→a1=a2 ˄s1=s2 [UNA]

2. P.P(S0)˄a,s.(P(s)→P(do(a,s)))→s.P(s) [SCA]

3. ¬(sS0) [nothing happened prior S0] 4. s  do(a,s’)ss’ with ss’ ~ ss’˅s=s’

Gerald Steinbauer Situation Calculus - Introduction 30 Institute for Software Technology

Basic Action Theory (BAT)

D    D  D  D  D ssa ap una S0

• Σ … set of foundational axioms for situations

• Dssa … set of successor state axioms

• Dap … set of action precondition axioms

• Duna … set of unique name axioms for actions

• DS0 … set of first order sentences uniform in S0

Gerald Steinbauer Situation Calculus - Introduction 31 Institute for Software Technology

Regression

• related to the projection problem • does a sentence hold for a future situation • used for automated reasoning and planning in the SC • sketch: prove if sentence W is entailed by BAT

• W mentions a relational fluent F(x1,…,xn,do(a,σ))

• successor state axiom F(x1,…,xn,do(a,s))F(x1,…,xn,a,s)

• obtain W’ by substituting F by F • eliminating complex situation do(a, σ) from W’

• W‘ is closer to S0 than W

• repeat the substitution until W0 uniform in S0 • now we can prove W in the initial database (no second order axioms)

Gerald Steinbauer Situation Calculus - Introduction 32 Institute for Software Technology

Regressable Formulas

a formula W in the situation calculus is regressable iff

1. situation terms mentioned in W are of the form

do([α1,…,αn],S0) 2. for atoms of form Poss(α,s) mentioned in W α has the

form A(t1,…,tn) and is an action function symbol 3. W does not quantify over situations 4. W does not mention the predicate symbol  nor any equality atom σ=σ’ for situations

Gerald Steinbauer Situation Calculus - Introduction 33 Institute for Software Technology

Examples for Regressable Formulas

1. Poss(walk(A,B)S0)˄ Poss(enter(office(Sue)),do(walk(A,B),S0))˄ Poss(giveCoffee(Sue),do([walk(A,B),enter(Office(Sue))],S0)

2. (a,a’).onTable(A,do(a,S0))˄(x).xA→¬onTable(x,do([a,a’],S0))

Regressable ? Poss(a,S0) holding(x,do(pickup(A),s))

Gerald Steinbauer Situation Calculus - Introduction 34 Institute for Software Technology

Regression Operator

1. if W is situation-independent or a relational fluent F(x,S0) [W]=W 2. if W is a regressable Poss(A(t),σ) atom and

Poss(A(x),s)A (x,s) [W]=[A (t,σ)] 3. if W is a relational fluent F(t,do(α,σ)) and

F(x,do(a,s))F(x,a,s) [W]=[F(t,α,σ)] 4. [¬W]=¬[W]

[W1˄W2]=[W1]˄[W2] [(v)W]=(v)[W]

Gerald Steinbauer Situation Calculus - Introduction 35 Institute for Software Technology

Important Result from Regression

• if D is a basic action theory and W is a regressable sentence then,

D╞ W iff DS0Duna╞[W]

Gerald Steinbauer Situation Calculus - Introduction 36 Institute for Software Technology

Summary

• Situation Calculus • allows for reasoning about change and actions • a dialect of the second-order logic • uses the concept of situations • allows for proving properties • solves the frame problem

• Basic Action Theory • implements the situation calculus • Action Precondition & Successor State Axioms & Unique Name Assumption & Foundation Axioms & Initial Situation • Regression • allows for automated reasoning and planning

Gerald Steinbauer Situation Calculus - Introduction 37 Institute for Software Technology

Questions ?

Gerald Steinbauer Situation Calculus - Introduction 38