Homework3 -- Due November 15th beginning of class. No late homeworks accepted.
1. Suppose we have EDB relations
(30 points)
frequents(Drinker, Bar)
serves(Bar, Beer)
likes(Drinker, Beer)
The first indicates the bars a drinker visits; the second tells what
beers each bar serves, and the last indicates which beers each drinker
likes to drink. Define the following predicates using safe datalog rules.
a) happy(D) that is true if drinker D frequents at least one
bar that serves a beer he likes.
b) shouldVisit(D,B) if bar B serves a beer drinker D likes.
c) disappointed(D) if drinker D frequents a bar that does not
serve a beer he likes.
2. Rectify the following datalog rules: (20 points)
p(X,X) :- q(X,Y) & r(Y,Z).
p(X,Y) :- q(X,X) & r(Y,Y).
q(a,X) :- s(X).
q(X,Y) :- r(X,Z) & r(Z,b) & r(Y,c).
r(X,Y) :- s(X) & s(Y).
3. Write relational algebra expressions for the relations defined by the IDB predicate p, q, and r in the previous problem. (20 points)
4. Consider the rules: (30 points)
p(X) :- q(X,Y) & t(Y).
p(X) :- p(X) & not t(X).
r(X,Y) :- q(X,Y) & not p(Y).
r(X,Y) :- s(X,Y) & not t(X).
a) Determine the stratum of each predicate. Is the program stratified?
b) Suppose the relations for the EDB predicates q, s,
and t are, respectively,
Q = {(1,2), (3,4), (2,2), (5,3)} , S = {(1,1), (2,2), (3,3)}, T ={2,
3, 4}. Find the perfect fixed point for the IDB predicates p
and r, given this EDB.