kelps lps - a logic-based framework for reactive system30 aug 2012

36
A Logic-Based Framework for Reactive Systems or Programming with Logic without Logic Programming Robert Kowalski and Fariba Sadri Department of Computing Imperial College London

Upload: adrian-giurca

Post on 02-Nov-2014

460 views

Category:

Technology


0 download

DESCRIPTION

Programming with Logic without Logic Programming

TRANSCRIPT

Page 1: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

A Logic-Based Framework for Reactive Systemsor

Programming with Logic without Logic Programming

Robert Kowalski and Fariba SadriDepartment of Computing

Imperial College London

Page 2: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Ambition: to unify

• Programming

• Databases

• AI knowledge representation and problem-solving

Page 3: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Outline

•KELPS - a simplified kernel for reactive logic-based production-style systems

•KELPS model-theoretic semantics

•KELPS operational semantics

•LPS = KELPS + LP

•MALPS = Multi Agent LPS (The Dining Philosophers)

•Related work (MetateM, Transaction Logic)

•Conclusions

Page 4: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

KELPS

Programs are reactive rules with explicit timein the logical form:

antecedent(X) consequent(X, Y)

i.e. X [antecedent(X) Y consequent(X, Y)]

whenever the antecedent is true in the past or present,then the consequent is true in the future.

Page 5: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

KELPS rules =Composite events + rules + composite actions

pre-sensor detects possible fire in area A at time T1 ∧smoke detector detects smoke in area A at time T2 ∧|T1 – T2 | 60 sec ∧ max(T1, T2, T)

activate local fire suppression in area A at time T3 ∧ T <T3 T + 10 sec ∧

fire in area A at time T4 ∧ T3 <T4 T3 + 30 sec ∧ send security guard to area A at time T5 ∧ T4 <T5 T4 + 10 sec

∨ call fire department to area A at time T3‘∧ T <T3‘ T + 60 sec

Page 6: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Syntax of reactive rulesantecedent1 (X) ∧… ∧ antecedentn (X)

consequent11 (X, Y) ∧… ∧ consequent1l1 (X, Y)

∨ …

∨ consequentm1 (X, Y) ∧… ∧ consequentmlm (X, Y)

Each antecedenti (X) and consequenti j(X, Y) is a condition, event atom or temporal constraint: A condition is an FOL formula in the vocabulary of state predicates.

An event atom is an atomic formula representing an event. An action atom is an event atom in which the event is an action.

A temporal constraint has the form time1 < time2 or time1 ≤ time2, where at least one of time1 and time2 is a variable.

Page 7: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Comparison with MetateM (Michael Fisher et al)

Programs = reactive rules in modal temporal logic:

‘past and present formula’ implies ‘present or future formula’ Computation = model generation.

Model = possible worlds connected by an accessibility relation.

States updated by frame axioms.

Page 8: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Comparison with Transaction Logic (Bonner and Kifer)

Programs = sequences of FOL queries and database updates.

Computation = model generation.

Model = possible worlds. Truth values relative to paths between possible worlds.

States (databases) updated destructively.

Page 9: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Reactive rules are like:

integrity constraints condition-action rules event-condition-action rules“plans” in BDI agents.

Reactive rules generate states using destructive updates.States are model-theoretic structures represented assets of atomic sentences (also called facts or fluents), like:

program variablesrelational databasesHerbrand modelsrepresentations of the real world.

The computational task is to generate a model in which all of the reactive rules are true.

Page 10: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Operational Semantics: States are updated destructively. Model-theoretic semantics: Facts are time-stamped.

old-factfact1

fact2

…factn

new-factfact1

fact2

…factn

eiSi Si+1

ti ti+1 = ti +εi ti

Page 11: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Other semantics can be dealt with similarly

old-factfact1

fact2

…factn

new-factfact1

fact2

…factn

eiSiSi+1

ti ti+1 ti

Page 12: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

LPS = KELPS + LP Dialogue/parsing example

Reactive rule:sentence(T1, T2) sentence (T3, T4) T3 < T2 < T3 + 10

Basic (or atomic events):word(my, 1, 2) word(name, 2, 3) word(is, 3, 4)

word(bob, 4, 5)Composite events (or actions) represented by logic programs:

adjective(T1, T2) word(my, T1, T2) adjective(T1, T2) word(your, T1, T2)

noun(T1, T2) word(name, T1, T2) verb(T1, T2) word(is, T1, T2)noun(T1, T2) word(bob, T1, T2) noun(T1, T2) word(what, T1, T2)

sentence(T1, T3) noun-phrase(T1, T2) verb-phrase(T2, T3)noun-phrase(T1, T3) adjective(T1, T2) noun(T2, T3)noun-phrase(T1, T2) noun(T1, T2)verb-phrase(T1, T3) verb(T1, T2) noun-phrase(T2, T3)verb-phrase(T1, T2) verb(T1, T2)

Page 13: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Example: teleo-reactive program

Let be a small number.

