LovelyHandle
Programmer
Hi, I'm trying to teach myself prolog, and have been using learnprolognow.org guide as it seems to be the best available free guide (and my other programming addictions are already expensive enough). Now, it was going fine, until I reached section 3.1.4. and got to this knowledge base:
By tracing it I can understand -what- its doing, using the recursive rule to progressively strip X down to 0, equating Z to Y by the first fact, then going back through all the temporary variables created for Z adding the layers of succ(). And I can somewhat understand how this method could be figured out from the given knowledge, but for the life of me I can't understand how prolog figured it out. Can someone give me some clues as to what prolog's "thought process" was?
Code:
add(0,Y,Y).
add(succ(X),Y,succ(Z)) :-
add(X,Y,Z).
By tracing it I can understand -what- its doing, using the recursive rule to progressively strip X down to 0, equating Z to Y by the first fact, then going back through all the temporary variables created for Z adding the layers of succ(). And I can somewhat understand how this method could be figured out from the given knowledge, but for the life of me I can't understand how prolog figured it out. Can someone give me some clues as to what prolog's "thought process" was?