Download presentation

Presentation is loading. Please wait.

Published byKaiya Holling Modified over 2 years ago

1
Semantics of Logic Programs and Non-monotonic Reasoning José Júlio Alferes David Pearce Birmingham, August 2000ESSLLI 2000

2
Motivation a language for knowledge representation a logic for nonmonotonic reasoning a new programming paradigm Three “points of view”:

3
Course topics Logic programming and the semantics of negation-as-failure –stable model semantics –well-founded semantics Intermediate logics and nonmonotonic extensions –equilibrium logic –strong negation Answer set programming –smodels –dlv Programming with XSB

4
Part I Logic Programming Semantics

5
Nonmonotonic inference traditional logic satisfies the Tarski conditions of consequence 1. A C(A) (inclusion) 2. C(A) = C(C(A)) (idempotence) 3. B A C (B) C(A) (monotony)

6
Nonmonotonic inference And as inference conditions: A

7
Nonmonotonic inference Weaker conditions than monotony cautious monotony: –A B C(A) => C(A) C(B) rationality: –A |- and not A { } |- => A |- ¬

8
Types of nonmonotonic reasoning Default rules Rules with exceptions Rules with negation-as-failure Example: birds fly, penguins are birds penguins don’t fly

9
Systems of nonmonotonic reasoning Logic programming default logic (Reiter) autoepistemic logic (Moore)

10
Deductive basis Let C be a consequence operation and L a monotonic logic (Tarski type) with consequence C L,such that: C L (X) C(X) C L (C(X)) = C(X) (left absorption) C L (X) = C L (Y) => C(X) =C(Y). (right absorption) Then L is said to be a deductive basis for C. (L is well-behaved wrt C)

11
LP for Knowledge Representation Due to its declarative nature, LP has become a prime candidate for Knowledge Representation and Reasoning This has been more noticeable since its relations to other NMR formalisms were established For this usage of LP, a precise declarative semantics was in order

12
Stable models and answer sets A semantics for logic programs with negation developed by Michael Gelfond and Vladimir Lifschitz ( )

13
Stable models and answer sets Studied for more than 10 years but implemented systems only available recently Two important implementations: smodels (Helsinki) dlv (Vienna)

14
Answer-set programming (ASP) Various types of combinatorial vproblems have a simple representation in the language of ASP Solutions are produced in the form of answer sets

15
Answer-set programming (ASP) Example: blocks world Write a program that describes the blocks world and the permitted transitions. An answer set corresponds to a history (set of movements).

16
Answer-set programming (ASP) Example: Hamiltonian paths Write a program to compute the Hamiltonian paths in a directed graph (a path that touches each node exactly once ). Each answer-set corresponds to a path. a b cd

17
Language of ASP Rules in the style of Prolog " if ” the part is called "head”, "body” disjunction is allowed in the head: studies_prolog(X) v studies_java(X) represents incomplete knowledge

18
Language of ASP There is a concept of negation-as-failure or negation-by default a(X) not b(X) "a, if b is not provable” this negation is nonmonotonic

19
Default Rules The representation of default rules, such as “All birds fly” can be done via the non-monotonic operator not

20
Language of ASP On is allowed to use "integrity constraints” not b(X) c(X) "the conjunction of c and not b is false” We will see that this does not requires new kinds of rules, as it is equivalent to new_pred not b(X) c(X) , not new_pred

21
Language of ASP There is a concept of explicit or strong negation: a(X) not b(X) versus a(X) ~ b(X) cf. “cross,if no train is passing”

22
Language A Normal Logic Programs P is a set of rules: H A 1, …, A n, not B 1, … not B m (n,m 0) where H, A i and B j are atoms Literal not B j are called default literals When no rule in P has default literal, P is called definite The Herbrand base H P is the set of all instantiated atoms from program P. We will consider programs as possibly infinite sets of instantiated rules.

23
2-valued Interpretations A 2-valued interpretation I of P is a subset of H P –A is true in I (ie. I(A) = 1) iff A I –Otherwise, A is false in I (ie. I(A) = 0) Interpretations can be viewed as representing possible states of knowledge. If knowledge is incomplete, there might be in some states atoms that are neither true nor false

24
3-valued Interpretations A 3-valued interpretation I of P is a set I = T U not F where T and F are disjoint subsets of H P –A is true in I iff A T –A is false in I iff A F –Otherwise, A is undefined (I(A) = 1/2) 2-valued interpretations are a special case, where: H P = T U F

25
Models Models can be defined via an evaluation function Î: –For an atom A, Î(A) = I(A) –For a formula F, Î(not F) = 1 - Î(F) –For formulas F and G: Î((F,G)) = min(Î(F), Î(G)) Î(F G)= 1 if Î(F) Î(G), and = 0 otherwise I is a model of P iff, for all rule H B of P: Î(H B) = 1

26
Minimal Models Semantics The idea of this semantics is to minimize positive information. What is implied as true by the program is true; everything else is false. {pr(s),pr(e),ph(s),ph(e),aM(s),aM(e)} is a model Lack of information that sampaio is a physicist, should indicate that he isn’t The minimal model is: {pr(s),ph(e),aM(e)}

27
Minimal Models Semantics D [Truth ordering] For interpretations I and J, I J iff for all atom A, I(A) I(J), i.e. I T J and F I F J T Every definite logic program has a least (truth ordering) model. D [minimal models semantics] An atom A is true in (definite) P iff A belongs to its least model. Otherwise, A is false in P.

28
T P operator The minimal models of a definite P can be computed (bottom-up) via operator T P D [T P ] Let I be an interpretation of definite P. T P (I) = {H: (H Body) P and Body I} T If P is definite, T P is monotone and continuous. Its minimal fixpoint can be built by: I 0 = {} and I n = T P (I n-1 ) T The least model of definite P is T P ({})

29
On Minimal Models 4SLD can be used as a proof procedure for the minimal models semantics: –If the is a SLD-derivation for A, then A is true –Otherwise, A is false 8The semantics does not apply to normal programs: –p not q has two minimal models: {p} and {q} There is no least model !

30
The idea of completion In LP one uses “if” but mean “iff” [Clark78] This doesn’t imply that -1 is not a natural number! With this program we mean: This is the idea of Clark’s completion: 3Syntactically transform if’s into iff’s 3Use classical logic in the transformed theory to provide the semantics of the program

31
Program completion The completion of P is the theory comp(P) obtained by: Replace p(t) by p(X) X = t, Replace p(X) by p(X) Y , where Y are the original variables of the rule Merge all rules with the same head into a single one p(X) 1 … n For every q(X) without rules, add q(X) Replace p(X) by X (p(X) )

32
Completion Semantics Though completion’s definition is not that simple, the idea behind it is quite simple Also, it defines a non-classical semantics by means of classical inference on a transformed theory Let comp(P) be the completion of P where not is interpreted as classical negation: A is true in P iff comp(P) |= A A is false in P iff comp(P) |= not A

33
SLDNF proof procedure By adopting completion, procedurally we have: not is “negation as finite failure” In SLDNF proceed as in SLD. To prove not A: –If there is a finite derivation for A, fail not A –If, after any finite number of steps, all derivations for A fail, remove not A from the resolvent (i.e. succeed not A) SLDNF can be efficiently implemented (cf. Prolog)

34
SLDNF example p p. q not p. a not b. b not c. a not b b not c c XX q not p p No success nor finite failure According to completion: comp(P) |= {not a, b, not c} comp(P) | p, comp(P) | not p comp(P) | q, comp(P) | not q

35
Problems with completion Some consistent programs may became inconsistent: p not p becomes p not p Does not correctly deal with deductive closures edge(a,b).edge(c,d).edge(d,c). reachable(a). reachable(A) edge(A,B), reachable(B). Completion doesn’t conclude not reachable(c), due to the circularity caused by edge(c,d) and edge(d,c) Circularity is a procedural concept, not a declarative one

36
Completion Problems (cont) Difficulty in representing equivalencies: bird(tweety). fly(B) bird(B), not abnormal(B). abnormal(B) irregular(B) irregular(B) abnormal(B) Completion doesn’t conclude fly(tweety)! Without the rules on the left fly(tweety) is true An explanation for this would be: “the rules on the left cause a loop”. *Again, looping is a procedural concept, not a declarative one *When defining declarative semantics, procedural concepts should be rejected

37
Program stratification Minimal models don’t have “loop” problems But are only applicable to definite programs Generalize Minimal Models to Normal LPs: –Divide the program into strata –The 1st is a definite program. Compute its minimal model –Eliminate all nots whose truth value was thus obtained –The 2nd becomes definite. Compute its MM –…–…

38
Stratification example Least(P 1 ) = {a, b, not p} Processing this, P 2 becomes: c true d c, false Its minimal model, together with P 1 is: {a, b, c, not d, not p} Processing this, P 3 becomes: e a, true f false p p a b b c not p d c, not a e a, not d f not c P1P1 P2P2 P3P3 P The (desired) semantics for P is then: {a, b,c, not d, e, not f, not p}

