CS345 PROBLEM SET #4

SOLUTIONS

4 Questions, 100 pts.

- P:
- p(X) :- q(X,Y) & q(Y,X) & r(Y,Y) & NOT q(X,X) & NOT r(Y,X).
- Q:
`p(B) :- q(A,B) & r(A,A) & NOT r(A,B).`

```
```

- There are two partitions of the variables in P: {XY} and {X} {Y}.
- The basic canonical database for the first partition is D =
{
*q(0,0), r(0,0)*}. Since P(D) is empty we don't need to check if Q(D) contains the frozen head of P. - The basic canonical database for the second partition is D =
{
*q(0,1), q(1,0), r(1,1)*}. Then we have P(D) = Q(D) = {*p(0)*}. We also have to consider all extended canonical databases for P. Let D' be an extended canonical database for P. Since*r(1,0)*is a frozen negated subgoal of P then it is not in D'. Then we have that the frozen head of P,*p(0)*, is in Q(D') because of the instantiation A->1, B->0.

- Consider the partition {B} {A} of the variables in Q.
- The basic canonical database for this partition is D =
{
*q(1,0), r(1,1)*}. Q(D) = {*p(0)*} but P(D) is empty.

- P:
- panic :- q(X,Y,Z) & q(X,Z,Y) & q(Y,Z,X).
- Q:
`panic :- q(X,Y,Z) & X<=Z & Y<=Z.`

```
```

- Let max(
*a,b,c*) =*a*. Then Q(D) contains the the frozen head of P,*panic*, because of the instantiation X->b, Y->c, Z->a. - Let max(
*a,b,c*) =*b*. Then Q(D) contains the the frozen head of P,*panic*, because of the instantiation X->a, Y->c, Z->b. - Let max(
*a,b,c*) =*c*. Then Q(D) contains the the frozen head of P,*panic*, because of the instantiation X->a, Y->b, Z->c

- The conjunctive query
`panic :- p(X,Y) & m(Y,X)`

contains the conjunctive query

`panic :- p(X,Y) & p(Y,X).`

- If both
*m(X,Y)*and*m(Y,Z)*are true than*m(Z,X)*is true.

`panic :- q(X,Y,Z) & m(Y,X) & m(Y,Z)`

```
```

contains the conjunctive query

`panic :- q(X,Y,X) & q(Y,Z,Y) & q(X,Z,X).`

```
```

- First, we apply the Gupta test for the first pair of queries.
Since
*m*is an interpreted predicate, and not an ordinary subgoal, we don't need to eliminate X and Y from*m*. There are 2 containment mappings, M1: {X->X, Y->Y} and M2: {X->Y, Y->X}. The logical expression that we get from the Gupta test is:`=> M1(m(X,Y)) OR M2(m(X,Y))`

. After simplifying it, we get`m(X,Y) OR m(Y,X)`

. Since we are given that the first query contains the second, the logical expression must be always true. - Then we apply the Gupta test to the second pair of queries.
There are 3 containment mappings, M1: {X->X, Y->Y, Z->X}, M2: {X->Y,
Y->Z, Z->Y}, and M3: {X->X, Y->Z, Z->X}. The logical expression we
get is:
`=> M1(m(Y,X) & m(Y,Z)) OR M2(m(Y,X) & m(Y,Z)) OR M3(m(Y,X) & m(Y,Z))`

. After simplifying it, we get`m(Y,X) OR m(Z,Y) OR m(Z,X)`

. We prove that this expression is always true by contradiction. - Suppose
`m(b,a) OR m(c,b) OR m(c,a)`

is false for some constants*a*,*b*,and*c*. Then, from the logical expression we derived from the first pair of queries we get that`m(a,b)`

and`m(b,c)`

are true because both`m(a,b) OR m(b,a)`

and`m(b,c) OR m(c,b)`

must be true. Then, by the given fact about*m*we get that`m(c,a)`

must be true. This is, however, a contradiction of our assumptions.

```
panic :- q(X,Y,Z) & m(Y,X) &
m(Y,Z)
```

contains ```
panic :- q(X,Y,X) & q(Y,Z,Y) &
q(X,Z,X)
```

.
- P:
- p(X,Y) :- arc(X,A) & arc(A,Y) & arc(X,B) & arc(B,Y) & X<A & B<Y.
- Q:
`p(X,Y) :- arc(X,Z) & arc(Z,Y) & X<Z & Z<Y.`

```
```

*Hint: *The Gupta test is messy here, since there are a lot
of containment mappings after we replace duplicate occurrences of
variables. However, in general, and here in particular, when there is
implication of the OR over all containment mappings, we can usually
identify one or a few of the containment mappings that are really
involved in the implication. Try first to understand what the CQ's
are saying, and the focus on the containment mappings you really need.

- Consider the database D = {
*arc(0,2), arc(1,0), arc(1,3), arc(3,2)*}. P(D) = {*p(1,2)*} but Q(D) is empty.

- First we eliminate duplicate variables from the ordinary subgoals
in P. The resulting query is:
`p(X,Y) :- arc(X,A) & arc(A1,Y) & arc(X1,B) & arc(B1,Y1) & X<A & B<Y & A1=A & X1=X & B1=B & Y1=Y`

. - Consider the containment mapping from P to Q, M: {X->X, Y->Y,
X1->X, Y1-Y, A-Z, A1->Z, B->Z, B1->Z}.
- M(
`X<A & B<Y & A1=A & X1=X & B1=B & Y1=Y`

) =`X<Z & Z<Y`

. From the Gupta test we have to test whether`X<Z & Z<Y`

(the interpreted subgoals in Q) logically imply the OR, over all containment mappings from P to Q, of the interpreted subgoals in P. Thus, we have that the implication is always true since M of the interpreted subgoals in P is the same as the interpreted subgoals in Q.