I have been reading up about inference in Prolog/Datalog and while forward chaining seems fairly simple to grasp, I have some issues with backward chaining with any sort of complex example which isn't simply propositional or used to determine a true or false value. I was reading an article the following example was given:
sg(X,X) sg(X,Y) :- par(X, X1), par(Y,Y1), sg(X1,Y1)
Suppose we were to query
a is a constant and
W is a variable. This could be read as saying:
Give me all those who are in the same generation as
The article firstly states that these particular rules will result in an infinite loop in Prolog/Datalog, but can be fixed by changing the second rule to:
sg(X,Y) :- par(X, X1), sg(X1,Y1), par(Y,Y1).
Why would the original result in a loop? Secondly, what would the execution of this kind of query look like? When do values get bound to these variables?