methane-level(M, T) critical M alarm(T’) T < T’ T + methane-level(M, T) critical > M water-level(W, T) high < W pump(T’) T < T’ T + methane-level (M, T) critical > M water-level(W, T) low < W pump-active(T) pump(T’) T < T’ T +

Page 14: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Non-modal time-free syntax

methane-level(M) critical M : alarm methane-level(M) critical > M water-level(W) high < W

: pump methane-level (M) critical > M water-level(W) low < W pump-active : pump

Page 15: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Model-theoretic Semantics:Facts are represented with time parameters.All states and events are combined into a single model.

methane-level(M, T) critical M alarm(T’) T < T’ T +

Page 16: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Outline

•KELPS - a simplified KErnel for reactive Logic-based Production-style Systems

•KELPS model-theoretic semantics

•KELPS operational semantics

•LPS = KELPS + LP

•MALPS = Multi Agent LPS (The Dining Philosophers)

•Related work (MetateM, Transaction Logic)

•Conclusions

Page 17: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

KELPS model-theoretic semanticsGiven reactive rules R0, initial state S0, set of ground atomsAux defining auxiliary predicates, andsequence of sets of external events ex1,…, exi,….

the computational task is to generate sets of actions a1,…, ai,…. such that R0 is true in the Herbrand model:

M = Aux S0* e1* S1* e2* … ei* Si* ei+1* ….

ei = exi ai ei* = {happens(e, ti) | e ei at time ti}

Si+1 = ( Si – {p | terminates(p, ei, ti) is true in Si} ) initiates and {p | initiates(p, ei, ti) is true in Si} terminates are

defined by a Si* = {holds(p, ti) | p Si at time ti} “domain theory” D

Page 18: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

KELPS model-theoretic semantics

The computational task is to generate sets of actions a1,…, ai,…. such that R0 is true in the Herbrand model:

M = Aux S0* e1* S1* e2* … ei* Si* ei+1* ….

Here R0 can be generalised to arbitrary sentences(or integrity constraints) of FOL.The operational semantics becomes more difficult.

Frame axioms of the situation calculus (or event calculus) are emergent properties that are true in M.

Page 19: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

KELPS model-theoretic semantics

Definition: ETholds holds(P, T) happens(E, T) initiates(E, P, T)holds(P, T2) holds(P, T1) happens(E, T2) next(T1, T2) ¬ terminates(E, P, T2)

Theorem. The Herbrand model:

Aux S0* e1* S1* e2* … ei* Si* ei+1* ….

Is contained in the weakly perfect modelof the weakly stratified logic program: ETholds D Aux S0* e1* e2* … ei* ei+1* …. where D defines initiates, terminates, possible and next.

Page 20: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Outline

•KELPS - a simplified KErnel for reactive Logic-based Production-style Systems

•KELPS model-theoretic semantics

•KELPS operational semantics

•LPS = KELPS + LP

•MALPS = Multi Agent LPS (The Dining Philosophers)

•Related work (MetateM, Transaction Logic)

•Conclusions

Page 21: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

KELPS operational semantics is an observe–decide–think –act cycle.

The i-th cycle starts with state Si-1, goal state Gi, rules Ri and events ei at time ti .

Logically, Gi is a conjunction of disjunctions of conjunctions.

Each disjunction has the syntax of the consequents of reactive rules.Operationally, each conjunct is a separate thread.

Each disjunct is an alternative partially executed conditional plan.

Page 22: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

KELPS operational semantics

Step 0. Observe. Use ei to transform state Si-1 into state Si.

Step 1. Think. If earlier-antecedents(X) later-antecedents(X) consequent(X, Y) is in Ri and earlier-antecedents(x) is true in Aux ei* Si*,

then simplify any temporal constraints in later-antecedents(x) consequent(x, Y) and add the result to Ri to obtain Ri+1.

If later-antecedents(x) is empty, then add the result to Gi as a new thread.

Step 2.1. Decide. Choose a set D of disjuncts from one or more threads in Gi.

Step 2.2. Think. For every disjunct in D, choose a form earlier-consequents(Y) later-consequents(Y). If earlier-consequents(y) is true in Aux ei* Si*, then

simplify any temporal constraints in later-consequents(y) and add the result as an new disjunct to the same thread in D to obtain Gi+1.

Step 2.3. Act. For every disjunct in D of a form actions(Z) other-consequents(Z), choose such a form,attempt to execute actions(Z) andadd any successfully executed instances actions(z) to ei+1.

Page 23: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

The operational semantics is sound with respect to the model-theoretic semantics.

Theorem 1. Soundness. Given a program R0 with domain theory D , an initial state S0, goal state G0, and a sequence of sets of external events ex1,…, exn,…., suppose the OS generates a possibly infinite sequence: S0, R0, G0 , a1, … ,Si, Ri, Gi, ai+1, …. Let M be the perfect model of: D S0* e1* …. Si* ei+1* ….. where ei = exi ai . Then R0 G0 is true in M if for every top-level goal G

added to a goal state Gi as a new thread, there exists a goal state Gj such that i ≤ j and the empty disjunct (equivalent to true) is added a disjunct to the same thread as G in Gj.

Page 24: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Incompleteness

