Understanding tabling in Prolog

Hello,

Consider the following example of tabling.

:- table reasoner_1/1, reasoner_2/1.

reasoner_1(Goal):- reasoner_2(Goal).
reasoner_1(a).
	
reasoner_2(Goal):- \+reasoner_1(Goal).
reasoner_2(b).

Notice negation in the body of the second rule. Now I query:

?- reasoner_2(a).
true.

?- reasoner_1(a).
true.

How can reasoner_2(a) be true? Which rule fired?

Thanks in advance.

Try using tnot/1 tabled negation instead of \+/1.

2 Likes

Eventually Iā€™d like to see \+/1 act as tnot/1 when the argument is a goal running a tabled predicate. Still not sure how though. A runtime mapping may slow down \+/1 a lot. Program rewriting cannot deal with dynamic or later declaration as a tabled predicate.

1 Like