Can an incrementally tabled predicate depend on itself?

Hi everyone,

Suppose I have the following predicate definitions:

[1] p(X,Y):- p(X,Z), r(Z,Y). 
[2] p(X,Y):- r(X,Y).
[3] r(a,b). 
[4] r(b,c). 

Now, I would like to do the following:
a) Retract clause [1] and call the goal p(a,c).
b) If p(a,c) succeeds, re-assert clause [1].
c) Retract clause [2] and call the goal p(a,c).
d) If p(a,c) succeeds, re-assert clause [2].

The purpose is to find out which clauses of p/2 do not entail p(a,c).

My problem is that p/2 is left-recursive and because of the ordering of its
clauses will not terminate. If I table p/2, it will terminate, but then
everytime I call p(a,c) after retracting a clause I will just get the result
that was stored in a table in the first call to p(a,c). So every single call
will succeed- even the ones that depend on clauses removed from the database.

What can I do? I think that what I would like is to update the table for p/2
everytime I call p(a,c), so the query only succeeds if the current definition
(i.e. the clauses remaining in the database) of p/2 entails p(a,c). Is something
like that possible?

Ah, never mind. I figured it out- I can declare p/2 itself as dynamic and incremental.

...
table(p/2 as incremental)
,(dynamic([p/2], [incremental(true)]))
...

This seemed to do the trick for me anyway.

I’ll leave this here in case anyone else needs it :slight_smile: