The magic sets optimisation of the following program;
triple(?y, ?a, ?z) :- triple(?x, '88', ?y), triple(?x, ?a, ?z), NOT_EQUAL(?a, '88'), NOT_EQUAL(?x, ?y).
triple(?z, ?a, ?y) :- triple(?x, '88', ?y), triple(?z, ?a, ?x), NOT_EQUAL(?a, '88'), NOT_EQUAL(?x, ?y).
?- triple('184', ?p, ?o).
includes the production of rules that can never fire:
label_xXx_prefix_xXx_triple_2_fbf(?a) :- magic_xXx_prefix_xXx_triple_fbf(?a).
triple(?y, ?a, ?z) :- magic_xXx_prefix_xXx_triple_fbf(?a), triple(?x, '88', ?y), triple(?x, ?a, ?z), NOT_EQUAL(?a, '88'), NOT_EQUAL(?x, ?y).
label_xXx_prefix_xXx_triple_1_fbf(?a) :- magic_xXx_prefix_xXx_triple_fbf(?a).
triple(?z, ?a, ?y) :- magic_xXx_prefix_xXx_triple_fbf(?a), triple(?x, '88', ?y), triple(?z, ?a, ?x), NOT_EQUAL(?a, '88'), NOT_EQUAL(?x, ?y).
because predicate magic_xXx_prefix_xXx_triple_fbf does not appear anywhere else.
The algorithm should not generate these unnecessary rules.