CSc 8710 Deductive Databases and Logic Programming
Fall 1999
Due: December 13th, 1999

  1. Create several (at least two) large EDBs for the databases. This should include narrow but deep tree/graph like data and wide and not so deep data. The data should also contain several trees/graphs. 100 depth and 100 width would be considered deep and wide enough.
  2. Write programs to answer queries in the following databases using

Bill of Materials Database

sub_part(X,Y,Q,T) :- comp(X,Y,Q,T).
sub_part(X,Y,Q,T) :- comp(Z,Y,Q2,T), sub_part(X,Z,Q1,T1),
                     Q is Q1 * Q2.
look_for(P,Y,Q) :- sub_part(P,Y,Q,b).

basic_comp(P,B,sum(<Q>)) :- look_for(P,B,Q).

temp_cost(P,X) :- basic_comp(P,B,Q), price(B,C), X is Q * C.
cost(P,sum(<C>)) :- temp_cost(P,C).

Anti-Trust Database

controls(Comp1,Comp2) :- has_shares(Comp1,Comp2,N), N > 50.

market(Comp1,Mrkt,Qty) :- company(Comp1,Mrkt,Qty).
market(Comp1,Mrkt,Qty) :- controls(Comp1,Comp2), market(Comp2,Mrkt,Qty).

inquire(Comp,Mrkt,sum(<Quota>)) :- market(Comp,Mrkt,Quota).

find_trust(Mrkt,Comp,Total) :- trust_limit(Mrkt,Threshold),
                               inquire(Comp,Mrkt,Total),
                               Total > Threshold.

Flights Database

reaches(X,Y) :- flights(_,X,Y,_,_).
reaches(X,Y) :- flights(_,X,Z,_,_), reaches(Z,Y).

connects(X,Y,D,A) :- flights(_,X,Y,FD,FA), FD >= D, FA <= A.
connects(X,Y,D,A) :- flights(_,X,Z,FD,FA), FD >= D, connects (Z,Y,FD2,A),
                     FD2 >= FA+100.

Siblings-Cousins-Related Database

sibling(X,Y) :- parent(X,Z), parent(Y,Z), X <> Y.
cousin(X,Y) :- parent(X,Xp), parent(Y,Yp), sibling(Xp,Yp).
cousin(X,Y) :- parent(X,Xp), parent(Y,Yp), cousin(Xp,Yp).
related (X,Y) :- sibling(X,Y).
related(X,Y) :- related(X,Z), parent(Y,Z).
related(X,Y) :- related(Z,Y), parent(X,Z).

Trip Database

trip(L,S,E) :- leg(L,S,E).
trip(L,S,E) :- leg(L,S,I), trip(L,I,E). 
trip(L,S,E) :- interchange(I,L,M), trip(L,S,I), trip(M,I,E).