The operational semantics is incomplete. It cannot preventively make a rule true by making its antecedents false:

attacks(X, me, T1) ¬ prepared-for-attack(me, T1) ® surrender(me, T2) T1 < T2 T1 +

It cannot proactively make a reactive rule true by making its consequents true before its antecedents become true:

enter-bus(me, T1) have-ticket(me, T2) T1 < T2 T1 +

Page 25: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Outline

•KELPS - a simplified KErnel for reactive Logic-based Production-style Systems

•KELPS model-theoretic semantics

•KELPS operational semantics

•LPS = KELPS + LP

•MALPS = Multi Agent LPS (The Dining Philosophers)

•Related work (MetateM, Transaction Logic)

•Conclusions

Page 26: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

LPS = KELPS + LP model-theoretic semantics

Let LP be a locally stratified logic program defining the auxiliary predicates . LP = Ltimeless Lint Levent D.

Ltimeless defines time-independent predicates. Lint defines intentional predicates.Lint defines composite events. D defines the domain theory.(Events initiate and terminate only extensional predicates.)

The computational task is to generate actions a1,…, ai,…. such that R0 is true in the perfect model of:

LP S0* e1* S1* e2* … ei* Si* ei+1* ….

Page 27: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Outline

•KELPS - a simplified KErnel for reactive Logic-based Production-style Systems

•KELPS model-theoretic semantics

•KELPS operational semantics

•LPS = KELPS + LP

•MALPS = Multi Agent LPS (The Dining Philosophers)

•Related work (MetateM, Transaction Logic)

•Conclusions

Page 28: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

The Dining Philosophers

Page 29: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

The Dining Philosophers – solution in MALPS(multi-agent LPS)The initial state S0:

available(fork0)available(fork1)available(fork2)available(fork3)available(fork4)

Aux/Ltimeless

adjacent(fork0, philosopher(0), fork1) adjacent(fork1, philosopher(1), fork2)adjacent(fork2, philosopher(2), fork3)adjacent(fork3, philosopher(3), fork4)adjacent(fork4, philosopher(4), fork0)

Page 30: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Actions are defined by a domain specific event theory D, specifying preconditions and the fluents that areinitiated and terminated.

think(philosopher(I))

initiates thinking(philosopher(I)).

eat(philosopher(I)) initiates eating(philosopher(I)) terminates thinking(philosopher(I)).

pickup-forks(philosopher(I))

terminates available(F1) and available(F2) preconditions available(F1), available(F2) where

adjacent(F1, philosopher(I), F2).

putdown-forks(philosopher(I)) terminates eating(philosopher(I))initiates available(F1), available(F2) where

adjacent(F1, philosopher(I), F2) .

Page 31: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

The Dining Philosophers – with time-free syntaxand auxiliary logic program

time-to-eat(philosopher(I)) dine(philosopher(I))

dine(philosopher(I)) think(philosopher(I)),

pickup-forks(philosopher(I)), eat(philosopher(I)), putdown-forks(philosopher(I)).

Page 32: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Outline

•KELPS - a simplified KErnel for reactive Logic-based Production-style Systems

•KELPS model-theoretic semantics

•KELPS operational semantics

•LPS = KELPS + LP

•MALPS = Multi Agent LPS (The Dining Philosophers)

•Related work (MetateM, Transaction Logic)

•Conclusions

Page 33: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Comparison with MetateM (Michael Fisher et al)

Programs = reactive rules in modal temporal logic:

‘past and present formula’ implies ‘present or future formula’ Computation = generate model of the reactive rules.

Model = possible worlds connected by an accessibility relation.

States updated by frame axioms.

Interaction by message passing.

Page 34: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Comparison with Transaction Logic (Bonner and Kifer)

Programs = complex actions (and transactions) =sequences of FOL queries and actions.

Computation = generate model of complex actions.

Model = possible worlds. Truth values relative to paths in a collection of possible worlds.

Reactive rule is true if, for every path over which the antecedents are true, there exists a later path over which the consequents are true.

States updated destructively.

Interaction via a global state.

Page 35: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

04/08/2023 35

LPS: alternative external notations

Transaction Logic:

P Q means P(T1) Q(T2) T1 < T2

or P(T1 , T2) Q(T3, T4) T2 < T3

Modal temporal logic:

P ◊Q means P(T1) Q(T2) T1 < T2. P Q means P(T) Q(T+1)

or P(T1) Q(T2) T1 <T2 T1+ ε

Graphical notation:

P R

Q

means P(T1) Q(T2) R(T3) T1 < T3 T2 < T3

Page 36: KELPS LPS - A Logic-Based Framework for Reactive System30 aug 2012

Conclusions

• KELPS simplifies LPS, by eliminating logic programming. It extends LPS, by including a form of composite events.

• The operational semantics is based on destructive updates.

• The model-theoretic semantics of KELPS is inspired by the minimal model semantics of logic programming.

• The model-theory and operational semantics can be extended to deal with other “integrity constraints”.

• KELPS gives a declarative semantics to imperative computing.

• KELPS puts logic programming in its place.