SLIDE 12 12
67
Minimal Models
When there is no negation, a Datalog program has a unique minimal model
One given by naïve and semi-naïve evaluation
With negation and recursion, there can be several minimal models
even if the program is stratified.
Fortunately, we can compute the minimal model that makes sense
And that is the stratified model
68
The Stratified Model
When the Datalog program is stratified:
We evaluate IDB predicates in stratum 0
- There can be several predicates in stratum but
they can’t depend negatively on themselves on any other IDB predicate strata.
Once evaluated, treat it as EDB for next strata. Proceed iteratively until all IDB predicates are evaluated
69
Example: Multiple Models --- 1
Reach(x) < - Source(x) Reach(x) < - Reach(y) AND Arc(y,x) NoReach(x) < - Target(x) AND NOT Reach(x)
1 2 3 4
Source Target Target Arc Arc Arc 1 is the only source; 2 and 3 are targets; 4 is an additional node. Reach is the only predicate at Stratum 0. Computation yeilds Reach(1) and Reach(2) Reach is fixed at 1 and 2. Since 1 and 2 can be reached, NoReach has one element in the set: 3.
70
Example: Multiple Models --- 1
Reach(x) < - Source(x) Reach(x) < - Reach(y) AND Arc(y,x) NoReach(x) < - Target(x) AND NOT Reach(x)
1 2 3 4
Source Target Target Arc Arc Arc Stratum 0: Reach(1), Reach(2) Stratum 1: NoReach(3) 1 is the only source; 2 and 3 are targets; 4 is an additional node. Reach is the only predicate at Stratum 0. Computation yeilds Reach(1) and Reach(2) Reach is fixed at 1 and 2. Since 1 and 2 can be reached, NoReach has one element in the set: 3.
71
Example: Multiple Models --- 2
Reach(x) < - Source(x) Reach(x) < - Reach(y) AND Arc(y,x) NoReach(x) < - Target(x) AND NOT Reach(x)
1 2 3 4
Source Target Target Arc Arc Arc Another model! Reach(1), Reach(2), Reach(3), Reach(4); NoReach is empty. 3rd rule is always true because head is false.
72
SQL-99 Recursion
Excellent example of Theory -> Practice Datalog recursion inspired the addition
- f recursion to the SQL-99 standard.
Trickier, because SQL allows
grouping-and-aggregation, which behaves like negation and requires a more complex notion of stratification.