Unformatted text preview: Semantics of Datalog With Negation
Local Stratification
Stable Models
WellFounded Models
1 The Story So Far 1
x When there is no (IDB) negation, there is a unique minimal model (least fixedpoint), which is the accepted meaning of the Datalog program.
x With negation, we often have several minimal models, and we need to decide which one is meant by the program.
2 The Story So Far 2
x When the program is stratified, one minimal model is the stratified model. This model appears in all cases to be the one we intuitively want.
Important technical point: if the program actually has no negation, then the stratified model is the unique minimal model.
Thus, stratified semantics extends least
fixedpoint semantics.
3 What About Unstratified Datalog?
x There are some more general conditions under which an “accepted” choice among models exists.
x From least to most general: Locally stratified models, modularly stratified models, stable/wellfounded models. 4 Why Should We Care?
1. Solidify our understanding of when declarative assertions, like logical rules, lead to a meaningful description of something.
2. SQL recursion really deals with ambiguities of the same kind, especially regarding aggregations, as well as negation.
5 Ground Atoms
x All these approaches start by instantiating the rules: replace variables by constants in all possible ways, and throw away instances of the rules with a known false EDB subgoal.
x An atom with no variables is a ground atom.
Like propositions in propositional calculus.
6 Example: Ground Atoms
x Consider the Win program:
win(X) : move(X,Y) & NOT win(Y)
with the following moves:
1 2 3 win(1) : move(1,2) & NOT win(2)
win(1) : move(1,3) & NOT win(3)
win(2) : move(2,3) & NOT win(3)
7 Example Continued
win(1) : move(1,2) & NOT win(2)
win(1) : move(1,3) & NOT win(3)
win(2) : move(2,3) & NOT win(3) x Other instantiations of the rule have a false move subgoal and therefore cannot infer anything.
x win(1), win(2), and win(3) are the only relevant IDB ground atoms for this game.
8 Locally Stratified Models
1. Build dependency graph with: x Nodes = relevant IDB ground atoms.
x Arc p > q iff q appears in an instantiated body with head p.
x Label – on arc if q is negated. 1. Stratum of each node defined as before.
2. Locally stratified = finite strata only.
9 Example
win(1) : move(1,2) & NOT win(2)
win(1) : move(1,3) & NOT win(3)
win(2) : move(2,3) & NOT win(3)
win(1)
Stratum 2 win(2)
Stratum 1 win(3)
Stratum 0 10 Locally Stratified Model
Include all EDB ground atoms;
FOR (stratum i = 0, 1, …) DO
WHILE (changes occur) DO
IF (some rule for some p at
stratum i has a true body)
THEN add p to model; 11 Example
win(1) win(2) win(3) win(1) : move(1,2) & NOT win(2)
win(1) : move(1,3) & NOT win(3)
win(2) : move(2,3) & NOT win(3) 1. No rules for win(3); therefore false.
2. win(2) rule satisfied; therefore true.
3. Second rule for win(1) satisfied,
therefore win(2) also true.
12 Stable Models Intuition
x A model M is “stable” if, when you apply the rules to M and add in the EDB, you infer exactly the IDB portion of M.
x But … when applying the rules to M, you can only use nonmembership in M. 13 Example
x The Win program again:
win(X) : move(X,Y) & NOT win(Y)
with moves:
1
2
3
x M = EDB + {win(1), win(2)} is stable.
Y = 3, X = 1 yields win(1).
Y = 3, X = 2 yields win(2).
Cannot yield win(3). 14 GelfondLifschitz Transform (Formal Notion of Stability) 1. Instantiate rules in all possible ways.
2. Delete instantiated rules with any false EDB or arithmetic subgoal (incl. NOT).
3. Delete instantiated rules with an IDB subgoal NOT p(…), where p(…) is in M.
4. Delete subgoal NOT p(…) if p(…) is not in M.
5. Delete true EDB and arithmetic subgoals.
15 GL Transform Continued
x Use the remaining instantiated rules plus EDB to infer all possible IDB ground atoms.
x Then add in the EDB.
x Result is GL(M ).
x M is stable iff GL(M ) = M. 16 Example
x The Win program yet again:
win(X) : move(X,Y) & NOT win(Y)
with moves:
1
2
3
x M = EDB + {win(1), win(2)}.
Step (3): neg
ated true IDB.
x After steps (1) and (2):
win(1) : move(1,2) & NOT win(2)
win(1) : move(1,3) & NOT win(3)
win(2) : move(2,3) & NOT win(3)
17 Example Continued
win(1) : move(1,3) & NOT
win(3)
win(2) : move(2,3) & NOT
win(3) Step (5): true
Step (4): negated
EDB subgoal.
false IDB subgoal. Remaining rules have true (empty) bodies.
Infer win(1), win(2).
GL(M ) = EDB + {win(1), win(2)} = M.
18 Bottom Line on the GL Transform
x You can use (positive or negative) IDB and EDB facts from M to satisfy or falsify a negated subgoal.
x You can use a positive EDB fact from M to satisfy a positive subgoal.
x But you can only use a positive IDB fact to satisfy a positive IDB subgoal if that fact has been derived in the final step.
19 To Make the Point Clear…
x If all I have is the instantiated rule p(1) : p(1), then M = {p(1)} is not stable.
x We cannot use the membership of positive IDB subgoal p(1) in M to make the body of the rule true. 20 The Stable Model
x If a program and EDB has exactly one model M with that EDB that is stable, then M is the stable model for the program and EDB.
x Otherwise, there is no stable model for this program and EDB. 21 Propositional Datalog
x Many useful examples use propostional variables (0ary predicates).
x All propositional variables are IDB.
x For GL transform, just: 1. Eliminate rules with a negated variable that is in M.
2. Eliminate subgoal NOT p if p in M.
3. Run the deduction step.
22 Example: p: NOT q, q : NOT p
{p} is stable. p : NOT q
q : NOT p Eliminate rule with
a false negated subgoal. Eliminate
true subgoal
that is the
NOT of IDB. Infer only p.
Thus, {p} is stable.
Unfortunately, so is {q}.
Thus, this program has no stable model.
23 p: p & NOT q, q : NOT p
{p} is not stable. p : p & NOT q
q : NOT p Eliminate rule with
a false subgoal. Eliminate
true negated subgoal. Cannot infer p !
GL({p}) = ∅.
{p} is not stable.
24 Example Continued
{q} is stable. p : p & NOT q
q : NOT p Eliminate rule with
a false negated subgoal. Eliminate
true negated
subgoal. Infer only q.
Thus, {q} is stable.
GL({p,q}) = ∅; GL(∅) = {q}.
Thus, {q} is the (unique) stable model.
25 3Valued Models
x Needed for “wellfounded semantics.”
x Model consists of:
1. A set of true EDB facts (all other EDB facts are assumed false).
2. A set of true IDB facts.
3. A set of false IDB facts (remaining IDB facts have truth value “unknown”).
26 WellFounded Models
x Start with instantiated rules.
x Clean the rules = eliminate rules with a known false subgoal, and drop known true subgoals.
x Two modes of inference:
1. “Ordinary”: if the body is true, infer head.
2. “Unfounded sets”: assume all members of an unfounded set are false.
27 Unfounded Sets
x U is an unfounded set (of positive, ground, IDB atoms) if every remaining instantiated rule with a member of U in the head also has a member of U in the body.
x Note we could never infer any member of U to be true.
x But assuming them false is still “metalogic.”
28 Example
p : q, q : p
x {p,q} is an unfounded set.
x So is ∅.
x Note the property of being an unfounded set is closed under union, so there is always a unique, maximal unfounded set.
29 Constructing the Well
Founded Model
REPEAT
“clean” instantiated rules;
make all ordinary inferences;
“clean” instantiated rules;
find the largest unfounded set
and make its atoms false;
UNTIL no changes;
make all remaining IDB atoms
“unknown”;
30 Example
win(X) : move(X,Y) & NOT win(Y)
with these moves:
1 2 3 4 5 6 31 Instantiated, Cleaned Rules
win(1)
win(2)
win(2)
win(3)
win(4)
win(5) :::::: NOT
NOT
NOT
NOT
NOT
NOT win(2)
win(1)
win(3)
win(4)
win(5)
win(6) No ordinary
inferences.
{win(6)} is the
largest unfounded
set. Infer
NOT win(6). 32 Second Round
win(1)
win(2)
win(2)
win(3)
win(4)
win(5) :::::: NOT
NOT
NOT
NOT
NOT win(2)
win(1)
win(3)
win(4)
win(5) Infer win(5). {win(4)} is the
largest unfounded
set. Infer
NOT win(4). 33 Third Round
win(1)
win(2)
win(2)
win(3)
win(5) : NOT win(2)
Infer win(3).
: NOT win(1)
: NOT win(3)
:No nonempty
:unfounded set,
so done.
34 Example Concluded
x Well founded model is:
{win(3), win(5), NOT win(4), NOT win(6)}.
x The remaining IDB ground atoms win(1) and win(2) have truth value “unknown.”
x Notice that if both sides play best, 3 and 5 are a win for the mover, 4 and 6 are a loss, and 1 and 2 are a draw.
1 2 3 4 5 6
35 Another Example
p : q
r : p & q
q : p
s : NOT p & NOT
q
x First round: no ordinary inferences.
x {p, q} is an unfounded set, but {p, q, r} is the largest unfounded set.
x Second round: infer s from NOT p and NOT q.
x Model: {NOT p, NOT q, NOT r, s}.
36 Alternating Fixedpoint
1. Instantiate and “clean” the rules.
2. In “round 0,” assume all IDB ground atoms are false.
3. In each round, apply the GL transform to the EDB plus true IDB ground atoms from the previous round. 37 Alternating Fixedpoint 2
x Process converges to an alternation of two sets of true IDB facts.
x Even rounds only increase; odd rounds only decrease the sets of true facts.
x In the limit, true facts are true in both sets; false facts are false in both sets, and “unknown” facts alternate.
38 Previous Win Example
1 win(1)
win(2)
win(2)
win(3)
win(4)
win(5) 2 :::::: 3 NOT
NOT
NOT
NOT
NOT
NOT 4 5 6 win(2)
win(1)
win(3)
win(4)
win(5)
win(6)
39 Computing the AFP
1 Round
win(1)
win(2)
win(3)
win(4)
win(5)
win(6) 2 0
0
0
0
0
0
0 3 1
1
1
1
1
1
0 2
0
0
0
0
1
0 4 3
1
1
1
0
1
0 4
0
0
1
0
1
0 5 6 5
1
1
1
0
1
0
40 Another Example
p : q
q : p
Round
p
q
r
s 0
0
0
0
0 r : p & q
s : NOT p & NOT q
12
00
00
00
11
41 Yet Another Example
p : q q : NOT p
Round 0 1 2
p
01 0
q
01 0
Notice how p
is inferred only
after we infer
q on this round Notice that we may
not use positive
IDB fact q from
previous round to
infer p. 42 Containment of Semantics
x Say method A < method B if: 1. Whenever a program has a model according to method A, it has the same model under method B.
2. There is at least one program that has a model under B but not under A. x Draw B above A in diagrams. 43 Comparison of Semantics
Stable Wellfounded Locally stratified
Stratified
Least Fixedpoint
44 LFP < Stratified
x LFP only applies to Datalog without negation.
x What does Stratified do when there is no negation?
x Everything is in stratum 0, and the whole IDB is computed by the LFP algorithm.
x So Stratified model = LFP model.
45 Stratified < Locally Stratified
x Consider a Datalog program P with a stratified model, S. Need to show:
1. P is locally stratified.
2. Fact q(…) in S is in the locally stratified model L.
3. Fact q(…) in L is also in S. 46 P Is Locally Stratified
x Key idea: path with n ’s starting at q(…) in dependency graph of ground atoms implies a path with n ’s starting at q in the dependency graph of predicates.
q(1,2) p(3,4) s(5,6) t(7,8) s t implies
q p 47 P Is Locally Stratified 2
x Thus, stratum of ground atom q(…) is no greater than the stratum of predicate q.
x If the strata of all predicates in P are finite, then the strata of all ground atoms are finite.
I.e., if P is stratified, it is locally stratified for any EDB.
48 q(…) in S iff q(…) in L
x Proof = induction on stratum of q.
x Basis: stratum 0.
x Then q(…) is inferred for S using naïve evaluation, with no negated IDB subgoals ever used.
x The same sequence of inferences, using instantiated rules, lets us infer q(…) as we compute L.
49 S = L, Continued
x Conversely, if q(…) is in L, then it is inferred using no negated IDB subgoals.
x Thus, the same sequence of inferences will be carried out using naïve evaluation for S. 50 Inductive Step
x Suppose q is at stratum i.
x Suppose q(…) is inferred for S at stratum i, using naïve evaluation with all IDB at stratum <i treated as EDB.
x By inductive hypothesis, L and S agree below stratum i.
x Thus, same sequence of inferences, starting with what is known about L, infers q(…) for L; i.e. S ⊆ L.
51 Inductive Step: L ⊆ S
x Suppose q(…) is inferred for L, and q is at stratum i.
x Then the inference uses an instantiated rule, with any negated IDB subgoals having predicates at strata <i.
x By the inductive hypothesis, L and S agree on all those instantiated subgoals.
52 Inductive Step Concluded
x Thus, naïve evaluation at stratum i puts q(…) in S.
Requires another induction about predicates at stratum i. x That is, L ⊆ S.
x Therefore L = S. 53 More Proofs
x We’re not going to prove that the locally stratified model, if it exists, is both the unique stable model and the well
founded model. 54 Comparison of Stable and WellFounded
x If there is a 2valued (no UNKNOWN’s) wellfounded model, then that is also the stable model.
x Yet, computing the wellfounded model by alternating fixedpoint is polynomial in the size of the database.
x But it is NPhard to tell whether a program has a unique stable model.
55 ...
View
Full
Document
This document was uploaded on 01/06/2012.
 Spring '09

Click to edit the document details