> ](
/0DTimes New Roman30Wo
0DTahomaew Roman30Wo
0" DMonotype Sorts30Wo
00DCourier Newts30Wo
01@DSymbol Newts30Wo
0PDWingdings 3ts30Wo
0
`.
@n?" dd@ @@``d\=10/.-,
+
c$`f3f33f@33g4CdCd0jppp@uʚ;2Nʚ;<4!d!dЁ
0<4ddddЁ
0<4BdBdЁ
0n___PPT9/00
<8%&?O=TDatalogRules
Programs
NegationReview of Logical If-Then Rules TerminologyHead and subgoals are atoms.
An atom consists of a predicate (lower case) applied to zero or more arguments (upper case letters or constants).H ' &
SemanticsPredicates represent relations.
An atom is true for given values of its variables iff the arguments form a tuple of the relation.
Whenever an assignment of values to all variables makes all subgoals true, the rule asserts that the resulting head is also true.>RM =ExampleWe shall develop rules that describe what is necessary to make a file.
The predicates/relations:
source(F) = F is a source file.
includes(F,G) = F #includes G.
create(F,P,G) = F is created by applying process P to file G.cc
Example --- ContinuedjRules to define view req(X,Y) = file Y is required to create file X :
req(F,F) :- source(F)
req(F,G) :- includes(F,G)
req(F,G) :- create(F,P,G)
req(F,G) :- req(F,H) & req(H,G)BHn'q/ Why Not Just Use SQL?Recursion is much easier to express in Datalog.
Viz. last rule for req.
Rules express things that go on in both FROM and WHERE clauses, and let us state some general principles (e.g., containment of rules) that are almost impossible to state correctly in SQL.b0uuu0'
IDB/EDBA predicate representing a stored relation is called EDB (extensional database).
A predicate representing a view, i.e., a defined relation that does not exist in the database is called IDB (intesional database).
Head is always IDB; subgoals may be IDB or EDB.65I, Datalog Programs A collection of rules is a (Datalog) program.
Each program has a distinguished IDB predicate that represents the result of the program.
E.g., req in our example.N%\,k
Extensions>Negated subgoals.
Constants as arguments.
Arithmetic subgoals.?u?,%
Negated SubgoalsNOT in front of a subgoal means that an assignment of values to variables must make it false in order for the body to be true.
Example: cycle(F) :- req(F,F) & NOT source(F),Constants as ArgumentsWe use numbers, lower-case letters, or quoted strings to indicate a constant.
Example: req( foo.c , stdio.h ) :-
Note that empty body is OK.
Mixed constants and variables also OK.0CuC>X KArithmetic SubgoalsComparisons like < may be thought of as infinite, binary relations.
Here, the set of all tuples (x,y) such that x 1 & B != A@D1D1N1Y
Evaluating Datalog Programs Nonrecursive programs.
Nave evaluation of recursive programs without IDB negation.
Seminave evaluation of recursive programs without IDB negation.
Eliminates some redundant computation.Du'uZ :'$
G
^SafetyWhen we apply a rule to finite relations, we need to get a finite result.
Simple guarantee: safety = all variables appear in some nonnegated, relational (not arithmetic) subgoal of the body.
Start with the join of the nonnegated, relational subgoals and select/delete from there.8Y\^YP
(
Examples: Nonsafety
^p(X) :- q(Y)
bachelor(X) :- NOT married(X,Y)
bachelor(X) :- person(X) &
NOT married(X,Y)__Nonrecursive Evaluation
If (and only if!) a Datalog program is not recursive, then we can order the IDB predicates so that in any rule for p (i.e., p is the head predicate), the only IDB predicates in the body precede p.Hs FWhy?Consider the dependency graph with:
Nodes = IDB predicates.
Arc p -> q iff there is a rule for p with q in the body.
Cycle involving node p means p is recursive.
No cycles: use topological order to evaluate predicates.%Th
IIApplying RuleslTo evaluate an IDB predicate p :
Apply each rule for p to the current relations corresponding to its subgoals.
Apply = If an assignment of values to variables makes the body true, insert the tuple that the head becomes into the relation for p (no duplicates).
Take the union of the result for each p-rule.!Puu.u:&,gTnExamplep(X,Y) :- q(X,Z) & r(Z,Y) & Y<10
Q = {(1,2), (3,4)}; R = {(2,5), (4,9), (4,10), (6,7)}
Assignments making the body true: (X,Y,Z) = (1,5,2), (3,9,4)
So P = {(1,5), (3,9)}.(zV!Algorithm for NonrecursiveFOR (each predicate p in topological order) DO
apply the rules for p to
previously computed relations
to compute relation P for p;Nave Evaluation for Recursivemake all IDB relations empty;
WHILE (changes to IDB) DO
FOR (each IDB predicate p) DO
evaluate p using current
values of all relations;Important PointsAs long as there is no negation of IDB subgoals, then each IDB relation grows, i.e., on each round it contains at least what it used to contain.
Since relations are finite, the loop must eventually terminate.
Result is the least fixedpoint (minimal model ) of rules.6,'Seminave Evaluation$
VKey idea: to get a new tuple for relation P on one round, the evaluation must use some tuple for some relation of the body that was obtained on the previous round.
Maintain DP = new tuples added to P on previous round.
Differentiate rule bodies to be union of bodies with one IDB subgoal made D. *,~P:Y]
,Example ( make files )r(F,F) :- s(F)
r(F,G) :- i(F,G))
r(F,G) :- c(F,P,G)
r(F,G) :- r(F,H) & r(H,F)
Assume EDB predicates s, i, c have relations S, I, C.(N6N6 Example --- ContinuedInitialize: R = DR = s#1=#2(S S) I p1,3(C)
Repeat until DR = f:
DR = p1,3(R wv DR DR wv R)
DR = DR - R
R = R DRF4u!Function Symbols in RulesExtends Datalog by allowing arguments built from constants, variables, and function names, recursively applied.
Function names look like predicate names, but are allowed only within the arguments of atoms.
Predicates return true/false; functions return arbitrary values.&AA"ExampleInstead of a string argument like 101 Maple we could use a term like
addr(street( Maple ), number(101))
Compare with the XML term
<ADDR><STREET>Maple</STREET>
<NUMBER>101</NUMBER>
</ADDR>bQ$;,";,".u#Another ExamplePredicates:
isTree(X) = X is a binary tree.
label(L) = L is a node label.
Functions:
node(A,L,R) = a tree with root labeled A, left subtree L, and right subtree R.
null = 0-ary function (constant) representing the empty tree.@uw :Pt
1$Example --- ContinuedcThe rules:
isTree(null) :-
isTree(node(L,T1,T2)) :-
label(L) &
isTree(T1) &
isTree(T2)(Y
WP
$
%Example --- ConcludedAssume label(a) and label(b) are true.
I.e., a and b are in the relation for label.
Infer isTree(node(a,null,null)).
Infer isTree(node(b,null,node(a,null,null))).Z'/O'!O,\"&)Evaluation of Rules With Function SymbolsNave, seminave still work when there are no negated IDB subgoals.
They both lead to the unique least fixedpoint (minimal model).
But& this fixedpoint may not be reached in any finite number of rounds.
The isTree rules are an example.F!
b
( %7' Problems With IDB NegationWhen rules have negated IDB subgoals, there can be several minimal models.
Recall: model = set of IDB facts, plus the given EDB facts, that make the rules true for every assignment of values to variables.
Rule is true unless body is true and head is false.L4Sv!(!Example: EDBb red(X,Y)= the Red bus line runs from X to Y.
green(X,Y)= the Green bus line runs from X to Y.
c )"Example: IDBH greenPath(X,Y)= you can get from X to Y using only Green buses.
monopoly(X,Y)= Red has a bus from X to Y, but you can t get there on Green, even changing buses.8
*#Example: Rules~greenPath(X,Y) :- green(X,Y)
greenPath(X,Y) :- greenPath(X,Z) & greenPath(Z,Y)
monopoly(X,Y) :- red(X,Y) & NOT greenPath(X,Y)Z
' +$EDB Datared(1,2), red(2,3), green(1,2),%Two Minimal ModelsEDB + greenPath(1,2) + monopoly(2,3)
EDB + greenPath(1,2) + greenPath(2,3) + greenPath(1,3)
greenPath(X,Y) :- green(X,Y)
greenPath(X,Y) :- greenPath(X,Z) &
greenPath(Z,Y)
monopoly(X,Y) :- red(X,Y) &
NOT greenPath(X,Y)4\u\
(
-&Stratified ModelsDependency graph describes how IDB predicates depend negatively on each other.
Stratified Datalog = no recursion involving negation.
Stratified model is a particular model that makes sense for stratified Datalog programs.Fu@%L,[n
.'Dependency GraphdNodes = IDB predicates.
Arc p -> q iff there is a rule for p that has a subgoal with predicate q.
Arc p -> q labeled iff there is a subgoal with predicate q that is negated.$1P##'#/(Monopoly Example0),Another Example: Win win(X) :- move(X,Y) & NOT win(Y)
Represents games like Nim where you win by forcing your opponent to a position where they have no move.("h"h8N1*4Dependency Graph for Win 2+StrataThe stratum of an IDB predicate is the largest number of s on a path from that predicate, in the dependency graph.
Examples:3-Stratified ProgramsIf all IDB predicates have finite strata, then the Datalog program is stratified.
If any IDB predicate has the infinite stratum, then the program is unstratified, and no stratified model exists.6G E",3Z"4,Stratified ModelEvaluate strata 0, 1,& in order.
If the program is stratified, then any negated IDB subgoal has already had its relation evaluated.
Safety assures that we can subtract it from something.
Treat it as EDB.
Result is the stratified model.6J J T5.Examples
For Monopoly, greenPath is in stratum 0: compute it (the transitive closure of green).
Then, monopoly is in stratum 1: compute it by taking the difference of red and greenPath.
Result is first model proposed.
Win is not stratified, thus no stratified model.nZ 8 9 U,
U ` ̙33` ` ff3333f` 333MMM` f` f` 3>?" dd@,?udd@ w " @ ` n?" dd@ @@``PR @ ` `p>>f(
6o P
T Click to edit Master title style!
!
0q
RClick to edit Master text styles
Second level
Third level
Fourth level
Fifth level!
S
0v ``
>*
0| `
@*
0 `
@*Z
Byh@ ? ̙33 Default Design
0zr
(
0h P
Q
P*
0h h
R*
d
c$ ?
h
0h
@h
RClick to edit Master text styles
Second level
Third level
Fourth level
Fifth level!
S
6Xh `P h
P*
6x< ` h
R*
H
0h ? ̙330$$(
$r
$ SU<p<
r
$ S8V< `
<
H
$0h ? ̙33
,*
(
,r
, SБhP
h
,
0h @
l:h(X,& ) :- a(Y,& ) & b(Z,& ) & & 2l `
,`,$D
0f2
,
6`
,
0h `
8head 2ZB
,
s*D l 0
,0 ,$D
0
,
0hp'
8body 2ZB
,B
s*D
f2
,
6`00 `l
,
,$D
0l2
,
< l2
,
<
,
6hP
Vsubgoals 2 `B
,
0Dp
`B
,
0DP
@
`B
,
0D@@
T
,
<h],$D
0
` The head is true if all the
subgoals are true. 11H
,0h ? ̙33
0P(
0r
0 S$hP
h
0 Sh<$
0h
H
00h ? ̙33
4P(
4r
4 ShP
h
4 S܆h<$
0h
H
40h ? ̙33
8P(
8r
8 S~hP
h
8 Slh0<$
0h
H
80h ? ̙33
PH<(
<r
< SP`hP
h
r
< Sahh
l @f
<@f,$D
0P
<
<Dchfg
HG is required for
F if there is some
process P that
creates F from G.xIf2
<
6@P
pZB
<B
s*D
l
<,$D
0
<
<nhf
,$D
0
"bG is required for F if there is some H such that
H is required for F and G is required for H.c`2
<
0
ZB
<
s*D@P
@H
<0h ? ̙33&
Lf(
Lr
L SHQhP
h
L SVhP<$
0h
"p`PpH
L0h ? ̙33
@P(
@r
@ SHhP
h
@ SIh0<$
0h
H
@0h ? ̙33
D$(
Dr
D SChP
h
r
D SDhh
H
D0h ? ̙33&
Pf(
Pr
P St9hP
h
P S=<<$
0h
"p`PpH
P0h ? ̙33
pTP(
Tr
T S2hP
h
T S3h<$
0h
H
T0h ? ̙33
`XP(
Xr
X Sp,hP
h
X SP-h<$
0h
H
X0h ? ̙33
P\P(
\r
\ S|%hP
h
\ S\&hP <$
0h
H
\0h ? ̙33&
@`f(
`r
` ShP
h
` S0h<$
0h
"p`PpH
`0h ? ̙33
0lP(
lr
l S0hP
h
l Sh @<$
0h
H
l0h ? ̙33
w p (
pr
p SԘ;P
;
r
p S;;
p
< d
l E
pE,$D
0
p
Bh
@X is the probleml2
p
< E`B
pB
0Dl P0
pP0 ,$D
0l2
p
<0
p
BhhP
IBoth X and Y
are problems`B
p
0D`l v
0
p0,$D
0f2
p
600
p
<
hv
DY is still a problemZB
p
s*DPP
H
p0h ? ̙33
d$(
dr
d SfP
f
r
d S$>L$LZ*$*Zh8$8hvF-$FvT$Tb$bp-$p~$~$-$-$$-$$-$-$,$,:
-$
:H$HV&-$&Vd4-$4drB-$BrP$P^-$^k-$ky-$y-$-$-$-$-$-$-$-$'-$'5-$5C-$CQ!-$!Q_/-$/_m=-$=m{K-$K{Y-$Yg-$gu-$u-$-$-$-$-$-$-$-$#-$#1-$1?-$?M-$M[+-$+[i9-$9iwG-$GwU-$Uc-$cq-$q-$-$-$-$-$-$-$-$-$--$-;-$;I-$IW'-$'We5-$5erB-$BrP-$P^-$^l-$lz-$z-$-$-$-$-$$-$-$($(6-$6D-$DR"$"R`0-$0`n>$>n|L-$L|Z$Zh$hv-$v$$$&&&-&$&&-&&
&&-&&&&-$0>$>L$LZ*$*Zh8$8hvF-$FvT$Tb$bp-$p~$~$-$-$$-$$-$-$,$,:
-$
:H$HV&-$&Vd4-$4drB-$BrP$P^-$^k-$ky-$y-$-$-$-$-$-$-$-$'-$'5-$5C-$CQ!-$!Q_/-$/_m=-$=m{K-$K{Y-$Yg-$gu-$u-$-$-$-$-$-$-$-$#-$#1-$1?-$?M-$M[+-$+[i9-$9iwG-$GwU-$Uc-$cq-$q-$-$-$-$-$-$-$-$-$--$-;-$;I-$IW'-$'We5-$5erB-$BrP-$P^-$^l-$lz-$z-$-$-$-$-$$-$-$($(6-$6D-$DR"$"R`0-$0`n>$>n|L-$L|Z$Zh$hv-$v$$$&-
--&&&y&hw@
ibwbw0- @Times New Romanbwbw0- . 2
f1 .--iyH-- @"Tahomaw@
lbwbw0- .2
C|Datalog(
!.--Q1-- @"Tahomaw@z
?bwbw0- .2
Rules
. .2
Programs$. .2
BNegation
.--"System
0-&TNPP &՜.+,0$
(On-screen ShowlStanford University, CS Dept.tilY/2 7Times New RomanTahomaMonotype SortsCourier NewSymbolWingdings 3Lucida Sans UnicodeDefault DesignDatalog Review of Logical If-Then RulesTerminology
SemanticsExampleExample --- ContinuedWhy Not Just Use SQL?IDB/EDBDatalog ProgramsExtensionsNegated SubgoalsConstants as ArgumentsArithmetic SubgoalsEvaluating Datalog ProgramsSafetyExamples: NonsafetyNonrecursive EvaluationWhy?Applying RulesExampleAlgorithm for NonrecursiveNave Evaluation for RecursiveImportant PointsSeminave EvaluationExample (make files)Example --- ContinuedFunction Symbols in RulesExampleAnother ExampleExample --- ContinuedExample --- Concluded*Evaluation of Rules With Function SymbolsProblems With IDB Negation
Example: EDB
Example: IDBExample: Rules EDB DataTwo Minimal ModelsStratified ModelsDependency GraphMonopoly ExampleAnother Example: WinDependency Graph for WinStrataStratified ProgramsStratified Model ExamplesFonts UsedDesign Template
Slide Titles/wts2|d0|Wo
0 1@DSymbol Newts2|d0|Wo
0 PDWingdings 3ts2|d0|Wo
0 `DLucida Sans Unicoded0|Wo
0 "
`.
@n?" dd@ @@``d\=1.
!"#$%&'()*+
,- .0/c$`f3f33f@33g4UdUd0pppp@uʚ;2Nʚ;<4!d!dЁ
0<4ddddЁ
0<4BdBdЁ
0___PPT9/00
<8%&?O=TDatalogRules
Programs
NegationReview of Logical If-Then Rules TerminologyHead and subgoals are atoms.
An atom consists of a predicate (lower case) applied to zero or more arguments (upper case letters or constants).H ' &
SemanticsPredicates represent relations.
An atom is true for given values of its variables iff the arguments form a tuple of the relation.
Whenever an assignment of values to all variables makes all subgoals true, the rule asserts that the resulting head is also true.>RM =ExampleWe shall develop rules that describe what is necessary to make a file.
The predicates/relations:
source(F) = F is a source file.
includes(F,G) = F #includes G.
create(F,P,G) = F is created by applying process P to file G.cc
Example --- ContinuedjRules to define view req(X,Y) = file Y is required to create file X :
req(F,F) :- source(F)
req(F,G) :-
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|~ includes(F,G)
req(F,G) :- create(F,P,G)
req(F,G) :- req(F,H) & req(H,G)BHn'q/ Why Not Just Use SQL?Recursion is much easier to express in Datalog.
Viz. last rule for req.
Rules express things that go on in both FROM and WHERE clauses, and let us state some general principles (e.g., containment of rules) that are almost impossible to state correctly in SQL.b0uuu0'
IDB/EDBA predicate representing a stored relation is calDocumentSummaryInformation8TRoot EntrydO)}TCurrent User2SummaryInformation(},/PowerPoint Document(lY
_HYUllmanUllman՜.+,0$
(On-screen ShowlStanford University, CS Dept.tilY/2 7Times New RomanTahomaMonotype SortsCourier NewSymbolWingdings 3led EDB (extensional database).
A predicate representing a view, i.e., a defined relation that does not exist in the database is called IDB (intesional database).
Head is always IDB; subgoals may be IDB or EDB.65I, Datalog Programs A collection of rules is a (Datalog) program.
Each program has a distinguished IDB predicate that represents the result of the program.
E.g., req in our example.N%\,k
Extensions>Negated subgoals.
Constants as arguments.
Arithmetic subgoals.?u?,%
Negated SubgoalsNOT in front of a subgoal means that an assignment of values to variables must make it false in order for the body to be true.
Example: cycle(F) :- req(F,F) & NOT source(F),Constants as ArgumentsWe use numbers, lower-case letters, or quoted strings to indicate a constant.
Example: req( foo.c , stdio.h ) :-
Note that empty body is OK.
Mixed constants and variables also OK.0CuC>X KArithmetic SubgoalsComparisons like < may be thought of as infinite, binary relations.
Here, the set of all tuples (x,y) such that x 1 & B != A@D1D1N1Y
Evaluating Datalog Programs Nonrecursive programs.
Nave evaluation of recursive programs without IDB negation.
Seminave evaluation of recursive programs without IDB negation.
Eliminates some redundant computation.Du'uZ :'$
G
^SafetyWhen we apply a rule to finite relations, we need to get a finite result.
Simple guarantee: safety = all variables appear in some nonnegated, relational (not arithmetic) subgoal of the body.
Start with the join of the nonnegated, relational subgoals and select/delete from there.8Y\^YP
(
Examples: Nonsafety
^p(X) :- q(Y)
bachelor(X) :- NOT married(X,Y)
bachelor(X) :- person(X) &
NOT married(X,Y)__Nonrecursive Evaluation
If (and only if!) a Datalog program is not recursive, then we can order the IDB predicates so that in any rule for p (i.e., p is the head predicate), the only IDB predicates in the body precede p.Hs FWhy?Consider the dependency graph with:
Nodes = IDB predicates.
Arc p -> q iff there is a rule for p with q in the body.
Cycle involving node p means p is recursive.
No cycles: use topological order to evaluate predicates.%Th
IIApplying RuleslTo evaluate an IDB predicate p :
Apply each rule for p to the current relations corresponding to its subgoals.
Apply = If an assignment of values to variables makes the body true, insert the tuple that the head becomes into the relation for p (no duplicates).
Take the union of the result for each p-rule.!Puu.u:&,gTnExamplep(X,Y) :- q(X,Z) & r(Z,Y) & Y<10
Q = {(1,2), (3,4)}; R = {(2,5), (4,9), (4,10), (6,7)}
Assignments making the body true: (X,Y,Z) = (1,5,2), (3,9,4)
So P = {(1,5), (3,9)}.(zV!Algorithm for NonrecursiveFOR (each predicate p in topological order) DO
apply the rules for p to
previously computed relations
to compute relation P for p;Nave Evaluation for Recursivemake all IDB relations empty;
WHILE (changes to IDB) DO
FOR (each IDB predicate p) DO
evaluate p using current
values of all relations;Important PointsAs long as there is no negation of IDB subgoals, then each IDB relation grows, i.e., on each round it contains at least what it used to contain.
Since relations are finite, the loop must eventually terminate.
Result is the least fixedpoint (minimal model ) of rules.6,'Seminave Evaluation$
VKey idea: to get a new tuple for relation P on one round, the evaluation must use some tuple for some relation of the body that was obtained on the previous round.
Maintain DP = new tuples added to P on previous round.
Differentiate rule bodies to be union of bodies with one IDB subgoal made D. *,~P:Y]
,Example ( make files )r(F,F) :- s(F)
r(F,G) :- i(F,G))
r(F,G) :- c(F,P,G)
r(F,G) :- r(F,H) & r(H,F)
Assume EDB predicates s, i, c have relations S, I, C.(N6N6 Example --- ContinuedInitialize: R = DR = s#1=#2(S S) I p1,3(C)
Repeat until DR = f:
DR = p1,3(R " DR DR " R)
DR = DR - R
R = R DRF2u!Function Symbols in RulesExtends Datalog by allowing arguments built from constants, variables, and function names, recursively applied.
Function names look like predicate names, but are allowed only within the arguments of atoms.
Predicates return true/false; functions return arbitrary values.&AA"ExampleInstead of a string argument like 101 Maple we could use a term like
addr(street( Maple ), number(101))
Compare with the XML term
<ADDR><STREET>Maple</STREET>
<NUMBER>101</NUMBER>
</ADDR>bQ$;,";,".u#Another ExamplePredicates:
isTree(X) = X is a binary tree.
label(L) = L is a node label.
Functions:
node(A,L,R) = a tree with root labeled A, left subtree L, and right subtree R.
null = 0-ary function (constant) representing the empty tree.@uw :Pt
1$Example --- ContinuedcThe rules:
isTree(null) :-
isTree(node(L,T1,T2)) :-
label(L) &
isTree(T1) &
isTree(T2)(Y
WP
$
%Example --- ConcludedAssume label(a) and label(b) are true.
I.e., a and b are in the relation for label.
Infer isTree(node(a,null,null)).
Infer isTree(node(b,null,node(a,null,null))).Z'/O'!O,\"&)Evaluation of Rules With Function SymbolsNave, seminave still work when there are no negated IDB subgoals.
They both lead to the unique least fixedpoint (minimal model).
But& this fixedpoint may not be reached in any finite number of rounds.
The isTree rules are an example.F!
b
( %7' Problems With IDB NegationWhen rules have negated IDB subgoals, there can be several minimal models.
Recall: model = set of IDB facts, plus the given EDB facts, that make the rules true for every assignment of values to variables.
Rule is true unless body is true and head is false.L4Sv!(!Example: EDBb red(X,Y)= the Red bus line runs from X to Y.
green(X,Y)= the Green bus line runs from X to Y.
c )"Example: IDBH greenPath(X,Y)= you can get from X to Y using only Green buses.
monopoly(X,Y)= Red has a bus from X to Y, but you can t get there on Green, even changing buses.8
*#Example: Rules~greenPath(X,Y) :- green(X,Y)
greenPath(X,Y) :- greenPath(X,Z) & greenPath(Z,Y)
monopoly(X,Y) :- red(X,Y) & NOT greenPath(X,Y)Z
' +$EDB Datared(1,2), red(2,3), green(1,2),%Two Minimal ModelsEDB + greenPath(1,2) + monopoly(2,3)
EDB + greenPath(1,2) + greenPath(2,3) + greenPath(1,3)
greenPath(X,Y) :- green(X,Y)
greenPath(X,Y) :- greenPath(X,Z) &
greenPath(Z,Y)
monopoly(X,Y) :- red(X,Y) &
NOT greenPath(X,Y)4\u\
(
-&Stratified ModelsDependency graph describes how IDB predicates depend negatively on each other.
Stratified Datalog = no recursion involving negation.
Stratified model is a particular model that makes sense for stratified Datalog programs.Fu@%L,[n
.'Dependency GraphdNodes = IDB predicates.
Arc p -> q iff there is a rule for p that has a subgoal with predicate q.
Arc p -> q labeled iff there is a subgoal with predicate q that is negated.$1P##'#/(Monopoly Example0),Another Example: Win win(X) :- move(X,Y) & NOT win(Y)
Represents games like Nim where you win by forcing your opponent to a position where they have no move.("h"h8N1*4Dependency Graph for Win 2+StrataThe stratum of an IDB predicate is the largest number of s on a path from that predicate, in the dependency graph.
Examples:3-Stratified ProgramsIf all IDB predicates have finite strata, then the Datalog program is stratified.
If any IDB predicate has the infinite stratum, then the program is unstratified, and no stratified model exists.6G E",3Z"4,Stratified ModelEvaluate strata 0, 1,& in order.
If the program is stratified, then any negated IDB subgoal has already had its relation evaluated.
Safety assures that we can subtract it from something.
Treat it as EDB.
Result is the stratified model.6J J T5.Examples
For Monopoly, greenPath is in stratum 0: compute it (the transitive closure of green).
Then, monopoly is in stratum 1: compute it by taking the difference of red and greenPath.
Result is first model proposed.
Win is not stratified, thus no stratified model.nZ 8 9 U,
U&
f(
r
SXnP
n
Shn<$
0n
"p`PpH
0h ? ̙33r W0Y5tLucida Sans UnicodeDefault DesignDatalog Review of Logical If-Then RulesTerminology
SemanticsExampleExample --- ContinuedWhy Not Just Use SQL?IDB/EDBDatalog ProgramsExtensionsNegated SubgoalsConstants as ArgumentsArithmetic SubgoalsEvaluating Datalog ProgramsSafetyExamples: NonsafetyNonrecursive EvaluationWhy?Applying RulesExampleAlgorithm for NonrecursiveNave Evaluation for RecursiveImportant PointsSeminave EvaluationExample (make files)Example --- ContinuedFunction Symbols in RulesExampleAnother ExampleExample --- ContinuedExample --- Concluded*Evaluation of Rules With Function SymbolsProblems With IDB Negation
Example: EDB
Example: IDBExample: Rules EDB DataTwo Minimal ModelsStratified ModelsDependency GraphMonopoly ExampleAnother Example: WinDependency Graph for WinStrataStratified ProgramsStratified Model ExamplesFonts UsedDesign Template
Slide Titles/