/* File: ancestors.pl Author: Dave Robertson Purpose: Relationships in a family tree Suppose we have a family tree like this : alan andrea bruce betty eddie elsie fred freda | | | | | | | | |_____| |_____| |_____| |_____| | | | | clive clarissa greg greta | |__________|___| | | |__________|__| |_____________| | | | dave doris henry which is defined in Prolog by the following 3 sets of predicates: */ % parent(Parent, Child). % Parent is the parent of Child. parent(alan, clive). parent(andrea, clive). parent(bruce, clarissa). parent(betty, clarissa). parent(clive, dave). parent(clarissa, dave). parent(clive, doris). parent(clarissa, doris). parent(eddie, greg). parent(elsie, greg). parent(fred, greta). parent(freda, greta). parent(greg, henry). parent(greta, henry). % male(Person). % This Person is male. male(alan). male(bruce). male(clive). male(dave). male(eddie). male(fred). male(greg). male(henry). % female(Person). % This Person is female. female(andrea). female(betty). female(clarissa). female(doris). female(elsie). female(freda). female(greta). % married(Person1, Person2). % Person1 is married to Person2. married(alan, andrea). married(bruce, betty). married(clive, clarissa). married(eddie, elsie). married(fred, freda). married(greg, greta). % PROBLEM 1 % How do you find out if someone is the ancestor of someone else ? % PROBLEM 2 % How do you find out if someone is the descendant of someone else ? % PROBLEM 3 % How do you know if someone is related to someone else ? % PROBLEM 4 % How can you decide whether two people could possibly marry, given that % only an unrelated male and female are allowed to do this ? % PROBLEM 5 % How can you decide whether two people can marry, given the current % matrimonial ties ? % FOOTNOTE % The symbol \== means "not the same as" (e.g. foo \== baz is true). % The symbol \+ means "not provable" (e.g. \+ false is always true). % The symbol _ represents an "anonymous variable" (i.e. a variable % for which there is no need for a particular name). % Comments are on lines beginning with % % or in sections bounded by /* and */