Write a PROLOG program that implements a family database for your family. Save it as an ordinary text file named family.pro.
Your program should implement the following facts for your immediate family, grandparents, and great-grandparents.
That is, your database should consist of a number of facts about who is the parent_of of whom, about which individuals are male and about which individuals are female. For example:parent_of(X,Y). male(X). female(Y).
parent_of(joe,susie). parent_of(joe,dan). parent_of(mary,susie). parent_of(mary,dan). male(dan). male(joe). female(susie). female(mary).
All other predicates should be implemented as rules -- i.e., as predicates involving variables and logical implication (:-). For example, the rules for father_of and daughter_of would be:
father_of(X,Y) :- parent_of(X,Y),male(X). daughter_of(X,Y) :- parent_of(Y,X),female(X).
Define the following predicates for your database. Your database should be rich enough to test all of these predicates. For example, if you are only child, you may have to make up fictitious siblings to test the sibling_of predicate.
predicate interpretation --------- -------------- father_of(X,Y) X is the father of Y mother_of(X,Y) X is the mother of Y son_of(X,Y) X is the son of Y daughter_of(X,Y) X is the daughter of Y sibling_of(X,Y) X is the sibling of Y brother_of(X,Y) X is the brother of Y sister_of(X,Y) X is the sister of Y grandparent_of(X,Y) X is the grandparent of Y ancestor_of(X,Y) X is the ancestor of Y Challenge: Recursive definition
Some of these predicates may be defined in terms of other predicates. For example, a sister is a female sibling and a grandparent is the parent of a parent. The ancestor_of predicate can be defined recursively to handle ancestors from any generation.
Rewrite your family database, but this time use PROLOG's lists ([H|T]) to represent the basic facts of your family. Save it as an ordinary text file named familylists.pro.
Your program should implement the following facts for your immediate family, grandparents, and great-grandparents.
family([mom,dad],[[daughter1, daughter2],[son1,son2]]).
In other words, each "nuclear" family is comprised of two lists: family(ParentList, ChildrenList). The ParentList is formatted with the name of the mother, followed by the name of the father. The ChildrenList consists of two sublists, the first giving the names of the daughters, in chronological order, and the second giving the names of the sons, in chronological order.
All other predicates should be defined in terms of the above facts. For example, consider the following definitions:
father_of(D,C) :- family([_,D],[Ds,Ss]), (member(C,Ds); member(C,Ss)). parent_of(P,C) :- father_of(P,C). parent_of(P,C) :- mother_of(P,C). male(M) :- family([_,M],_). male(M) :- family(_,[_,Ss]), member(M,Ss). member(M,[M|_]). % base case member(M,[H|T] :- member(M,T). % recursive case
Define the following predicates for your database:
predicate interpretation --------- -------------- father_of(X,Y) X is the father of Y mother_of(X,Y) X is the mother of Y son_of(X,Y) X is the son of Y daughter_of(X,Y) X is the daughter of Y sibling_of(X,Y) X is the sibling of Y brother_of(X,Y) X is the brother of Y sister_of(X,Y) X is the sister of Y grandparent_of(X,Y) X is the grandparent of Y ancestor_of(X,Y) X is the ancestor of Y oldest_son(S,P) S is the oldest son of P oldest_daughter(D,P) D is the oldest daughter of P
To test and debug your program, follow the directions in the Guide to Using PROLOG. This provides a guide to using PROLOG on Trinity's Unix system.
All members of class should have an account on this system. Your account should consist of the first letter of your first name plus the first seven characters of your last name. For example, if your name is John McCarthy, your account name would be jmccarth. Your password should be the same as your Trinity mail password.
To make a copy of your PROLOG sessions, you use the Unix script command:
$ script sfilename // a copy of your session will be saved bash$ prolog // script changes the unix prompt ?- // Do your PROLOG thing. ?- ... ?- ^D // exit PROLOG bash$ ^D // control-D exits from script Script done. File is sfilename. $lpr sfilename // print your script and annotate it
If you are using a Windows PC, there is a similar command to the Unix script command.