CS345A PROBLEM SET #1
SOLUTIONS
4 Questions, 100 pts.
Consider the rule
p(X) :- q(X,Y) & q(Y,X) & r(Y).
- p(X) :- r(X,Y) & s(Y,X).
- p(X) :- q(Y,X).
- q(X,Y) :- p(X) & s(Y,X).
Suppose the EDB relation R for r contains the tuples {ab,ac,bc,ad,dd} and the EDB relation S for s contains the tuples {ba,ac,cb,dd}. Execute the seminaive evaluation (SNE) algorithm on these rules. What are the final values of IDB relations for p and q? To demonstrate your understanding of the process, show the DELTA-IDB after each round of the SNE algorithm. You need not show the new IDB itself after each round.
- chain(X,Y) :- eats(X,Y).
- chain(X,Y) :- chain(X,Z) & chain(Z,Y).
Prove that for any (possibly infinite) EDB eats there is a minimal model for the rules such that chain(X,Y) is true if and only if there is a sequence of Z1,...Zn, where Z1=X, Zn=Y, and eats(Zi,Z{i+1}) for all i.
Round Number | DELTA-P | DELTA-Q |
---|---|---|
Round 0 | {a,b,d} | {} |
Round 1 | {} | {ab,bc,dd} |
Round 2 | {c} | {} |
Round 3 | {} | {ca} |
Round 4 | {} | {} |
end |
- lessThan(X,Y) :- next(X,Y).
- lessThan(X,Y) :- next(X,Z) & lessThan(Y,Z).
It is easy to show that lessThan(n,n+m), where m and n are positive integers, is first discovered at the end of round m-1 of the SNE algorithm. Since n can be arbitrarily large the SNE algorithm does not converge in a finite number of rounds. The minimal model is lessThan(n,n+m) for all positive integers n and m
- p(X,Y) :- q(X,Y) & NOT r(X).
- r(X) :- s(X,Y) & NOT t(Y).
- r(X) :- s(X,Y) & r(Y).