Understanding Stable and Well-Founded Semantics in Logic Programming, Study notes of Database Programming

The concepts of stable and well-founded semantics in logic programming, focusing on the relationship between a program and its database (edb). It covers the uniqueness of stable models, the role of locally stratified models, and the comparison of complexities between stable and well-founded approaches.

Typology: Study notes

2011/2012

Uploaded on 07/15/2012

salagame
salagame 🇮🇳

4

(3)

36 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Relationships Among Semantics
If a program + EDB has a stratied or perfect
(locally stratied) model, then that is the unique
stable model.
A program + EDB can have a unique stable
model even if there is no perfect model.
Example
p :- NOT q
q :- NOT p
p :- NOT p
Only
f
p
g
is a stable model.
Note that without the 3rd rule, both
f
p
g
and
f
q
g
are stable.
Why Stratied Models are Stable
Intuition to prove stratied model
M
is stable:
Divide
M
into strata
M
0
;M
1
;:::
(
M
0
includes
the EDB).
LFP of stratum 0 does not involve negation,
so its instantiated rules survivetothe
inference step of the GL transform, and
exactly
M
0
is inferred.
Thus,
M
0
, and nothing else for stratum 0, is
in
GL
(
M
).
Consider what happens computing the
stratied model at stratum 1.
Negated subgoals are resolved according
to
M
0
.
Instantiated rules with a negated member
of
M
0
eectively disappear, and those
with a negated nonmember of
M
0
eectively lose that subgoal.
Thus, the LFP for stratum 1 looks just like
the GL transform for the relevant instantiated
rules.
Example
Let's revisit the locally stratied \Win" example:
1 2 3
whose relevant instantiated rules were:
1
docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Understanding Stable and Well-Founded Semantics in Logic Programming and more Study notes Database Programming in PDF only on Docsity!

Relationships Among Semantics

If a program + EDB has a strati ed or p erfect (lo cally strati ed) mo del, then that is the unique stable mo del.

 A program + EDB can have a unique stable mo del even if there is no p erfect mo del.

Example

p :- NOT q q :- NOT p p :- NOT p

 Only fpg is a stable mo del.

 Note that without the 3rd rule, b oth fpg and fq g are stable.

Why Strati ed Mo dels are Stable

Intuition to prove strati ed mo del M is stable:

 Divide M into strata M 0 ; M 1 ; : : : (M 0 includes the EDB).

 LFP of stratum 0 do es not involve negation, so its instantiated rules survive to the inference step of the GL transform, and exactly M 0 is inferred.

 Thus, M 0 , and nothing else for stratum 0, is in GL(M ).

 Consider what happ ens computing the strati ed mo del at stratum 1.

F Negated subgoals are resolved according to M 0.

F Instantiated rules with a negated memb er of M 0 e ectively disapp ear, and those with a negated nonmemb er of M 0 e ectively lose that subgoal.

 Thus, the LFP for stratum 1 lo oks just like the GL transform for the relevant instantiated rules.

Example

Let's revisit the lo cally strati ed \Win" example:

whose relevant instantiated rules were:

r 1 : win(1) :- move(1,2) & NOT win(2) r 2 : win(1) :- move(1,3) & NOT win(3) r 3 : win(2) :- move(2,3) & NOT win(3)

 Recall stratum 0 = w in(3) + EDB facts; stratum 1 = w in(2); stratum 2 = w in(1).

 Also recall: the strati ed mo del is fw in(1); w in(2)g + the EDB; we must show this mo del is also stable.

 Stratum 0: No relevant rules, so w in(3) is false. Likewise, w in(3) is not inferred in the GL pro cedure.

 Stratum 1: Since w in(3) is false, the rules for stratum 1 b ecome: r 3 : win(2) :-

w in(2) is inferred, b oth in the strati ed and GL pro cedures.

 Stratum 2: Since w in(2) is true and w in(3) is false, the rule for stratum 2 b ecomes: r 2 : win(1) :- Again, the same thing happ ens to this rule in the GL pro cedure, so we infer w in(1) in b oth strati ed and stable approaches.

Well-Founded Mo del

 3-valued mo del: true, false, unknown.

 WF mo del has p ositive facts like p(1) and negative facts like :p(1).

 IDB ground atoms not mentioned are assumed to b e \unknown."

 EDB ground atoms not mentioned are assumed false.

Two Mo des of Inference

  1. If b o dy is true, infer head.
  2. Lo ok for unfounded sets : If, after instantiating rules in all p ossible ways and eliminating those with a known false subgoal, there is a set U of p ositive ground atoms such that every rule with a memb er of U in the head has a memb er of U as one of its subgoals, then U is unfounded. F We cannot prove any memb er of U , b ecause we would have to prove another

2

 Truth value of w in(1) and w in(2) is \unknown."

Example

p :- q q :- p r :- p & q s :- NOT p & NOT q

 fp; q g is an unfounded set.

 But fp; q ; r g is the largest unfounded set.

F Note: union of unfounded sets is unfounded, so there is always a largest.

 WF mo del: f:p; :q ; :r; sg.

