Is there a library / technique for collecting statistics for optimal ordering of clause in Prolog?

I am writing a program where I need to see if the lines match a specific pattern. Right now I have it implemented in Prolog, which usually matches Pattern (S), with over 20 different definitions.

I end up running all binary strings up to a certain length through the pattern validation predicate. The program is quite slow (as is often the case in Prolog), and since there are so many different definitions, I would ideally like to order them, so the most suitable ones are most ranked in the order and, thus, agreed first with Prolog, avoid backtracking like how I can.

I am using SWI Prolog right now, but I have access to SICStus, so I am ready to use it or any Prolog interpreter that I can get for free.

+4
source share
3 answers

SWI-Prolog has profile / 3 and show_profile / 2 , which can help with your task.

Left-factoring your template rules and applying cuts can improve runtime if there are common parts between templates. Such an analysis should be combined with statistics.

+2
source

You might consider using DCG and cuts.

-2
source

You have to look at cuts. Prolog syntax for this:

! 
-3
source

All Articles