39
Stratification D Let S 1 ;…;S n be such that S 1 U…U S n = H P, all the S i are disjoint, and for all rules of P: A B 1,…,B m, not C 1,…,not C k if A S i then: {B 1,…,B m } U i j=1 S j {C 1,…,C k } U i-1 j=1 S j Let P i contain all rules of P whose head belongs to S i. P 1 ;…;P n is a stratification of P

40
Stratification (cont) A program may have several stratifications: a b a c not a P1P1 P2P2 P3P3 P a b a c not a P1P1 P2P2 P or Or may have no stratification: b not a a not b D A Normal Logic Program is stratified iff it admits (at least) one stratification.

41
Semantics of stratified LPs D Let I|R be the restriction of interpretation I to the atoms in R, and P 1 ;…;P n be a stratification of P. Define the sequence: M 1 = least(P 1 ) M i+1 is the minimal models of P i+1 such that: M i+1 | (U i j=1 S j ) = M i M n is the standard model of P A is true in P iff A M n Otherwise, A is false

42
Properties of Standard Model Let M P be the standard model of stratified P 4M P is unique (does not depend on the stratification) 4M P is a minimal model of P 4M P is supported D A model M of program P is supported iff: A M (A Body) P : Body M (true atoms must have a rule in P with true body)

43
Perfect models The original definition of stratification (Apt et al.) was made on predicate names rather than atoms. By abandoning the restriction of a finite number of strata, the definitions of Local Stratification and Perfect Models (Przymusinski) are obtained. This enlarges the scope of application: even(0) even(s(X)) not even(X) P1= {even(0)} P2= {even(1) not even(0)}... The program isn’t stratified (even/1 depends negatively on itself) but is locally stratified. Its perfect model is: {even(0),not even(1),even(2),…}

44
Problems with stratification Perfect models are adequate for stratified LPs –Newer semantics are generalization of it But there are (useful) non-stratified LPs even(X) zero(X)zero(0) even(Y) suc(X,Y),not even(X)suc(X,s(X)) Is not stratified because (even(0) suc(0,0),not even(0)) P No stratification is possible if P has: pacifist(X) not hawk(X) hawk(Y) not pacifist(X) This is useful in KR: “X is pacifist if it cannot be assume X is hawk, and vice-versa. If nothing else is said, it is undefined whether X is pacifist or hawk”

45
SLS procedure In perfect models not includes infinite failure SLS is a (theoretical) procedure for perfect models based on possible infinite failure No complete implementation is possible (how to detect infinite failure?) Sound approximations exist: –based on loop checking (with ancestors) –based on tabulation techniques (cf. XSB-Prolog implementation)

46
Stable Models Idea The construction of perfect models can be done without stratifying the program. Simply guess the model, process it into P and see if its least model coincides with the guess. If the program is stratified, the results coincide: –A correct guess must coincide on the 1st strata; –and on the 2nd (given the 1st), and on the 3rd … But this can be applied to non-stratified programs…

47
Stable Models Idea (cont) “Guessing a model” corresponds to “assuming default negations not”. This type of reasoning is usual in NMR –Assume some default literals –Check in P the consequences of such assumptions –If the consequences completely corroborate the assumptions, they form a stable model The stable models semantics is defined as the intersection of all the stable models (i.e. what follows, no matter what stable assumptions)

48
SMs: preliminary example a not bc a p not q b not ac b q not rr Assume, e.g., not r and not p as true, and all other nots as false. By processing this into P: a falsec a p false b falsec b q truer Its least model is {not a, not b, not c, not p, q, r} So, it isn’t a stable model: By assuming not r, r becomes true not a is not assumed and a becomes false

49
SMs example (cont) a not bc a p not q b not ac b q not rr Now assume not b and not q as true, and all other nots as false. By processing this into P: a truec a p true b falsec b q falser Its least model is {a, not b, c, p, not q, r} I is a stable model The other one is {not a, b, c, p, not q, r} According to Stable Model Semantics: c, r and p are true and q is false. a and b are undefined

50
Stable Models definition Let I be a (2-valued) interpretation of P. The definite program P/I is obtained from P by: deleting all rules whose body has not A, and A I deleting from the bodies all the remaining default literals P (I) = least(P/I) M is a stable model of P iffM = P (M). A is true in P iff A belongs to all SMs of P A is false in P iff A doesn’t belongs to any SMs of P (i.e. not A “belongs” to all SMs of P).

51
Properties of SMs 3Stable models are minimal models 3Stable models are supported 3If P is locally stratified then its single stable model is the perfect model 3Stable models semantics assign meaning to (some) non-stratified programs –E.g. the one in the example before

52
Importance of Stable Models Stable Models were an important contribution: –Introduced the notion of default negation (versus negation as failure) –Allowed important connections to NMR. Started the area of LP&NMR –Allowed for a better understanding of the use of LPs in Knowledge Representation It is considered as THE semantics of LPs by a significant part of the community.

53
Default Logic To deal with incomplete information and default rules, Reiter introduced the Default Logics A theory is a pair where: –T is a set of 1st. order formulae (certain knowledge) –D is a set of default rules

54
Default Logic (Syntax) Default rules are of the form: where , and are formulae – are the pre-requisites – are the justifications – are the conclusions Default rules with free variables are viewed as macros standing for their ground instatiations

55
Meaning of defaults if is true, and it is consistent to assume , then conclude Rules are to be maximally applied The semantics has also to make clear: –“true” where? –“consistent” with what? –how to add the conclusion?

56
Examples of default rules bird(X) : flies(X) flies(X) true : ¬connection(X,Y) ¬connection(X,Y) friend(X,Y), friend(Y,Z) : friend(X,Z) friend(X,Z) holds(F,S) : holds(F,res(A,S)) holds(F,res(A,S)) adult(X) : employed(X), ¬dropout(X) employed(X)

57
Default Logics (Semantics) Let = be a theory, and E a set of literals. (E) is the smallest set such that: it contains all logical consequences of T it is closed under rules / where / D and T U E | ¬ E is a default extension of iff E = (E).

58
LP and Default Theories Let P be the default theory obtained by transforming: H B 1,…,B n, not C 1,…, not C m into: B 1,…,B n : ¬C 1,…, ¬C m H There is a one-to-one correspondence between the SMs of P and the default extensions of P

59
LPs as defaults LPs can be viewed as sets of default rules Default literals are the justification: –can be assumed if it is consistent to do so –are withdrawn if inconsistent In this reading of LPs, is not viewed as implication. Instead, LP rules are viewed as inference rules.

60
Auto Epistemic Logic Adds a modal operator to denote knowledge –Allows expressing knowledge about the agent’s own knowledge Eg. –A B ¬C D means “if I know A is true, B is true, and I don’t know whether C is true, then D is true”.

61
AEL and incomplete knowledge Allows (non-monotonic) completion of the knowledge: –concert concert “if there was a concert, I would know”. If I don’t have evidence for concert (i.e. I don’t know concert), then concert is false. –bird(X) ¬flies(X) ¬flies(X) “I know all birds that do not fly”. Thus, if there is some bird, for which I have no evidence of non-flying, I conclude it doesn’t fly.

62
AEL (Moore’s Semantics) I know everything I can conclude from my theory. I don’t know everything that I cannot conclude from my theory (i.e. that doesn’t belong to all models of the theory) A consistent theory T* is an expansion of the AEL theory T iff: T* = T U {F: T* |= F} U {¬F: T* | F}

63
LP and Auto-Epistemic Logic Let P be the AEL theory obtained by transforming: H B 1,…,B n, not C 1,…, not C m into: B 1 … B n ¬ C 1 … ¬ C m H There is a one-to-one correspondence between the SMs of P and the (Moore) expansions of P

64
LPs as AEL theories LPs can be viewed as theories that refer to their own knowledge Default negation not A is interpreted as “A is not known” The LP rule symbol is here viewed as material implication

65
Extended LPs In Normal LPs all the negative information is implicit. Though that’s desired in some cases (e.g. the database with flight connections), sometimes an explicit form of negation is needed for Knowledge Representation “Penguins don’t fly” could be: noFly(X) penguin(X) This does not relate fly(X) and noFly(X) in: fly(X) bird(X) noFly(X) penguin(X) For establishing such relations, and representing negative information a new form of negation is needed in LP: Explicit negation - ~

66
Extended LP: motivation ~ is also needed in bodies: “Someone is guilty if is not innocent” –cannot be represented by: guilty(X) not innocent(X) –This would imply guilty in the absence of information about innocent –Instead, guilty(X) ~innocent(X) only implies guilty(X) if X is proven not to be innocent The difference between not p and ~p is essential whenever the information about p cannot be assumed to be complete

