% file: ancestor.pro % author: Robert Keller % purpose: Logic rules for ancestry % Here a graph is represented as a list of ordered pairs % of the form [Parent, Child] % One rule for a Parent having a Child child(Parent, Child, Graph) :- member([Parent, Child], Graph). % Two rules for an Ancestor having a Descendant % A child is a descendant. isDescendant(Ancestor, Desc, Graph) :- child(Ancestor, Desc, Graph). % A descendant of a child is a descendant isDescendant(Ancestor, Desc, Graph) :- child(Ancestor, Child, Graph), isDescendant(Child, Desc, Graph). test :- isDescendant(e, a, [[a,b], [b, c], [c,d], [b,e], [a,f]]).