# CS345 Assignment #4

### Problem Set

1. (25 pts.) Consider the conjunctive queries Q1 and Q2. Q1: p(X) :- q(X,Y) & q(X,Z) & r(Y,Z) & NOT q(Z,X) & NOT r(Y,Y) Q2: p(B) :- q(B,A) & q(B,C) & r(C,D) & NOT q(D,B) Use the Levy-Sagiv test to show that Q1 is contained in Q2, and that Q2 is not contained in Q1. Remember that to show a noncontainment, you do not have to perform the complete test, as long as you find the counterexample.

2. (25 pts.) Consider the conjunctive queries Q1 and Q2. Q1: p :- q(X,Y) & q(Y,Z) & q(Z,X) Q2: p :- q(A,B) & q(B,C) & A<=C Use the Klug-Levy-Sagiv test to show that Q1 is contained in Q2, and that Q2 is not contained in Q1.

3. (20 pts.) Consider the conjunctive queries Q1 and Q2. Q1: p(X,Y) :- q(X,Y) & q(Y,X) & X>=0 & Y>=0 Q2: p(A,B) :- q(A,B) & q(B,C) & A+B>=C Use the Gupta-Zhang-Ozsoyoglu test to show that Q1 is contained in Q2.

4. (30 pts.) Consider the built-in predicate m, where m(X,Y,Z) is true if and only if X*Y=Z. You may assume that the values of variables in arguments of m are integers.

(a)
Does the containment theorem for unions of CQ's hold when mis the only interpreted predicate? Prove it is, or provide a counterexample. (Hint: One or more of the arguments can be constants.)

(b)
Use the Gupta-Zhang-Ozsoyoglu test to test the equivalence of the following two conjunctive queries: panic :- e(X) & m(X,X,X) panic :- e(X) & e(Y) & m(X,Y,Y)

In your test you may use any reasonable law about how multiplication of integers behaves.