67
ELP motivation (cont) ~ allows for greater expressivity: “If you’re not sure that someone is not innocent, then further investigation is needed” –Can be represented by: investigate(X) not ~innocent(X) ~ extends the relation of LP to other NMR formalisms. E.g –it can represent default rules with negative conclusions and pre-requisites, and positive justifications –it can represent normal default rules

68
ELP Language An Extended Logic Program P is a set of rules: L 0 L 1, …, L m, not L m+1, … not L n (n,m 0) where the L i are objective literals An objective literal is an atoms A or its explicit negation ~A Literals not L j are called default literals The Extended Herbrand base H P is the set of all instantiated objective literals from program P We will consider programs as possibly infinite sets of instantiated rules.

69
ELP Interpretations An interpretation I of P is a set I = T U not F where T and F are disjoint subsets of H P and ~L T L F (Coherence Principle) i.e. if L is explicitly false, it must be assumed false by default I is total iff H P = T U F I is consistent iff ¬ L: {L, ~L} T –In total consistent interpretations the Coherence Principle is trivially satisfied

70
Answer sets It was the 1st semantics for ELPs [Gelfond&Lifschitz90] Generalizes stable models to ELPs Let M - be a stable models of the normal P - obtained by replacing in the ELP P every ~ A by a new atom A -. An answer-set M of P is obtained by replacing A - by ~ A in M - A is true in an answer set M iff A M A is false iff ~A M Otherwise, A is unknown Some programs have no consistent answer sets: e.g. P = {a ~a }

71
Answer sets and Defaults Let P be the default theory obtained by transforming: L 0 L 1,…,L m, not L m+1,…, not L n into: L 1,…,L m : ¬L m+1,…, ¬L n L 0 where ¬ ~A is (always) replaced by A There is a one-to-one correspondence between the answer-sets of P and the default extensions of P

72
Answer-sets and AEL Let P be the AEL theory obtained by transforming: L 0 L 1,…,L m, not L m+1,…, not L n into: L 1 L 1 … L m L m ¬ L m+1 … ¬ L m L 0 L 0 There is a one-to-one correspondence between the answer-sets of P and the expansions of P

73
WFS motivation Answer-sets (and stable models) are a good tool for representing knowledge. However: –its computation is NP-complete –it doesn’t comply with various structural properties, desirable for goal-driven implementations –in various application domains, it is important to have efficient implementations for answering queries (that need not compute the whole model) The Well Founded Semantics is a weaker semantics –sound wrt stable models –with polynomial time complexity –amenable to goal-driven implementations

74
Cumulativity A semantics Sem is cumulative iff for every P: if A Sem(P) and B Sem(P) then B Sem(P U {A}) (i.e. all derived atoms can be added as facts, without changing the program’s meaning) This property is important for implementation: without cumulativity, tabling methods cannot be used

75
Relevance A directly depends on B if B occur in the body of some rule with head A. A depends on B if A directly depends on B or there is a C such that A directly depends on C and C depends on B. A semantics Sem is relevant iff for every P: A Sem(P) iff A Sem(Rel A (P)) where Rel A (P) contains all rules of P whose head is A or some B on which A depends on. Only this property allows for the usual top-down execution of logic programs.

76
Problems with SMs The only SM is {not a, c,b} a not bc not a b not ac not c Don’t provide a meaning to every program: P = {a not a} has no stable models It’s non-cumulative and non-relevant: However b is not true in P U {c} (non-cumulative) P U {c} has 2 SMs: {not a, b, c} and {a, not b, c} b is not true in Rel b (P) (non-relevance) The rules in Rel b (P) are the 2 on the left Rel b (P) has 2 SMs: {not a, b} and {a, not b}

77
Problems with SMs (cont) Its computation is NP-Complete The intersection of SMs is non-supported: c is true but neither a nor b are true. a not bc a b not ac b Note that the perfect model semantics: is cumulative is relevant is supported its computation is polynomial

78
Well Founded Semantics Defined in [GRS90], generalizes SMs to 3- valued models. Note that: –there are programs with no fixpoints of –but all have fixpoints of 2 P = {a not a} ({a}) = {} and ({}) = {a} There are no stable models But: ({}) = {} and ({a}) = {a}

79
Partial Stable Models A 3-valued intr. (T U not F) is a PSM of P iff: T = P 2 (T) T (T) F = H P - (T) The 2nd condition guarantees that no atom is both true and false: T F = {} P = {a not a}, has a single PSM : {} a not bc not a b not ac not c This program has 3 PSMs: {}, {a, not b} and {c, b, not a} The 3rd corresponds to the single SM

80
WFS definition [WF Model] Every P has a knowledge ordering (i.e. wrt ) least PSM, obtainable by the transfinite sequence: T 0 = {} T i+1 = 2 (T i ) T = U < T , for limit ordinals Let T be the least fixpoint obtained. M P = T U not (H P - (T)) is the well founded model of P.

81
Well Founded Semantics Let M be the well founded model of P: –A is true in P iff A M –A is false in P iff not A M –Otherwise (i.e. A M and not A M) A is undefined in P

82
WFS Properties Every program is assigned a meaning Every PSM extends one SM –If WFM is total it coincides with the single SM It is sound wrt to the SMs semantics –If P has stable models and A is true (resp. false) in the WFM, it is also true (resp. false) in the intersection of SMs WFM coincides with the perfect model in locally stratified programs (and with the least model in definite programs)

83
More WFS Properties The WFM is supported WFS is cumulative and relevant Its computation is polynomial (on the number of instantiated rule of P) There are top-down proof-procedures, and sound implementations –these are mentioned in the sequel

84
WFS for extended programs Generalizing WFS for ELPs in the same way as answer-sets yields unintuitive results: pacifist(X) not hawk(X) hawk(X) not pacifist(X) ~ pacifist(a) Using the same method the WFS is: {~pacifist(a)} Though it is explicitly stated that a is non-pacifist, not pacifist(a) is not assumed, and so hawk(a) cannot be concluded. Coherence is not satisfied... Ü Coherence must be imposed

85
Imposing Coherence Coherence is: ~L T L F, for objective L According to the WFS definition, everything is false that doesn’t belong to (T) To impose coherence, when applying (T) simply delete all rules for the objective complement of literals in T “If L is explicitly true then when computing undefined literals forget all rules with head ~L”

86
WFSX definition The semi-normal version of P, P s, is obtained by adding not ~L to every rule of P with head L An interpretation (T U not F) is a PSM of ELP P iff: T = P Ps (T) T Ps (T) F = H P - Ps (T) The WFSX semantics is determined by the knowledge ordering least PSM (wrt )

87
WFSX example P:pacifist(X) not hawk(X) hawk(X) not pacifist(X) ~ pacifist(a) Ps:pacifist(X) not hawk(X), not ~pacifist(X) hawk(X) not pacifist(X ), not ~hawk(X) ~pacifist(a) not pacifist(a) T 0 = {} s (T 0 ) = {~p(a),p(a),h(a),p(b),h(b)} T 1 = {~p(a)} s (T 1 ) = {~p(a),h(a),p(b),h(b)} T 2 = {~p(a),h(a)} T 3 = T 2 The WFM is: {~p(a),h(a), not p(a), not ~h(a), not ~p(b), not ~h(b)}

88
Properties of WFSX Complies with the coherence principle Coincides with WFS in normal programs If WFSX is total it coincides with the only answer-set It is sound wrt answer-sets It is supported, cumulative, and relevant Its computation is polynomial It has sound implementations (cf. below)

89
Part II Nonclassical Logics and nonmonotonic extensions

90
Intuitionistic logic H H introduced by Arend Heyting in 1930 a formalisation of the constructive reasoning of Brouwer one explains the meaning of the logical connective using a notion of proof (in place of truth)

91
Intuitionistic logic (cont) A proof of consists in giving a proof of and a proof of A proof of consists in giving a proof of or a proof of A proof of is a construction that converts a proof of in a proof of A proof of ¬ is a construction that converts an hypothethical proof of in a proof of a contradiction

92
Intuitionistic logic (Kripke semantics) A Kripke frame is a pair, where W is a set of worlds (states, points...) and is a partial order on W. In each world w one verifies a set of atoms i(w), such that if w w´ then i(w) i(w´) i is an assignment that is extended to all formulas i(v) i(w) i(u) u v w i(x) i(u) i(x) i(w) y i(u) i(v) x

93
Intuitionistic logic (semantics) i(w) iff i(w) and i(w) i(w) iff i(w) or i(w) i(w) if w´, such that w w´, if i(w´) then i(w´) ¬ i(w) if w´ such that w w´, i(w´)

94
Intuitionistic logic (semantics) A frame extended with an assignment i determins a Kripke model M =. A formula is true in M if true in each world w in W, ie. M |= iff i(w), w W Completeness: is a theorem of H iff M |= , for each model M

95
Classical logic contains intuitionistic logic Theorems of H form a sub-collection of classsical theorems. Not valid in H are:

