CS345 PROBLEM SET #5
SOLUTIONS
3 Questions, 100 pts.

Problem 1 (40 pts.)

Consider the global predicates in an integrated information system about the Stanford students.
student(S)
S is a student at Stanford.
office(S,O)
O is the office of S.
phone(S,P)
P is the phone of S.
major(S,M)
S is majoring in M.
advisor(S,A)
A is the advisor of S.
machine(S,M)
M is the machine of S.
group(S,G)
G is the group of S.
Suppose there are five source, each providing one view:
phone-dir(S,O,P) :- student(S) & office(S,O) & phone(S,P)

su-info(S,A,M) :- student(S) & advisor(S,A) & major(S,M)

acad-info(S,M,G) :- student(S) & major(S,M) & group(S,G)

cs-info(S,O,M) :- student(S) & major(S,cs) & office(S,O) & machine(S,M)

db-info(S,A,M,P) :- student(S) & major(S,cs) & group(S,db) & advisor(S,A) & machine(S,M) & phone(S,P).

Note that cs and db are constants.
a)
Express each of the following queries in terms of the global predicates.
b)
Find all minimal solutions (in terms of the available views) to each of the queries from a).

Solution

a)
answer1(P,O) :- student(a) & phone(a,P) & office(a,O)

answer2(O,M,A) :- student(b) & major(b,cs) & office(b,O) & machine(b,M) & advisor(b,A)

answer3(M,A,G) :- student(c) & major(c,M) & advisor(c,A) & group(c,G)

answer4(A,O,P) :- student(d) & major(d,cs) & group(d,db) & advisor(d,A) & office(d,O) & phone(d,P)
b)
answer1(P,O) :- phone-dir(a,O,P).

answer2(O,M,A) :- cs-info(b,O,M) & su-info(b,A,cs).

answer3(M,A,G) :- su-info(c,A,M) & acad-info(c,M,G).

answer4(A,O,P) :- phone-dir(d,O,P) & su-info(d,A,cs) & acad-info(d,cs,db).

Problem 2 (30 pts.)

For this problem, suppose that the views from Problem 1 have the following binding patterns:
phone-dir(S,O,P) - fff.
su-info(S,A,M) - bff.
acad-info(S,M,G) - bbf.
cs-info(S,O,M) - ffb or fbf.
db-info(S,A,M,P) - bfbf or bffb.
Find all minimal solutions (in terms of the adorned views) to each of the following queries:

Solution

query1_fb(S,A) :- phone-dir_fff(S,O,P) & su-info_bff(S,A,M).

query2_fb(S,O) :- phone-dir_fff(S,O,P).
query2_fb(S,O) :- cs-info_fbf(S,O,P).

query3_f(S) :- phone-dir_fff(S,O,P) & su-info_bff(S,A,cs).
query3_f(S) :- phone-dir_fff(S,O,P) & acad-info_bbf(S,cs,G).
query3_f(S) :- phone-dir_fff(S,O,P) & cs-info_fbf(S,O,M).

query4_fb(G,M) :- cs-info_ffb(S,O,M) & su-info_bff(S,A,N) & acad-info_bff(S,N,G)

Problem 3 (30 pts.)

Consider the following conjunctive queries:
Q1:
p(X) :- arc(X,Y) & arc(Y,Z) & arc(Z,X)
Q2:
p(X) :- arc(X,W) & arc(Y,W) & arc(W,Z) & arc(Z,Y) & arc(Z,X)
Q3:
p(X) :- arc(X,X1) & arc(X1,X2) & arc(X2,X3) & arc(X3,X4) & arc(X4,X5) & arc(X5,X)
Q4:
p(X) :- arc(X,Y) & arc(Y,X) & arc(X,Z).
a)
Minimize each query.
b)
Minimize their union.

Solution

a)
Q1:
p(X) :- arc(X,Y) & arc(Y,Z) & arc(Z,X) /* no change */.

Q2:
p(X) :- arc(X,W) & arc(W,Z) & arc(Z,X).

Q3:
p(X) :- arc(X,X1) & arc(X1,X2) & arc(X2,X3) & arc(X3,X4) & arc(X4,X5) & arc(X5,X) /* no change */.

Q4:
p(X) :- arc(X,Y) & arc(Y,X).

b)
Since Q1 and Q2 are equivalent and Q1 and Q4 are contained in Q3 then the minimized union of Q1, Q2, Q3, and Q4 is Q3.