The Magic-Set Transformed rules for the project are:

Bill of Materials Problem

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).

Anti-Trust Problem

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.

Siblings-Cousins-Related Problem

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).