96
Intermediate Logics Between H and classical logics there are infinitely many logics Adding axioms to H one forms intermediate logics Intermediate logics are complete wrt a generalised concept of Kripke frame/model

97
Classical logic Here-and-there The lattice of intermediate logics

98
Correspondences Each intermediate logic I has modal companions S under the Gödel (1933) translation t. In t(p) each subformula a of p is replaced by La.

99
Inter- mediate logics I Modal companions S H S4 Gödel transation t |- I p |- s t(p) Correspondences

100
The logic of here-and-there As a basis for studying the language of answer sets and ist extensions, we look at the logic of two worlds: here and there

101
a 2-dimensional logic. There are two worlds....

102
Heaven and Earth....

103

104
Travel is in one direction only....

105

106
or the worlds are called here and there, and you can see from here to there

107
At each world a set of atoms is verified {H} {T} and H T

108
At each world w a set of atoms i(w) is verified {H} {T} h t i(h) = H i(t) = T

109
The assignment i is extended to formulas {H} {T} h t a b i(w) a i(w) & b i(w) a b i(w) a i(w) or b i(w)

110
The there world looks classical in negation and implication, too... {H} {T} h t a i(t) a i(t) a b i(t) a i(t) b i(t)

111
But to know what is true here you have to look there... {H} {T} h t a i(h) a i(t) a b i(h) a b i(t) & & (a i(h) b i(h))

112
The two worlds together with i form a model. A formula is true in the model if it is true at each world (iff it is true at h). {H} {T} h t |= p p i(h)

113
For instance in the language with atoms a, b, c, in this model M: M {a} {a,b} h t M |= aM |= b M |= cM | a b M |= c aM |= c b

114
Or, given a theory T, in a language with atoms a, b, c, we can look for (small) models of T, eg. T a b c b {} {a,b} {b}

115
The logic of here-and-there The logic of here-and-there will be denoted by J The theorems of J are the formulas true in all such here-and-there models They are a subset of the classical theorems

116
The logic of here-and-there Some theorems of JSome non-theorems a a a b) ( a b) a b) ( a b) a a a a a b) a) a

117
Minimal models We define a partial ordering on models by Given a theory T, a model of T is said to be minimal if it is minimal among models of T under the ordering H,T H’,T’ T=T’ & H H’

118
Equilibrium logic A model of a theory T is said to be an equilibrium model of T if it is a minimal model of T and H=T. Equilibrium logic is determined by the class of all equilibrium models of a theory, ie. a formula a is an equil. consequence of T iff a is true in all equil. models of T.

119
Some examples ¬¬a has no e. model ¬a –> b has a single e. model ¬a —> b, ¬b —> a has 2 e. models consider, for consider,

120
Why negation-by-default? J-consequence: p is in Cn J (T) iff for all models M and worlds w, if M,w |= T, then M,w |= p. J-completions: E is a J-completion of T iff E=Cn J (T U {¬a: a E}) Observation: equilibrium models correspond to J- completions Corollary: to reach equilibrium consistently add negated sentences until complete

121
Examples ¬¬p cannot be consistently completed by negation ¬¬p –> p can be completed by adding either ¬p or ¬¬p. In this case one of the corresponding e. models is “bigger” than the other.

122
“Minimal” equilibrium logic taking J-completions by negated atoms corresponds to selecting minimal equilibrium models (ie minimal in their verified atoms)

123
Intuitionistic and intermediate logics Arend Heyting gave the first formalisation H of intuitionistic logic in Here the truth-tables for “here-and-there” were also first given. third value described as “cannot be false, but not provably true”.

124
Kurt Gödel ( ) used the logic J of here-and-there in a famous paper of He was Privatdozent at the University of Vienna.

125
Gödel was typically brief He showed that H cannot be viewed as a many-valued logic And there is an infinite descending chain of logics intermediate between classical logic and H J lies at the top

126
Jan Lukasiewicz ( ) first axiomatised the logic of here-and-there in He showed that disjunction is a definable connective. CCCNpqCCCqpqq ( p q) (((q p) q) q)

127
Classical logic Here-and-there The lattice of intermediate logics

128
J as a 3-valued logic vs L JLukasiewicz logic L

129
J as a 3-valued logic vs L JLukasiewicz logic L ¬¬ 0 1 0

130
Here-and-there in Russia the logic of here-and-there was later studied in Russia by Smetanich (1960) by Maksimova, 1970s shown to have several “good” properties, eg interpolation Sobolev Math Inst, Siberian Acad Sci

131
“Minimal” equilibrium logic defining J-completions using only the negation of atoms corresponds to choosing equilibrium models that are minimal (ie minimal in the set of verified atoms)

132
Some generalisations adding strong negation David Nelson (1949) introduced strong negation in a constructive setting. Main idea: atoms can also be constructively falsified. Strong negation ~ can be used to replace intuitionistic negation, or added as a new connective. In either case the resulting logic N is a conservative extension of H

133
On strong negation ~p –> ¬ p is a theorem, and intuitionistic (weak) negation is definable, eg by ¬ p := p -> ~p system axiomatised by Vorob’ev (1952) ~~p p is a theorem, but not (p v ~p). Semantics of N studied algebraically by Rasiowa 1950s, and by Kripke models in 60s-70s, by Thomason and Gurevich (standard completeness proof), and (algebraically again) by Vakarelov. Kripke models now consist of verified and falsified atoms, or equivalently sets of literals.

134
Intermediate logics with strong negation Vakarelov-style algebraic studies of N continued in 80s and 90s, by Goranko, Sendlewski, Kracht. Strong negation with Vorob’ev axioms can be added to any intermediate logic. The resulting logic is always a conservative extension and complete for the same class of frames (under the generalised valuations). Many properties carry over from an intermediate logic to its ~-extension, eg fmp, tabularity, decidability, interpolation.

135
Equilibrium logic with strong negation based on here-and-there with strong negation(studied by Kracht, 1998). A 5-valued logic. equilibrium construction is the same, but at each world sets of literals(atoms and strongly negated atoms) are verified. Again, minimise true literals wrt (weakly) false literals. e. models are those whose literals are either true or weakly false.

136
Examples Let T = ~ b; c –> b; ¬ c –> d; ¬ d –> c. Let T = ~ a; a –> c; b –> a; ¬ b –> b. Let T = ~ b; ¬ a –> b Equilibrium model of T is T is inconsistent (no model) T has no e-model, by

