I'm following a Prolog book and currently trying the following example. My facts are;
parent(tom, bob).
parent(pam, bob).
parent(tom, liz).
parent(bob, ann).
parent(bob, pat).
parent(pat, jim).
I queried Prolog as:
?- parent(X, Y).
Results were;
X = tom,
Y = bob ;
X = pam,
Y = bob ;
X = tom,
Y = liz ;
X = bob,
Y = ann ;
X = bob,
Y = pat ;
X = pat,
Y = jim
Why Prolog doesn't show 'false' at the end to show that there aren't anymore possible results?
Moreover, I tried following query. But it gave me different result which was unexpected, gives extra 'false'. Can you tell me what is the reason for that?
?- parent(Y,jim), parent(X,Y).
Y = pat,
X = bob.
?- parent(X,Y), parent(Y,jim).
X = bob,
Y = pat ;
false.
I'm using SWI-Prolog version (threaded, 64 bits, version 8.2.4).
SLD resolution, the Prolog's proof procedure, implicitly defines a search tree of alternative computations.
Prolog searches this tree using a depth-first strategy, one branch at a time, backtracking when it encounters a failure node.
SWI-Prolog prints
false
only when the last node visited during the search is a failure node.Considering the program:
The search trees are: