Forward chaining like Rete algorithm in rule engine?

As you probably have grasped, Prolog is a backward chaining engine :slight_smile: To know all consequences of a program, just ask the most general question, i.e.,

?- db(S,P,O).

and backtrack through all alternatives. Now, in this type of recursive rules for knowledge modeling it is really easy to get into loops this way. To solve that, we have tabling. So add this to your program.

:- table db/3.

Now the above query is guaranteed to terminate and the results are materialized in a table, so your next query is really fast. Tabling can be considered as demand driven forward chaining, i.e., it only effectuates based on a query and only creates tables for the given instantiation. It also only switches to forward chaining there were backward chaining would loop, i.e., where a recursive call calls a variant of an already open goal.

If you are not bound to RDF you can of course add more columns :slight_smile: Either by hand or automatically.

5 Likes