137
Axioms for strong negation N1 ~( N2 ~( ~ ~ N3 ~( ~ ~ N4 N5 N6 (for atoms )

138
The logic N of Nelson intuicionistic logic H extended with strong negation (N1-N6) is called constructive logic (with strong negation): N. N is a conservative extension of H ie. for a formula in the language of H, |= H iff |= N

139
Semantics of N Kripke models where now i assigns to each world a set of literals ie. atoms a or atoms prefixed by strong negation ~a.. Rules for ~: ~ ( ) i(w) iff ~ i(w) or ~ i(w) ~( ) i(w) iff ~ i(w) & ~ i(w) ~( ) i(w) iff i(w) & ~ i(w) ~ i(w) iff ~ ~ i(w) iff i(w)

140
Principles that fail in N Some principles valid for intuicionistic negation ¬, are invalid for ~, eg. : modus tollens , – contraposition –

141
Here-and-there with strong negation J extended with ~ is denoted by N5 linear models with two worlds (‘here’ and ‘there’), ´h´ and ´t´. a model can be represented by a pair, where H,T are sets of literals, and H T.

142
N5 as a 5 valued logic N ¬ ~

143
Equilibrium logic with strong negation Based on here-and-there with strong negation(studied by Kracht, 1998). A 5-valued logic. Equilibrium construction is the same, but at each world sets of literals(atoms and strongly negated atoms) are verified. Again, minimise true literals wrt (weakly) false literals. e. models are those whose literals are either true or weakly false.

144
Syntactic Method : completion logics The idea: consider an intermediate logic L and a theory T in L. In palce of the L-consequences of T, form extensions E of T (called completions) that are complete in the sense that E E. the logic L* is determined by the formulas true in all completions of T.

145
Syntactic Method : completion logics If L is an intermediate logic, T a theory in L. E is an L-completion of T iff E=Cn L (T U {¬a: a E}). Define a logic L* (in general nonmonotonic) such that C L *(T) if E for each L-completion E of T.

146
Examples in J* ¬¬p cannot be completed consistently adding negated sentences ¬¬p –> p can be completed adding either ¬p or ¬¬p. Each determines a completion.

147
Observations The logic J* coincides con with the logic of equilibrium N5* coincides with N5-equilibrium Define J*min as J* with completions E such that E=Cn L (T U {¬a: a E}) for an atom a. then J*min is the logic of equilibrium models that are minimal in the works ‘there’.

148
Stable model and answer set semantics Stable models first defined for normal logic programs(1988); ie for sets of formulas a 1 &..& a n & ¬b 1 &...& ¬b m –> c, where a,b,c ´s are atoms. Answer sets generalise (1990) to disjunctive and extended programs, ie formulas a 1 &..& a n & ¬b 1 &...& ¬b m –>c 1 v..v c k, where a,b,c ´s are literals.

149
Some observations On normal, disjunctive and extended logic programs, stable models (resp. answer sets) correspond (exactly) to equilibrium models. The logic J of here-and-there is a maximal deductive basis for answer set inference, ie max monotonic sublogic in which equivalent theories have the same answer sets.

150
Further observations Stable models of a program P correspond to the J- completions of P. But this can be extended: (1) it suffices to complete by negated atoms; (2) J can be replaced by intuitionistic logic H. (3) for extended programs replace H by N

151
Correspondences Each intermediate logic I has modal companions S under the Gödel (1933) translation t. In t(p) each subformula a of p is replaced by La.

152
Inter- mediate logics I Modal companions S H S4 Gödel transation t |- I p |- s t(p) Correspondences

153
Do these embeddings lift to the nonmonotonic case? Consider vs Correspondences E = Cn J (P { a : a E}) E = Cn S (P { La : a E})

154
If P is a logic program, then Gödel embedding extends, since completion is by negated atoms. So eg. stable models correspond to S4 expansions. Correspondences

155
Programs with nested expressions Lifschitz, Tang, Turner, 1998 Motivation: in addition to usual program rules, allow rules such as p r; s) or even p; ¬q <– ¬~r Provide an adequate semantics that extends answer sets to such cases

156
Nested expressions Step 1: consider formulas of form F –> G, where F,G are any boolean combinations of atoms and strongly negated atoms (literals). Step 2: extend the concept of program reduct inductively to all boolean combinations of literals, and then to implications (F –> G). Step 3: define answer set S in usual way, ie as minimal model of P reduced by S.

157
Some facts Any program is (answer set) equivalent to a program with formulas of form a 1 &..& a n & ¬b 1 &...& ¬b m –>c 1 v..v c k v ¬d 1 v..v ¬ d l generalised answer sets correspond to equilibrium models

158
Some (LP-relevant) behaviour Representing conditional antecedents (bodies):- Can one re-write (F –> G) –> H by ¬ (F& ¬ G) –> H ? Yes. If P is any program, then P U (a –> b) –> c and P U ¬ (a & ¬ b) –> c have the same equilibrium models. But note that replacing (F –> G) by (¬F v G) produces a different result.

159
Conservative extensions Introduce into a program P a new predicate by definition. Eg consider the program P’ = P U {F –> r} where F is a formula in language of P, and r is a new predicate (atom). The extended program P’ is a conservative extension of P. For any formula G in language of P, P |~ G iff P’ |~ G.(Where |~ is equiibrium. consequence).

160
Stable vs partial stable inference Note that stable inference is supra- classical, but classical logic is not a basis for stable inference... ¬ a –> b and ¬b –> a are class. equivalent Likewise WF- inference (or inference on P-stable models) is supra-intuitionistic but H is not a basis for WF-inference.... in H, ¬ a –> a derives ¬ a –> b.

161
P- stable models P-stable models can be represented as J-models, but do not appear to be characterisable (as minimal models) in the logic of here-and-there. Suggestion: change to (extensions of) minimal logic.

162
further observations Stable models of a program P correspond to the J- completions of P. But this can be extended: (1) it suffices to complete by negated atoms; (2) J can be replaced by intuitionistic logic H. (3) for extended programs replace H by N

163
Stable Models (corollary 1) Let P be a logic program (normal or disjunctive) M is a stable model of P iff Th(M) = Cn H (P U {¬a: a Th(M)}) (for atoms a), or Th(M) = Cn J (P U {¬a: a Th(M)})

164
in- termediate logic I modal companion S H S4 tradution ofGödel |= I p |= S (p) J SW5 Stable Models (corollary 2)

165
Modal Correspondences Let be a formula a 1 ... a n ¬b 1 ... ¬b m c 1 v..v c k of an LP, ´then is the formula a 1 ... a n ¬b 1 ... ¬b m c 1 v..v c k Compare: Th(M) = Cn J (P U {¬a: a Th(M)}) with E = Cn SW5 ( (P) U {¬ a: a E})

166
Modal Correspondences (2) Given that T |- iff (T) |- , we obtain the result of Marek & Truszczynski: M is a stable model of P iff M is the set of atoms true in an SW5-expansion of (P). Th(M) = Cn J (P U {¬a: a Th(M)}) y E = Cn SW5 ( (P) U {¬ a: a E})

167
Complexity The problem of non-satisfiability in classical logic is polynomially reducible to the problem of verifying the property of equilibrium for a model of a formula in N5. Therefore the problem of deciding if a model M of a set of formulas is N5-equilibrium is coNP-complete. The proble of deciding if a theory has equilibrium models P 2 -hard The problem of decidability in N5* is P 2 -hard

168
Computation A tableaux system for N5, for total models and for verifying the property of equilibrim. Pearce, Guzman, Valverde, A Tableau Calculus for Equilibrium Entailment, Tableaux 2000 (R Dyckhoff ed), Springer, LNAI.

169
Computation Proof theoretic foundations for equilibrium logic using the method of signed formulas Pearce, Guzman, Valverde, Computing Equilibrium Entailment using Signed Formulas Proceedings CL2000, Springer, LNAI.

170
Equivalent programs Lifschitz, Pearce, Valverde, Strongly Equivalent Logic Programs, draft, 2000.

171
Part III Answer set programming

172
Basic Idea Give a declarative description of a problem in the form of a logic program Solutions to the problem are represented by answer sets (rather than by variable substitutions). Input is given as a set of facts (rather than as input arguments). Generation of possible solutions (answer-sets) Elimination of those that are not really solutions

173
Answer set solvers Dlv : smodels:

174
Subset example Write a program that, given facts for element(_), has an answer-set for each subset of the elements in_sub(X) :- element(X), not out_sub(X). out_sub(X) :- element(X), not in_sub(X). element(1). element(2). element(3). IN RUN

175
AS programming vs Prolog in_sub(X) :- element(X), not out_sub(X). out_sub(X) :- element(X), not in_sub(X). element(1).element(2).element(3). sub_set([],_). sub_set(S, [_|C]) :- sub_set(S,C). sub_set([E|S],[E|C]) :- sub_set(S,C). ?- sub_set(S,[1,2,3]). versus

176
Small subsets An answer-set for each subset of cardinality 1 From the previous program, eliminate answer- sets with more than one member Eliminate an answer-set if in_sub(X), in_sub(Y), X != Y Add: foo :- in_sub(X), in_sub(Y), X != Y, not foo RUN

177
Graph colouring: 3-colours Problem: find all colourings of a map of countries using not more than 3 colours, such that neighbouring countries are not given the same colour. the predicate arc connects two countries. Use rules of dlv to generate colourings, and integrity constraints to eliminate unwanted solutions Is there a 3-colouring of France, Luxembourg, Germany and Belgium?

178
Graph colouring arc(minnesota, wisconsin).arc(illinois, iowa). arc(illinois, michigan).arc(illinois, wisconsin). arc(illinois, indiana).arc(indiana, ohio). arc(michigan, indiana).arc(michigan, ohio). arc(michigan, wisconsin).arc(minnesota, iowa). arc(wisconsin, iowa).arc(minnesota, michigan). col(Country,Colour) ?? min wis ill iowind mic ohio

179
Graph colouring %generate col(C,red) :- node(C), not col(C,blue), not col(C,green). col(C,blue) :- node(C), not col(C,red), not col(C,green). col(C,green) :- node(C), not col(C,blue), not col(C,red). %eliminate false :- con(C1,C2), col(C1,C), col(C2,C), not false. RUN %auxiliary con(X,Y) :- arc(X,Y). con(X,Y) :- arc(Y,X). node(N) :- con(N,_).

180
min wis ill iowind mic ohio One colouring solution min wis ill iowind mic ohio

181
Hamiltonian paths Given a graph, find all Hamiltonian paths arc(a,b). arc(a,d). arc(b,a). arc(b,c). arc(d,b). arc(d,c). ab dc

182
Hamiltonian paths % Subsets of arcs in_arc(X,Y) :- arc(X,Y), not out_arc(X,Y). out_arc(X,Y) :- arc(X,Y), not in_arc(X,Y). % Nodes node(N) :- arc(N,_). node(N) :- arc(_,N). % Notion of reachable reachable(X) :- initial(X). reachable(X) :- in_arc(Y,X), reachable(Y).

183
Hamiltonian paths % initial is one (and only one) of the nodes initial(N) :- node(N), not non_initial(N). non_initial(N) :- node(N), not initial(N). :- initial(N1), initial(N2), N1 != N2. % In Hamiltonian paths all nodes are reachable :- node(N), not reachable(N). % Paths must be connected subsets of arcs % I.e. an arc from X to Y can only belong to the path if X is reachable :- arc(X,Y), in_arc(X,Y), not reachable(X). % No node can be visited more than once :- node(X), node(Y), node(Z), in_arc(X,Y), in_arc(X,Z), Y != Z. RUN

184
Hamiltonian paths (solutions) ab dc {in_arc(a,d), in_arc(b,c), in_arc(d,b)} {in_arc(a,d), in_arc(b,a), in_arc(d,c)}

185
Generation of answer-sets Multiple answer-sets can also be produced via rules with disjunction A; ~A a program with n rules of this form has 2 n answer-sets. For example p; ~p q; ~q has the answer-sets: {p,q}, {p,~q},{~p,q}, {~p,~q}

186
Generation of answer-sets The rule A; ~A can be replaced in any program by the two non-disjunctive rules A :- not ~A ~A :- not A (Why?)

187
Generation of answer-sets The rule A; not A also produces several answer-sets. It has answer-sets {A} and {} for example A ; not A B ; not B has as answer-sets the 4 subsets of {A,B}

188
Elimination of answer-sets Integrity constraints reduce the number of answer sets, eliminating undesired ones. For example :- L1,..., Lm, not K1,..., not Kn eliminates an answer set S, iff L1,..., Lm S and K1,...,Kn S. This rule can be replaced by: new :- L1,..., Lm, not K1,..., not Kn, not new where new is a new predicate, not appearing elsewhere. Why?

189
smodels Permits the representation of the combination A; not A :- in the head, putting A in parentheses: {A}. A list of rules of the form Ai; not Ai :- body can be represented in smodels by {A1,...,An} :- body

190
smodels No strong negation. If a programs has a literal ~A substitute ~A by a new atom A´ add the constraint :- A, A´

191
Planning In many planners the problem of generating a plan is reduced to the problem of satisfaction of a setv of propositional formulas Subrahmanian & Zaniolo (1995) proposed to reduce plan generation to the problem of finding an answer-set of a logic progam.

192
Planning in the blocks world Write a program describing the blocks world and the permitted moves. An answer-set corresponds to a history (set of moves)

193
Planning in the blocks world Situation: there is a robot with various arms that can move several blocks at the same time. One may not place one cube on top of another that is being moved at the same time. A block can only move if there is no other block on top of it

194
Planning in the blocks world Three basic predicates : block time location a constant lasttime fixes a maximum length of a plan.

195
Planning in the blocks world We fix time and location: eg. time(0....lasttime) location(B):- block(B). location(table).

196
Planning in the blocks world % GENERATE {move(B,L,T) : block(B) : location(L)}arms :- time(T), T

197
Planning in the blocks world % DEFINE % effect of moving a block on(B,L,T+1) :- % inertia on(B,L,T+1) :- % Single location on´(B,L1,T) :-

198
Planning in the blocks world % TEST % on´is the negation of on % two blocks cannot be directly on top of a block % one can only move a block if it is ‚free‘ % one cannot move a block on to another block being moved at the same time

199
Planning in the blocks world example const arms = 2 const lasttime = 3 block(1...6) %define on(1,2,0). on(2,table,0). on(3,4,0). on(4,table.0). on(5,6,0). on(6,table,o).

200
Planning in the blocks world Initial state goal 4 5 6

201
Planning in the blocks world %TEST (eliminate actions that do not lead to the goal) :- not on(3,2,lasttime) :- not on(2,1,lasttime) :- not on(1,table,lasttime) :- not on(6,5,lasttime) :- not on(5,4,lasttime) :- not on(4,table,lasttime)

202
Planning in the blocks world Execution of the plan is a set of “move“ literals move(1,table,0), move(3,table,0), move(2,1,1), move(5,4,1), move(3,2,2), move(6,5,2),

203
Planning in the blocks world Comments the problem is more sophisticated than eg. the Yale-shooting-problem (it has simultaneous actions) the movement of a block has eg two effects: an on predicate becomes true, another false. One is described explicitly by the DEFINE rule, other is indirect and implicit. This problem is not treated in STRIPS.

204
Planning in the blocks world Comments actions are also executed implicitly. (eg. That two blocks cannot be moved onto the same block)

205
Diagnosis a test beam is directed onto a scintillating crystal whose light emission is measured by an avalanche photodiode (APD). The measurement is then read with some readout electronics. Alternatively to the beam reading, the APD can receive a test pulse signal, which allows to check the correct functioning of the APD independently from the crystal. Write a program to diagnose malfunctioning parts:

206
Diagnosis crystal Test Beam APDRead Out Test pulse injector

207
Diagnosis Language: Constants:a apd, b beam, c crystal, t testpulse_injector r readout Represent the system as a graph of its units: Primitive Predicate: connected(X,Y)

208
Diagnosis Defined predicate: good_path(X,Y) good_path is a transitive relation that holds between two items that are connected and not bad. Defined readout constants: testpulse_readout_ok beam_readout_ok readouts are OK if there is a good path between the readouts and the source

209
Diagnosis Assume that there is a fault in the system and either the crystal or the apd is bad. Write a dlv program to describe the system.

210
Diagnosis Observations (formulate these as constraints) testpulse_readout is not OK beam_readout not OK beam and testpulse_readouts not OK testpulse_readout OK beam_readout OK beam and testpulse_readouts OK

211
Diagnosis Find the equilibrium models of the program. Find the equilibrium models corresponding to the 6 observation states.

212
Banana (planning) A monkey is in a room with a chair and a banana which is fixed to the ceiling. The monkey cannot reach the banana unless it stands on the chair; it is simply too high up. The chair is now at a position different from the place where the banana is hung, and the monkey itself initially is at again a different place.

213
Banana (planning) At each discrete point in time, the monkey performs one of the following for actions: it walks, it moves the chair (while doing this, it also moves through the room), it climbs up the chair, or it does nothing. #int is again a built-in predicate which is true exactly if its argument is an integer value.

214
Banana (planning) After climbing up the chair, it is on it. If is is already on it, it cannot climb up any further. While on the chair, it cannot walk around. If it was on the chair earlier, it will be there in the future.

215
Banana (planning) If the chair is not moved, it will stay at the same place. If the monkey moves the chair, it changes its position.

216
Banana (planning) The monkey is somewhere in the room. (For simplicity, only three positions are possible.)

217
Banana (planning) The monkey cannot change its position without moving. The monkey cannot stay at the same place if it moves. It cannot climb up the chair if it is somewhere else. It cannot move the chair if it is somewhere else.

218
Banana (planning) Initially, the monkey and the chair are at different positions.

219
Banana (planning) The monkey can only reach the banana if it stands on the chair and the chair is below the banana. If it can reach the banana, it will eat it, and this will make it happy. Our goal is to make the monkey happy.

220
Banana (planning) The step rules collect all the things we can derive from the situation and build a consistent plan. (There is no step rule for the action idle since we are not interested in it.)

221
Banana (planning) walk(Time) v move_chair(Time) v ascend(Time) v idle(Time) :- #int(Time).

222
Banana (planning) After climbing up the chair, it is on it. If is is already on it, it cannot climb up any further. While on the chair, it cannot walk around. If it was on the chair earlier, it will be there in the future.

223
Banana (planning) monkey_motion(T) :- walk(T). monkey_motion(T) :- move_chair(T). stands_on_chair(T2) :- ascend(T), T2 = T + 1. :- stands_on_chair(T), ascend(T). :- stands_on_chair(T), monkey_motion(T). stands_on_chair(T2) :- stands_on_chair(T), T2 = T +1.

224
Banana (planning) If the chair is not moved, it will stay at the same place. If the monkey moves the chair, it changes its position.

225
Banana (planning) chair_at_place(X, T2) :- chair_at_place(X, T1), T2 = T1 + 1, not move_chair(T1). chair_at_place(Pos, T2) :- move_chair(T1), T2 = T1 + 1, monkey_at_place(Pos, T2).

226
Banana (planning) The monkey is somewhere in the room. (For simplicity, only three positions are possible.)

227
Banana (planning) monkey_at_place(monkey_starting_point, T) v monkey_at_place(chair_starting_point, T) v monkey_at_place(below_banana, T) :- #int(T).

228
Banana (planning) The monkey cannot change its position without moving. The monkey cannot stay at the same place if it moves. It cannot climb up the chair if it is somewhere else. It cannot move the chair if it is somewhere else.

229
Banana (planning) :- monkey_at_place(Pos1, T2), monkey_at_place(Pos2, T1), T2 = T1 + 1, Pos1 != Pos2, not monkey_motion(T1). :- monkey_at_place(Pos, T2), monkey_at_place(Pos, T1), T2 = T1 + 1, monkey_motion(T1). :- ascend(T), monkey_at_place(Pos1, T), chair_at_place(Pos2, T), Pos1 != Pos2. :- move_chair(T), monkey_at_place(Pos1, T), chair_at_place(Pos2, T), Pos1 != Pos2.

230
Banana (planning) Initially, the monkey and the chair are at different positions.

231
Banana (planning) monkey_at_place(monkey_starting_point, 0). chair_at_place(chair_starting_point, 0).

232
Banana (planning) The monkey can only reach the banana if it stands on the chair and the chair is below the banana. If it can reach the banana, it will eat it, and this will make it happy. Our goal is to make the monkey happy.

233
Banana (planning) can_reach_banana :- stands_on_chair(T), chair_at_place(below_banana, T). eats_banana :- can_reach_banana. happy :- eats_banana. :- not happy.

234
Banana (planning) The step rules collect all the things we can derive from the situation and build a consistent plan. (There is no step rule for the action idle since we are not interested in it.)

235
Banana (planning) step(N, walk, Destination) :- walk(N), monkey_at_place(Destination, N2), N2 = N + 1. step(N, move_chair, Destination) :- move_chair(N), monkey_at_place(Destination, N2), N2 = N + 1. step(N, ascend, " ") :- ascend(N). Set maximum integer to 3 (or more) -N=3 and create plan.

236
Banana (planning) {chair_at_place(chair_starting_point,0), monkey_at_place(monkey_starting_point,0), monkey_at_place(chair_starting_point,1), monkey_at_place(below_banana,2), monkey_at_place(below_banana,3), walk(0), move_chair(1), ascend(2), idle(3), chair_at_place(chair_starting_point,1), chair_at_place(below_banana,2), chair_at_place(below_banana,3),

237
Banana (planning) monkey_motion(0), monkey_motion(1), step(0,walk,chair_starting_point), step(1,move_chair,below_banana), step(2,ascend," "), stands_on_chair(3), can_reach_banana, eats_banana, happy}

238
“Clique” : an example in smodels Problem: describe a large clique: a subset V of the vertices of a graph such that: every two vertices in V are connected by an edge V contains a minimum of j elements

239
Predicates: vertex(X) joined(X,Y) edge(X,Y) in(X) (vertices in V) “Clique” : an example in smodels

240
A cardinality restriction can be represented in smodels by j {in(X): vertex(X)} (a minimum of j elements) where {in(X): vertex(X)} is the set of atoms in(X) such that vertex(X) “Clique” : an example in smodels

241
if vertex(0,...,5), then {in(X): vertex(X)} is the conjunction {in(0),in(1),...in(5)}. %Define joined(X,Y) :- edge(X,Y) joined(X,Y) :- edge (Y,X) “Clique” : an example in smodels

242
%TEST :- in(X), in(Y), X/=Y, not joined(X,Y), vertex(X), vertex(Y). Example: const j=3, vertex(0...5), edge(01,), edge(1,2). edge(2,0). edge(3,4) edge(4,5). edge(5,3). edge(4,0). edge(2,5) “Clique” : an example in smodels

243
In smodels one can hide atoms in the answer set that are not relevant for the solution, eg. hide vertex(X) hide edge(X,Y) hide joined(X,Y) So with the given example, smodels produces: in(2) in(1) in(0) “Clique” : an example in smodels

244
Part IV WFS Programming

245
AS vs. Prolog programming AS-programming is adequate for: –NP-complete problems –situation where the whole program is relevant for the problem at hands èIf the problem is polynomial, why using such a complex system? èIf only part of the program is relevant for the desired query, why computing the whole model?

246
AS vs. Prolog (cont.) For such problems top-down, goal-driven mechanisms seem more adequate This type of mechanisms is used by Prolog –Solutions come in variable substitutions rather than in complete models –The system is activated by queries –No global analisys is made: only the relevant part of the program is visited

247
Problems with Prolog Its declarative semantics is the completion –All the problems of completion are inherited by Prolog According to SLDNF, termination is not guaranteed, even for Datalog programs (i.e. programs with finite ground version) No explicit negation operator is available

248
WFS programming Prolog programming style, but with the WFS semantics Requires: *A new proof procedure (different from SLDNF), complying with WFS, and with explicit negation *The corresponding Prolog-like implementation: XSB-Prolog

249
SLX: Proof procedure for WFSX SLX (SL with eXplicit negation) is a top-down procedure for WFSX –Here we only present an AND-trees characterization –The proof procedure details are in [AP96] Is similar to SLDNF –Nodes are either successful or failed –Resolution with program rules and resolution of default literals by failure of their complements are as in SLDNF In SLX, failure doesn’t mean falsity. It simply means non-verity (i.e. false or undefined)

250
Success and failure A finite tree is successful if its root is successful, and failed if its root is failed The status of a node is determined by: –A leaf labeled with an objective literal is failed –A leaf with true is successful –An intermediate node is successful if all its children are successful, and failed otherwise (i.e. at least one of its children is failed)

251
Negation as Failure? As in SLS, to solve infinite positive recursion, infinite trees are (by definition) failed Can a NAF rule be used? YES True of not A succeeds if true-or-undefined of A fails True-or-undefined of not A succeeds if true of A fails This is the basis of SLX. It defines: T-Trees for proving truth TU-Trees for proving truth or undefinedness

252
T and TU-trees They differ in that literals involved in recursion through negation, and so undefined in WFSXp, are failed in T-Trees and successful in TU-Trees a not b b not a … b not a TU b not a TU a not b T a T

253
Explicit negation in SLX ¬-literals are treated as atoms To impose coherence, the semi-normal program is used in TU-trees a not b b not a ¬a b not a 6 a not b not ¬a ¬a¬a true 6 b not a ¬a¬a true … 6 6 a not b not ¬a 6

254
Explicit negation in SLX (2) In TU-trees: L also fails if ¬L succeeds true I.e. if not ¬L fail as true-or-undefined c not c b not c ¬b a b not a 6 ¬b¬b true c not c ¬a¬a b not ¬b a not ¬a c not c c c c …

255
T and TU-trees definition T-Trees (resp TU-trees) are AND-trees labeled by literals, constructed top-down from the root by expanding nodes with the rules Nodes labeled with objective literal A If there are no rules for A, the node is a leaf Otherwise, non-deterministically select a rule for A A L 1,…,L m, not L m+1,…, not L n In a T-tree the children of A are L 1,…,L m, not L m+1,…, not L n In a TU-tree A has, additionally, the child not ¬A Nodes labeled with default literals are leafs

256
Success and Failure All infinite trees are failed. A finite tree is successful if its root is successful and failed if its root is failed. The status of nodes is determined by: A leaf node labeled with true is successful A leaf node labeled with an objective literal is failed A leaf node of a T-tree (resp. TU) labeled with not A is successful if all TU-trees (resp. T) with root A (subsidiary tree) are failed; and failed otherwise An intermediate node is successful if all its children are successful; and failed otherwise After applying these rules, some nodes may remain undetermined (recursion through not). Undetermined nodes in T-trees (resp.TU) are by definition failed (resp. successful)

257
Properties of SLX SLX is sound and (theoretically) complete wrt WFSX. If there is no explicit negation, SLX is sound and (theoretically) complete wrt WFS. See [AP96] for the definition of a refutation procedure based on the AND-trees characterization, and for all proofs and details

258
Infinite trees example s not p, not q, not r p not s, q, not r q r, not p r p, not q WFM is {s, not p, not q, not r} not pnot qnot r s 6 p q not s r not q not r r not p p q not snot r r not p p not q 6 6 q r not p p not q q not snot r

259
Negative recursion example q not p(0), not s p(N) not p(s(N)) s true WFM = {s, not q} … not q p(0) not p(1) not p(0) q not s 6 6 p(1) not p(2) p(2) not p(3) s true not p(0) … p(1) not p(2) p(0) not p(1) p(2) not p(3)

260
Guaranteeing termination The method is not effective, because of loops To guarantee termination in ground programs: Local ancestors of node n are literals in the path from n to the root, exclusive of n Global ancestors are assigned to trees: the root tree has no global ancestors the global ancestors of T, a subsidiary tree of leaf n of T’, are the global ancestors of T’ plus the local ancestors of n global ancestors are divided into those occurring in T-trees and those occurring in TU-trees

261
Pruning rules For cyclic positive recursion: Rule 1 If the label of a node belongs to its local ancestors, then the node is marked failed, and its children are ignored For recursion through negation: Rule 2 If a literal L in a T-tree occurs in its global T-ancestors then it is marked failed and its children are ignored

262
Rule 2Rule 1 Pruning rules (2) L L L L …

263
Other sound rules Rule 3 If a literal L in a T-tree occurs in its global TU-ancestors then it is marked failed, and its children are ignored Rule 4 If a literal L in a TU-tree occurs in its global T-ancestors then it is marked successful, and its children are ignored Rule 5 If a literal L in a TU-tree occurs in its global TU-ancestors then it is marked successful, and its children are ignored

264
Pruning examples a not b b not a ¬a b not a 6 a not b not ¬a ¬a¬a true 6 c not c b not c ¬b a b not a 6 ¬b¬b true c not c ¬a¬a b not ¬b a not ¬a Rule 3 b Rule 2 6

265
Non-ground case The characterization and pruning rules apply to allowed non-ground programs, with ground queries It is well known that pruning rules do not generalize to general programs with variables: p(X) p(Y) p(a) p(X) p(Y) What to do? p(Z) If “fail”, the answers are incomplete If “proceed” then loop

266
Tabling To guarantee termination in non-ground programs, instead of ancestors and pruning rules, tabulation mechanisms are required –when there is a possible loop, suspend the literal and try alternative solutions –when a solution is found, store it in a table –resume suspended nodes with new solutions in the table –apply an algorithm to determine completion of the process, i.e. when no more solutions exist, and fail the corresponding suspended nodes

267
Tabling example SLX is also implemented with tabulation mechanisms It uses XSB-Prolog tabling implementation SLX with tabling is available with XSB-Prolog Version 2.0 Try it at: p(X) p(Y) p(a) p(X) p(Y) 1) suspend X = a 2) resume Y = a X = _ Table for p(X)

