# CS345 Solutions #3

1. (20 pts.) We can group a,b, and r into one module, and q and p into a higher module.

Module for a,b, and r: We compute the locally stratified model. There is just one stratum, and we are able to infer r(1,2) and r(2,3). The locally stratified model for this module is EDB + {r(1,2), r(2,3)}.

Module for q and p: We treat all true facts belonging to the previous model as if they were EDB facts, and compute the locally stratified model.

Stratum 0: We infer that q(3) and q(4) are true, and find that p(3) is false.
Stratum 1: We find that q(2) is false, and p(2) is false.
Stratum 2: We infer that q(1) and p(1) are true.
The locally stratified model for this module is EDB + {r(1,2), r(2,3)} + {q(1), q(3), q(4), p(1)}.

The modularly stratified model is EDB + {r(1,2), r(2,3), q(1), q(3), q(4), p(1)}.

2. (20 pts.) Q1 is not contained in Q2. To find a containment mapping from Q2 to Q1, the head maps U->U and V->Z. The third subgoal for Q2 is r(U,V), and so must map to an r(U,Z) in Q1, but there is no r(U,Z) in Q1.

Q2 is contained in Q1. Containment mapping from Q1 to Q2: U->U, Z->V, V->X, X->Y, Y->U.

3. (20 pts.) Q1 is contained in Q2. Choose contstants X->0, Y->1, Z->2. The canonical database D for Q1 is {q(0,1), q(1,2), q(2,0)}. Q2(D) is {p(0), p(1), p(2)}. Q2(D) contains p(0), which is the frozen head of Q1. (The instantiation of Q2 that shows that p(0) is in Q2(D) is: X->0, Y->1, Z->2, U->0, V->1.)

Q2 is not contained in Q1. Choose constants X->0, Y->1, Z->2, U->3, V->4. The canonical database D for Q2 is {q(0,1), q(1,2), q(2,3), q(3,4)}, and p(0) is the frozen head of Q2. Q1(D) = {}. Q1(D) does not contain the frozen head of Q2.

4. (20 pts.) We test if Q1 is contained in Q2 by mapping subgoals of Q2 to subgoals of Q1.

(1) Suppose q(X,Y) -> q(X,Y). (2) Then X->X and Y->Y. (3) q(Y,Z) -> q(Y,X), Z->X. (4) r(X,Y,T) -> r(X,Y,?). (5) Since there is no r(X,Y,?), fail. (6) Thus, we must map q(X,Y) -> q(Y,X). (7) Then X->Y and Y->X. (8) However, the head requires X->X, fail. Thus, Q1 is not contained in Q2.

5. (20 pts.) Q3 is contained in Q2, Q3 is contained in Q4, and Q2 and Q4 are equivalent (Q2 is contained Q4, and Q4 is contained in Q2).

Q3 is contained in Q2: X->X, A->A, B->c, C->B, Y->Y
Q3 is contained in Q4: X->X, A->A, C->c, B->A, E->B, D->B, Y->Y
Q2 is contained in Q4: X->X, A->A, C->B, B->A, E->C, D->C, Y->Y
Q4 is contained in Q2: X->X, A->A, B->C, C->E, Y->Y

None of Q2, Q3, and Q4 are contained in Q1, since for a containment mapping from Q1 to one of the other queries, the head would force X to map to both X and Y.

None of Q1, Q2, and Q4 are contained in Q3, since it would not be possible to map the third subgoal of Q3 (q(c,B)) to any subgoal in the other queries (the other queries don't have a subgoal of the form q(c,?)).

The canonical database D for Q1 is {q(0,1), q(1,2)}, with X->0, A->1, Z->2. The frozen head of Q1 is p(0,0). Q2(D) does not contain the frozen head of Q1, so Q1 is not contained in Q2. Similarly, Q4(D) does not contain the frozen head of Q1, so Q1 is not contained in Q4.