% cat female Female ------ michele beth % cat male kirk rod % cat parent Parent Child ------ ----- michele rod kirk rod % cat isa Name Isa ---- --- rod human human mammal mammal animal animal lifeform % tabletofact female male parent isa > fact % cat fact female(michele). female(beth). male(kirk). male(rod). parent(michele,rod). parent(kirk,rod). isa(rod,human). isa(human,mammal). isa(mammal,animal). isa(animal,lifeform). % cat ruletable True If ---- -- mother(X,Y) female(X) , parent(X,Y) father(X,Y) male(X) , parent(X,Y) son(X,Y) male(X) , parent(Y,X) isa(X,Y) isa(X,Z) , isa(Z,Y) % tabletorule ruletable > rule % cat rule mother(X,Y) :- female(X) , parent(X,Y). father(X,Y) :- male(X) , parent(X,Y). son(X,Y) :- male(X) , parent(Y,X). isa(X,Y) :- isa(X,Z) , isa(Z,Y)With this database of facts and rules, you can ask Prolog questions about motherhood and fatherhood, as well as questions like is rod a lifeform? Prolog will answer yes, showing the limits of this approach. Prolog uses depth-first searching which requires it to backtrack. searchtree is a breadth-first goal-oriented search without memory limitations that finds all of the children at each level of a tree.% prolog consult ("fact"). yes consult ("rule"). yes
% [ searchtree isa rod lifeform Name Isa ] && echo yes yes