CPSC352 -- Artificial Intelligence -- Fall 2011
Homework -- Part I Due Friday, October 30
Part II Due Wednesday, October 5

Reading

Read section 15.1-15.2 in Chapter 15 of Luger.

Part I: A Simple Family Database.

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.

parent_of(X,Y).
male(X).
female(Y).
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(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.

Part II: A List-based Version of the Family Database

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

Running PROLOG on the Unix System

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.

Running PROLOG on a Windows Systems

If you prefer to use a Windows PC, you should download a copy of a Prolog Interpreter for Windows Computers. To run this interpreter, just type bp_w95c at the DOS prompt. To load a program into the interpreter, type compile('filename'). (including the period) at the PROLOG interpreter's prompt.

Handin Directions