Magic set transformed IDB for a particular query form:

query(C) :- costBF(engine,C).
costBF(P,sum(<C>)) :- partCostBF(P,C).
partCostBF(P,X) :- basicCompBFF(P,B,Q), price(B,C), X is Q * C.
basicCompBFF(P,B,sum(<Q>)) :- basicPartsBFF(P,B,Q), magicBasicCompBFF(P).
basicPartsBFF(P,B,Q) :- subPartBFFB(P,B,Q,b), magicBasicPartsBFF(P).

subPartBFFB(X,Y,Q,T) :- 
  bomComp(X,Y,Q,T), magicSubPartBFFB(X,T).
subPartBFFB(X,Y,Q,T) :- 
  bomComp(Z,Y,Q2,T), subPartBBFF(X,Z,Q1,T1),
  Q is Q1 * Q2, magicSubPartBFFB(X,T).

subPartBBFF(X,Y,Q,T) :- 
  bomComp(X,Y,Q,T), magicSubPartBBFF(X,Y).
subPartBBFF(X,Y,Q,T) :- 
  bomComp(Z,Y,Q2,T), subPartBBFF(X,Z,Q1,T1),
  Q is Q1 * Q2, magicSubPartBBFF(X,Y).

magicBasicCompBFF(engine).
magicBasicPartsBFF(P) :- magicBasicCompBFF(P).
magicSubPartBFFB(P,b) :- magicBasicPartsBFF(P).

magicSubPartBBFF(X,Z) :- bomComp(Z,Y,Q2,T), magicSubPartBFFB(X,T).
magicSubPartBBFF(X,Z) :- bomComp(Z,Y,Q2,T), magicSubPartBBFF(X,Y).