CS345 PROBLEM SET #5
SOLUTIONS
3 Questions, 100 pts.
- 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).
- 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)
- 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).
- 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.
- 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)
- 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).
- 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).