268
Tabling (cont.) If a solution is already stored in a table, and the predicate is called again, then: –there is no need to compute the solution again –simply pick it from the table! This increases eficiency. Sometimes by one order of magnitude.

269
Fibonacci example fib(1,1). fib(2,1). fib(X,F) :- fib(X-1,F1), fib(X-2,F2), F is F1 + F2. fib(4,A)fib(3,B)fib(2,C) C=1D=1 fib(1,D) B=3 fib(2,E) E=1 A=4 fib(3,F) F=3 Y=7 Table for fib Q F fib(6,X) fib(5,Y) fib(4,H) H=4 X= Linear rather than exponential

270
XSB-Prolog Can be used to compute under WFS Prolog + tabling –To using tabling on, eg, predicate p with 3 arguments: :- table p/3. –To table all the needed predicates: :- auto_table.

271
XSB Prolog (cont.) Table are used from call to call until: abolish_all_table,abolish_table_pred(P/A) WF negation can be used via tnot(Pred) Explicit negation via -Pred The answer to query Q is yes if Q is either true or undefined in the WFM The answer is no if Q is false in the WFM of the program

272
Distinguishing T from U After providing all answers, tables store suspended literals due to recursion through negation + Residual Program If the residual is empty then True If it is not empty then Undefined The residual can be inspected with: get_residual(Pred,Residual)

