Consider the following logic program:
p(b) :- p(b).
p(X) :- r(b).
p(a) :- p(a).
r(Y).
For what terms t does the evaluation of the goal p(t) terminate and which does it not?
Consider the following logic program:
p(b) :- p(b).
p(X) :- r(b).
p(a) :- p(a).
r(Y).
For what terms t does the evaluation of the goal p(t) terminate and which does it not?
What you want is to determine all the queries that do not terminate. And I assume you mean terminate universally. That is, we are not only looking at the first answer, but we look at all of them.
There is a very quick answer to this, provided your program is pure, monotonic: Simply take the most general query. That is, if there is any possibility for any term
T
to makep(T)
not terminating, thenp(X)
will be non-terminating too.If we want to known more, we have to look closer. With a failure-slice we may narrow down actual reasons for non-termination. By inserting goals
false
into your program, we are reducing the number of inferences that are possible for a query. But if the remaining program still permits infinitely many inferences, we have found a loop. In this case:Is one minimal failure-slice. That is,
p(a)
will not terminate. Beware, however, that simply queryingp(a)
(in your original program) will succeed, you need to insist to look at further answers:To save you the labor of asking for further answers, simply use
p(a), false
instead.There is another minimal failure-slice:
See failure-slice for more examples.