Alternating Fixed Point

  1. Instantiate rules in all p ossible ways.
  2. Eliminate rules with false EDB or arithmetic subgoal; eliminate true EDB and arithmetic subgoals from remaining rules for convenience.
  3. Initialize all IDB ground atoms to false.
  4. Rep eatedly evaluate IDB subgoals by applying the GL transform to the mo del consisting of the EDB + an IDB based on the previous round's true/false decisions.

 In the limit, IDB ground atoms that converge to true are true. Those that converge to false are false. Those that oscillate are unknown.

Example

Rep eating ab ove \Win" example:

Rules pro cessed by (1) and (2):

win(1) :- NOT win(2) win(2) :- NOT win(1) win(2) :- NOT win(3) win(3) :- NOT win(4) win(4) :- NOT win(5) win(5) :- NOT win(6)

Using alternating xed p oint:

Round 0 1 2 3 4 5 w in(1) 0 1 0 1 0 1 w in(2) 0 1 0 1 0 1 w in(3) 0 1 0 1 1 1 w in(4) 0 1 0 0 0 0 w in(5) 0 1 1 1 1 1 w in(6) 0 0 0 0 0 0

Another Example

p :- q; q :- NOT p

Round 0 1 2 3 4 5 p 0 1 0 1 0 1 q 0 1 0 1 0 1

 Round 0: Both are 0 as always.

 Round 1: Rules simplify to p :- q; q :-. Infer b oth q and p.

 Round 2: Rules simplify to p :- q. No inference p ossible!

 Round 3 and later: Rep eats.

 Conclude b oth p and q are \unknown."

Relationships Among Semantics

 If there is a 2-valued WF mo del, it is the unique stable mo del.

 If there is a p erfect mo del (i.e., program + EDB is lo cally strati ed), then this mo del is also the stable and WF mo del, and obviously is 2-valued.

 There can b e a 3-valued WF mo del when there is no stable semantics (i.e., no unique stable mo del).

Example

Win program with EDB move(1,2), move(2,1).

 Two stable mo dels, fw in(1)g and fw in(2)g. Thus, a stable semantics do es not exist.

 However, the WF mo del exists and makes b oth w in(1) and w in(2) \unknown."

 There can b e a unique stable mo del 6 = WF mo del.

5

Example

Consider a collection of buildings:

 Buildings have either lounges or cafeterias, not b oth.

 No adjacent buildings b oth have cafeterias.

 If a building do es not have a cafeteria, then an adjacent building must have one. lounge(X) :- adj(X,Y) & cafeteria(Y) cafeteria(X) :- NOT lounge(X)

If we get rid of \cafeteria":

lounge(X) :- adj(X,Y) & NOT lounge(Y)

Lo oks just like \win."

 Problem is really: nd a maximal indep endent set of buildings in which to put cafeterias.

 The stable mo dels are the maximal indep endent sets.

 But the WF mo del makes cafeteria(X) true i X is in every maximal indep endent set.

Comparison of Complexity for Stable Versus WF

 It is NP-hard to tell whether a prop ositional logic program has a stable semantics, i.e., a unique stable mo del.

 It is p olynomial to construct the WF mo del.

 Same comments hold for rst-order logic, but with complexity measured in terms of the EDB size rather than the numb er of prop ositions.

Mo dularly Strati ed Semantics

 Motivation: largest known class of Datalog- with-negation programs for which magic-sets (query optimization technique to b e discussed) works.

 Must b e able to partition the rules into \mo dules," such that

  1. All recursion is within a mo dule.
  1. All mo dules have lo cally strati ed semantics with resp ect to the EDB and the previously computed mo dels for any lower mo dules. F I.e., treat all true facts b elonging to lower mo dules as if they were EDB facts.

 Mo dularly strati ed semantics = what we get by computing lo cally strati ed semantics for mo dules, b ottom up.

 Note mo dules are partially ordered by dep endence among their predicates, b ecause all recursion must take place within a single mo dule.

Example

Consider:

win(X) :- move(X,Y) & NOT win(Y)

with mov e relation fmov e(1; 2)g.

 We might app ear to have a cycle in the instantiated rules r 1 : win(1) :- move(1,2) & NOT win(2) r 2 : win(2) :- move(2,1) & NOT win(1) But the fact that mov e(2; 1) is false removes r 2.

 The only dep endence is w in(1)! w in(2), and this program + EDB is lo cally strati ed.

Example (Continued)

 Next, supp ose we add an IDB predicate mov e 1 to b e identical to mov e: win(X) :- move1(X,Y) & NOT win(Y) move1(X,Y) :- move(X,Y)

Now, with the same EDB, we instantiate the w in rule as:

r 1 : win(1) :- move1(1,2) & NOT win(2) r 2 : win(2) :- move1(2,1) & NOT win(1)

 It is not apparent that w in(2) do es not dep end on w in(1), so it lo oks like we have a cycle in the dep endency graph. F The di erence is that mov e 1 is IDB, while mov e is EDB.

 This program + EDB is not lo cally strati ed.