273
Residual program example :- table a/0. :- table b/0. :- table c/0. :- table d/0. a :- b, tnot(c). c :- tnot(a). b :- tnot(d). d :- d. | ?- a,b,c,d,fail. no | ?- get_residual(a,RA). RA = [tnot(c)] ; no | ?- get_residual(b,RB). RB = [] ; no | ?- get_residual(c,RC). RC = [tnot(a)] ; no | ?- get_residual(d,RD). no | ?-

274
Transitive closure Due to circularity completion cannot conclude not reach(c) SLDNF (and Prolog) loops on that query XSB-Prolog works fine :- auto_table. edge(a,b). edge(c,d). edge(d,c). reach(a). reach(A) :- edge(A,B),reach(B). |?- reach(X). X = a; no. |?- reach(c). no. |?-tnot(reach(c)). yes.

275
Transitive closure (cont) :- auto_table. edge(a,b). edge(c,d). edge(d,c). reach(a). reach(A) :- edge(A,B),reach(B). Declarative semantics closer to operational Left recursion is handled properly The version on the right is usually more efficient :- auto_table. edge(a,b). edge(c,d). edge(d,c). reach(a). reach(A) :- reach(B), edge(A,B). Instead one could have written

276
Grammars Prolog provides “for free” a right-recursive descent parser With tabling left-recursion can be handled It also eliminates redundancy (gaining on efficiency), and handle grammars that loop under Prolog.

