Docsity

Negation in Datalog and Its Semantics, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Negation in Datalog and Its Semantics and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

1

Datalog with negation

2

Problem: the meaning of negation

Example 1 (propositional)

p:- NOT qq:- NOT p

Several minimal models/fixpoints:

{p}, {q}

Bottom-up fixpoint evaluation: {p,q}

4

IDB

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.

5

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)

7

Two Minimal Models

EDB + 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)

1

2

3

8

Syntactic restriction: safety

all variables appear in some positive

relational subgoal of the body.

Start with the join of the positive relational

subgoals and select/delete from there.

10

Semi-positive programs

Simplest case: negate

only

EDB predicates

Redonly(X,Y):- red(X,Y),NOT green(X,Y) Natural meaning:

NOT green(a,b)

is true iff

(a,b)

is not in

green

(closed world assumption)

11

Next step: stratified negation

Idea: if an IDB

R has already been

defined

, then we know what

NOT R

is

“Stratified program”: can be parsed so that each IDB relation is defined byprevious rules before its negation isneeded

13

Stratified programs

Dependency graph

describes how IDB

predicates depend negatively on eachother.

Stratified Datalog

= no recursion

involving negation.

Stratified model

is a particular model

that “makes sense” for stratifiedDatalog programs.

14

Dependency Graph

Nodes = 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.

16

Another Example: “Win”

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

Represents games like Nim where you win by forcing your opponent to a positionwhere they have no move.

17

Dependency Graph for “Win”

win

--

19

Stratified Programs

If all IDB predicates have finite strata, then the Datalog program is s

tratified

If any IDB predicate has the infinite

stratum, then the program isunstratified

, and no stratified model

exists.

20

Stratified Model

Evaluate strata 0, 1,… in order.

If the program is stratified, then any negated IDB subgoal has already beenevaluated.



Safety assures that we can “subtract itfrom something.”



Treat it as EDB.

Result is the stratified model.