Forward Debugging

We now turn our attention to the forward chaining engine. The forward chaining engine allows forward chaining rules in the form "New-facts <= Facts". We also use the Byrd Box model to debug forward chaining rules. A call to the forward chaining instruction post/1 will indicate that a new fact is to be added to the forward store.

The forward chaining instruction post/1 will in turn check the forward chaining rules for new facts and put them on an agenda. These checks might involve some ordinary backward chain-ing calls, which will then be seen by ordinary Byrd Box calls. The forward chaining instruction post/1 itself will only exit when the agenda has been worked off.

Forward chaining has a distinct bottom-up pattern from facts to new-facts. We will now demon-strate this pattern. As an example problem, we will use the same propositional problem again. This time we will use forward chaining rules to represent the problem. We will not use a fact but post a fact as port of the query to start the forward chaining engine:

:- use_module(library(minimal/delta)).
:- thread_local s/0, q/0, r/0, p/0.
:- forward s/1.

post(r) <= posted(p).
post(q) <= posted(p).
post(s) <= posted(q), posted(r).
?- post(p), s.
Yes

When we run the forward chaining query in our default debugger, we get the following trace. We have also again depicted the dependency graph among the facts, rules and query. The numbering in the dependency graph now shows the order of the Byrd Box for the calls of the forward chaining instruction post/1 during tracing.

?- trace.
Yes
?- post(p), s.
0 Call post(p) ?
1 Call post(r) ?
2 Call q ?
2 Fail q ?
1 Exit post(r) ?
1 Call post(q) ?
2 Call r ?
2 Exit r ?
2 Call post(s) ?
2 Exit post(s) ?
1 Exit post(q) ?
0 Exit post(p) ?
0 Call s ?
0 Exit s ?

Since the dependency shows sub-goals and therefore facts further down, the tracing happens this time in a bottom-up fashion. Otherwise, default debugger offers the same debugging as for ordinary backward chaining. It is possible to set spy points or break points and it is possible to have different debug modes.

Comments