277
Grammars example :- table expr/2, term/2. expr --> expr, [+], term. expr --> term. term --> term, [*], prim. term --> prim. prim --> [‘(‘], expr, [‘)’]. prim --> [Int], {integer(Int)}. This grammar loops in Prolog XSB handles it correctly, properly associating * and + to the left

278
Grammars example :- table expr/3, term/3. expr(V) --> expr(E), [+], term(T), {V is E + T}. expr(V) --> term(V). term(V) --> term(T), [*], prim(P), {V is T * P}. term(V) --> prim(V). prim(V) --> [‘(‘], expr(V), [‘)’]. prim(Int) --> [Int], {integer(Int)}. With XSB one gets “for free” a parser based on a variant of Earley’s algorithm, or an active chart recognition algorithm Its time complexity is better!

279
Finite State Machines :- table rec/2. rec(St) :- initial(I), rec(St,I). rec([],S) :- is_final(S). rec([C|R],S) :- d(S,C,S2), rec(R,S2). Tabling is well suited for Automata Theory implementations q0q1 q2 q3 a a b a initial(q0). d(q0,a,q1). d(q1,a,q2). d(q2,b,q1). d(q1,a,q3). is_final(q3).

280
Dynamic Programming Strategy for evaluating subproblems only once. –Problems amenable for DP, might also be for XSB. The Knap-Sack Problem: –Given n items, each with a weight K i (1 i n), determine whether there is a subset of the items that sums to K

281
The Knap-Sack Problem :- table ks/2. ks(0,0). ks(I,K) :- I > 0, I1 is I-1, ks(I1,K). ks(I,K) :- I > 0, item(I,Ki), K1 is K-Ki, I1 is I-1, ks(I1,K1). Given n items, each with a weight K i (1 i n), determine whether there is a subset of the items that sums to K. There is an exponential number of subsets. Computing this with Prolog is exponential. There are only I 2 possible distinct calls. Computing this with tabling is polynomial.

282
Knowledge Bases Mammal are animal Bats are mammals Birds are animal Penguins are birds Dead animals are animals Normally animals don’t fly Normally bats fly Normally birds fly Normally penguins don’t fly Normally dead animals don’t fly The taxonomy: Pluto is a mammal Joe is a penguin Tweety is a bird Dracula is a dead bat The elements: Dead bats don’t fly though bats do Dead birds don’t fly though birds do Dracula is an exception to the above In general, more specific information is preferred The preferences:

283
The taxonomy plutotweetydraculajoeanimalbirdmammaldead animalpenguinbatflies Definite rules Default rules Negated default rules

284
Taxonomy representation Taxonomy animal(X) mammal(X) mammal(X) bat(X) animal(X) bird(X) bird(X) penguin(X) deadAn(X) dead(X) Default rules ¬flies(X) animal(X), adf(X), not flies(X) adf(X) not ¬adf(X) flies(X) bat(X), btf(X), not ¬flies(X) btf(X) not ¬btf(X) flies(X) bat(X), bf(X), not ¬flies(X) bf(X) not ¬bf(X) ¬flies(X) penguin(X), pdf(X), not flies(X) pdf(X) not ¬pdf(X) ¬flies(X) deadAn(X), ddf(X), not flies(X) ddf(X) not ¬ddf(X) Facts mammal(pluto). bird(tweety). deadAn(dracula). penguin(joe). bat(dracula). Explicit preferences ¬btf(X) deadAn(X), bat(X), r1(X) r1(X) not ¬r1(X) ¬btf(X) deadAn(X), bird(X), r2(X) r2(X) not ¬r2(X) ¬r1(dracula) ¬r2(dracula) Implicit preferences ¬adf(X) bat(X), btf(X) ¬adf(X) bird(X), bf(X) ¬bf(X) penguin(X), pdf(X)

285
Bibliography (1) The first part of this course is covered in detail in: –[AP96] J.J. Alferes and L.M. Pereira. Reasoning with Logic Programming. Springer LNAI 1111, 1996 See references there for the original definitions For more on semantics of normal LPs see: –[PP90] H. Przymusinska and T. Przymusinski. Semantic issues in deductive databases and logic programs. In R. Banerji ed, Formal Techniques in AI, a Sourcebook. North Holland, 1990 For more on derivation procedures: –[AB94] K. Apt and R. Bol. Logic Programming and Negation: A survey. In Journal of L.P., 1994

286
Bibliography (2) For more on LP for KRR: –[BG94] C. Baral and M. Gelfond. Logic Programming and Knowledge Representation. In Journal of L.P., 1994 For relation with NMR and structural properties: –[BDK97] G. Brewka, J. Dix and K. Konolige. Nonmonotonic Reasoning: an overview. CSLI Publications, 1997 For more on tabling and XSB-Prolog see the following page, and references therein: –http://xsb.sourceforge.net

287
Bibliography (3) For more on answer-set programming: –V. Lifschitz. Answer-set programming and plan generation (draft). Available at: –Christoph Koch. The DLV tutorial. Available at:

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google