The Magic-Set Transformed rules for the project are:
query(X,Y) :- basic_comp_bff(engine,X,Y). basic_comp_bff(P,B,sum(<Q>)) :- look_for_bff(P,B,Q), magic_basic_comp_bff(P). look_for_bff(P,B,Q) :- sub_part_bffb(P,B,Q,b), magic_look_for_bff(P). sub_part_bffb(X,Y,Q,T) :- comp(X,Y,Q,T), magic_sub_part_bffb(X,T). sub_part_bffb(X,Y,Q,T) :- comp(Z,Y,Q2,T), sub_part_bbff(X,Z,Q1,T1), Q is Q1 * Q2, magic_sub_part_bffb(X,T). sub_part_bbff(X,Y,Q,T) :- comp(X,Y,Q,T), magic_sub_part_bbff(X,Y). sub_part_bbff(X,Y,Q,T) :- comp(Z,Y,Q2,T), sub_part_bbff(X,Z,Q1,T1), Q is Q1 * Q2, magic_sub_part_bbff(X,Y). magic_basic_comp_bff(engine). magic_look_for_bff(P) :- magic_basic_comp_bff(P). magic_sub_part_bffb(P,b) :- magic_look_for_bff(P). magic_sub_part_bbff(X,Z) :- comp(Z,Y,Q2,T), magic_sub_part_bffb(X,T). magic_sub_part_bbff(X,Z) :- comp(Z,Y,Q2,T), magic_sub_part_bbff(X,Y). temp_cost_bf(P,X) :- basic_comp_bff(P,B,Q), price(B,C), X is Q * C. cost_bf(P,sum(<C>)) :- temp_cost_bf(P,C).
query(X) :- market_bbf(violet,toys,X). market_bbf(Comp1,Mrkt,Qty) :- company(Comp1,Mrkt,Qty), magic_market_bbf(Comp1,Mrkt). market_bbf(Comp1,Mrkt,Qty) :- has_shares(Comp1,Comp2,N), N > 50, market_bbf(Comp2,Mrkt,Qty), magic_market_bbf(Comp1,Mrkt). magic_market_bbf(violet,toys). magic_market_bbf(C,M) :- has_shares(C1,C,N), N > 50, magic_market_bbf(C1,M). inquire(Comp,Mrkt,sum(<Quota>)) :- market(Comp,Mrkt,Quota). find_trust(Mrkt,Comp,Total) :- trust_limit(Mrkt,Threshold), inquire(Comp,Mrkt,Total), Total > Threshold.
query(X) :- cousin_bf(h,X). cousin_bf(X,Y) :- parent(X,Xp), parent(Y,Yp), sibling_bf(Xp,Yp), magic_cousin_bf(X). cousin_bf(X,Y) :- parent(X,Xp), parent(Y,Yp), cousin_bf(Xp,Yp), magic_cousin_bf(X). sibling_bf(X,Y) :- parent(X,Z), parent(Y,Z), X <> Y, magic_sibling_bf(X). magic_cousin_bf(h). magic_cousin_bf(Xp) :- parent(X,Xp), magic_cousin_bf(X). magic_sibling_bf(Xp) :- parent(X,Xp), magic_cousin_bf(X).
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). query(X):-trip(blue, suwanee, X). Adorned Set of Rules: query_f(X):-trip_bbf(blue,suwanee,X). trip_bbf(L,S,E):-leg(L,S,E). trip_bbf(L,S,E):-leg(L,S,I), trip_bbf(L,I,E). trip_bbf(L,S,E):-interchange(I,L,M), trip_bbb(L,S,I), trip_bbf(M,I,E). trip_bbb(L,S,E):-leg(L,S,E). trip_bbb(L,S,E):-leg(L,S,I), trip_bbb(L,I,E). trip_bbb(L,S,E):-interchange(I,L,M), trip_bbb(L,S,I), trip_bbb(M,I,E). Magic-set of Rules: magic_trip_bbf(blue,suwanee). magic_trip_bbf(L,I):-leg(L,S,I),magic_trip_bbf(L,S). magic_trip_bbb(L,S,I):-interchange(I,L,M),magic_trip_bbf(L,S). magic_trip_bbf(M,I):-interchange(I,L,M),magic_trip_bbf(L,S). magic_trip_bbb(L,I,E):-leg(L,S,I),trip_bbb(L,S,E). magic_trip_bbb(L,S,I):-interchange(I,L,M),magic_trip_bbb(L,S,E). magic_trip_bbb(M,I,E):-interchange(I,L,M),magic_trip_bbb(L,S,E). Modified Adorned Set of Rules: query_f(X):-trip_bbf(blue,suwanee,X). trip_bbf(L,S,E):-leg(L,S,E),magic_trip_bbf(L,S). trip_bbf(L,S,E):-leg(L,S,I), trip_bbf(L,I,E),magic_trip_bbf(L,S). trip_bbf(L,S,E):-interchange(I,L,M), trip_bbb(L,S,I), trip_bbf(M,I,E),magic_trip_bbf(L,S). trip_bbb(L,S,E):-leg(L,S,E),magic_trip_bbb(L,S,E). trip_bbb(L,S,E):-leg(L,S,I), trip_bbb(L,I,E),magic_trip_bbb(L,S,E). trip_bbb(L,S,E):-interchange(I,L,M), trip_bbb(L,S,I), trip_bbb(M,I,E),magic_trip_bbb(L,S,E). Output: Magic-set of Rules + Modified Adorned Set of Rules