?- father_child(paul,Z2),mother_child(Z2,peter). ?- father_child(paul,Z1),father_child(Z1,peter). When we now query: ?- grandfather_grandchild(paul,peter).įollowing proof tree visualises the depth-first search process: ?- grandfather_grandchild(paul,peter). Branches only become leafs when either true/false was proven for the required (set of) goal(s) and search in Prolog is performed in a left-to-right depth-first fashion.įather_child(paul,chris). Every node in the tree thus represents a goal. Using this rule, Prolog resolves the query successor(X, Y) roughly as follows: For each Z who is a son of X: Bind Y to Z, giving Z as a solution. This version gives the result you're looking for: successor(X, Y) :- son(X, Z), (Y Z successor(Z, Y)). The root of the tree represents the initial query and branches are created when choice points occur. Instead, you want to do a depth-first traversal of the royal family tree. This tree helps visualise the chronological backtracking process present in Prolog. The proof tree (also search tree or derivation tree) is a tree that shows the execution of a Prolog program.
0 Comments
Leave a Reply. |