?- time(a).
% 200,005 inferences, 0.006 CPU in 0.006 seconds (100% CPU, 32734043 Lips)
false.
?- time(b).
% 5 inferences, 0.000 CPU in 0.000 seconds (32% CPU, 454545 Lips)
false.
Is anyone aware of an existing technique and ideally a link a paper describing it? Google search is failing me on this question. I can see ways to order the literals in a rule but without any strong guarantees.
Still, coroutining can improve order dependency and so can tabling. I’ve done something as you describe for optimizing SPARQL queries as described in this ICLP’05 publication This requires estimates of cost and number of solutions per goal, as well as instantiation restrictions. Recently I have worked on an improved version, but I’m afraid that work is not public. The overall idea is to generate orderings, validate whether they are legal and compute a cost estimate. Then select the best.
Should be doable for a well defined subset of Prolog. Stats on facts can probably be estimated from the JIT index properties. Internally there are some more stats that drive the JIT index and that could be made available.
That link is perfect, thanks! I found a closely related paper (Query optimization in inductive logic programming by reordering literals) in the related work section.