Here is the reason for this non-termination. Your query does not terminate, because there is a failure-slice of your program that does not terminate:
?- frack(4).
frack(3) :- false.
frack(X) :-
frack(X-1), false.
You can fix this only by modifying something in the visible part. Three SO-answers suggest to use (is)/2
. But this will not remove non-termination! In fact, using (is)/2
leads to essentially the same fragment:
?- frack(4).
frack(3) :- false.
frack(X) :-
Y is X - 1,
frack(Y), false.
At least, frack(4)
now succeeds, but it will loop on backtracking. You have to change something in the visible part, like some test for X
, in order to avoid non-termination. See failure-slice for more.